chore: add default impls for withdrawals and ommers root (#13229)

This commit is contained in:
Matthias Seitz
2024-12-09 15:59:18 +01:00
committed by GitHub
parent 233f893a93
commit 3e859058cd

View File

@ -1,7 +1,7 @@
//! Block body abstraction.
use crate::{
FullSignedTx, InMemorySize, MaybeArbitrary, MaybeSerde, MaybeSerdeBincodeCompat,
BlockHeader, FullSignedTx, InMemorySize, MaybeArbitrary, MaybeSerde, MaybeSerdeBincodeCompat,
SignedTransaction,
};
use alloc::{fmt, vec::Vec};
@ -36,7 +36,7 @@ pub trait BlockBody:
type Transaction: SignedTransaction;
/// Ommer header type.
type OmmerHeader;
type OmmerHeader: BlockHeader;
/// Returns reference to transactions in block.
fn transactions(&self) -> &[Self::Transaction];
@ -52,9 +52,25 @@ pub trait BlockBody:
/// Returns block withdrawals if any.
fn withdrawals(&self) -> Option<&Withdrawals>;
/// Calculate the withdrawals root for the block body.
///
/// Returns `None` if there are no withdrawals in the block.
fn calculate_withdrawals_root(&self) -> Option<B256> {
self.withdrawals().map(|withdrawals| {
alloy_consensus::proofs::calculate_withdrawals_root(withdrawals.as_slice())
})
}
/// Returns block ommers if any.
fn ommers(&self) -> Option<&[Self::OmmerHeader]>;
/// Calculate the ommers root for the block body.
///
/// Returns `None` if there are no ommers in the block.
fn calculate_ommers_root(&self) -> Option<B256> {
self.ommers().map(alloy_consensus::proofs::calculate_ommers_root)
}
/// Calculates the total blob gas used by _all_ EIP-4844 transactions in the block.
fn blob_gas_used(&self) -> u64 {
// TODO(mattss): simplify after <https://github.com/alloy-rs/alloy/pull/1704>