diff --git a/crates/transaction-pool/src/client.rs b/crates/transaction-pool/src/client.rs deleted file mode 100644 index 0e1d9b4d7..000000000 --- a/crates/transaction-pool/src/client.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Provides access to the chain's storage - -use crate::{error::PoolError, validate::TransactionValidator}; - -/// The interface used to interact with the blockchain and access storage. -#[async_trait::async_trait] -pub trait PoolClient: Send + Sync + TransactionValidator { - /// Error type that can be converted to the crate's internal Error. - type Error: Into; -} diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index dd10670ce..b00f43963 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -15,10 +15,10 @@ //! //! The transaction pool is responsible for //! -//! - recording incoming transactions -//! - providing existing transactions -//! - ordering and providing the best transactions for block production -//! - monitoring memory footprint and enforce pool size limits +//! - recording incoming transactions +//! - providing existing transactions +//! - ordering and providing the best transactions for block production +//! - monitoring memory footprint and enforce pool size limits //! //! ## Assumptions //! @@ -51,9 +51,9 @@ //! //! Once a new block is mined, the pool needs to be updated with a changeset in order to: //! -//! - remove mined transactions -//! - update using account changes: balance changes -//! - base fee updates +//! - remove mined transactions +//! - update using account changes: balance changes +//! - base fee updates //! //! ## Implementation details //! @@ -76,7 +76,6 @@ //! that provides the `TransactionPool` interface. pub use crate::{ - client::PoolClient, config::PoolConfig, ordering::TransactionOrdering, traits::{BestTransactions, NewBlockEvent, PoolTransaction, TransactionPool}, @@ -89,7 +88,6 @@ use futures::channel::mpsc::Receiver; use reth_primitives::{BlockID, TxHash, U256, U64}; use std::{collections::HashMap, sync::Arc}; -mod client; mod config; pub mod error; mod identifier; @@ -102,33 +100,33 @@ mod validate; mod test_util; /// A shareable, generic, customizable `TransactionPool` implementation. -pub struct Pool { +pub struct Pool { /// Arc'ed instance of the pool internals - pool: Arc>, + pool: Arc>, } // === impl Pool === -impl Pool +impl Pool where - P: PoolClient, - T: TransactionOrdering::Transaction>, + V: TransactionValidator, + T: TransactionOrdering::Transaction>, { /// Create a new transaction pool instance. - pub fn new(client: Arc

, ordering: Arc, config: PoolConfig) -> Self { + pub fn new(client: Arc, ordering: Arc, config: PoolConfig) -> Self { Self { pool: Arc::new(PoolInner::new(client, ordering, config)) } } /// Returns the wrapped pool. - pub(crate) fn inner(&self) -> &PoolInner { + pub(crate) fn inner(&self) -> &PoolInner { &self.pool } /// Returns future that validates all transaction in the given iterator. async fn validate_all( &self, - transactions: impl IntoIterator, - ) -> PoolResult>> { + transactions: impl IntoIterator, + ) -> PoolResult>> { let outcome = futures::future::join_all(transactions.into_iter().map(|tx| self.validate(tx))) .await @@ -141,12 +139,12 @@ where /// Validates the given transaction async fn validate( &self, - transaction: P::Transaction, - ) -> (TxHash, TransactionValidationOutcome) { + transaction: V::Transaction, + ) -> (TxHash, TransactionValidationOutcome) { let hash = *transaction.hash(); // TODO(mattsse): this is where additional validate checks would go, like banned senders // etc... - let outcome = self.pool.client().validate_transaction(transaction).await; + let outcome = self.pool.validator().validate_transaction(transaction).await; (hash, outcome) } @@ -164,10 +162,10 @@ where /// implements the `TransactionPool` interface for various transaction pool API consumers. #[async_trait::async_trait] -impl TransactionPool for Pool +impl TransactionPool for Pool where - P: PoolClient, - T: TransactionOrdering::Transaction>, + V: TransactionValidator, + T: TransactionOrdering::Transaction>, { type Transaction = T::Transaction; @@ -216,7 +214,7 @@ where } } -impl Clone for Pool { +impl Clone for Pool { fn clone(&self) -> Self { Self { pool: Arc::clone(&self.pool) } } diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index e465d82de..84cdad681 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -69,7 +69,7 @@ use crate::{ pool::{listener::PoolEventListener, state::SubPool, txpool::TxPool}, traits::{NewTransactionEvent, PoolTransaction}, validate::{TransactionValidationOutcome, ValidPoolTransaction}, - PoolClient, PoolConfig, TransactionOrdering, TransactionValidator, U256, + PoolConfig, TransactionOrdering, TransactionValidator, U256, }; use best::BestTransactions; pub use events::TransactionEvent; @@ -89,11 +89,11 @@ mod transaction; pub mod txpool; /// Transaction pool internals. -pub struct PoolInner { +pub struct PoolInner { /// Internal mapping of addresses to plain ints. identifiers: RwLock, - /// Chain/Storage access. - client: Arc

, + /// Transaction validation. + validator: Arc, /// The internal pool that manages all transactions. pool: RwLock>, /// Pool settings. @@ -108,16 +108,16 @@ pub struct PoolInner { // === impl PoolInner === -impl PoolInner +impl PoolInner where - P: PoolClient, - T: TransactionOrdering::Transaction>, + V: TransactionValidator, + T: TransactionOrdering::Transaction>, { /// Create a new transaction pool instance. - pub fn new(client: Arc

, ordering: Arc, config: PoolConfig) -> Self { + pub fn new(client: Arc, ordering: Arc, config: PoolConfig) -> Self { Self { identifiers: Default::default(), - client, + validator: client, config, event_listener: Default::default(), pool: RwLock::new(TxPool::new(ordering)), @@ -136,9 +136,9 @@ where self.pool.write().update_base_fee(base_fee); } - /// Get client reference. - pub fn client(&self) -> &P { - &self.client + /// Get the validator reference. + pub fn validator(&self) -> &V { + &self.validator } /// Adds a new transaction listener to the pool that gets notified about every new _ready_ diff --git a/crates/transaction-pool/src/validate.rs b/crates/transaction-pool/src/validate.rs index 024303a1f..d03b289ee 100644 --- a/crates/transaction-pool/src/validate.rs +++ b/crates/transaction-pool/src/validate.rs @@ -39,9 +39,7 @@ pub trait TransactionValidator: Send + Sync { async fn validate_transaction( &self, _transaction: Self::Transaction, - ) -> TransactionValidationOutcome { - unimplemented!() - } + ) -> TransactionValidationOutcome; } /// A valida transaction in the pool.