chore: relax more consensus functions (#13236)

This commit is contained in:
Matthias Seitz
2024-12-09 19:26:32 +01:00
committed by GitHub
parent a3e90e18b6
commit 3af2afe995
5 changed files with 79 additions and 61 deletions

View File

@ -296,6 +296,40 @@ impl SealedBlock {
}
}
impl<H, B> SealedBlock<H, B>
where
H: alloy_consensus::BlockHeader,
B: reth_primitives_traits::BlockBody,
{
/// Ensures that the transaction root in the block header is valid.
///
/// The transaction root is the Keccak 256-bit hash of the root node of the trie structure
/// populated with each transaction in the transactions list portion of the block.
///
/// # Returns
///
/// Returns `Ok(())` if the calculated transaction root matches the one stored in the header,
/// indicating that the transactions in the block are correctly represented in the trie.
///
/// Returns `Err(error)` if the transaction root validation fails, providing a `GotExpected`
/// error containing the calculated and expected roots.
pub fn ensure_transaction_root_valid(&self) -> Result<(), GotExpected<B256>>
where
B::Transaction: Encodable2718,
{
let calculated_root = self.body.calculate_tx_root();
if self.header.transactions_root() != calculated_root {
return Err(GotExpected {
got: calculated_root,
expected: self.header.transactions_root(),
})
}
Ok(())
}
}
impl<H, B> SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
@ -385,34 +419,6 @@ where
Block::new(self.header.unseal(), self.body)
}
/// Ensures that the transaction root in the block header is valid.
///
/// The transaction root is the Keccak 256-bit hash of the root node of the trie structure
/// populated with each transaction in the transactions list portion of the block.
///
/// # Returns
///
/// Returns `Ok(())` if the calculated transaction root matches the one stored in the header,
/// indicating that the transactions in the block are correctly represented in the trie.
///
/// Returns `Err(error)` if the transaction root validation fails, providing a `GotExpected`
/// error containing the calculated and expected roots.
pub fn ensure_transaction_root_valid(&self) -> Result<(), GotExpected<B256>>
where
B::Transaction: Encodable2718,
{
let calculated_root = self.body.calculate_tx_root();
if self.header.transactions_root() != calculated_root {
return Err(GotExpected {
got: calculated_root,
expected: self.header.transactions_root(),
})
}
Ok(())
}
/// Returns a vector of encoded 2718 transactions.
///
/// This is also known as `raw transactions`.