Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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];
Expand All @@ -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>
Expand Down
Loading