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 7ed0174 commit be20af2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ serde = { workspace = true, optional = true}
arbitrary = { workspace = true, features = ["derive"], optional = true }
proptest = { workspace = true, optional = true }
proptest-arbitrary-interop = { workspace = true, optional = true }
rayon = { workspace = true, optional = true }

[dev-dependencies]
reth-codecs.workspace = true
Expand Down Expand Up @@ -142,3 +143,6 @@ reth-codec = [
op = [
"dep:op-alloy-consensus",
]
rayon = [
"dep:rayon",
]
23 changes: 22 additions & 1 deletion crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use alloc::{fmt, vec::Vec};
use alloy_consensus::{Header, Transaction};
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_primitives::{Bytes, B256};
use alloy_primitives::{Address, Bytes, B256};

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> + MaybeSerdeBincodeCompat {}
Expand Down Expand Up @@ -97,6 +97,27 @@ pub trait BlockBody:
fn encoded_2718_transactions(&self) -> Vec<Bytes> {
self.encoded_2718_transactions_iter().map(Into::into).collect()
}

/// Recover signer addresses for all transactions in the block body.
#[cfg(feature = "rayon")]
fn recover_signers(&self) -> Option<Vec<Address>>
where
Self::Transaction: SignedTransaction,
{
recover_signers(self.transactions(), self.transactions().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`].
fn recover_signers_unchecked(&self) -> Option<Vec<Address>>
where
Self::Transaction: SignedTransaction,
{
recover_signers_unchecked(self.transactions(), self.transactions().len())
}
}

impl<T> BlockBody for alloy_consensus::BlockBody<T>
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ where
impl<H, B> SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
B: reth_primitives_traits::BlockBody + BlockExt,
B: reth_primitives_traits::BlockBody,
{
/// Expensive operation that recovers transaction signer. See [`SealedBlockWithSenders`].
pub fn senders(&self) -> Option<Vec<Address>>
Expand Down
29 changes: 3 additions & 26 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.recover_signers()
self.body().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.recover_signers_unchecked() else { return Err(self) };
let Some(senders) = self.body().recover_signers_unchecked() else { return Err(self) };
senders
};

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

/// Recover signer addresses for all transactions in the block body.
#[cfg(feature = "rayon")]
fn recover_signers(&self) -> Option<Vec<Address>>
where
<Self::Body as BlockBody>::Transaction: SignedTransaction,
{
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.
#[cfg(feature = "rayon")]
fn recover_signers_unchecked(&self) -> Option<Vec<Address>>
where
<Self::Body as BlockBody>::Transaction: SignedTransaction,
{
let txs = self.body().transactions();
recover_signers_unchecked(txs, txs.len())
}
}

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

0 comments on commit be20af2

Please sign in to comment.