Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use cache to determine hardfork #6989

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/node-api/src/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}

Expand Down
5 changes: 2 additions & 3 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use reth_primitives::{
stage::{StageCheckpoint, StageId},
trie::Nibbles,
Account, Address, Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders,
ChainInfo, ChainSpec, GotExpected, Hardfork, Head, Header, PruneCheckpoint, PruneModes,
ChainInfo, ChainSpec, GotExpected, Head, Header, PruneCheckpoint, PruneModes,
PruneSegment, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment,
StorageEntry, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
TransactionSignedNoHash, TxHash, TxNumber, Withdrawal, Withdrawals, B256, U256,
Expand Down Expand Up @@ -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() {
Expand Down
Loading