Skip to content

Commit

Permalink
consensus/auto-seal: simiply the complete_header for op or non-op (#6870
Browse files Browse the repository at this point in the history
)

Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa authored Feb 29, 2024
1 parent 559124a commit f829633
Showing 1 changed file with 13 additions and 45 deletions.
58 changes: 13 additions & 45 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,13 @@ impl StorageInner {

/// Fills in the post-execution header fields based on the given BundleState and gas used.
/// In doing this, the state root is calculated and the final header is returned.
///
/// This is optimism-specific and contains the `ChainSpec` so the proper state root can be
/// calculated.
#[cfg(feature = "optimism")]
pub(crate) fn complete_header<S: StateProviderFactory>(
&self,
mut header: Header,
bundle_state: &BundleStateWithReceipts,
client: &S,
gas_used: u64,
chain_spec: &ChainSpec,
#[cfg(feature = "optimism")] chain_spec: &ChainSpec,
) -> Result<Header, BlockExecutionError> {
let receipts = bundle_state.receipts_by_block(header.number);
header.receipts_root = if receipts.is_empty() {
Expand All @@ -369,46 +365,18 @@ impl StorageInner {
.collect::<Vec<ReceiptWithBloom>>();
header.logs_bloom =
receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | r.bloom);
proofs::calculate_receipt_root_optimism(
&receipts_with_bloom,
chain_spec,
header.timestamp,
)
};

header.gas_used = gas_used;

// calculate the state root
let state_root = client
.latest()
.map_err(|_| BlockExecutionError::ProviderError)?
.state_root(bundle_state)
.unwrap();
header.state_root = state_root;
Ok(header)
}

/// Fills in the post-execution header fields based on the given BundleState and gas used.
/// In doing this, the state root is calculated and the final header is returned.
#[cfg(not(feature = "optimism"))]
pub(crate) fn complete_header<S: StateProviderFactory>(
&self,
mut header: Header,
bundle_state: &BundleStateWithReceipts,
client: &S,
gas_used: u64,
) -> Result<Header, BlockExecutionError> {
let receipts = bundle_state.receipts_by_block(header.number);
header.receipts_root = if receipts.is_empty() {
EMPTY_RECEIPTS
} else {
let receipts_with_bloom = receipts
.iter()
.map(|r| (*r).clone().expect("receipts have not been pruned").into())
.collect::<Vec<ReceiptWithBloom>>();
header.logs_bloom =
receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | r.bloom);
proofs::calculate_receipt_root(&receipts_with_bloom)
#[cfg(feature = "optimism")]
{
proofs::calculate_receipt_root_optimism(
&receipts_with_bloom,
chain_spec,
header.timestamp,
)
}
#[cfg(not(feature = "optimism"))]
{
proofs::calculate_receipt_root(&receipts_with_bloom)
}
};

header.gas_used = gas_used;
Expand Down

0 comments on commit f829633

Please sign in to comment.