mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: re-add validate_against_parent_4844 to optimism header validation (#8835)
This commit is contained in:
@ -6,6 +6,7 @@ use reth_primitives::{
|
||||
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
|
||||
MAXIMUM_EXTRA_DATA_SIZE,
|
||||
},
|
||||
eip4844::calculate_excess_blob_gas,
|
||||
ChainSpec, GotExpected, Hardfork, Header, SealedBlock, SealedHeader,
|
||||
};
|
||||
|
||||
@ -229,6 +230,41 @@ pub fn validate_against_parent_timestamp(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validates that the EIP-4844 header fields are correct with respect to the parent block. This
|
||||
/// ensures that the `blob_gas_used` and `excess_blob_gas` fields exist in the child header, and
|
||||
/// that the `excess_blob_gas` field matches the expected `excess_blob_gas` calculated from the
|
||||
/// parent header fields.
|
||||
pub fn validate_against_parent_4844(
|
||||
header: &SealedHeader,
|
||||
parent: &SealedHeader,
|
||||
) -> Result<(), ConsensusError> {
|
||||
// From [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#header-extension):
|
||||
//
|
||||
// > For the first post-fork block, both parent.blob_gas_used and parent.excess_blob_gas
|
||||
// > are evaluated as 0.
|
||||
//
|
||||
// This means in the first post-fork block, calculate_excess_blob_gas will return 0.
|
||||
let parent_blob_gas_used = parent.blob_gas_used.unwrap_or(0);
|
||||
let parent_excess_blob_gas = parent.excess_blob_gas.unwrap_or(0);
|
||||
|
||||
if header.blob_gas_used.is_none() {
|
||||
return Err(ConsensusError::BlobGasUsedMissing)
|
||||
}
|
||||
let excess_blob_gas = header.excess_blob_gas.ok_or(ConsensusError::ExcessBlobGasMissing)?;
|
||||
|
||||
let expected_excess_blob_gas =
|
||||
calculate_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used);
|
||||
if expected_excess_blob_gas != excess_blob_gas {
|
||||
return Err(ConsensusError::ExcessBlobGasDiff {
|
||||
diff: GotExpected { got: excess_blob_gas, expected: expected_excess_blob_gas },
|
||||
parent_excess_blob_gas,
|
||||
parent_blob_gas_used,
|
||||
})
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user