Skip to main content

reth_transaction_pool/
lib.rs

1//! Reth's transaction pool implementation.
2//!
3//! This crate provides a generic transaction pool implementation.
4//!
5//! ## Functionality
6//!
7//! The transaction pool is responsible for
8//!
9//!    - recording incoming transactions
10//!    - providing existing transactions
11//!    - ordering and providing the best transactions for block production
12//!    - monitoring memory footprint and enforce pool size limits
13//!    - storing blob data for transactions in a separate blobstore on insertion
14//!
15//! ## Transaction Flow: From Network/RPC to Pool
16//!
17//! Transactions enter the pool through two main paths:
18//!
19//! ### 1. Network Path (P2P)
20//!
21//! ```text
22//! Network Peer
23//!     ↓
24//! Transactions or NewPooledTransactionHashes message
25//!     ↓
26//! TransactionsManager (crates/net/network/src/transactions/mod.rs)
27//!     │
28//!     ├─→ For Transactions message:
29//!     │   ├─→ Validates message format
30//!     │   ├─→ Checks if transaction already known
31//!     │   ├─→ Marks peer as having seen the transaction
32//!     │   └─→ Queues for import
33//!     │
34//!     └─→ For NewPooledTransactionHashes message:
35//!         ├─→ Filters out already known transactions
36//!         ├─→ Queues unknown hashes for fetching
37//!         ├─→ Sends GetPooledTransactions request
38//!         ├─→ Receives PooledTransactions response
39//!         └─→ Queues fetched transactions for import
40//!             ↓
41//! pool.add_external_transactions() [Origin: External]
42//!     ↓
43//! Transaction Validation & Pool Addition
44//! ```
45//!
46//! ### 2. RPC Path (Local submission)
47//!
48//! ```text
49//! eth_sendRawTransaction RPC call
50//!     ├─→ Decodes raw bytes
51//!     └─→ Recovers sender
52//!         ↓
53//! pool.add_transaction() [Origin: Local]
54//!     ↓
55//! Transaction Validation & Pool Addition
56//! ```
57//!
58//! ### Transaction Origins
59//!
60//! - **Local**: Transactions submitted via RPC (trusted, may have different fee requirements)
61//! - **External**: Transactions from network peers (untrusted, subject to stricter validation)
62//! - **Private**: Local transactions that should not be propagated to the network
63//!
64//! ## Validation Process
65//!
66//! ### Stateless Checks
67//!
68//! Ethereum transactions undergo several stateless checks:
69//!
70//! - **Transaction Type**: Fork-dependent support (Legacy always, EIP-2930/1559/4844/7702 need
71//!   activation)
72//! - **Size**: Input data ≤ 128KB (default)
73//! - **Gas**: Limit ≤ block gas limit
74//! - **Fees**: Priority fee ≤ max fee; local tx fee cap; external minimum priority fee
75//! - **Chain ID**: Must match current chain
76//! - **Intrinsic Gas**: Sufficient for data and access lists
77//! - **Blobs** (EIP-4844): Valid count, KZG proofs
78//!
79//! ### Stateful Checks
80//!
81//! 1. **Sender**: No bytecode (unless EIP-7702 delegated in Prague)
82//! 2. **Nonce**: ≥ account nonce
83//! 3. **Balance**: Covers value + (`gas_limit` × `max_fee_per_gas`)
84//!
85//! ### Common Errors
86//!
87//! - [`NonceNotConsistent`](reth_primitives_traits::transaction::error::InvalidTransactionError::NonceNotConsistent): Nonce too low
88//! - [`InsufficientFunds`](reth_primitives_traits::transaction::error::InvalidTransactionError::InsufficientFunds): Insufficient balance
89//! - [`ExceedsGasLimit`](crate::error::InvalidPoolTransactionError::ExceedsGasLimit): Gas limit too
90//!   high
91//! - [`SignerAccountHasBytecode`](reth_primitives_traits::transaction::error::InvalidTransactionError::SignerAccountHasBytecode): EOA has code
92//! - [`Underpriced`](crate::error::InvalidPoolTransactionError::Underpriced): Fee too low
93//! - [`ReplacementUnderpriced`](crate::error::PoolErrorKind::ReplacementUnderpriced): Replacement
94//!   transaction fee too low
95//! - Blob errors:
96//!   - [`MissingEip4844BlobSidecar`](crate::error::Eip4844PoolTransactionError::MissingEip4844BlobSidecar): Missing sidecar
97//!   - [`InvalidEip4844Blob`](crate::error::Eip4844PoolTransactionError::InvalidEip4844Blob):
98//!     Invalid blob proofs
99//!   - [`NoEip4844Blobs`](crate::error::Eip4844PoolTransactionError::NoEip4844Blobs): EIP-4844
100//!     transaction without blobs
101//!   - [`TooManyEip4844Blobs`](crate::error::Eip4844PoolTransactionError::TooManyEip4844Blobs): Too
102//!     many blobs
103//!
104//! ## Subpool Design
105//!
106//! The pool maintains four distinct subpools, each serving a specific purpose
107//!
108//! ### Subpools
109//!
110//! 1. **Pending**: Ready for inclusion (no gaps, sufficient balance/fees)
111//! 2. **Queued**: Future transactions (nonce gaps or insufficient balance)
112//! 3. **`BaseFee`**: Valid but below current base fee
113//! 4. **Blob**: EIP-4844 transactions not pending due to insufficient base fee or blob fee
114//!
115//! ### State Transitions
116//!
117//! Transactions move between subpools based on state changes:
118//!
119//! ```text
120//! Queued ─────────→ BaseFee/Blob ────────→ Pending
121//!   ↑                      ↑                       │
122//!   │                      │                       │
123//!   └────────────────────┴─────────────────────┘
124//!         (demotions due to state changes)
125//! ```
126//!
127//! **Promotions**: Nonce gaps filled, balance/fee improvements
128//! **Demotions**: Nonce gaps created, balance/fee degradation
129//!
130//! ## Pool Maintenance
131//!
132//! 1. **Block Updates**: Removes mined txs, updates accounts/fees, triggers movements
133//! 2. **Size Enforcement**: Discards worst transactions when limits exceeded
134//! 3. **Propagation**: External (always), Local (configurable), Private (never)
135//!
136//! ## Assumptions
137//!
138//! ### Transaction type
139//!
140//! The pool expects certain ethereum related information from the generic transaction type of the
141//! pool ([`PoolTransaction`]), this includes gas price, base fee (EIP-1559 transactions), nonce
142//! etc. It makes no assumptions about the encoding format, but the transaction type must report its
143//! size so pool size limits (memory) can be enforced.
144//!
145//! ### Transaction ordering
146//!
147//! The pending pool contains transactions that can be mined on the current state.
148//! The order in which they're returned are determined by a `Priority` value returned by the
149//! `TransactionOrdering` type this pool is configured with.
150//!
151//! This is only used in the _pending_ pool to yield the best transactions for block production. The
152//! _base pool_ is ordered by base fee, and the _queued pool_ by current distance.
153//!
154//! ### Validation
155//!
156//! The pool itself does not validate incoming transactions, instead this should be provided by
157//! implementing `TransactionsValidator`. Only transactions that the validator returns as valid are
158//! included in the pool. It is assumed that transaction that are in the pool are either valid on
159//! the current state or could become valid after certain state changes. Transactions that can never
160//! become valid (e.g. nonce lower than current on chain nonce) will never be added to the pool and
161//! instead are discarded right away.
162//!
163//! ### State Changes
164//!
165//! New blocks trigger pool updates via changesets (see Pool Maintenance).
166//!
167//! ## Implementation details
168//!
169//! The `TransactionPool` trait exposes all externally used functionality of the pool, such as
170//! inserting, querying specific transactions by hash or retrieving the best transactions.
171//! In addition, it enables the registration of event listeners that are notified of state changes.
172//! Events are communicated via channels.
173//!
174//! ### Architecture
175//!
176//! The final `TransactionPool` is made up of two layers:
177//!
178//! The lowest layer is the actual pool implementations that manages (validated) transactions:
179//! [`TxPool`](crate::pool::txpool::TxPool). This is contained in a higher level pool type that
180//! guards the low level pool and handles additional listeners or metrics: [`PoolInner`].
181//!
182//! The transaction pool will be used by separate consumers (RPC, P2P), to make sharing easier, the
183//! [`Pool`] type is just an `Arc` wrapper around `PoolInner`. This is the usable type that provides
184//! the `TransactionPool` interface.
185//!
186//!
187//! ## Blob Transactions
188//!
189//! Blob transaction can be quite large hence they are stored in a separate blobstore. The pool is
190//! responsible for inserting blob data for new transactions into the blobstore.
191//! See also [`ValidTransaction`](validate::ValidTransaction)
192//!
193//!
194//! ## Examples
195//!
196//! Listen for new transactions and print them:
197//!
198//! ```
199//! use reth_chainspec::MAINNET;
200//! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory};
201//! use reth_tasks::Runtime;
202//! use reth_chainspec::ChainSpecProvider;
203//! use reth_transaction_pool::{TransactionValidationTaskExecutor, Pool, TransactionPool};
204//! use reth_transaction_pool::blobstore::InMemoryBlobStore;
205//! use reth_chainspec::EthereumHardforks;
206//! use reth_evm::ConfigureEvm;
207//! use alloy_consensus::Header;
208//! async fn t<C, Evm>(client: C, evm_config: Evm)
209//! where
210//!     C: ChainSpecProvider<ChainSpec: EthereumHardforks> + StateProviderFactory + BlockReaderIdExt<Header = Header> + Clone + 'static,
211//!     Evm: ConfigureEvm<Primitives: reth_primitives_traits::NodePrimitives<BlockHeader = Header>> + 'static,
212//! {
213//!     let blob_store = InMemoryBlobStore::default();
214//!     let runtime = Runtime::test();
215//!     let pool = Pool::eth_pool(
216//!         TransactionValidationTaskExecutor::eth(client, evm_config, blob_store.clone(), runtime),
217//!         blob_store,
218//!         Default::default(),
219//!     );
220//!   let mut transactions = pool.pending_transactions_listener();
221//!   tokio::task::spawn( async move {
222//!      while let Some(tx) = transactions.recv().await {
223//!          println!("New transaction: {:?}", tx);
224//!      }
225//!   });
226//!
227//!   // do something useful with the pool, like RPC integration
228//!
229//! # }
230//! ```
231//!
232//! Spawn maintenance task to keep the pool updated
233//!
234//! ```
235//! use futures_util::Stream;
236//! use reth_chain_state::CanonStateNotification;
237//! use reth_chainspec::{MAINNET, ChainSpecProvider, ChainSpec};
238//! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory};
239//! use reth_tasks::Runtime;
240//! use reth_transaction_pool::{TransactionValidationTaskExecutor, Pool};
241//! use reth_transaction_pool::blobstore::InMemoryBlobStore;
242//! use reth_transaction_pool::maintain::{maintain_transaction_pool_future};
243//! use reth_evm::ConfigureEvm;
244//! use reth_ethereum_primitives::EthPrimitives;
245//! use alloy_consensus::Header;
246//!
247//!  async fn t<C, St, Evm>(client: C, stream: St, evm_config: Evm)
248//!    where C: StateProviderFactory + BlockReaderIdExt<Header = Header> + ChainSpecProvider<ChainSpec = ChainSpec> + Clone + 'static,
249//!     St: Stream<Item = CanonStateNotification<EthPrimitives>> + Send + Unpin + 'static,
250//!     Evm: ConfigureEvm<Primitives = EthPrimitives> + 'static,
251//!     {
252//!     let blob_store = InMemoryBlobStore::default();
253//!     let runtime = Runtime::test();
254//!     let pool = Pool::eth_pool(
255//!         TransactionValidationTaskExecutor::eth(client.clone(), evm_config, blob_store.clone(), runtime.clone()),
256//!         blob_store,
257//!         Default::default(),
258//!     );
259//!
260//!   // spawn a task that listens for new blocks and updates the pool's transactions, mined transactions etc..
261//!   tokio::task::spawn(maintain_transaction_pool_future(client, pool, stream, runtime.clone(), Default::default()));
262//!
263//! # }
264//! ```
265//!
266//! ## Feature Flags
267//!
268//! - `serde` (default): Enable serde support
269//! - `test-utils`: Export utilities for testing
270
271#![doc(
272    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
273    html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
274    issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
275)]
276#![cfg_attr(docsrs, feature(doc_cfg))]
277#![cfg_attr(not(test), warn(unused_crate_dependencies))]
278
279pub use crate::{
280    batcher::{BatchTxProcessor, BatchTxRequest},
281    blobstore::{BlobStore, BlobStoreError},
282    config::{
283        LocalTransactionConfig, PoolConfig, PriceBumpConfig, SubPoolLimit,
284        DEFAULT_MAX_INFLIGHT_DELEGATED_SLOTS, DEFAULT_PRICE_BUMP,
285        DEFAULT_TXPOOL_ADDITIONAL_VALIDATION_TASKS, MAX_NEW_PENDING_TXS_NOTIFICATIONS,
286        REPLACE_BLOB_PRICE_BUMP, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
287        TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
288    },
289    error::PoolResult,
290    ordering::{CoinbaseTipOrdering, Priority, TransactionOrdering},
291    pool::{
292        blob_tx_priority, fee_delta, state::SubPool, AddedTransactionOutcome,
293        AllTransactionsEvents, FullTransactionEvent, NewTransactionEvent, TransactionEvent,
294        TransactionEvents, TransactionListenerKind,
295    },
296    traits::*,
297    validate::{
298        EthTransactionValidator, TransactionValidationOutcome, TransactionValidationTaskExecutor,
299        TransactionValidator, ValidPoolTransaction,
300    },
301};
302use crate::{identifier::TransactionId, pool::PoolInner};
303use alloy_eips::{
304    eip4844::{BlobAndProofV1, BlobAndProofV2},
305    eip7594::BlobTransactionSidecarVariant,
306};
307use alloy_primitives::{map::AddressSet, Address, TxHash, B256, U256};
308use aquamarine as _;
309use reth_chainspec::{ChainSpecProvider, EthereumHardforks};
310use reth_eth_wire_types::HandleMempoolData;
311use reth_evm::ConfigureEvm;
312use reth_evm_ethereum::EthEvmConfig;
313use reth_execution_types::ChangedAccount;
314use reth_primitives_traits::{HeaderTy, Recovered};
315use reth_storage_api::{BlockReaderIdExt, StateProviderFactory};
316use std::sync::Arc;
317use tokio::sync::mpsc::Receiver;
318use tracing::{instrument, trace};
319
320pub mod error;
321pub mod maintain;
322pub mod metrics;
323pub mod noop;
324pub mod pool;
325pub mod validate;
326
327pub mod batcher;
328pub mod blobstore;
329mod config;
330pub mod identifier;
331mod ordering;
332mod traits;
333
334#[cfg(any(test, feature = "test-utils"))]
335/// Common test helpers for mocking a pool
336pub mod test_utils;
337
338/// Type alias for default ethereum transaction pool
339pub type EthTransactionPool<Client, S, Evm = EthEvmConfig, T = EthPooledTransaction> = Pool<
340    TransactionValidationTaskExecutor<EthTransactionValidator<Client, T, Evm>>,
341    CoinbaseTipOrdering<T>,
342    S,
343>;
344
345/// A shareable, generic, customizable `TransactionPool` implementation.
346#[derive(Debug)]
347pub struct Pool<V, T: TransactionOrdering, S> {
348    /// Arc'ed instance of the pool internals
349    pool: Arc<PoolInner<V, T, S>>,
350}
351
352// === impl Pool ===
353
354impl<V, T, S> Pool<V, T, S>
355where
356    V: TransactionValidator,
357    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
358    S: BlobStore,
359{
360    /// Create a new transaction pool instance.
361    pub fn new(validator: V, ordering: T, blob_store: S, config: PoolConfig) -> Self {
362        Self { pool: Arc::new(PoolInner::new(validator, ordering, blob_store, config)) }
363    }
364
365    /// Returns the wrapped pool internals.
366    pub fn inner(&self) -> &PoolInner<V, T, S> {
367        &self.pool
368    }
369
370    /// Get the config the pool was configured with.
371    pub fn config(&self) -> &PoolConfig {
372        self.inner().config()
373    }
374
375    /// Get the validator reference.
376    pub fn validator(&self) -> &V {
377        self.inner().validator()
378    }
379
380    /// Validates the given transaction
381    async fn validate(
382        &self,
383        origin: TransactionOrigin,
384        transaction: V::Transaction,
385    ) -> TransactionValidationOutcome<V::Transaction> {
386        self.pool.validator().validate_transaction(origin, transaction).await
387    }
388
389    /// Number of transactions in the entire pool
390    pub fn len(&self) -> usize {
391        self.pool.len()
392    }
393
394    /// Whether the pool is empty
395    pub fn is_empty(&self) -> bool {
396        self.pool.is_empty()
397    }
398
399    /// Returns whether or not the pool is over its configured size and transaction count limits.
400    pub fn is_exceeded(&self) -> bool {
401        self.pool.is_exceeded()
402    }
403
404    /// Returns the configured blob store.
405    pub fn blob_store(&self) -> &S {
406        self.pool.blob_store()
407    }
408}
409
410impl<Client, S, Evm> EthTransactionPool<Client, S, Evm>
411where
412    Client: ChainSpecProvider<ChainSpec: EthereumHardforks>
413        + StateProviderFactory
414        + Clone
415        + BlockReaderIdExt<Header = HeaderTy<Evm::Primitives>>
416        + 'static,
417    S: BlobStore,
418    Evm: ConfigureEvm + 'static,
419{
420    /// Returns a new [`Pool`] that uses the default [`TransactionValidationTaskExecutor`] when
421    /// validating [`EthPooledTransaction`]s and ords via [`CoinbaseTipOrdering`]
422    ///
423    /// # Example
424    ///
425    /// ```
426    /// use reth_chainspec::MAINNET;
427    /// use reth_storage_api::{BlockReaderIdExt, StateProviderFactory};
428    /// use reth_tasks::Runtime;
429    /// use reth_chainspec::ChainSpecProvider;
430    /// use reth_transaction_pool::{
431    ///     blobstore::InMemoryBlobStore, Pool, TransactionValidationTaskExecutor,
432    /// };
433    /// use reth_chainspec::EthereumHardforks;
434    /// use reth_evm::ConfigureEvm;
435    /// use alloy_consensus::Header;
436    /// # fn t<C, Evm>(client: C, evm_config: Evm, runtime: Runtime)
437    /// # where
438    /// #     C: ChainSpecProvider<ChainSpec: EthereumHardforks> + StateProviderFactory + BlockReaderIdExt<Header = Header> + Clone + 'static,
439    /// #     Evm: ConfigureEvm<Primitives: reth_primitives_traits::NodePrimitives<BlockHeader = Header>> + 'static,
440    /// # {
441    /// let blob_store = InMemoryBlobStore::default();
442    /// let pool = Pool::eth_pool(
443    ///     TransactionValidationTaskExecutor::eth(
444    ///         client,
445    ///         evm_config,
446    ///         blob_store.clone(),
447    ///         runtime,
448    ///     ),
449    ///     blob_store,
450    ///     Default::default(),
451    /// );
452    /// # }
453    /// ```
454    pub fn eth_pool(
455        validator: TransactionValidationTaskExecutor<
456            EthTransactionValidator<Client, EthPooledTransaction, Evm>,
457        >,
458        blob_store: S,
459        config: PoolConfig,
460    ) -> Self {
461        Self::new(validator, CoinbaseTipOrdering::default(), blob_store, config)
462    }
463}
464
465/// implements the `TransactionPool` interface for various transaction pool API consumers.
466impl<V, T, S> TransactionPool for Pool<V, T, S>
467where
468    V: TransactionValidator,
469    <V as TransactionValidator>::Transaction: EthPoolTransaction,
470    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
471    S: BlobStore,
472{
473    type Transaction = T::Transaction;
474
475    fn pool_size(&self) -> PoolSize {
476        self.pool.size()
477    }
478
479    fn block_info(&self) -> BlockInfo {
480        self.pool.block_info()
481    }
482
483    async fn add_transaction_and_subscribe(
484        &self,
485        origin: TransactionOrigin,
486        transaction: Self::Transaction,
487    ) -> PoolResult<TransactionEvents> {
488        let tx = self.validate(origin, transaction).await;
489        self.pool.add_transaction_and_subscribe(origin, tx)
490    }
491
492    async fn add_transaction(
493        &self,
494        origin: TransactionOrigin,
495        transaction: Self::Transaction,
496    ) -> PoolResult<AddedTransactionOutcome> {
497        let tx = self.validate(origin, transaction).await;
498        let mut results = self.pool.add_transactions(origin, std::iter::once(tx));
499        results.pop().expect("result length is the same as the input")
500    }
501
502    async fn add_transactions(
503        &self,
504        origin: TransactionOrigin,
505        transactions: Vec<Self::Transaction>,
506    ) -> Vec<PoolResult<AddedTransactionOutcome>> {
507        if transactions.is_empty() {
508            return Vec::new()
509        }
510        let validated = self
511            .pool
512            .validator()
513            .validate_transactions(transactions.into_iter().map(|tx| (origin, tx)))
514            .await;
515        self.pool.add_transactions(origin, validated)
516    }
517
518    async fn add_transactions_with_origins(
519        &self,
520        transactions: Vec<(TransactionOrigin, Self::Transaction)>,
521    ) -> Vec<PoolResult<AddedTransactionOutcome>> {
522        if transactions.is_empty() {
523            return Vec::new()
524        }
525        let origins: Vec<_> = transactions.iter().map(|(origin, _)| *origin).collect();
526        let validated = self.pool.validator().validate_transactions(transactions).await;
527        self.pool.add_transactions_with_origins(origins.into_iter().zip(validated))
528    }
529
530    fn transaction_event_listener(&self, tx_hash: TxHash) -> Option<TransactionEvents> {
531        self.pool.add_transaction_event_listener(tx_hash)
532    }
533
534    fn all_transactions_event_listener(&self) -> AllTransactionsEvents<Self::Transaction> {
535        self.pool.add_all_transactions_event_listener()
536    }
537
538    fn pending_transactions_listener_for(&self, kind: TransactionListenerKind) -> Receiver<TxHash> {
539        self.pool.add_pending_listener(kind)
540    }
541
542    fn blob_transaction_sidecars_listener(&self) -> Receiver<NewBlobSidecar> {
543        self.pool.add_blob_sidecar_listener()
544    }
545
546    fn new_transactions_listener_for(
547        &self,
548        kind: TransactionListenerKind,
549    ) -> Receiver<NewTransactionEvent<Self::Transaction>> {
550        self.pool.add_new_transaction_listener(kind)
551    }
552
553    fn pooled_transaction_hashes(&self) -> Vec<TxHash> {
554        self.pool.pooled_transactions_hashes()
555    }
556
557    fn pooled_transaction_hashes_max(&self, max: usize) -> Vec<TxHash> {
558        self.pool.pooled_transactions_hashes_max(max)
559    }
560
561    fn pooled_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
562        self.pool.pooled_transactions()
563    }
564
565    fn pooled_transactions_max(
566        &self,
567        max: usize,
568    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
569        self.pool.pooled_transactions_max(max)
570    }
571
572    fn get_pooled_transaction_elements(
573        &self,
574        tx_hashes: Vec<TxHash>,
575        limit: GetPooledTransactionLimit,
576    ) -> Vec<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled> {
577        self.pool.get_pooled_transaction_elements(tx_hashes, limit)
578    }
579
580    fn append_pooled_transaction_elements(
581        &self,
582        tx_hashes: &[TxHash],
583        limit: GetPooledTransactionLimit,
584        out: &mut Vec<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled>,
585    ) {
586        self.pool.append_pooled_transaction_elements(tx_hashes, limit, out)
587    }
588
589    fn get_pooled_transaction_element(
590        &self,
591        tx_hash: TxHash,
592    ) -> Option<Recovered<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled>>
593    {
594        self.pool.get_pooled_transaction_element(tx_hash)
595    }
596
597    fn best_transactions(
598        &self,
599    ) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
600        Box::new(self.pool.best_transactions())
601    }
602
603    fn best_transactions_with_attributes(
604        &self,
605        best_transactions_attributes: BestTransactionsAttributes,
606    ) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
607        self.pool.best_transactions_with_attributes(best_transactions_attributes)
608    }
609
610    fn pending_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
611        self.pool.pending_transactions()
612    }
613
614    fn get_pending_transaction_by_sender_and_nonce(
615        &self,
616        sender: Address,
617        nonce: u64,
618    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
619        self.pool.get_pending_transaction_by_sender_and_nonce(sender, nonce)
620    }
621
622    fn pending_transactions_max(
623        &self,
624        max: usize,
625    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
626        self.pool.pending_transactions_max(max)
627    }
628
629    fn queued_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
630        self.pool.queued_transactions()
631    }
632
633    fn pending_and_queued_txn_count(&self) -> (usize, usize) {
634        let data = self.pool.get_pool_data();
635        let pending = data.pending_transactions_count();
636        let queued = data.queued_transactions_count();
637        (pending, queued)
638    }
639
640    fn all_transactions(&self) -> AllPoolTransactions<Self::Transaction> {
641        self.pool.all_transactions()
642    }
643
644    fn all_transaction_hashes(&self) -> Vec<TxHash> {
645        self.pool.all_transaction_hashes()
646    }
647
648    fn remove_transactions(
649        &self,
650        hashes: Vec<TxHash>,
651    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
652        self.pool.remove_transactions(hashes)
653    }
654
655    fn remove_transactions_and_descendants(
656        &self,
657        hashes: Vec<TxHash>,
658    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
659        self.pool.remove_transactions_and_descendants(hashes)
660    }
661
662    fn remove_transactions_by_sender(
663        &self,
664        sender: Address,
665    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
666        self.pool.remove_transactions_by_sender(sender)
667    }
668
669    fn prune_transactions(
670        &self,
671        hashes: Vec<TxHash>,
672    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
673        self.pool.prune_transactions(hashes)
674    }
675
676    fn retain_unknown<A>(&self, announcement: &mut A)
677    where
678        A: HandleMempoolData,
679    {
680        self.pool.retain_unknown(announcement)
681    }
682
683    fn get(&self, tx_hash: &TxHash) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
684        self.inner().get(tx_hash)
685    }
686
687    fn get_all(&self, txs: Vec<TxHash>) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
688        self.inner().get_all(txs)
689    }
690
691    fn on_propagated(&self, txs: PropagatedTransactions) {
692        self.inner().on_propagated(txs)
693    }
694
695    fn get_transactions_by_sender(
696        &self,
697        sender: Address,
698    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
699        self.pool.get_transactions_by_sender(sender)
700    }
701
702    fn get_pending_transactions_with_predicate(
703        &self,
704        predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
705    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
706        self.pool.pending_transactions_with_predicate(predicate)
707    }
708
709    fn get_pending_transactions_by_sender(
710        &self,
711        sender: Address,
712    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
713        self.pool.get_pending_transactions_by_sender(sender)
714    }
715
716    fn get_queued_transactions_by_sender(
717        &self,
718        sender: Address,
719    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
720        self.pool.get_queued_transactions_by_sender(sender)
721    }
722
723    fn get_highest_transaction_by_sender(
724        &self,
725        sender: Address,
726    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
727        self.pool.get_highest_transaction_by_sender(sender)
728    }
729
730    fn get_highest_consecutive_transaction_by_sender(
731        &self,
732        sender: Address,
733        on_chain_nonce: u64,
734    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
735        self.pool.get_highest_consecutive_transaction_by_sender(sender, on_chain_nonce)
736    }
737
738    fn get_transaction_by_sender_and_nonce(
739        &self,
740        sender: Address,
741        nonce: u64,
742    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
743        let transaction_id = TransactionId::new(self.pool.get_sender_id(sender), nonce);
744
745        self.inner().get_pool_data().all().get(&transaction_id).map(|tx| tx.transaction.clone())
746    }
747
748    fn get_transactions_by_origin(
749        &self,
750        origin: TransactionOrigin,
751    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
752        self.pool.get_transactions_by_origin(origin)
753    }
754
755    /// Returns all pending transactions filtered by [`TransactionOrigin`]
756    fn get_pending_transactions_by_origin(
757        &self,
758        origin: TransactionOrigin,
759    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
760        self.pool.get_pending_transactions_by_origin(origin)
761    }
762
763    fn unique_senders(&self) -> AddressSet {
764        self.pool.unique_senders()
765    }
766
767    fn get_blob(
768        &self,
769        tx_hash: TxHash,
770    ) -> Result<Option<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
771        self.pool.blob_store().get(tx_hash)
772    }
773
774    fn get_all_blobs(
775        &self,
776        tx_hashes: Vec<TxHash>,
777    ) -> Result<Vec<(TxHash, Arc<BlobTransactionSidecarVariant>)>, BlobStoreError> {
778        self.pool.blob_store().get_all(tx_hashes)
779    }
780
781    fn get_all_blobs_exact(
782        &self,
783        tx_hashes: Vec<TxHash>,
784    ) -> Result<Vec<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
785        self.pool.blob_store().get_exact(tx_hashes)
786    }
787
788    fn get_blobs_for_versioned_hashes_v1(
789        &self,
790        versioned_hashes: &[B256],
791    ) -> Result<Vec<Option<BlobAndProofV1>>, BlobStoreError> {
792        self.pool.blob_store().get_by_versioned_hashes_v1(versioned_hashes)
793    }
794
795    fn get_blobs_for_versioned_hashes_v2(
796        &self,
797        versioned_hashes: &[B256],
798    ) -> Result<Option<Vec<BlobAndProofV2>>, BlobStoreError> {
799        self.pool.blob_store().get_by_versioned_hashes_v2(versioned_hashes)
800    }
801
802    fn get_blobs_for_versioned_hashes_v3(
803        &self,
804        versioned_hashes: &[B256],
805    ) -> Result<Vec<Option<BlobAndProofV2>>, BlobStoreError> {
806        self.pool.blob_store().get_by_versioned_hashes_v3(versioned_hashes)
807    }
808}
809
810impl<V, T, S> TransactionPoolExt for Pool<V, T, S>
811where
812    V: TransactionValidator,
813    <V as TransactionValidator>::Transaction: EthPoolTransaction,
814    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
815    S: BlobStore,
816{
817    type Block = V::Block;
818
819    #[instrument(skip(self), target = "txpool")]
820    fn set_block_info(&self, info: BlockInfo) {
821        trace!(target: "txpool", "updating pool block info");
822        self.pool.set_block_info(info)
823    }
824
825    fn on_canonical_state_change(&self, update: CanonicalStateUpdate<'_, Self::Block>) {
826        self.pool.on_canonical_state_change(update);
827    }
828
829    fn update_accounts(&self, accounts: Vec<ChangedAccount>) {
830        self.pool.update_accounts(accounts);
831    }
832
833    fn delete_blob(&self, tx: TxHash) {
834        self.pool.delete_blob(tx)
835    }
836
837    fn delete_blobs(&self, txs: Vec<TxHash>) {
838        self.pool.delete_blobs(txs)
839    }
840
841    fn cleanup_blobs(&self) {
842        self.pool.cleanup_blobs()
843    }
844}
845
846impl<V, T: TransactionOrdering, S> Clone for Pool<V, T, S> {
847    fn clone(&self) -> Self {
848        Self { pool: Arc::clone(&self.pool) }
849    }
850}