chore: remove rayon from reth primitives (#13711)

This commit is contained in:
Matthias Seitz
2025-01-07 22:00:48 +01:00
committed by GitHub
parent 7fca8ceb3f
commit 760062288e
5 changed files with 5 additions and 48 deletions

1
Cargo.lock generated
View File

@ -8660,7 +8660,6 @@ dependencies = [
"proptest", "proptest",
"proptest-arbitrary-interop", "proptest-arbitrary-interop",
"rand 0.8.5", "rand 0.8.5",
"rayon",
"reth-chainspec", "reth-chainspec",
"reth-codecs", "reth-codecs",
"reth-ethereum-forks", "reth-ethereum-forks",

View File

@ -53,7 +53,6 @@ derive_more.workspace = true
modular-bitfield = { workspace = true, optional = true } modular-bitfield = { workspace = true, optional = true }
once_cell.workspace = true once_cell.workspace = true
rand = { workspace = true, optional = true } rand = { workspace = true, optional = true }
rayon.workspace = true
serde.workspace = true serde.workspace = true
serde_with = { workspace = true, optional = true } serde_with = { workspace = true, optional = true }

View File

@ -26,7 +26,6 @@ use op_alloy_consensus::DepositTransaction;
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
use op_alloy_consensus::TxDeposit; use op_alloy_consensus::TxDeposit;
pub use pooled::PooledTransactionsElementEcRecovered; pub use pooled::PooledTransactionsElementEcRecovered;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
pub use reth_primitives_traits::{ pub use reth_primitives_traits::{
sync::{LazyLock, OnceLock}, sync::{LazyLock, OnceLock},
transaction::{ transaction::{
@ -51,15 +50,6 @@ pub mod util;
mod pooled; mod pooled;
mod tx_type; mod tx_type;
/// Expected number of transactions where we can expect a speed-up by recovering the senders in
/// parallel.
pub static PARALLEL_SENDER_RECOVERY_THRESHOLD: LazyLock<usize> =
LazyLock::new(|| match rayon::current_num_threads() {
0..=1 => usize::MAX,
2..=8 => 10,
_ => 5,
});
/// A raw transaction. /// A raw transaction.
/// ///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). /// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
@ -1724,37 +1714,6 @@ pub mod serde_bincode_compat {
} }
} }
/// Recovers a list of signers from a transaction list iterator.
///
/// Returns `None`, if some transaction's signature is invalid
pub fn recover_signers<'a, I, T>(txes: I, num_txes: usize) -> Option<Vec<Address>>
where
T: SignedTransaction,
I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
{
if num_txes < *PARALLEL_SENDER_RECOVERY_THRESHOLD {
txes.into_iter().map(|tx| tx.recover_signer()).collect()
} else {
txes.into_par_iter().map(|tx| tx.recover_signer()).collect()
}
}
/// Recovers a list of signers from a transaction list iterator _without ensuring that the
/// signature has a low `s` value_.
///
/// Returns `None`, if some transaction's signature is invalid.
pub fn recover_signers_unchecked<'a, I, T>(txes: I, num_txes: usize) -> Option<Vec<Address>>
where
T: SignedTransaction,
I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
{
if num_txes < *PARALLEL_SENDER_RECOVERY_THRESHOLD {
txes.into_iter().map(|tx| tx.recover_signer_unchecked()).collect()
} else {
txes.into_par_iter().map(|tx| tx.recover_signer_unchecked()).collect()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{

View File

@ -18,8 +18,7 @@ use reth_db::{
table::{Decompress, Value}, table::{Decompress, Value},
}; };
use reth_node_types::NodePrimitives; use reth_node_types::NodePrimitives;
use reth_primitives::{transaction::recover_signers, SealedHeader}; use reth_primitives_traits::{SealedHeader, SignedTransaction};
use reth_primitives_traits::SignedTransaction;
use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::{ use std::{
fmt::Debug, fmt::Debug,
@ -297,7 +296,8 @@ impl<N: NodePrimitives<SignedTx: Decompress + SignedTransaction>> TransactionsPr
range: impl RangeBounds<TxNumber>, range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Address>> { ) -> ProviderResult<Vec<Address>> {
let txs = self.transactions_by_tx_range(range)?; let txs = self.transactions_by_tx_range(range)?;
recover_signers(&txs, txs.len()).ok_or(ProviderError::SenderRecoveryError) reth_primitives_traits::transaction::recover::recover_signers(&txs)
.ok_or(ProviderError::SenderRecoveryError)
} }
fn transaction_sender(&self, num: TxNumber) -> ProviderResult<Option<Address>> { fn transaction_sender(&self, num: TxNumber) -> ProviderResult<Option<Address>> {

View File

@ -33,7 +33,6 @@ use reth_primitives::{
find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive,
DEFAULT_BLOCKS_PER_STATIC_FILE, DEFAULT_BLOCKS_PER_STATIC_FILE,
}, },
transaction::recover_signers,
BlockWithSenders, Receipt, SealedBlockFor, SealedBlockWithSenders, SealedHeader, BlockWithSenders, Receipt, SealedBlockFor, SealedBlockWithSenders, SealedHeader,
StaticFileSegment, TransactionSigned, StaticFileSegment, TransactionSigned,
}; };
@ -1554,7 +1553,8 @@ impl<N: NodePrimitives<SignedTx: Decompress + SignedTransaction>> TransactionsPr
range: impl RangeBounds<TxNumber>, range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Address>> { ) -> ProviderResult<Vec<Address>> {
let txes = self.transactions_by_tx_range(range)?; let txes = self.transactions_by_tx_range(range)?;
recover_signers(&txes, txes.len()).ok_or(ProviderError::SenderRecoveryError) reth_primitives_traits::transaction::recover::recover_signers(&txes)
.ok_or(ProviderError::SenderRecoveryError)
} }
fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>> { fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>> {