diff --git a/crates/transaction-pool/src/client.rs b/crates/transaction-pool/src/client.rs index 9e367bc8c..0e1d9b4d7 100644 --- a/crates/transaction-pool/src/client.rs +++ b/crates/transaction-pool/src/client.rs @@ -1,24 +1,10 @@ //! Provides access to the chain's storage -use crate::{ - error::{PoolError, PoolResult}, - validate::TransactionValidator, -}; -use reth_primitives::{BlockID, U64}; +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; - - /// Returns the block number for the given block identifier. - fn convert_block_id(&self, block_id: &BlockID) -> PoolResult>; - - /// Same as [`PoolClient::convert_block_id()`] but returns an error if no matching block number - /// was found - fn ensure_block_number(&self, block_id: &BlockID) -> PoolResult { - self.convert_block_id(block_id) - .and_then(|number| number.ok_or_else(|| PoolError::BlockNumberNotFound(*block_id))) - } } diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 4d7039de3..d3cb2d53c 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -84,7 +84,6 @@ pub use crate::{ }; use crate::{error::PoolResult, pool::PoolInner, validate::ValidPoolTransaction}; use futures::channel::mpsc::Receiver; - use reth_primitives::{BlockID, TxHash, U256, U64}; use std::{collections::HashMap, sync::Arc}; @@ -123,27 +122,17 @@ where &self.pool } - /// Returns the actual block number for the block id - fn resolve_block_number(&self, block_id: &BlockID) -> PoolResult { - self.pool.client().ensure_block_number(block_id) - } - /// Returns future that validates all transaction in the given iterator at the block the /// `block_id` points to. async fn validate_all( &self, - block_id: &BlockID, transactions: impl IntoIterator, ) -> PoolResult>> { - // get the actual block number which is required to validate the transactions - let block_number = self.resolve_block_number(block_id)?; - - let outcome = futures::future::join_all( - transactions.into_iter().map(|tx| self.validate(block_id, block_number, tx)), - ) - .await - .into_iter() - .collect::>(); + let outcome = + futures::future::join_all(transactions.into_iter().map(|tx| self.validate(tx))) + .await + .into_iter() + .collect::>(); Ok(outcome) } @@ -151,13 +140,11 @@ where /// Validates the given transaction at the given block async fn validate( &self, - block_id: &BlockID, - _block_number: U64, transaction: P::Transaction, ) -> (TxHash, TransactionValidationOutcome) { let _hash = *transaction.hash(); // TODO this is where additional validate checks would go, like banned senders etc... - let _res = self.pool.client().validate_transaction(block_id, transaction).await; + let _res = self.pool.client().validate_transaction(transaction).await; // TODO blockstamp the transaction @@ -189,23 +176,16 @@ where todo!() } - async fn add_transaction( - &self, - block_id: BlockID, - transaction: Self::Transaction, - ) -> PoolResult { - self.add_transactions(block_id, vec![transaction]) - .await? - .pop() - .expect("transaction exists; qed") + async fn add_transaction(&self, transaction: Self::Transaction) -> PoolResult { + let (_, tx) = self.validate(transaction).await; + self.pool.add_transactions(std::iter::once(tx)).pop().expect("exists; qed") } async fn add_transactions( &self, - block_id: BlockID, transactions: Vec, ) -> PoolResult>> { - let validated = self.validate_all(&block_id, transactions).await?; + let validated = self.validate_all(transactions).await?; let transactions = self.pool.add_transactions(validated.into_values()); Ok(transactions) } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 034bfce00..3a1052339 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -23,11 +23,7 @@ pub trait TransactionPool: Send + Sync { /// Adds an _unvalidated_ transaction into the pool. /// /// Consumer: RPC - async fn add_transaction( - &self, - block_id: BlockID, - transaction: Self::Transaction, - ) -> PoolResult; + async fn add_transaction(&self, transaction: Self::Transaction) -> PoolResult; /// Adds the given _unvalidated_ transaction into the pool. /// @@ -36,7 +32,6 @@ pub trait TransactionPool: Send + Sync { /// Consumer: RPC async fn add_transactions( &self, - block_id: BlockID, transactions: Vec, ) -> PoolResult>>; diff --git a/crates/transaction-pool/src/validate.rs b/crates/transaction-pool/src/validate.rs index 4b3891806..024303a1f 100644 --- a/crates/transaction-pool/src/validate.rs +++ b/crates/transaction-pool/src/validate.rs @@ -38,7 +38,6 @@ pub trait TransactionValidator: Send + Sync { /// transactions for the sender. async fn validate_transaction( &self, - _block_id: &BlockID, _transaction: Self::Transaction, ) -> TransactionValidationOutcome { unimplemented!()