Skip to content

Commit

Permalink
chore(op): simplify blob fields in newly built block header
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-rise committed Oct 25, 2024
1 parent 2ae7ee5 commit 36861ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/optimism/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
op-alloy-rpc-types-engine.workspace = true
revm-primitives.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true

Expand All @@ -56,5 +55,4 @@ optimism = [
"revm/optimism",
"reth-execution-types/optimism",
"reth-optimism-consensus/optimism",
"revm-primitives/optimism"
]
36 changes: 11 additions & 25 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use alloy_eips::merge::BEACON_NONCE;
use alloy_primitives::U256;
use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock;
use reth_chainspec::{ChainSpecProvider, EthereumHardforks};
use reth_chainspec::ChainSpecProvider;
use reth_evm::{system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_execution_types::ExecutionOutcome;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
use reth_optimism_forks::OptimismHardfork;
use reth_optimism_forks::{OptimismHardfork, OptimismHardforks};
use reth_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError};
use reth_primitives::{
proofs,
Expand All @@ -30,7 +30,6 @@ use revm::{
primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState},
DatabaseCommit,
};
use revm_primitives::calc_excess_blob_gas;
use tracing::{debug, trace, warn};

use crate::{
Expand Down Expand Up @@ -460,26 +459,16 @@ where
// create the block header
let transactions_root = proofs::calculate_transaction_root(&executed_txs);

// initialize empty blob sidecars. There are no blob transactions on L2.
let blob_sidecars = Vec::new();
let mut excess_blob_gas = None;
let mut blob_gas_used = None;

// only determine cancun fields when active
if chain_spec.is_cancun_active_at_timestamp(attributes.payload_attributes.timestamp) {
excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_block.timestamp) {
let parent_excess_blob_gas = parent_block.excess_blob_gas.unwrap_or_default();
let parent_blob_gas_used = parent_block.blob_gas_used.unwrap_or_default();
Some(calc_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used))
// OP doesn't support blobs/EIP-4844.
// https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions
// Need [Some] or [None] based on hardfork to match block hash.
let (excess_blob_gas, blob_gas_used) =
if chain_spec.is_ecotone_active_at_timestamp(attributes.payload_attributes.timestamp) {
(Some(0), Some(0))
} else {
// for the first post-fork block, both parent.blob_gas_used and
// parent.excess_blob_gas are evaluated as 0
Some(calc_excess_blob_gas(0, 0))
(None, None)
};

blob_gas_used = Some(0);
}

let header = Header {
parent_hash: parent_block.hash(),
ommers_hash: EMPTY_OMMER_ROOT_HASH,
Expand All @@ -500,7 +489,7 @@ where
extra_data,
parent_beacon_block_root: attributes.payload_attributes.parent_beacon_block_root,
blob_gas_used,
excess_blob_gas: excess_blob_gas.map(Into::into),
excess_blob_gas,
requests_hash: None,
};

Expand All @@ -522,7 +511,7 @@ where
trie: Arc::new(trie_output),
};

let mut payload = OptimismBuiltPayload::new(
let payload = OptimismBuiltPayload::new(
attributes.payload_attributes.id,
sealed_block,
total_fees,
Expand All @@ -531,8 +520,5 @@ where
Some(executed),
);

// extend the payload with the blob sidecars from the executed txs
payload.extend_sidecars(blob_sidecars);

Ok(BuildOutcome::Better { payload, cached_reads })
}

0 comments on commit 36861ac

Please sign in to comment.