Skip to content

Commit

Permalink
bet
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Jan 1, 2025
1 parent c0a8a7b commit 7ed0174
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 3 additions & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ derive_more.workspace = true
modular-bitfield = { workspace = true, optional = true }
once_cell.workspace = true
rand = { workspace = true, optional = true }
rayon.workspace = true
rayon = {workspace = true, optional = true }
serde.workspace = true
serde_with = { workspace = true, optional = true }

Expand Down Expand Up @@ -183,6 +183,8 @@ serde-bincode-compat = [
"reth-primitives-traits/serde-bincode-compat",
"reth-trie-common/serde-bincode-compat",
]
rayon = ["dep:rayon"]


[[bench]]
name = "recover_ecdsa_crit"
Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
traits::BlockExt, transaction::SignedTransactionIntoRecoveredExt, BlockBodyTxExt, GotExpected,
RecoveredTx, SealedHeader, TransactionSigned,
traits::BlockExt, transaction::SignedTransactionIntoRecoveredExt, GotExpected, RecoveredTx,
SealedHeader, TransactionSigned,
};
use alloc::vec::Vec;
use alloy_consensus::Header;
Expand Down Expand Up @@ -259,7 +259,7 @@ where
impl<H, B> SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
B: reth_primitives_traits::BlockBody,
B: reth_primitives_traits::BlockBody + BlockExt,
{
/// Expensive operation that recovers transaction signer. See [`SealedBlockWithSenders`].
pub fn senders(&self) -> Option<Vec<Address>>
Expand Down
26 changes: 12 additions & 14 deletions crates/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait BlockExt: Block {
where
<Self::Body as BlockBody>::Transaction: SignedTransaction,
{
self.body().recover_signers()
self.recover_signers()
}

/// Transform into a [`BlockWithSenders`].
Expand Down Expand Up @@ -66,7 +66,7 @@ pub trait BlockExt: Block {
let senders = if self.body().transactions().len() == senders.len() {
senders
} else {
let Some(senders) = self.body().recover_signers_unchecked() else { return Err(self) };
let Some(senders) = self.recover_signers_unchecked() else { return Err(self) };
senders
};

Expand All @@ -84,31 +84,29 @@ pub trait BlockExt: Block {
let senders = self.senders()?;
Some(BlockWithSenders::new_unchecked(self, senders))
}
}

impl<T: Block> BlockExt for T {}

/// Extension trait for [`BlockBody`] adding helper methods operating with transactions.
pub trait BlockBodyTxExt: BlockBody {
/// Recover signer addresses for all transactions in the block body.
#[cfg(feature = "rayon")]
fn recover_signers(&self) -> Option<Vec<Address>>
where
Self::Transaction: SignedTransaction,
<Self::Body as BlockBody>::Transaction: SignedTransaction,
{
recover_signers(self.transactions(), self.transactions().len())
let txs = self.body().transactions();
recover_signers(txs, txs.len())
}

/// Recover signer addresses for all transactions in the block body _without ensuring that the
/// signature has a low `s` value_.
///
/// Returns `None`, if some transaction's signature is invalid, see also
/// [`recover_signers_unchecked`].
/// Returns `None`, if some transaction's signature is invalid.
#[cfg(feature = "rayon")]
fn recover_signers_unchecked(&self) -> Option<Vec<Address>>
where
Self::Transaction: SignedTransaction,
<Self::Body as BlockBody>::Transaction: SignedTransaction,
{
recover_signers_unchecked(self.transactions(), self.transactions().len())
let txs = self.body().transactions();
recover_signers_unchecked(txs, txs.len())
}
}

impl<T: BlockBody> BlockBodyTxExt for T {}
impl<T: Block> BlockExt for T {}

0 comments on commit 7ed0174

Please sign in to comment.