chore(op): simplify blob fields in newly built block header (#12035)

This commit is contained in:
Hai | RISE
2024-10-27 00:02:14 +07:00
committed by GitHub
parent 1bdf429af5
commit ab07fcfb11
3 changed files with 11 additions and 28 deletions

1
Cargo.lock generated
View File

@ -8279,7 +8279,6 @@ dependencies = [
"reth-transaction-pool", "reth-transaction-pool",
"reth-trie", "reth-trie",
"revm", "revm",
"revm-primitives",
"sha2 0.10.8", "sha2 0.10.8",
"thiserror", "thiserror",
"tracing", "tracing",

View File

@ -39,7 +39,6 @@ alloy-eips.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-rlp.workspace = true alloy-rlp.workspace = true
op-alloy-rpc-types-engine.workspace = true op-alloy-rpc-types-engine.workspace = true
revm-primitives.workspace = true
alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true alloy-consensus.workspace = true
@ -56,5 +55,4 @@ optimism = [
"revm/optimism", "revm/optimism",
"reth-execution-types/optimism", "reth-execution-types/optimism",
"reth-optimism-consensus/optimism", "reth-optimism-consensus/optimism",
"revm-primitives/optimism"
] ]

View File

@ -7,12 +7,12 @@ use alloy_eips::merge::BEACON_NONCE;
use alloy_primitives::U256; use alloy_primitives::U256;
use reth_basic_payload_builder::*; use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock; 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_evm::{system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; 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_payload_primitives::{PayloadBuilderAttributes, PayloadBuilderError};
use reth_primitives::{ use reth_primitives::{
proofs, proofs,
@ -30,7 +30,6 @@ use revm::{
primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState}, primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState},
DatabaseCommit, DatabaseCommit,
}; };
use revm_primitives::calc_excess_blob_gas;
use tracing::{debug, trace, warn}; use tracing::{debug, trace, warn};
use crate::{ use crate::{
@ -460,26 +459,16 @@ where
// create the block header // create the block header
let transactions_root = proofs::calculate_transaction_root(&executed_txs); let transactions_root = proofs::calculate_transaction_root(&executed_txs);
// initialize empty blob sidecars. There are no blob transactions on L2. // OP doesn't support blobs/EIP-4844.
let blob_sidecars = Vec::new(); // https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions
let mut excess_blob_gas = None; // Need [Some] or [None] based on hardfork to match block hash.
let mut blob_gas_used = None; let (excess_blob_gas, blob_gas_used) =
if chain_spec.is_ecotone_active_at_timestamp(attributes.payload_attributes.timestamp) {
// only determine cancun fields when active (Some(0), Some(0))
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))
} else { } else {
// for the first post-fork block, both parent.blob_gas_used and (None, None)
// parent.excess_blob_gas are evaluated as 0
Some(calc_excess_blob_gas(0, 0))
}; };
blob_gas_used = Some(0);
}
let header = Header { let header = Header {
parent_hash: parent_block.hash(), parent_hash: parent_block.hash(),
ommers_hash: EMPTY_OMMER_ROOT_HASH, ommers_hash: EMPTY_OMMER_ROOT_HASH,
@ -500,7 +489,7 @@ where
extra_data, extra_data,
parent_beacon_block_root: attributes.payload_attributes.parent_beacon_block_root, parent_beacon_block_root: attributes.payload_attributes.parent_beacon_block_root,
blob_gas_used, blob_gas_used,
excess_blob_gas: excess_blob_gas.map(Into::into), excess_blob_gas,
requests_hash: None, requests_hash: None,
}; };
@ -524,7 +513,7 @@ where
let no_tx_pool = attributes.no_tx_pool; let no_tx_pool = attributes.no_tx_pool;
let mut payload = OptimismBuiltPayload::new( let payload = OptimismBuiltPayload::new(
attributes.payload_attributes.id, attributes.payload_attributes.id,
sealed_block, sealed_block,
total_fees, total_fees,
@ -533,9 +522,6 @@ where
Some(executed), Some(executed),
); );
// extend the payload with the blob sidecars from the executed txs
payload.extend_sidecars(blob_sidecars);
if no_tx_pool { if no_tx_pool {
// if `no_tx_pool` is set only transactions from the payload attributes will be included in // if `no_tx_pool` is set only transactions from the payload attributes will be included in
// the payload. In other words, the payload is deterministic and we can freeze it once we've // the payload. In other words, the payload is deterministic and we can freeze it once we've