Skip to content

Commit

Permalink
feat: move is_empty to trait function (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 4, 2024
1 parent 35f4712 commit 7095b64
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/consensus/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ impl Header {
keccak256(&out)
}

/// Checks if the header is empty - has no transactions and no ommers
pub fn is_empty(&self) -> bool {
let txs_and_ommers_empty = self.transaction_root_is_empty() && self.ommers_hash_is_empty();
self.withdrawals_root.map_or(txs_and_ommers_empty, |withdrawals_root| {
txs_and_ommers_empty && withdrawals_root == EMPTY_ROOT_HASH
})
}

/// Check if the ommers hash equals to empty hash list.
pub fn ommers_hash_is_empty(&self) -> bool {
self.ommers_hash == EMPTY_OMMER_ROOT_HASH
Expand Down Expand Up @@ -723,6 +715,15 @@ pub trait BlockHeader {
fn parent_num_hash(&self) -> BlockNumHash {
BlockNumHash { number: self.number().saturating_sub(1), hash: self.parent_hash() }
}

/// Checks if the header is considered empty - has no transactions, no ommers or withdrawals
fn is_empty(&self) -> bool {
let txs_and_ommers_empty = self.transactions_root() == EMPTY_ROOT_HASH
&& self.ommers_hash() == EMPTY_OMMER_ROOT_HASH;
self.withdrawals_root().map_or(txs_and_ommers_empty, |withdrawals_root| {
txs_and_ommers_empty && withdrawals_root == EMPTY_ROOT_HASH
})
}
}

impl BlockHeader for Header {
Expand Down Expand Up @@ -904,6 +905,10 @@ impl<T: BlockHeader> BlockHeader for alloy_serde::WithOtherFields<T> {
fn target_blobs_per_block(&self) -> Option<u64> {
self.inner.target_blobs_per_block()
}

fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}

/// Bincode-compatibl [`Header`] serde implementation.
Expand Down

0 comments on commit 7095b64

Please sign in to comment.