diff --git a/crates/payload/ethereum/src/lib.rs b/crates/payload/ethereum/src/lib.rs index e17802ea7d..610ee9af71 100644 --- a/crates/payload/ethereum/src/lib.rs +++ b/crates/payload/ethereum/src/lib.rs @@ -120,6 +120,25 @@ mod builder { err })?; + let mut excess_blob_gas = None; + let mut blob_gas_used = None; + + if chain_spec.is_cancun_active_at_timestamp(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(calculate_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used)) + } else { + // for the first post-fork block, both parent.blob_gas_used and + // parent.excess_blob_gas are evaluated as 0 + Some(calculate_excess_blob_gas(0, 0)) + }; + + blob_gas_used = Some(0); + } + let header = Header { parent_hash: parent_block.hash, ommers_hash: EMPTY_OMMER_ROOT_HASH, @@ -138,8 +157,8 @@ mod builder { difficulty: U256::ZERO, gas_used: 0, extra_data, - blob_gas_used: None, - excess_blob_gas: None, + blob_gas_used, + excess_blob_gas, parent_beacon_block_root: attributes.parent_beacon_block_root, }; diff --git a/crates/primitives/src/header.rs b/crates/primitives/src/header.rs index 10acec149f..bb195e0dd5 100644 --- a/crates/primitives/src/header.rs +++ b/crates/primitives/src/header.rs @@ -423,6 +423,12 @@ impl Encodable for Header { self.mix_hash.encode(out); // Encode mix hash. B64::new(self.nonce.to_be_bytes()).encode(out); // Encode nonce. + // The following code is needed only to handle proptest-generated headers that are + // technically invalid. + // + // TODO: make proptest generate more valid headers, ie if there is no base fee, there + // should be no withdrawals root or any future fork field. + // Encode base fee. Put empty list if base fee is missing, // but withdrawals root is present. if let Some(ref base_fee) = self.base_fee_per_gas {