@@ -30,7 +30,7 @@ use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
3030use reth_ethereum_primitives:: { Block , EthPrimitives , TransactionSigned } ;
3131use reth_evm:: {
3232 eth:: NextEvmEnvAttributes , precompiles:: PrecompilesMap , ConfigureEvm , EvmEnv , EvmFactory ,
33- JitBackend , NextBlockEnvAttributes , TransactionEnvMut ,
33+ JitBackend , NextBlockEnvAttributes , SenderRecoveryCache , TransactionEnvMut ,
3434} ;
3535use reth_primitives_traits:: { SealedBlock , SealedHeader } ;
3636use revm:: { context:: BlockEnv , primitives:: hardfork:: SpecId } ;
@@ -87,6 +87,8 @@ pub struct EthEvmConfig<C = ChainSpec, EvmFactory = EthEvmFactory> {
8787 pub executor_factory : EthBlockExecutorFactory < RethReceiptBuilder , Arc < C > , EvmFactory > ,
8888 /// Ethereum block assembler.
8989 pub block_assembler : EthBlockAssembler < C > ,
90+ /// Cache of recovered transaction senders.
91+ pub sender_recovery_cache : SenderRecoveryCache ,
9092}
9193
9294impl EthEvmConfig {
@@ -113,6 +115,7 @@ impl<ChainSpec, EvmFactory> EthEvmConfig<ChainSpec, EvmFactory> {
113115 pub fn new_with_evm_factory ( chain_spec : Arc < ChainSpec > , evm_factory : EvmFactory ) -> Self {
114116 Self {
115117 block_assembler : EthBlockAssembler :: new ( chain_spec. clone ( ) ) ,
118+ sender_recovery_cache : SenderRecoveryCache :: default ( ) ,
116119 executor_factory : EthBlockExecutorFactory :: new (
117120 RethReceiptBuilder :: default ( ) ,
118121 chain_spec,
@@ -125,6 +128,12 @@ impl<ChainSpec, EvmFactory> EthEvmConfig<ChainSpec, EvmFactory> {
125128 pub const fn chain_spec ( & self ) -> & Arc < ChainSpec > {
126129 self . executor_factory . spec ( )
127130 }
131+
132+ /// Uses the provided sender recovery cache.
133+ pub fn with_sender_recovery_cache ( mut self , cache : SenderRecoveryCache ) -> Self {
134+ self . sender_recovery_cache = cache;
135+ self
136+ }
128137}
129138
130139impl < ChainSpec , EvmF > ConfigureEvm for EthEvmConfig < ChainSpec , EvmF >
@@ -345,10 +354,11 @@ where
345354 payload : & ExecutionData ,
346355 ) -> Result < impl ExecutableTxIterator < Self > , Self :: Error > {
347356 let txs = payload. payload . transactions ( ) . clone ( ) ;
348- let convert = |tx : Bytes | {
357+ let sender_recovery_cache = self . sender_recovery_cache . clone ( ) ;
358+ let convert = move |tx : Bytes | {
349359 let tx =
350360 TxTy :: < Self :: Primitives > :: decode_2718_exact ( tx. as_ref ( ) ) . map_err ( AnyError :: new) ?;
351- let signer = tx . try_recover ( ) . map_err ( AnyError :: new) ?;
361+ let signer = sender_recovery_cache . recover ( & tx ) . map_err ( AnyError :: new) ?;
352362 Ok :: < _ , AnyError > ( tx. with_signer ( signer) )
353363 } ;
354364
0 commit comments