diff --git a/Cargo.lock b/Cargo.lock index 997d83087b..984cb8c1a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5820,7 +5820,6 @@ dependencies = [ "proptest", "proptest-derive", "rand 0.8.5", - "rayon", "reth-codecs", "reth-rlp", "reth-rlp-derive", diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index afd47662f1..7b14f544a4 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -349,8 +349,10 @@ impl StorageInner { let block = Block { header, body: transactions, ommers: vec![], withdrawals: None }; - let senders = TransactionSigned::recover_signers(block.body.iter(), block.body.len()) - .ok_or(BlockExecutionError::Validation(BlockValidationError::SenderRecoveryError))?; + let senders = + block.body.iter().map(|tx| tx.recover_signer()).collect::>>().ok_or( + BlockExecutionError::Validation(BlockValidationError::SenderRecoveryError), + )?; trace!(target: "consensus::auto", transactions=?&block.body, "executing transactions"); diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 8394559219..e73b59d885 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -60,7 +60,6 @@ impl-serde = "0.4.0" once_cell = "1.17.0" zstd = { version = "0.12", features = ["experimental"] } paste = "1.0" -rayon = "1.7" # proof related triehash = "0.8" diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 6ae1a8e062..0c9866ba28 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -163,7 +163,7 @@ impl SealedBlock { /// Expensive operation that recovers transaction signer. See [SealedBlockWithSenders]. pub fn senders(&self) -> Option> { - TransactionSigned::recover_signers(self.body.iter(), self.body.len()) + self.body.iter().map(|tx| tx.recover_signer()).collect::>>() } /// Seal sealed block with recovered transaction senders. diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index fae91a3318..d3f03e0820 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -7,7 +7,6 @@ use bytes::{Buf, BytesMut}; use derive_more::{AsRef, Deref}; pub use error::InvalidTransactionError; pub use meta::TransactionMeta; -use rayon::prelude::{ParallelBridge, ParallelIterator}; use reth_codecs::{add_arbitrary_tests, derive_arbitrary, Compact}; use reth_rlp::{ length_of_length, Decodable, DecodeError, Encodable, Header, EMPTY_LIST_CODE, EMPTY_STRING_CODE, @@ -33,10 +32,6 @@ mod signature; mod tx_type; pub(crate) mod util; -// Expected number of transactions where we can expect a speed-up by recovering the senders in -// parallel. -const PARALLEL_SENDER_RECOVERY_THRESHOLD: usize = 10; - /// A raw transaction. /// /// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). @@ -942,21 +937,6 @@ impl TransactionSigned { self.signature.recover_signer(signature_hash) } - /// Recovers a list of signers from a transaction list iterator - /// - /// Returns `None`, if some transaction's signature is invalid, see also - /// [Self::recover_signer]. - pub fn recover_signers<'a>( - txes: impl Iterator + Send, - num_txes: usize, - ) -> Option> { - if num_txes < PARALLEL_SENDER_RECOVERY_THRESHOLD { - txes.map(|tx| tx.recover_signer()).collect() - } else { - txes.cloned().par_bridge().map(|tx| tx.recover_signer()).collect() - } - } - /// Consumes the type, recover signer and return [`TransactionSignedEcRecovered`] /// /// Returns `None` if the transaction's signature is invalid, see also [Self::recover_signer]. diff --git a/crates/revm/src/executor.rs b/crates/revm/src/executor.rs index e52bdb4bc1..5ce714521f 100644 --- a/crates/revm/src/executor.rs +++ b/crates/revm/src/executor.rs @@ -84,8 +84,11 @@ where Err(BlockValidationError::SenderRecoveryError.into()) } } else { - TransactionSigned::recover_signers(body.iter(), body.len()) - .ok_or(BlockValidationError::SenderRecoveryError.into()) + body.iter() + .map(|tx| { + tx.recover_signer().ok_or(BlockValidationError::SenderRecoveryError.into()) + }) + .collect() } } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index fe691b0441..56d4c0f392 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -22,10 +22,7 @@ use reth_db::{ transaction::{DbTx, DbTxMut}, BlockNumberList, DatabaseError, }; -use reth_interfaces::{ - executor::{BlockExecutionError, BlockValidationError}, - Result, -}; +use reth_interfaces::Result; use reth_primitives::{ keccak256, stage::{StageCheckpoint, StageId}, @@ -1913,12 +1910,14 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> BlockWriter for DatabaseProvider<' let tx_iter = if Some(block.body.len()) == senders_len { block.body.into_iter().zip(senders.unwrap()).collect::>() } else { - let senders = TransactionSigned::recover_signers(block.body.iter(), block.body.len()) - .ok_or(BlockExecutionError::Validation( - BlockValidationError::SenderRecoveryError, - ))?; - - block.body.into_iter().zip(senders).collect() + block + .body + .into_iter() + .map(|tx| { + let signer = tx.recover_signer(); + (tx, signer.unwrap_or_default()) + }) + .collect::>() }; for (transaction, sender) in tx_iter {