fix: set excess blob gas and blob gas used for empty payloads (#6328)

This commit is contained in:
Dan Cline
2024-02-01 12:11:46 -05:00
committed by GitHub
parent 9f82af20f9
commit 7f2167f1bd
2 changed files with 27 additions and 2 deletions

View File

@@ -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,
};

View File

@@ -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 {