diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 8e9a195a1..18a8c4737 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -18,7 +18,10 @@ use reth_evm::{ ConfigureEvm, }; use reth_payload_validator::ExecutionPayloadValidator; -use reth_primitives::{proofs, Block, BlockBody, BlockExt, Receipt, Receipts}; +use reth_primitives::{ + proofs, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, BlockExt, Receipt, + Receipts, +}; use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory}; use reth_revm::{ database::StateProviderDatabase, diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index ad673588b..58b6aeaf6 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -13,7 +13,7 @@ use reth_evm::execute::BasicBlockExecutorProvider; use reth_evm_ethereum::execute::EthExecutionStrategyFactory; use reth_network::{NetworkHandle, PeersInfo}; use reth_node_api::{ - AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, NodeTypesWithDB, + AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, NodeTypesWithDB, TxTy, }; use reth_node_builder::{ components::{ @@ -30,7 +30,7 @@ use reth_provider::{CanonStateSubscriptions, EthStorage}; use reth_rpc::EthApi; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ - blobstore::DiskFileBlobStore, EthTransactionPool, TransactionPool, + blobstore::DiskFileBlobStore, EthTransactionPool, PoolTransaction, TransactionPool, TransactionValidationTaskExecutor, }; use reth_trie_db::MerklePatriciaTrie; @@ -243,7 +243,9 @@ impl EthereumPayloadBuilder { Types: NodeTypesWithEngine, Node: FullNodeTypes, Evm: ConfigureEvm
, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, Types::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, PayloadAttributes = EthPayloadAttributes, @@ -280,7 +282,9 @@ impl PayloadServiceBuilder for EthereumPayloadBui where Types: NodeTypesWithEngine, Node: FullNodeTypes, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, Types::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, PayloadAttributes = EthPayloadAttributes, @@ -305,7 +309,9 @@ pub struct EthereumNetworkBuilder { impl NetworkBuilder for EthereumNetworkBuilder where Node: FullNodeTypes>, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, { async fn build_network( self, diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index a5c643431..df900f1f3 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -31,12 +31,13 @@ use reth_payload_primitives::PayloadBuilderAttributes; use reth_primitives::{ proofs::{self}, Block, BlockBody, BlockExt, EthereumHardforks, InvalidTransactionError, Receipt, + TransactionSigned, }; use reth_provider::{ChainSpecProvider, StateProviderFactory}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{ error::InvalidPoolTransactionError, noop::NoopTransactionPool, BestTransactions, - BestTransactionsAttributes, TransactionPool, ValidPoolTransaction, + BestTransactionsAttributes, PoolTransaction, TransactionPool, ValidPoolTransaction, }; use reth_trie::HashedPostState; use revm::{ @@ -93,7 +94,7 @@ impl PayloadBuilder for EthereumPayloadBu where EvmConfig: ConfigureEvm
, Client: StateProviderFactory + ChainSpecProvider, - Pool: TransactionPool, + Pool: TransactionPool>, { type Attributes = EthPayloadBuilderAttributes; type BuiltPayload = EthBuiltPayload; @@ -157,7 +158,7 @@ pub fn default_ethereum_payload( where EvmConfig: ConfigureEvm
, Client: StateProviderFactory + ChainSpecProvider, - Pool: TransactionPool, + Pool: TransactionPool>, F: FnOnce(BestTransactionsAttributes) -> BestTransactionsIter, { let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args; @@ -244,7 +245,7 @@ where } // convert tx to a signed transaction - let tx = pool_tx.to_recovered_transaction(); + let tx = pool_tx.to_consensus(); // There's only limited amount of blob space available per block, so we need to check if // the EIP-4844 can still fit in the block diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index 9acad4d4b..939bf21c0 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -30,7 +30,8 @@ use reth_execution_types::Chain; use reth_exex::{ExExContext, ExExEvent, ExExNotification, ExExNotifications, Wal}; use reth_network::{config::SecretKey, NetworkConfigBuilder, NetworkManager}; use reth_node_api::{ - FullNodeTypes, FullNodeTypesAdapter, NodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine, + FullNodeTypes, FullNodeTypesAdapter, NodePrimitives, NodeTypes, NodeTypesWithDBAdapter, + NodeTypesWithEngine, }; use reth_node_builder::{ components::{ @@ -45,7 +46,7 @@ use reth_node_ethereum::{ EthEngineTypes, EthEvmConfig, }; use reth_payload_builder::noop::NoopPayloadBuilderService; -use reth_primitives::{BlockExt, EthPrimitives, Head, SealedBlockWithSenders}; +use reth_primitives::{BlockExt, EthPrimitives, Head, SealedBlockWithSenders, TransactionSigned}; use reth_provider::{ providers::{BlockchainProvider, StaticFileProvider}, BlockReader, EthStorage, ProviderFactory, @@ -64,7 +65,7 @@ pub struct TestPoolBuilder; impl PoolBuilder for TestPoolBuilder where - Node: FullNodeTypes, + Node: FullNodeTypes>>, { type Pool = TestPool; diff --git a/crates/net/network/src/test_utils/testnet.rs b/crates/net/network/src/test_utils/testnet.rs index bdd021183..08bf24b88 100644 --- a/crates/net/network/src/test_utils/testnet.rs +++ b/crates/net/network/src/test_utils/testnet.rs @@ -17,6 +17,7 @@ use reth_network_api::{ NetworkEvent, NetworkEventListenerProvider, NetworkInfo, Peers, }; use reth_network_peers::PeerId; +use reth_primitives::TransactionSigned; use reth_provider::{test_utils::NoopProvider, ChainSpecProvider}; use reth_storage_api::{BlockReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory}; use reth_tasks::TokioTaskExecutor; @@ -24,7 +25,7 @@ use reth_tokio_util::EventStream; use reth_transaction_pool::{ blobstore::InMemoryBlobStore, test_utils::{TestPool, TestPoolBuilder}, - EthTransactionPool, TransactionPool, TransactionValidationTaskExecutor, + EthTransactionPool, PoolTransaction, TransactionPool, TransactionValidationTaskExecutor, }; use secp256k1::SecretKey; use std::{ @@ -202,7 +203,9 @@ where + Clone + Unpin + 'static, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, { /// Spawns the testnet to a separate task pub fn spawn(self) -> TestnetHandle { @@ -267,7 +270,9 @@ where > + HeaderProvider + Unpin + 'static, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, { type Output = (); @@ -468,7 +473,9 @@ where > + HeaderProvider + Unpin + 'static, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, { type Output = (); diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index e17069b67..5463b20f7 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -702,9 +702,8 @@ where BroadcastedTransaction: SignedTransaction, PooledTransaction: SignedTransaction, >, - <::Transaction as PoolTransaction>::Consensus: - Into, - <::Transaction as PoolTransaction>::Pooled: Into, + Pool::Transaction: + PoolTransaction>, { /// Invoked when transactions in the local mempool are considered __pending__. /// @@ -1011,9 +1010,8 @@ where impl TransactionsManager where Pool: TransactionPool + 'static, - <::Transaction as PoolTransaction>::Consensus: Into, - <::Transaction as PoolTransaction>::Pooled: - Into, + Pool::Transaction: + PoolTransaction>, { /// Handles dedicated transaction events related to the `eth` protocol. fn on_network_tx_event(&mut self, event: NetworkTransactionEvent) { @@ -1313,9 +1311,8 @@ where impl Future for TransactionsManager where Pool: TransactionPool + Unpin + 'static, - <::Transaction as PoolTransaction>::Consensus: Into, - <::Transaction as PoolTransaction>::Pooled: - Into, + Pool::Transaction: + PoolTransaction>, { type Output = (); @@ -1503,11 +1500,11 @@ impl PropagateTransaction { /// Create a new instance from a pooled transaction fn new

(tx: Arc>) -> Self where - P: PoolTransaction>, + P: PoolTransaction, { let size = tx.encoded_length(); - let transaction = tx.transaction.clone_into_consensus().into(); - let transaction = Arc::new(transaction); + let transaction = tx.transaction.clone_into_consensus(); + let transaction = Arc::new(transaction.into_signed()); Self { size, transaction } } diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index 7778fea7b..83947208c 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -8,11 +8,11 @@ use reth_consensus::FullConsensus; use reth_evm::execute::BlockExecutorProvider; use reth_network_api::FullNetwork; use reth_node_core::node_config::NodeConfig; -use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine}; +use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, TxTy}; use reth_payload_builder_primitives::PayloadBuilder; use reth_provider::FullProvider; use reth_tasks::TaskExecutor; -use reth_transaction_pool::TransactionPool; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; use std::{future::Future, marker::PhantomData}; /// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds stateful @@ -47,7 +47,7 @@ where /// Encapsulates all types and components of the node. pub trait FullNodeComponents: FullNodeTypes + Clone + 'static { /// The transaction pool of the node. - type Pool: TransactionPool + Unpin; + type Pool: TransactionPool>> + Unpin; /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. type Evm: ConfigureEvm

; diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index b311cc4e2..3cab01aa7 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -37,7 +37,7 @@ use reth_provider::{ BlockReader, ChainSpecProvider, FullProvider, }; use reth_tasks::TaskExecutor; -use reth_transaction_pool::{PoolConfig, TransactionPool}; +use reth_transaction_pool::{PoolConfig, PoolTransaction, TransactionPool}; use revm_primitives::EnvKzgSettings; use secp256k1::SecretKey; use std::sync::Arc; @@ -650,7 +650,10 @@ impl BuilderContext { /// connected to that network. pub fn start_network(&self, builder: NetworkBuilder<(), ()>, pool: Pool) -> NetworkHandle where - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool< + Transaction: PoolTransaction, + > + Unpin + + 'static, Node::Provider: BlockReader< Block = reth_primitives::Block, Receipt = reth_primitives::Receipt, @@ -673,7 +676,10 @@ impl BuilderContext { tx_config: TransactionsManagerConfig, ) -> NetworkHandle where - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool< + Transaction: PoolTransaction, + > + Unpin + + 'static, Node::Provider: BlockReader< Block = reth_primitives::Block, Receipt = reth_primitives::Receipt, diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index b265dc927..4c04c9200 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -10,9 +10,9 @@ use crate::{ use alloy_consensus::Header; use reth_consensus::FullConsensus; use reth_evm::execute::BlockExecutorProvider; -use reth_node_api::{NodeTypes, NodeTypesWithEngine}; +use reth_node_api::{NodeTypes, NodeTypesWithEngine, TxTy}; use reth_payload_builder::PayloadBuilderHandle; -use reth_transaction_pool::TransactionPool; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; use std::{future::Future, marker::PhantomData}; /// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation. @@ -375,7 +375,9 @@ where Node: FullNodeTypes, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future>> + Send, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, EVM: ConfigureEvm
, Executor: BlockExecutorProvider::Primitives>, Cons: FullConsensus<::Primitives> + Clone + Unpin + 'static, diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index a7d15dd29..22a47e3da 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -27,9 +27,9 @@ use reth_consensus::FullConsensus; use reth_evm::execute::BlockExecutorProvider; use reth_network::NetworkHandle; use reth_network_api::FullNetwork; -use reth_node_api::{NodeTypes, NodeTypesWithEngine}; +use reth_node_api::{NodeTypes, NodeTypesWithEngine, TxTy}; use reth_payload_builder::PayloadBuilderHandle; -use reth_transaction_pool::TransactionPool; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; /// An abstraction over the components of a node, consisting of: /// - evm and executor @@ -38,7 +38,7 @@ use reth_transaction_pool::TransactionPool; /// - payload builder. pub trait NodeComponents: Clone + Unpin + Send + Sync + 'static { /// The transaction pool of the node. - type Pool: TransactionPool + Unpin; + type Pool: TransactionPool>> + Unpin; /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. type Evm: ConfigureEvm
; @@ -97,7 +97,9 @@ impl NodeComponents for Components where Node: FullNodeTypes, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, EVM: ConfigureEvm
, Executor: BlockExecutorProvider::Primitives>, Cons: FullConsensus<::Primitives> + Clone + Unpin + 'static, diff --git a/crates/node/builder/src/components/pool.rs b/crates/node/builder/src/components/pool.rs index 436a80c52..5b08e0a77 100644 --- a/crates/node/builder/src/components/pool.rs +++ b/crates/node/builder/src/components/pool.rs @@ -1,7 +1,8 @@ //! Pool component for the node builder. use alloy_primitives::Address; -use reth_transaction_pool::{PoolConfig, SubPoolLimit, TransactionPool}; +use reth_node_api::TxTy; +use reth_transaction_pool::{PoolConfig, PoolTransaction, SubPoolLimit, TransactionPool}; use std::{collections::HashSet, future::Future}; use crate::{BuilderContext, FullNodeTypes}; @@ -9,7 +10,9 @@ use crate::{BuilderContext, FullNodeTypes}; /// A type that knows how to build the transaction pool. pub trait PoolBuilder: Send { /// The transaction pool to build. - type Pool: TransactionPool + Unpin + 'static; + type Pool: TransactionPool>> + + Unpin + + 'static; /// Creates the transaction pool. fn build_pool( @@ -21,7 +24,9 @@ pub trait PoolBuilder: Send { impl PoolBuilder for F where Node: FullNodeTypes, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future> + Send, { diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 55313f3e9..24b7db77d 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -33,6 +33,7 @@ use reth_rpc_builder::{ use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi}; use reth_tasks::TaskExecutor; use reth_tracing::tracing::{debug, info}; +use reth_transaction_pool::TransactionPool; use crate::EthApiBuilderCtx; @@ -405,6 +406,7 @@ where N: FullNodeComponents< Types: ProviderNodeTypes, PayloadBuilder: PayloadBuilder::Engine>, + Pool: TransactionPool::Transaction>, >, EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static, EV: EngineValidatorBuilder, @@ -527,6 +529,7 @@ where N: FullNodeComponents< Types: ProviderNodeTypes, PayloadBuilder: PayloadBuilder::Engine>, + Pool: TransactionPool::Transaction>, >, EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static, EV: EngineValidatorBuilder, diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 73adcb43f..a13ab9dce 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -13,7 +13,7 @@ use reth_db::transaction::{DbTx, DbTxMut}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo}; use reth_node_api::{ - AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, PayloadBuilder, + AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, PayloadBuilder, TxTy, }; use reth_node_builder::{ components::{ @@ -42,7 +42,7 @@ use reth_provider::{ use reth_rpc_server_types::RethRpcModule; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ - blobstore::DiskFileBlobStore, CoinbaseTipOrdering, TransactionPool, + blobstore::DiskFileBlobStore, CoinbaseTipOrdering, PoolTransaction, TransactionPool, TransactionValidationTaskExecutor, }; use reth_trie_db::MerklePatriciaTrie; @@ -465,7 +465,9 @@ where Primitives = OpPrimitives, >, >, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, Evm: ConfigureEvm
, { let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::new(evm_config) @@ -505,7 +507,9 @@ where Primitives = OpPrimitives, >, >, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, Txs: OpPayloadTransactions, { async fn spawn_payload_service( @@ -577,7 +581,9 @@ impl OpNetworkBuilder { impl NetworkBuilder for OpNetworkBuilder where Node: FullNodeTypes>, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool>> + + Unpin + + 'static, { async fn build_network( self, diff --git a/crates/optimism/node/src/txpool.rs b/crates/optimism/node/src/txpool.rs index d8246aeb7..a3e474a60 100644 --- a/crates/optimism/node/src/txpool.rs +++ b/crates/optimism/node/src/txpool.rs @@ -70,7 +70,7 @@ impl OpTransactionValidator { impl OpTransactionValidator where Client: StateProviderFactory + BlockReaderIdExt, - Tx: EthPoolTransaction, + Tx: EthPoolTransaction, { /// Create a new [`OpTransactionValidator`]. pub fn new(inner: EthTransactionValidator) -> Self { @@ -142,7 +142,7 @@ where let l1_block_info = self.block_info.l1_block_info.read().clone(); let mut encoded = Vec::with_capacity(valid_tx.transaction().encoded_length()); - let tx: TransactionSigned = valid_tx.transaction().clone_into_consensus().into(); + let tx = valid_tx.transaction().clone_into_consensus(); tx.encode_2718(&mut encoded); let cost_addition = match l1_block_info.l1_tx_data_fee( @@ -196,7 +196,7 @@ where impl TransactionValidator for OpTransactionValidator where Client: StateProviderFactory + BlockReaderIdExt, - Tx: EthPoolTransaction, + Tx: EthPoolTransaction, { type Transaction = Tx; diff --git a/crates/optimism/node/tests/it/priority.rs b/crates/optimism/node/tests/it/priority.rs index b5487987f..1b49ed684 100644 --- a/crates/optimism/node/tests/it/priority.rs +++ b/crates/optimism/node/tests/it/priority.rs @@ -30,7 +30,7 @@ use reth_payload_util::{PayloadTransactions, PayloadTransactionsChain, PayloadTr use reth_primitives::{RecoveredTx, SealedBlock, Transaction, TransactionSigned}; use reth_provider::providers::BlockchainProvider2; use reth_tasks::TaskManager; -use reth_transaction_pool::pool::BestPayloadTransactions; +use reth_transaction_pool::{pool::BestPayloadTransactions, PoolTransaction}; use std::sync::Arc; use tokio::sync::Mutex; @@ -44,9 +44,11 @@ impl OpPayloadTransactions for CustomTxPriority { &self, pool: Pool, attr: reth_transaction_pool::BestTransactionsAttributes, - ) -> impl PayloadTransactions + ) -> impl PayloadTransactions where - Pool: reth_transaction_pool::TransactionPool, + Pool: reth_transaction_pool::TransactionPool< + Transaction: PoolTransaction, + >, { // Block composition: // 1. Best transactions from the pool (up to 250k gas) diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 6ae52188d..d385ca795 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -19,12 +19,13 @@ use reth_payload_builder_primitives::PayloadBuilderError; use reth_payload_primitives::PayloadBuilderAttributes; use reth_payload_util::PayloadTransactions; use reth_primitives::{ - proofs, Block, BlockBody, BlockExt, Receipt, SealedHeader, TransactionSigned, TxType, + proofs, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, BlockExt, Receipt, + SealedHeader, TransactionSigned, TxType, }; use reth_provider::{ProviderError, StateProofProvider, StateProviderFactory, StateRootProvider}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{ - noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool, + noop::NoopTransactionPool, BestTransactionsAttributes, PoolTransaction, TransactionPool, }; use reth_trie::HashedPostState; use revm::{ @@ -112,7 +113,7 @@ where ) -> Result, PayloadBuilderError> where Client: StateProviderFactory + ChainSpecProvider, - Pool: TransactionPool, + Pool: TransactionPool>, { let (initialized_cfg, initialized_block_env) = self .cfg_and_block_env(&args.config.attributes, &args.config.parent_header) @@ -213,7 +214,7 @@ where impl PayloadBuilder for OpPayloadBuilder where Client: StateProviderFactory + ChainSpecProvider, - Pool: TransactionPool, + Pool: TransactionPool>, EvmConfig: ConfigureEvm
, Txs: OpPayloadTransactions, { @@ -281,7 +282,7 @@ pub struct OpBuilder { impl OpBuilder where - Pool: TransactionPool, + Pool: TransactionPool>, Txs: OpPayloadTransactions, { /// Executes the payload and returns the outcome. @@ -479,19 +480,23 @@ where pub trait OpPayloadTransactions: Clone + Send + Sync + Unpin + 'static { /// Returns an iterator that yields the transaction in the order they should get included in the /// new payload. - fn best_transactions( + fn best_transactions< + Pool: TransactionPool>, + >( &self, pool: Pool, attr: BestTransactionsAttributes, - ) -> impl PayloadTransactions; + ) -> impl PayloadTransactions; } impl OpPayloadTransactions for () { - fn best_transactions( + fn best_transactions< + Pool: TransactionPool>, + >( &self, pool: Pool, attr: BestTransactionsAttributes, - ) -> impl PayloadTransactions { + ) -> impl PayloadTransactions { BestPayloadTransactions::new(pool.best_transactions_with_attributes(attr)) } } @@ -830,11 +835,10 @@ where &self, info: &mut ExecutionInfo, db: &mut State, - mut best_txs: impl PayloadTransactions, + mut best_txs: impl PayloadTransactions, ) -> Result, PayloadBuilderError> where DB: Database, - Pool: TransactionPool, { let block_gas_limit = self.block_gas_limit(); let base_fee = self.base_fee(); diff --git a/crates/optimism/rpc/src/eth/pending_block.rs b/crates/optimism/rpc/src/eth/pending_block.rs index fec610bb1..9a8d169e5 100644 --- a/crates/optimism/rpc/src/eth/pending_block.rs +++ b/crates/optimism/rpc/src/eth/pending_block.rs @@ -9,7 +9,7 @@ use reth_evm::ConfigureEvm; use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; use reth_primitives::{Receipt, SealedBlockWithSenders}; use reth_provider::{ - BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ExecutionOutcome, + BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ExecutionOutcome, ProviderTx, ReceiptProvider, StateProviderFactory, }; use reth_rpc_eth_api::{ @@ -17,7 +17,7 @@ use reth_rpc_eth_api::{ FromEthApiError, RpcNodeCore, }; use reth_rpc_eth_types::{EthApiError, PendingBlock}; -use reth_transaction_pool::TransactionPool; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; use revm::primitives::BlockEnv; impl LoadPendingBlock for OpEthApi @@ -25,13 +25,14 @@ where Self: SpawnBlocking, N: RpcNodeCore< Provider: BlockReaderIdExt< + Transaction = reth_primitives::TransactionSigned, Block = reth_primitives::Block, Receipt = reth_primitives::Receipt, Header = reth_primitives::Header, > + EvmEnvProvider + ChainSpecProvider + StateProviderFactory, - Pool: TransactionPool, + Pool: TransactionPool>>, Evm: ConfigureEvm
, >, { diff --git a/crates/payload/util/src/traits.rs b/crates/payload/util/src/traits.rs index 5c1eb38be..e9bb7e037 100644 --- a/crates/payload/util/src/traits.rs +++ b/crates/payload/util/src/traits.rs @@ -7,12 +7,15 @@ use reth_primitives::RecoveredTx; /// Can include transactions from the pool and other sources (alternative pools, /// sequencer-originated transactions, etc.). pub trait PayloadTransactions { + /// The transaction type this iterator yields. + type Transaction; + /// Returns the next transaction to include in the block. fn next( &mut self, // In the future, `ctx` can include access to state for block building purposes. ctx: (), - ) -> Option; + ) -> Option>; /// Exclude descendants of the transaction with given sender and nonce from the iterator, /// because this transaction won't be included in the block. diff --git a/crates/payload/util/src/transaction.rs b/crates/payload/util/src/transaction.rs index ebd3b0796..71387946a 100644 --- a/crates/payload/util/src/transaction.rs +++ b/crates/payload/util/src/transaction.rs @@ -26,8 +26,10 @@ impl PayloadTransactionsFixed { } } -impl PayloadTransactions for PayloadTransactionsFixed { - fn next(&mut self, _ctx: ()) -> Option { +impl PayloadTransactions for PayloadTransactionsFixed> { + type Transaction = T; + + fn next(&mut self, _ctx: ()) -> Option> { (self.index < self.transactions.len()).then(|| { let tx = self.transactions[self.index].clone(); self.index += 1; @@ -87,20 +89,22 @@ impl PayloadTransactionsChain PayloadTransactions for PayloadTransactionsChain +impl PayloadTransactions for PayloadTransactionsChain where - B: PayloadTransactions, - A: PayloadTransactions, + A: PayloadTransactions, + B: PayloadTransactions, { - fn next(&mut self, ctx: ()) -> Option { + type Transaction = A::Transaction; + + fn next(&mut self, ctx: ()) -> Option> { while let Some(tx) = self.before.next(ctx) { if let Some(before_max_gas) = self.before_max_gas { - if self.before_gas + tx.transaction.gas_limit() <= before_max_gas { - self.before_gas += tx.transaction.gas_limit(); + if self.before_gas + tx.as_signed().gas_limit() <= before_max_gas { + self.before_gas += tx.as_signed().gas_limit(); return Some(tx); } - self.before.mark_invalid(tx.signer(), tx.transaction.nonce()); - self.after.mark_invalid(tx.signer(), tx.transaction.nonce()); + self.before.mark_invalid(tx.signer(), tx.as_signed().nonce()); + self.after.mark_invalid(tx.signer(), tx.as_signed().nonce()); } else { return Some(tx); } @@ -108,11 +112,11 @@ where while let Some(tx) = self.after.next(ctx) { if let Some(after_max_gas) = self.after_max_gas { - if self.after_gas + tx.transaction.gas_limit() <= after_max_gas { - self.after_gas += tx.transaction.gas_limit(); + if self.after_gas + tx.as_signed().gas_limit() <= after_max_gas { + self.after_gas += tx.as_signed().gas_limit(); return Some(tx); } - self.after.mark_invalid(tx.signer(), tx.transaction.nonce()); + self.after.mark_invalid(tx.signer(), tx.as_signed().nonce()); } else { return Some(tx); } diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index bae221531..6fd8fb55a 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1130,23 +1130,6 @@ impl TransactionSigned { Some(RecoveredTx { signed_transaction: self, signer }) } - /// Tries to recover signer and return [`RecoveredTx`] by cloning the type. - pub fn try_ecrecovered(&self) -> Option { - let signer = self.recover_signer()?; - Some(RecoveredTx { signed_transaction: self.clone(), signer }) - } - - /// Tries to recover signer and return [`RecoveredTx`]. - /// - /// Returns `Err(Self)` if the transaction's signature is invalid, see also - /// [`Self::recover_signer`]. - pub fn try_into_ecrecovered(self) -> Result { - match self.recover_signer() { - None => Err(self), - Some(signer) => Ok(RecoveredTx { signed_transaction: self, signer }), - } - } - /// Tries to recover signer and return [`RecoveredTx`]. _without ensuring that /// the signature has a low `s` value_ (EIP-2). /// @@ -1707,6 +1690,23 @@ impl Encodable2718 for RecoveredTx { /// Extension trait for [`SignedTransaction`] to convert it into [`RecoveredTx`]. pub trait SignedTransactionIntoRecoveredExt: SignedTransaction { + /// Tries to recover signer and return [`RecoveredTx`] by cloning the type. + fn try_ecrecovered(&self) -> Option> { + let signer = self.recover_signer()?; + Some(RecoveredTx { signed_transaction: self.clone(), signer }) + } + + /// Tries to recover signer and return [`RecoveredTx`]. + /// + /// Returns `Err(Self)` if the transaction's signature is invalid, see also + /// [`SignedTransaction::recover_signer`]. + fn try_into_ecrecovered(self) -> Result, Self> { + match self.recover_signer() { + None => Err(self), + Some(signer) => Ok(RecoveredTx { signed_transaction: self, signer }), + } + } + /// Consumes the type, recover signer and return [`RecoveredTx`] _without /// ensuring that the signature has a low `s` value_ (EIP-2). /// diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index e2141dcf1..99912eddf 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -26,7 +26,7 @@ //! RethRpcModule, RpcModuleBuilder, RpcServerConfig, ServerBuilder, TransportRpcModuleConfig, //! }; //! use reth_tasks::TokioTaskExecutor; -//! use reth_transaction_pool::TransactionPool; +//! use reth_transaction_pool::{PoolTransaction, TransactionPool}; //! //! pub async fn launch( //! provider: Provider, @@ -44,7 +44,9 @@ //! Header = reth_primitives::Header, //! > + AccountReader //! + ChangeSetReader, -//! Pool: TransactionPool + Unpin + 'static, +//! Pool: TransactionPool> +//! + Unpin +//! + 'static, //! Network: NetworkInfo + Peers + Clone + 'static, //! Events: //! CanonStateSubscriptions + Clone + 'static, @@ -95,7 +97,7 @@ //! }; //! use reth_rpc_layer::JwtSecret; //! use reth_tasks::TokioTaskExecutor; -//! use reth_transaction_pool::TransactionPool; +//! use reth_transaction_pool::{PoolTransaction, TransactionPool}; //! use tokio::try_join; //! //! pub async fn launch< @@ -125,7 +127,9 @@ //! Header = reth_primitives::Header, //! > + AccountReader //! + ChangeSetReader, -//! Pool: TransactionPool + Unpin + 'static, +//! Pool: TransactionPool> +//! + Unpin +//! + 'static, //! Network: NetworkInfo + Peers + Clone + 'static, //! Events: //! CanonStateSubscriptions + Clone + 'static, @@ -277,7 +281,7 @@ where Header = reth_primitives::Header, > + AccountReader + ChangeSetReader, - Pool: TransactionPool + 'static, + Pool: TransactionPool::Transaction> + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, @@ -674,6 +678,7 @@ where Receipt = ::Receipt, Header = ::Header, >, + Pool: TransactionPool::Transaction>, { let Self { provider, @@ -793,6 +798,7 @@ where Receipt = ::Receipt, Header = ::Header, >, + Pool: TransactionPool::Transaction>, { let mut modules = TransportRpcModules::default(); @@ -1328,7 +1334,7 @@ where Header = ::Header, > + AccountReader + ChangeSetReader, - Pool: TransactionPool + 'static, + Pool: TransactionPool::Transaction> + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index 72d53a22a..782c1a2a8 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -22,7 +22,7 @@ use reth_primitives::{ }; use reth_provider::{ BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderError, - ProviderReceipt, ReceiptProvider, StateProviderFactory, + ProviderReceipt, ProviderTx, ReceiptProvider, StateProviderFactory, }; use reth_revm::{ database::StateProviderDatabase, @@ -33,7 +33,8 @@ use reth_revm::{ }; use reth_rpc_eth_types::{EthApiError, PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin}; use reth_transaction_pool::{ - error::InvalidPoolTransactionError, BestTransactionsAttributes, TransactionPool, + error::InvalidPoolTransactionError, BestTransactionsAttributes, PoolTransaction, + TransactionPool, }; use reth_trie::HashedPostState; use revm::{db::states::bundle_state::BundleRetention, DatabaseCommit, State}; @@ -48,13 +49,14 @@ pub trait LoadPendingBlock: EthApiTypes + RpcNodeCore< Provider: BlockReaderIdExt< + Transaction = reth_primitives::TransactionSigned, Block = reth_primitives::Block, Receipt = reth_primitives::Receipt, Header = reth_primitives::Header, > + EvmEnvProvider + ChainSpecProvider + StateProviderFactory, - Pool: TransactionPool, + Pool: TransactionPool>>, Evm: ConfigureEvm
, > { @@ -319,7 +321,7 @@ pub trait LoadPendingBlock: } // convert tx to a signed transaction - let tx = pool_tx.to_recovered_transaction(); + let tx = pool_tx.to_consensus(); // There's only limited amount of blob space available per block, so we need to check if // the EIP-4844 can still fit in the block diff --git a/crates/rpc/rpc-eth-api/src/helpers/transaction.rs b/crates/rpc/rpc-eth-api/src/helpers/transaction.rs index 43ac03ada..9d77e0119 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/transaction.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/transaction.rs @@ -240,7 +240,7 @@ pub trait EthTransactions: LoadTransaction { RpcNodeCore::pool(self).get_transaction_by_sender_and_nonce(sender, nonce) { let transaction = tx.transaction.clone_into_consensus(); - return Ok(Some(from_recovered(transaction.into(), self.tx_resp_builder())?)); + return Ok(Some(from_recovered(transaction, self.tx_resp_builder())?)); } } @@ -385,7 +385,7 @@ pub trait EthTransactions: LoadTransaction { let pool_transaction = <::Pool as TransactionPool>::Transaction::try_from_consensus( - transaction.into(), + transaction, ) .map_err(|_| EthApiError::TransactionConversionError)?; diff --git a/crates/rpc/rpc-eth-api/src/types.rs b/crates/rpc/rpc-eth-api/src/types.rs index 2bac06848..62af1432b 100644 --- a/crates/rpc/rpc-eth-api/src/types.rs +++ b/crates/rpc/rpc-eth-api/src/types.rs @@ -8,8 +8,9 @@ use std::{ use alloy_network::Network; use alloy_rpc_types_eth::Block; use reth_primitives::TransactionSigned; -use reth_provider::{ReceiptProvider, TransactionsProvider}; +use reth_provider::{ProviderTx, ReceiptProvider, TransactionsProvider}; use reth_rpc_types_compat::TransactionCompat; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; use crate::{AsEthApiError, FromEthApiError, FromEvmError, RpcNodeCore}; @@ -50,6 +51,9 @@ where Self: RpcNodeCore< Provider: TransactionsProvider + ReceiptProvider, + Pool: TransactionPool< + Transaction: PoolTransaction>, + >, > + EthApiTypes< TransactionCompat: TransactionCompat< ::Transaction, @@ -64,6 +68,9 @@ impl FullEthApiTypes for T where T: RpcNodeCore< Provider: TransactionsProvider + ReceiptProvider, + Pool: TransactionPool< + Transaction: PoolTransaction>, + >, > + EthApiTypes< TransactionCompat: TransactionCompat< ::Transaction, diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index c1ef67d9b..6ed72b6ca 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -9,7 +9,7 @@ use alloy_rpc_types_eth::{ use async_trait::async_trait; use jsonrpsee::{core::RpcResult, server::IdProvider}; use reth_chainspec::ChainInfo; -use reth_primitives::{Receipt, RecoveredTx, SealedBlockWithSenders}; +use reth_primitives::{Receipt, SealedBlockWithSenders}; use reth_provider::{BlockIdReader, BlockReader, ProviderError}; use reth_rpc_eth_api::{ EthApiTypes, EthFilterApiServer, FullEthApiTypes, RpcTransaction, TransactionCompat, @@ -145,7 +145,7 @@ where impl EthFilter where Provider: BlockReader + BlockIdReader + 'static, - Pool: TransactionPool + 'static, + Pool: TransactionPool::Transaction> + 'static, Eth: FullEthApiTypes, { /// Returns all the filter changes for the given id, if any @@ -245,7 +245,7 @@ impl EthFilterApiServer> for EthFilter where Provider: BlockReader + BlockIdReader + 'static, - Pool: TransactionPool + 'static, + Pool: TransactionPool::Transaction> + 'static, Eth: FullEthApiTypes + 'static, { /// Handler for `eth_newFilter` @@ -611,7 +611,7 @@ struct FullTransactionsReceiver { impl FullTransactionsReceiver where T: PoolTransaction + 'static, - TxCompat: TransactionCompat, + TxCompat: TransactionCompat, { /// Creates a new `FullTransactionsReceiver` encapsulating the provided transaction stream. fn new(stream: NewSubpoolTransactionStream, tx_resp_builder: TxCompat) -> Self { @@ -619,15 +619,12 @@ where } /// Returns all new pending transactions received since the last poll. - async fn drain(&self) -> FilterChanges - where - T: PoolTransaction>, - { + async fn drain(&self) -> FilterChanges { let mut pending_txs = Vec::new(); let mut prepared_stream = self.txs_stream.lock().await; while let Ok(tx) = prepared_stream.try_recv() { - match from_recovered(tx.transaction.to_recovered_transaction(), &self.tx_resp_builder) { + match from_recovered(tx.transaction.to_consensus(), &self.tx_resp_builder) { Ok(tx) => pending_txs.push(tx), Err(err) => { error!(target: "rpc", @@ -651,8 +648,8 @@ trait FullTransactionsFilter: fmt::Debug + Send + Sync + Unpin + 'static { impl FullTransactionsFilter for FullTransactionsReceiver where - T: PoolTransaction> + 'static, - TxCompat: TransactionCompat + 'static, + T: PoolTransaction + 'static, + TxCompat: TransactionCompat + 'static, { async fn drain(&self) -> FilterChanges { Self::drain(self).await diff --git a/crates/rpc/rpc/src/eth/helpers/pending_block.rs b/crates/rpc/rpc/src/eth/helpers/pending_block.rs index 794b9dde8..34c0ae962 100644 --- a/crates/rpc/rpc/src/eth/helpers/pending_block.rs +++ b/crates/rpc/rpc/src/eth/helpers/pending_block.rs @@ -3,13 +3,15 @@ use alloy_consensus::Header; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_evm::ConfigureEvm; -use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory}; +use reth_provider::{ + BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderTx, StateProviderFactory, +}; use reth_rpc_eth_api::{ helpers::{LoadPendingBlock, SpawnBlocking}, RpcNodeCore, }; use reth_rpc_eth_types::PendingBlock; -use reth_transaction_pool::TransactionPool; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; use crate::EthApi; @@ -19,13 +21,16 @@ where Self: SpawnBlocking + RpcNodeCore< Provider: BlockReaderIdExt< + Transaction = reth_primitives::TransactionSigned, Block = reth_primitives::Block, Receipt = reth_primitives::Receipt, Header = reth_primitives::Header, > + EvmEnvProvider + ChainSpecProvider + StateProviderFactory, - Pool: TransactionPool, + Pool: TransactionPool< + Transaction: PoolTransaction>, + >, Evm: ConfigureEvm
, >, { diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index 8ad809b8b..58c621337 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -23,7 +23,7 @@ use reth_rpc_eth_types::logs_utils; use reth_rpc_server_types::result::{internal_rpc_err, invalid_params_rpc_err}; use reth_rpc_types_compat::transaction::from_recovered; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; -use reth_transaction_pool::{NewTransactionEvent, TransactionPool}; +use reth_transaction_pool::{NewTransactionEvent, PoolConsensusTx, TransactionPool}; use serde::Serialize; use tokio_stream::{ wrappers::{BroadcastStream, ReceiverStream}, @@ -95,7 +95,7 @@ where > + Clone + 'static, Network: NetworkInfo + Clone + 'static, - Eth: TransactionCompat + 'static, + Eth: TransactionCompat> + 'static, { /// Handler for `eth_subscribe` async fn subscribe( @@ -135,7 +135,7 @@ where > + Clone + 'static, Network: NetworkInfo + Clone + 'static, - Eth: TransactionCompat, + Eth: TransactionCompat>, { match kind { SubscriptionKind::NewHeads => { @@ -165,7 +165,7 @@ where // full transaction objects requested let stream = pubsub.full_pending_transaction_stream().filter_map(|tx| { let tx_value = match from_recovered( - tx.transaction.to_recovered_transaction(), + tx.transaction.to_consensus(), &tx_resp_builder, ) { Ok(tx) => { diff --git a/crates/rpc/rpc/src/txpool.rs b/crates/rpc/rpc/src/txpool.rs index b12e8e7ab..4709c9878 100644 --- a/crates/rpc/rpc/src/txpool.rs +++ b/crates/rpc/rpc/src/txpool.rs @@ -8,10 +8,11 @@ use alloy_rpc_types_txpool::{ }; use async_trait::async_trait; use jsonrpsee::core::RpcResult; -use reth_primitives::RecoveredTx; use reth_rpc_api::TxPoolApiServer; use reth_rpc_types_compat::{transaction::from_recovered, TransactionCompat}; -use reth_transaction_pool::{AllPoolTransactions, PoolTransaction, TransactionPool}; +use reth_transaction_pool::{ + AllPoolTransactions, PoolConsensusTx, PoolTransaction, TransactionPool, +}; use tracing::trace; /// `txpool` API implementation. @@ -33,8 +34,8 @@ impl TxPoolApi { impl TxPoolApi where - Pool: TransactionPool + 'static, - Eth: TransactionCompat, + Pool: TransactionPool> + 'static, + Eth: TransactionCompat>, { fn content(&self) -> Result, Eth::Error> { #[inline] @@ -44,12 +45,12 @@ where resp_builder: &RpcTxB, ) -> Result<(), RpcTxB::Error> where - Tx: PoolTransaction>, - RpcTxB: TransactionCompat, + Tx: PoolTransaction, + RpcTxB: TransactionCompat, { content.entry(tx.sender()).or_default().insert( tx.nonce().to_string(), - from_recovered(tx.clone_into_consensus().into(), resp_builder)?, + from_recovered(tx.clone_into_consensus(), resp_builder)?, ); Ok(()) @@ -72,8 +73,8 @@ where #[async_trait] impl TxPoolApiServer for TxPoolApi where - Pool: TransactionPool + 'static, - Eth: TransactionCompat + 'static, + Pool: TransactionPool> + 'static, + Eth: TransactionCompat> + 'static, { /// Returns the number of transactions currently pending for inclusion in the next block(s), as /// well as the ones that are being scheduled for future execution only. @@ -96,19 +97,19 @@ where trace!(target: "rpc::eth", "Serving txpool_inspect"); #[inline] - fn insert>>( + fn insert>( tx: &T, inspect: &mut BTreeMap>, ) { let entry = inspect.entry(tx.sender()).or_default(); - let tx: RecoveredTx = tx.clone_into_consensus().into(); + let tx = tx.clone_into_consensus(); entry.insert( tx.nonce().to_string(), TxpoolInspectSummary { to: tx.to(), value: tx.value(), gas: tx.gas_limit() as u128, - gas_price: tx.transaction.max_fee_per_gas(), + gas_price: tx.max_fee_per_gas(), }, ); } diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 7e28b6e26..fa7b75e34 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -10,6 +10,7 @@ use crate::{ use alloy_consensus::BlockHeader; use alloy_eips::BlockNumberOrTag; use alloy_primitives::{Address, BlockHash, BlockNumber}; +use alloy_rlp::Encodable; use futures_util::{ future::{BoxFuture, Fuse, FusedFuture}, FutureExt, Stream, StreamExt, @@ -19,7 +20,8 @@ use reth_chainspec::{ChainSpecProvider, EthChainSpec}; use reth_execution_types::ChangedAccount; use reth_fs_util::FsPathError; use reth_primitives::{ - PooledTransactionsElementEcRecovered, RecoveredTx, SealedHeader, TransactionSigned, + transaction::SignedTransactionIntoRecoveredExt, PooledTransactionsElementEcRecovered, + SealedHeader, TransactionSigned, }; use reth_primitives_traits::SignedTransaction; use reth_storage_api::{errors::provider::ProviderError, BlockReaderIdExt, StateProviderFactory}; @@ -78,7 +80,7 @@ pub fn maintain_transaction_pool_future( ) -> BoxFuture<'static, ()> where Client: StateProviderFactory + BlockReaderIdExt + ChainSpecProvider + Clone + Send + 'static, - P: TransactionPoolExt + 'static, + P: TransactionPoolExt> + 'static, St: Stream + Send + Unpin + 'static, Tasks: TaskSpawner + 'static, { @@ -99,7 +101,7 @@ pub async fn maintain_transaction_pool( config: MaintainPoolConfig, ) where Client: StateProviderFactory + BlockReaderIdExt + ChainSpecProvider + Clone + Send + 'static, - P: TransactionPoolExt + 'static, + P: TransactionPoolExt> + 'static, St: Stream + Send + Unpin + 'static, Tasks: TaskSpawner + 'static, { @@ -342,7 +344,7 @@ pub async fn maintain_transaction_pool(

::Transaction::from_pooled(tx.into()) }) } else { -

::Transaction::try_from_consensus(tx.into()).ok() +

::Transaction::try_from_consensus(tx).ok() } }) .collect::>(); @@ -559,7 +561,7 @@ async fn load_and_reinsert_transactions

( file_path: &Path, ) -> Result<(), TransactionsBackupError> where - P: TransactionPool, + P: TransactionPool>, { if !file_path.exists() { return Ok(()) @@ -572,14 +574,15 @@ where return Ok(()) } - let txs_signed: Vec = alloy_rlp::Decodable::decode(&mut data.as_slice())?; + let txs_signed: Vec<::Consensus> = + alloy_rlp::Decodable::decode(&mut data.as_slice())?; let pool_transactions = txs_signed .into_iter() .filter_map(|tx| tx.try_ecrecovered()) .filter_map(|tx| { // Filter out errors - ::try_from_consensus(tx.into()).ok() + ::try_from_consensus(tx).ok() }) .collect(); @@ -592,7 +595,7 @@ where fn save_local_txs_backup

(pool: P, file_path: &Path) where - P: TransactionPool, + P: TransactionPool>, { let local_transactions = pool.get_local_transactions(); if local_transactions.is_empty() { @@ -602,10 +605,7 @@ where let local_transactions = local_transactions .into_iter() - .map(|tx| { - let recovered: RecoveredTx = tx.transaction.clone_into_consensus().into(); - recovered.into_signed() - }) + .map(|tx| tx.transaction.clone_into_consensus().into_signed()) .collect::>(); let num_txs = local_transactions.len(); @@ -645,7 +645,7 @@ pub async fn backup_local_transactions_task

( pool: P, config: LocalTransactionBackupConfig, ) where - P: TransactionPool + Clone, + P: TransactionPool> + Clone, { let Some(transactions_path) = config.transactions_path else { // nothing to do diff --git a/crates/transaction-pool/src/pool/best.rs b/crates/transaction-pool/src/pool/best.rs index be49ce0b1..b770e3da4 100644 --- a/crates/transaction-pool/src/pool/best.rs +++ b/crates/transaction-pool/src/pool/best.rs @@ -226,7 +226,7 @@ impl Iterator for BestTransactions { #[derive(Debug)] pub struct BestPayloadTransactions where - T: PoolTransaction>, + T: PoolTransaction, I: Iterator>>, { invalid: HashSet

, @@ -235,7 +235,7 @@ where impl BestPayloadTransactions where - T: PoolTransaction>, + T: PoolTransaction, I: Iterator>>, { /// Create a new `BestPayloadTransactions` with the given iterator. @@ -246,16 +246,18 @@ where impl PayloadTransactions for BestPayloadTransactions where - T: PoolTransaction>, + T: PoolTransaction, I: Iterator>>, { - fn next(&mut self, _ctx: ()) -> Option { + type Transaction = T::Consensus; + + fn next(&mut self, _ctx: ()) -> Option> { loop { let tx = self.best.next()?; if self.invalid.contains(&tx.sender()) { continue } - return Some(tx.to_recovered_transaction()) + return Some(tx.to_consensus()) } } diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index 05551151d..471956fdc 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -592,15 +592,17 @@ impl MockTransaction { impl PoolTransaction for MockTransaction { type TryFromConsensusError = TryFromRecoveredTransactionError; - type Consensus = RecoveredTx; + type Consensus = TransactionSigned; type Pooled = PooledTransactionsElementEcRecovered; - fn try_from_consensus(tx: Self::Consensus) -> Result { + fn try_from_consensus( + tx: RecoveredTx, + ) -> Result { tx.try_into() } - fn into_consensus(self) -> Self::Consensus { + fn into_consensus(self) -> RecoveredTx { self.into() } @@ -609,7 +611,7 @@ impl PoolTransaction for MockTransaction { } fn try_consensus_into_pooled( - tx: Self::Consensus, + tx: RecoveredTx, ) -> Result { Self::Pooled::try_from(tx).map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing) } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index a5c85ce12..6d4d562b3 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -38,6 +38,9 @@ use tokio::sync::mpsc::Receiver; /// The `PeerId` type. pub type PeerId = alloy_primitives::B512; +/// Helper type alias to access [`PoolTransaction::Consensus`] for a given [`TransactionPool`]. +pub type PoolConsensusTx

= <

::Transaction as PoolTransaction>::Consensus; + /// General purpose abstraction of a transaction-pool. /// /// This is intended to be used by API-consumers such as RPC that need inject new incoming, @@ -577,17 +580,17 @@ pub struct AllPoolTransactions { impl AllPoolTransactions { /// Returns an iterator over all pending [`RecoveredTx`] transactions. - pub fn pending_recovered(&self) -> impl Iterator + '_ { + pub fn pending_recovered(&self) -> impl Iterator> + '_ { self.pending.iter().map(|tx| tx.transaction.clone().into()) } /// Returns an iterator over all queued [`RecoveredTx`] transactions. - pub fn queued_recovered(&self) -> impl Iterator + '_ { + pub fn queued_recovered(&self) -> impl Iterator> + '_ { self.queued.iter().map(|tx| tx.transaction.clone().into()) } /// Returns an iterator over all transactions, both pending and queued. - pub fn all(&self) -> impl Iterator + '_ { + pub fn all(&self) -> impl Iterator> + '_ { self.pending.iter().chain(self.queued.iter()).map(|tx| tx.transaction.clone().into()) } } @@ -963,30 +966,39 @@ impl BestTransactionsAttributes { /// This distinction is necessary for the EIP-4844 blob transactions, which require an additional /// sidecar when they are gossiped around the network. It is expected that the `Consensus` format is /// a subset of the `Pooled` format. -pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone { +pub trait PoolTransaction: + fmt::Debug + + Send + + Sync + + Clone + + TryFrom, Error = Self::TryFromConsensusError> + + Into> +{ /// Associated error type for the `try_from_consensus` method. type TryFromConsensusError: fmt::Display; /// Associated type representing the raw consensus variant of the transaction. - type Consensus: From + TryInto; + type Consensus; /// Associated type representing the recovered pooled variant of the transaction. type Pooled: Encodable2718 + Into; /// Define a method to convert from the `Consensus` type to `Self` - fn try_from_consensus(tx: Self::Consensus) -> Result { + fn try_from_consensus( + tx: RecoveredTx, + ) -> Result { tx.try_into() } /// Clone the transaction into a consensus variant. /// /// This method is preferred when the [`PoolTransaction`] already wraps the consensus variant. - fn clone_into_consensus(&self) -> Self::Consensus { + fn clone_into_consensus(&self) -> RecoveredTx { self.clone().into_consensus() } /// Define a method to convert from the `Self` type to `Consensus` - fn into_consensus(self) -> Self::Consensus { + fn into_consensus(self) -> RecoveredTx { self.into() } @@ -1002,7 +1014,7 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone { /// Tries to convert the `Consensus` type into the `Pooled` type. fn try_consensus_into_pooled( - tx: Self::Consensus, + tx: RecoveredTx, ) -> Result; /// Hash of the transaction. @@ -1131,7 +1143,6 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone { /// Ethereum pool. pub trait EthPoolTransaction: PoolTransaction< - Consensus: From + Into + Into, Pooled: From + Into + Into, @@ -1242,16 +1253,16 @@ impl From for EthPooledTransaction { impl PoolTransaction for EthPooledTransaction { type TryFromConsensusError = TryFromRecoveredTransactionError; - type Consensus = RecoveredTx; + type Consensus = TransactionSigned; type Pooled = PooledTransactionsElementEcRecovered; - fn clone_into_consensus(&self) -> Self::Consensus { + fn clone_into_consensus(&self) -> RecoveredTx { self.transaction().clone() } fn try_consensus_into_pooled( - tx: Self::Consensus, + tx: RecoveredTx, ) -> Result { Self::Pooled::try_from(tx).map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing) } diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index d333be879..6c6253734 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -378,7 +378,7 @@ impl ValidPoolTransaction { /// Converts to this type into the consensus transaction of the pooled transaction. /// /// Note: this takes `&self` since indented usage is via `Arc`. - pub fn to_consensus(&self) -> T::Consensus { + pub fn to_consensus(&self) -> RecoveredTx { self.transaction.clone_into_consensus() } @@ -435,15 +435,6 @@ impl ValidPoolTransaction { } } -impl>> ValidPoolTransaction { - /// Converts to this type into a [`RecoveredTx`]. - /// - /// Note: this takes `&self` since indented usage is via `Arc`. - pub fn to_recovered_transaction(&self) -> RecoveredTx { - self.to_consensus().into() - } -} - #[cfg(test)] impl Clone for ValidPoolTransaction { fn clone(&self) -> Self { diff --git a/examples/custom-engine-types/src/main.rs b/examples/custom-engine-types/src/main.rs index f9ac5c238..1034effeb 100644 --- a/examples/custom-engine-types/src/main.rs +++ b/examples/custom-engine-types/src/main.rs @@ -38,14 +38,14 @@ use reth::{ }, network::NetworkHandle, payload::ExecutionPayloadValidator, - primitives::{Block, EthPrimitives, SealedBlockFor}, + primitives::{Block, EthPrimitives, SealedBlockFor, TransactionSigned}, providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory}, rpc::{ eth::EthApi, types::engine::{ExecutionPayload, ExecutionPayloadSidecar, PayloadError}, }, tasks::TaskManager, - transaction_pool::TransactionPool, + transaction_pool::{PoolTransaction, TransactionPool}, }; use reth_basic_payload_builder::{ BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome, @@ -340,7 +340,9 @@ where Primitives = EthPrimitives, >, >, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, { async fn spawn_payload_service( self, @@ -380,7 +382,7 @@ pub struct CustomPayloadBuilder; impl PayloadBuilder for CustomPayloadBuilder where Client: StateProviderFactory + ChainSpecProvider, - Pool: TransactionPool, + Pool: TransactionPool>, { type Attributes = CustomPayloadBuilderAttributes; type BuiltPayload = EthBuiltPayload; diff --git a/examples/custom-evm/src/main.rs b/examples/custom-evm/src/main.rs index e7999818a..d9e341c02 100644 --- a/examples/custom-evm/src/main.rs +++ b/examples/custom-evm/src/main.rs @@ -20,7 +20,7 @@ use reth::{ }, rpc::types::engine::PayloadAttributes, tasks::TaskManager, - transaction_pool::TransactionPool, + transaction_pool::{PoolTransaction, TransactionPool}, }; use reth_chainspec::{Chain, ChainSpec}; use reth_evm_ethereum::EthEvmConfig; @@ -183,7 +183,9 @@ impl PayloadServiceBuilder for MyPayloadBuilder where Types: NodeTypesWithEngine, Node: FullNodeTypes, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, Types::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, PayloadAttributes = PayloadAttributes, diff --git a/examples/custom-inspector/src/main.rs b/examples/custom-inspector/src/main.rs index 67863d00e..6b25c46b7 100644 --- a/examples/custom-inspector/src/main.rs +++ b/examples/custom-inspector/src/main.rs @@ -54,8 +54,7 @@ fn main() { if let Some(recipient) = tx.to() { if args.is_match(&recipient) { // convert the pool transaction - let call_request = - transaction_to_call_request(tx.to_recovered_transaction()); + let call_request = transaction_to_call_request(tx.to_consensus()); let result = eth_api .spawn_with_call_at( diff --git a/examples/custom-payload-builder/src/main.rs b/examples/custom-payload-builder/src/main.rs index 6047da0dd..d7c42e341 100644 --- a/examples/custom-payload-builder/src/main.rs +++ b/examples/custom-payload-builder/src/main.rs @@ -17,14 +17,14 @@ use reth::{ cli::{config::PayloadBuilderConfig, Cli}, payload::PayloadBuilderHandle, providers::CanonStateSubscriptions, - transaction_pool::TransactionPool, + transaction_pool::{PoolTransaction, TransactionPool}, }; use reth_basic_payload_builder::BasicPayloadJobGeneratorConfig; use reth_chainspec::ChainSpec; use reth_node_api::NodeTypesWithEngine; use reth_node_ethereum::{node::EthereumAddOns, EthEngineTypes, EthEvmConfig, EthereumNode}; use reth_payload_builder::PayloadBuilderService; -use reth_primitives::EthPrimitives; +use reth_primitives::{EthPrimitives, TransactionSigned}; pub mod generator; pub mod job; @@ -42,7 +42,9 @@ where Primitives = EthPrimitives, >, >, - Pool: TransactionPool + Unpin + 'static, + Pool: TransactionPool> + + Unpin + + 'static, { async fn spawn_payload_service( self, diff --git a/examples/txpool-tracing/src/main.rs b/examples/txpool-tracing/src/main.rs index 94f800987..76abd65f4 100644 --- a/examples/txpool-tracing/src/main.rs +++ b/examples/txpool-tracing/src/main.rs @@ -44,8 +44,7 @@ fn main() { if let Some(recipient) = tx.to() { if args.is_match(&recipient) { // trace the transaction with `trace_call` - let callrequest = - transaction_to_call_request(tx.to_recovered_transaction()); + let callrequest = transaction_to_call_request(tx.to_consensus()); let tracerequest = TraceCallRequest::new(callrequest) .with_trace_type(TraceType::Trace); if let Ok(trace_result) = traceapi.trace_call(tracerequest).await {