mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use cache to determine hardfork (#6989)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -33,17 +33,16 @@ pub fn validate_header_standalone(
|
||||
let wd_root_missing = header.withdrawals_root.is_none() && !chain_spec.is_optimism();
|
||||
|
||||
// EIP-4895: Beacon chain push withdrawals as operations
|
||||
if chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(header.timestamp) && wd_root_missing
|
||||
{
|
||||
if chain_spec.is_shanghai_active_at_timestamp(header.timestamp) && wd_root_missing {
|
||||
return Err(ConsensusError::WithdrawalsRootMissing)
|
||||
} else if !chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(header.timestamp) &&
|
||||
} else if !chain_spec.is_shanghai_active_at_timestamp(header.timestamp) &&
|
||||
header.withdrawals_root.is_some()
|
||||
{
|
||||
return Err(ConsensusError::WithdrawalsRootUnexpected)
|
||||
}
|
||||
|
||||
// Ensures that EIP-4844 fields are valid once cancun is active.
|
||||
if chain_spec.fork(Hardfork::Cancun).active_at_timestamp(header.timestamp) {
|
||||
if chain_spec.is_cancun_active_at_timestamp(header.timestamp) {
|
||||
validate_4844_header_standalone(header)?;
|
||||
} else if header.blob_gas_used.is_some() {
|
||||
return Err(ConsensusError::BlobGasUsedUnexpected)
|
||||
@ -109,7 +108,7 @@ pub fn validate_transaction_regarding_header(
|
||||
..
|
||||
}) => {
|
||||
// EIP-4844: Shard Blob Transactions https://eips.ethereum.org/EIPS/eip-4844
|
||||
if !chain_spec.fork(Hardfork::Cancun).active_at_timestamp(at_timestamp) {
|
||||
if !chain_spec.is_cancun_active_at_timestamp(at_timestamp) {
|
||||
return Err(InvalidTransactionError::Eip4844Disabled.into())
|
||||
}
|
||||
|
||||
@ -219,7 +218,7 @@ pub fn validate_block_standalone(
|
||||
}
|
||||
|
||||
// EIP-4895: Beacon chain push withdrawals as operations
|
||||
if chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(block.timestamp) {
|
||||
if chain_spec.is_shanghai_active_at_timestamp(block.timestamp) {
|
||||
let withdrawals =
|
||||
block.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
|
||||
let withdrawals_root = reth_primitives::proofs::calculate_withdrawals_root(withdrawals);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! This contains the [EngineTypes] trait and implementations for ethereum mainnet types.
|
||||
|
||||
use core::fmt;
|
||||
use reth_primitives::{ChainSpec, Hardfork};
|
||||
use reth_primitives::ChainSpec;
|
||||
|
||||
/// Contains traits to abstract over payload attributes types and default implementations of the
|
||||
/// [PayloadAttributes] trait for ethereum mainnet and optimism types.
|
||||
@ -119,7 +119,7 @@ pub fn validate_withdrawals_presence(
|
||||
timestamp: u64,
|
||||
has_withdrawals: bool,
|
||||
) -> Result<(), AttributesValidationError> {
|
||||
let is_shanghai = chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(timestamp);
|
||||
let is_shanghai = chain_spec.is_shanghai_active_at_timestamp(timestamp);
|
||||
|
||||
match version {
|
||||
EngineApiMessageVersion::V1 => {
|
||||
|
||||
@ -549,7 +549,7 @@ impl ChainSpec {
|
||||
// * blob gas used to provided genesis or 0x0
|
||||
// * excess blob gas to provided genesis or 0x0
|
||||
let (parent_beacon_block_root, blob_gas_used, excess_blob_gas) =
|
||||
if self.fork(Hardfork::Cancun).active_at_timestamp(self.genesis.timestamp) {
|
||||
if self.is_cancun_active_at_timestamp(self.genesis.timestamp) {
|
||||
let blob_gas_used = self.genesis.blob_gas_used.unwrap_or(0);
|
||||
let excess_blob_gas = self.genesis.excess_blob_gas.unwrap_or(0);
|
||||
(Some(B256::ZERO), Some(blob_gas_used), Some(excess_blob_gas))
|
||||
|
||||
@ -775,7 +775,7 @@ impl SealedHeader {
|
||||
}
|
||||
|
||||
// ensure that the blob gas fields for this block
|
||||
if chain_spec.fork(Hardfork::Cancun).active_at_timestamp(self.timestamp) {
|
||||
if chain_spec.is_cancun_active_at_timestamp(self.timestamp) {
|
||||
self.validate_4844_header_against_parent(parent)?;
|
||||
}
|
||||
|
||||
|
||||
@ -37,10 +37,10 @@ use reth_primitives::{
|
||||
stage::{StageCheckpoint, StageId},
|
||||
trie::Nibbles,
|
||||
Account, Address, Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders,
|
||||
ChainInfo, ChainSpec, GotExpected, Hardfork, Head, Header, PruneCheckpoint, PruneModes,
|
||||
PruneSegment, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment,
|
||||
StorageEntry, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
|
||||
TransactionSignedNoHash, TxHash, TxNumber, Withdrawal, Withdrawals, B256, U256,
|
||||
ChainInfo, ChainSpec, GotExpected, Head, Header, PruneCheckpoint, PruneModes, PruneSegment,
|
||||
Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment, StorageEntry,
|
||||
TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
|
||||
TxHash, TxNumber, Withdrawal, Withdrawals, B256, U256,
|
||||
};
|
||||
use reth_trie::{
|
||||
prefix_set::{PrefixSet, PrefixSetMut, TriePrefixSets},
|
||||
@ -706,8 +706,7 @@ impl<TX: DbTxMut + DbTx> DatabaseProvider<TX> {
|
||||
};
|
||||
|
||||
// withdrawal can be missing
|
||||
let shanghai_is_active =
|
||||
chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(header.timestamp);
|
||||
let shanghai_is_active = chain_spec.is_shanghai_active_at_timestamp(header.timestamp);
|
||||
let mut withdrawals = Some(Withdrawals::default());
|
||||
if shanghai_is_active {
|
||||
if let Some((block_number, _)) = block_withdrawals.as_ref() {
|
||||
|
||||
Reference in New Issue
Block a user