chore: pass generic header and body to validate_shanghai_withdrawals (#12923)

This commit is contained in:
Tien Nguyen
2024-11-28 14:49:27 +07:00
committed by GitHub
parent 2179301590
commit 0df02ca2b9
3 changed files with 8 additions and 5 deletions

1
Cargo.lock generated
View File

@ -6827,6 +6827,7 @@ dependencies = [
"reth-chainspec",
"reth-consensus",
"reth-primitives",
"reth-primitives-traits",
"reth-storage-api",
"revm-primitives",
]

View File

@ -19,6 +19,7 @@ reth-consensus.workspace = true
# ethereum
alloy-primitives.workspace = true
revm-primitives.workspace = true
reth-primitives-traits.workspace = true
alloy-consensus.workspace = true
alloy-eips.workspace = true

View File

@ -41,15 +41,16 @@ pub fn validate_header_base_fee<H: BlockHeader, ChainSpec: EthereumHardforks>(
///
/// [EIP-4895]: https://eips.ethereum.org/EIPS/eip-4895
#[inline]
pub fn validate_shanghai_withdrawals(block: &SealedBlock) -> Result<(), ConsensusError> {
let withdrawals =
block.body.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
pub fn validate_shanghai_withdrawals<H: BlockHeader, B: reth_primitives_traits::BlockBody>(
block: &SealedBlock<H, B>,
) -> Result<(), ConsensusError> {
let withdrawals = block.body.withdrawals().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
let withdrawals_root = reth_primitives::proofs::calculate_withdrawals_root(withdrawals);
let header_withdrawals_root =
block.withdrawals_root.as_ref().ok_or(ConsensusError::WithdrawalsRootMissing)?;
block.withdrawals_root().ok_or(ConsensusError::WithdrawalsRootMissing)?;
if withdrawals_root != *header_withdrawals_root {
return Err(ConsensusError::BodyWithdrawalsRootDiff(
GotExpected { got: withdrawals_root, expected: *header_withdrawals_root }.into(),
GotExpected { got: withdrawals_root, expected: header_withdrawals_root }.into(),
));
}
Ok(())