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::StateProviderFactory;
201//! use reth_tasks::TokioTaskExecutor;
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//! async fn t<C>(client: C)  where C: ChainSpecProvider<ChainSpec: EthereumHardforks> + StateProviderFactory + Clone + 'static{
207//!     let blob_store = InMemoryBlobStore::default();
208//!     let pool = Pool::eth_pool(
209//!         TransactionValidationTaskExecutor::eth(client, blob_store.clone(), TokioTaskExecutor::default()),
210//!         blob_store,
211//!         Default::default(),
212//!     );
213//!   let mut transactions = pool.pending_transactions_listener();
214//!   tokio::task::spawn( async move {
215//!      while let Some(tx) = transactions.recv().await {
216//!          println!("New transaction: {:?}", tx);
217//!      }
218//!   });
219//!
220//!   // do something useful with the pool, like RPC integration
221//!
222//! # }
223//! ```
224//!
225//! Spawn maintenance task to keep the pool updated
226//!
227//! ```
228//! use futures_util::Stream;
229//! use reth_chain_state::CanonStateNotification;
230//! use reth_chainspec::{MAINNET, ChainSpecProvider, ChainSpec};
231//! use reth_storage_api::{BlockReaderIdExt, StateProviderFactory};
232//! use reth_tasks::TokioTaskExecutor;
233//! use reth_tasks::TaskSpawner;
234//! use reth_tasks::TaskManager;
235//! use reth_transaction_pool::{TransactionValidationTaskExecutor, Pool};
236//! use reth_transaction_pool::blobstore::InMemoryBlobStore;
237//! use reth_transaction_pool::maintain::{maintain_transaction_pool_future};
238//! use alloy_consensus::Header;
239//!
240//!  async fn t<C, St>(client: C, stream: St)
241//!    where C: StateProviderFactory + BlockReaderIdExt<Header = Header> + ChainSpecProvider<ChainSpec = ChainSpec> + Clone + 'static,
242//!     St: Stream<Item = CanonStateNotification> + Send + Unpin + 'static,
243//!     {
244//!     let blob_store = InMemoryBlobStore::default();
245//!     let rt = tokio::runtime::Runtime::new().unwrap();
246//!     let manager = TaskManager::new(rt.handle().clone());
247//!     let executor = manager.executor();
248//!     let pool = Pool::eth_pool(
249//!         TransactionValidationTaskExecutor::eth(client.clone(), blob_store.clone(), executor.clone()),
250//!         blob_store,
251//!         Default::default(),
252//!     );
253//!
254//!   // spawn a task that listens for new blocks and updates the pool's transactions, mined transactions etc..
255//!   tokio::task::spawn(maintain_transaction_pool_future(client, pool, stream, executor.clone(), Default::default()));
256//!
257//! # }
258//! ```
259//!
260//! ## Feature Flags
261//!
262//! - `serde` (default): Enable serde support
263//! - `test-utils`: Export utilities for testing
264
265#![doc(
266    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
267    html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
268    issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
269)]
270#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
271#![cfg_attr(not(test), warn(unused_crate_dependencies))]
272
273pub use crate::{
274    batcher::{BatchTxProcessor, BatchTxRequest},
275    blobstore::{BlobStore, BlobStoreError},
276    config::{
277        LocalTransactionConfig, PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP,
278        DEFAULT_TXPOOL_ADDITIONAL_VALIDATION_TASKS, MAX_NEW_PENDING_TXS_NOTIFICATIONS,
279        REPLACE_BLOB_PRICE_BUMP, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
280        TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT,
281    },
282    error::PoolResult,
283    ordering::{CoinbaseTipOrdering, Priority, TransactionOrdering},
284    pool::{
285        blob_tx_priority, fee_delta, state::SubPool, AddedTransactionOutcome,
286        AllTransactionsEvents, FullTransactionEvent, NewTransactionEvent, TransactionEvent,
287        TransactionEvents, TransactionListenerKind,
288    },
289    traits::*,
290    validate::{
291        EthTransactionValidator, TransactionValidationOutcome, TransactionValidationTaskExecutor,
292        TransactionValidator, ValidPoolTransaction,
293    },
294};
295use crate::{identifier::TransactionId, pool::PoolInner};
296use alloy_eips::{
297    eip4844::{BlobAndProofV1, BlobAndProofV2},
298    eip7594::BlobTransactionSidecarVariant,
299};
300use alloy_primitives::{Address, TxHash, B256, U256};
301use aquamarine as _;
302use reth_chainspec::{ChainSpecProvider, EthereumHardforks};
303use reth_eth_wire_types::HandleMempoolData;
304use reth_execution_types::ChangedAccount;
305use reth_primitives_traits::{Block, Recovered};
306use reth_storage_api::StateProviderFactory;
307use std::{collections::HashSet, sync::Arc};
308use tokio::sync::mpsc::Receiver;
309use tracing::{instrument, trace};
310
311pub mod error;
312pub mod maintain;
313pub mod metrics;
314pub mod noop;
315pub mod pool;
316pub mod validate;
317
318pub mod batcher;
319pub mod blobstore;
320mod config;
321pub mod identifier;
322mod ordering;
323mod traits;
324
325#[cfg(any(test, feature = "test-utils"))]
326/// Common test helpers for mocking a pool
327pub mod test_utils;
328
329/// Type alias for default ethereum transaction pool
330pub type EthTransactionPool<Client, S, T = EthPooledTransaction> = Pool<
331    TransactionValidationTaskExecutor<EthTransactionValidator<Client, T>>,
332    CoinbaseTipOrdering<T>,
333    S,
334>;
335
336/// A shareable, generic, customizable `TransactionPool` implementation.
337#[derive(Debug)]
338pub struct Pool<V, T: TransactionOrdering, S> {
339    /// Arc'ed instance of the pool internals
340    pool: Arc<PoolInner<V, T, S>>,
341}
342
343// === impl Pool ===
344
345impl<V, T, S> Pool<V, T, S>
346where
347    V: TransactionValidator,
348    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
349    S: BlobStore,
350{
351    /// Create a new transaction pool instance.
352    pub fn new(validator: V, ordering: T, blob_store: S, config: PoolConfig) -> Self {
353        Self { pool: Arc::new(PoolInner::new(validator, ordering, blob_store, config)) }
354    }
355
356    /// Returns the wrapped pool.
357    pub(crate) fn inner(&self) -> &PoolInner<V, T, S> {
358        &self.pool
359    }
360
361    /// Get the config the pool was configured with.
362    pub fn config(&self) -> &PoolConfig {
363        self.inner().config()
364    }
365
366    /// Validates the given transaction
367    async fn validate(
368        &self,
369        origin: TransactionOrigin,
370        transaction: V::Transaction,
371    ) -> TransactionValidationOutcome<V::Transaction> {
372        self.pool.validator().validate_transaction(origin, transaction).await
373    }
374
375    /// Returns future that validates all transactions in the given iterator.
376    ///
377    /// This returns the validated transactions in the iterator's order.
378    async fn validate_all(
379        &self,
380        origin: TransactionOrigin,
381        transactions: impl IntoIterator<Item = V::Transaction> + Send,
382    ) -> Vec<TransactionValidationOutcome<V::Transaction>> {
383        self.pool
384            .validator()
385            .validate_transactions_with_origin(origin, transactions)
386            .await
387            .into_iter()
388            .collect()
389    }
390
391    /// Validates all transactions with their individual origins.
392    ///
393    /// This returns the validated transactions in the same order as input.
394    async fn validate_all_with_origins(
395        &self,
396        transactions: Vec<(TransactionOrigin, V::Transaction)>,
397    ) -> Vec<(TransactionOrigin, TransactionValidationOutcome<V::Transaction>)> {
398        let origins: Vec<_> = transactions.iter().map(|(origin, _)| *origin).collect();
399        let tx_outcomes = self.pool.validator().validate_transactions(transactions).await;
400        origins.into_iter().zip(tx_outcomes).collect()
401    }
402
403    /// Number of transactions in the entire pool
404    pub fn len(&self) -> usize {
405        self.pool.len()
406    }
407
408    /// Whether the pool is empty
409    pub fn is_empty(&self) -> bool {
410        self.pool.is_empty()
411    }
412
413    /// Returns whether or not the pool is over its configured size and transaction count limits.
414    pub fn is_exceeded(&self) -> bool {
415        self.pool.is_exceeded()
416    }
417
418    /// Returns the configured blob store.
419    pub fn blob_store(&self) -> &S {
420        self.pool.blob_store()
421    }
422}
423
424impl<Client, S> EthTransactionPool<Client, S>
425where
426    Client:
427        ChainSpecProvider<ChainSpec: EthereumHardforks> + StateProviderFactory + Clone + 'static,
428    S: BlobStore,
429{
430    /// Returns a new [`Pool`] that uses the default [`TransactionValidationTaskExecutor`] when
431    /// validating [`EthPooledTransaction`]s and ords via [`CoinbaseTipOrdering`]
432    ///
433    /// # Example
434    ///
435    /// ```
436    /// use reth_chainspec::MAINNET;
437    /// use reth_storage_api::StateProviderFactory;
438    /// use reth_tasks::TokioTaskExecutor;
439    /// use reth_chainspec::ChainSpecProvider;
440    /// use reth_transaction_pool::{
441    ///     blobstore::InMemoryBlobStore, Pool, TransactionValidationTaskExecutor,
442    /// };
443    /// use reth_chainspec::EthereumHardforks;
444    /// # fn t<C>(client: C)  where C: ChainSpecProvider<ChainSpec: EthereumHardforks> + StateProviderFactory + Clone + 'static {
445    /// let blob_store = InMemoryBlobStore::default();
446    /// let pool = Pool::eth_pool(
447    ///     TransactionValidationTaskExecutor::eth(
448    ///         client,
449    ///         blob_store.clone(),
450    ///         TokioTaskExecutor::default(),
451    ///     ),
452    ///     blob_store,
453    ///     Default::default(),
454    /// );
455    /// # }
456    /// ```
457    pub fn eth_pool(
458        validator: TransactionValidationTaskExecutor<
459            EthTransactionValidator<Client, EthPooledTransaction>,
460        >,
461        blob_store: S,
462        config: PoolConfig,
463    ) -> Self {
464        Self::new(validator, CoinbaseTipOrdering::default(), blob_store, config)
465    }
466}
467
468/// implements the `TransactionPool` interface for various transaction pool API consumers.
469impl<V, T, S> TransactionPool for Pool<V, T, S>
470where
471    V: TransactionValidator,
472    <V as TransactionValidator>::Transaction: EthPoolTransaction,
473    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
474    S: BlobStore,
475{
476    type Transaction = T::Transaction;
477
478    fn pool_size(&self) -> PoolSize {
479        self.pool.size()
480    }
481
482    fn block_info(&self) -> BlockInfo {
483        self.pool.block_info()
484    }
485
486    async fn add_transaction_and_subscribe(
487        &self,
488        origin: TransactionOrigin,
489        transaction: Self::Transaction,
490    ) -> PoolResult<TransactionEvents> {
491        let tx = self.validate(origin, transaction).await;
492        self.pool.add_transaction_and_subscribe(origin, tx)
493    }
494
495    async fn add_transaction(
496        &self,
497        origin: TransactionOrigin,
498        transaction: Self::Transaction,
499    ) -> PoolResult<AddedTransactionOutcome> {
500        let tx = self.validate(origin, transaction).await;
501        let mut results = self.pool.add_transactions(origin, std::iter::once(tx));
502        results.pop().expect("result length is the same as the input")
503    }
504
505    async fn add_transactions(
506        &self,
507        origin: TransactionOrigin,
508        transactions: Vec<Self::Transaction>,
509    ) -> Vec<PoolResult<AddedTransactionOutcome>> {
510        if transactions.is_empty() {
511            return Vec::new()
512        }
513        let validated = self.validate_all(origin, transactions).await;
514
515        self.pool.add_transactions(origin, validated.into_iter())
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 validated = self.validate_all_with_origins(transactions).await;
526
527        self.pool.add_transactions_with_origins(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.pooled_transaction_hashes().into_iter().take(max).collect()
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 get_pooled_transaction_element(
581        &self,
582        tx_hash: TxHash,
583    ) -> Option<Recovered<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled>>
584    {
585        self.pool.get_pooled_transaction_element(tx_hash)
586    }
587
588    fn best_transactions(
589        &self,
590    ) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
591        Box::new(self.pool.best_transactions())
592    }
593
594    fn best_transactions_with_attributes(
595        &self,
596        best_transactions_attributes: BestTransactionsAttributes,
597    ) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
598        self.pool.best_transactions_with_attributes(best_transactions_attributes)
599    }
600
601    fn pending_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
602        self.pool.pending_transactions()
603    }
604
605    fn pending_transactions_max(
606        &self,
607        max: usize,
608    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
609        self.pool.pending_transactions_max(max)
610    }
611
612    fn queued_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
613        self.pool.queued_transactions()
614    }
615
616    fn pending_and_queued_txn_count(&self) -> (usize, usize) {
617        let data = self.pool.get_pool_data();
618        let pending = data.pending_transactions_count();
619        let queued = data.queued_transactions_count();
620        (pending, queued)
621    }
622
623    fn all_transactions(&self) -> AllPoolTransactions<Self::Transaction> {
624        self.pool.all_transactions()
625    }
626
627    fn all_transaction_hashes(&self) -> Vec<TxHash> {
628        self.pool.all_transaction_hashes()
629    }
630
631    fn remove_transactions(
632        &self,
633        hashes: Vec<TxHash>,
634    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
635        self.pool.remove_transactions(hashes)
636    }
637
638    fn remove_transactions_and_descendants(
639        &self,
640        hashes: Vec<TxHash>,
641    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
642        self.pool.remove_transactions_and_descendants(hashes)
643    }
644
645    fn remove_transactions_by_sender(
646        &self,
647        sender: Address,
648    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
649        self.pool.remove_transactions_by_sender(sender)
650    }
651
652    fn retain_unknown<A>(&self, announcement: &mut A)
653    where
654        A: HandleMempoolData,
655    {
656        self.pool.retain_unknown(announcement)
657    }
658
659    fn get(&self, tx_hash: &TxHash) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
660        self.inner().get(tx_hash)
661    }
662
663    fn get_all(&self, txs: Vec<TxHash>) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
664        self.inner().get_all(txs)
665    }
666
667    fn on_propagated(&self, txs: PropagatedTransactions) {
668        self.inner().on_propagated(txs)
669    }
670
671    fn get_transactions_by_sender(
672        &self,
673        sender: Address,
674    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
675        self.pool.get_transactions_by_sender(sender)
676    }
677
678    fn get_pending_transactions_with_predicate(
679        &self,
680        predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
681    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
682        self.pool.pending_transactions_with_predicate(predicate)
683    }
684
685    fn get_pending_transactions_by_sender(
686        &self,
687        sender: Address,
688    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
689        self.pool.get_pending_transactions_by_sender(sender)
690    }
691
692    fn get_queued_transactions_by_sender(
693        &self,
694        sender: Address,
695    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
696        self.pool.get_queued_transactions_by_sender(sender)
697    }
698
699    fn get_highest_transaction_by_sender(
700        &self,
701        sender: Address,
702    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
703        self.pool.get_highest_transaction_by_sender(sender)
704    }
705
706    fn get_highest_consecutive_transaction_by_sender(
707        &self,
708        sender: Address,
709        on_chain_nonce: u64,
710    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
711        self.pool.get_highest_consecutive_transaction_by_sender(sender, on_chain_nonce)
712    }
713
714    fn get_transaction_by_sender_and_nonce(
715        &self,
716        sender: Address,
717        nonce: u64,
718    ) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
719        let transaction_id = TransactionId::new(self.pool.get_sender_id(sender), nonce);
720
721        self.inner().get_pool_data().all().get(&transaction_id).map(|tx| tx.transaction.clone())
722    }
723
724    fn get_transactions_by_origin(
725        &self,
726        origin: TransactionOrigin,
727    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
728        self.pool.get_transactions_by_origin(origin)
729    }
730
731    /// Returns all pending transactions filtered by [`TransactionOrigin`]
732    fn get_pending_transactions_by_origin(
733        &self,
734        origin: TransactionOrigin,
735    ) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
736        self.pool.get_pending_transactions_by_origin(origin)
737    }
738
739    fn unique_senders(&self) -> HashSet<Address> {
740        self.pool.unique_senders()
741    }
742
743    fn get_blob(
744        &self,
745        tx_hash: TxHash,
746    ) -> Result<Option<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
747        self.pool.blob_store().get(tx_hash)
748    }
749
750    fn get_all_blobs(
751        &self,
752        tx_hashes: Vec<TxHash>,
753    ) -> Result<Vec<(TxHash, Arc<BlobTransactionSidecarVariant>)>, BlobStoreError> {
754        self.pool.blob_store().get_all(tx_hashes)
755    }
756
757    fn get_all_blobs_exact(
758        &self,
759        tx_hashes: Vec<TxHash>,
760    ) -> Result<Vec<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
761        self.pool.blob_store().get_exact(tx_hashes)
762    }
763
764    fn get_blobs_for_versioned_hashes_v1(
765        &self,
766        versioned_hashes: &[B256],
767    ) -> Result<Vec<Option<BlobAndProofV1>>, BlobStoreError> {
768        self.pool.blob_store().get_by_versioned_hashes_v1(versioned_hashes)
769    }
770
771    fn get_blobs_for_versioned_hashes_v2(
772        &self,
773        versioned_hashes: &[B256],
774    ) -> Result<Option<Vec<BlobAndProofV2>>, BlobStoreError> {
775        self.pool.blob_store().get_by_versioned_hashes_v2(versioned_hashes)
776    }
777}
778
779impl<V, T, S> TransactionPoolExt for Pool<V, T, S>
780where
781    V: TransactionValidator,
782    <V as TransactionValidator>::Transaction: EthPoolTransaction,
783    T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
784    S: BlobStore,
785{
786    #[instrument(skip(self), target = "txpool")]
787    fn set_block_info(&self, info: BlockInfo) {
788        trace!(target: "txpool", "updating pool block info");
789        self.pool.set_block_info(info)
790    }
791
792    fn on_canonical_state_change<B>(&self, update: CanonicalStateUpdate<'_, B>)
793    where
794        B: Block,
795    {
796        self.pool.on_canonical_state_change(update);
797    }
798
799    fn update_accounts(&self, accounts: Vec<ChangedAccount>) {
800        self.pool.update_accounts(accounts);
801    }
802
803    fn delete_blob(&self, tx: TxHash) {
804        self.pool.delete_blob(tx)
805    }
806
807    fn delete_blobs(&self, txs: Vec<TxHash>) {
808        self.pool.delete_blobs(txs)
809    }
810
811    fn cleanup_blobs(&self) {
812        self.pool.cleanup_blobs()
813    }
814}
815
816impl<V, T: TransactionOrdering, S> Clone for Pool<V, T, S> {
817    fn clone(&self) -> Self {
818        Self { pool: Arc::clone(&self.pool) }
819    }
820}