Skip to content

Commit

Permalink
feat: use new ChainHardforks type on ChainSpec (#9065)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Jun 27, 2024
1 parent c23fe39 commit 50ee497
Show file tree
Hide file tree
Showing 57 changed files with 1,704 additions and 1,461 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use reth_evm::execute::BlockExecutorProvider;
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{
BlockHash, BlockNumHash, BlockNumber, ForkBlock, GotExpected, Hardfork, Receipt, SealedBlock,
SealedBlockWithSenders, SealedHeader, StaticFileSegment, B256, U256,
BlockHash, BlockNumHash, BlockNumber, EthereumHardfork, ForkBlock, GotExpected, Receipt,
SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment, B256, U256,
};
use reth_provider::{
BlockExecutionWriter, BlockNumReader, BlockWriter, CanonStateNotification,
Expand Down Expand Up @@ -402,7 +402,7 @@ where
.externals
.provider_factory
.chain_spec()
.fork(Hardfork::Paris)
.fork(EthereumHardfork::Paris)
.active_at_ttd(parent_td, U256::ZERO)
{
return Err(BlockExecutionError::Validation(BlockValidationError::BlockPreMerge {
Expand Down Expand Up @@ -1043,7 +1043,7 @@ where
.externals
.provider_factory
.chain_spec()
.fork(Hardfork::Paris)
.fork(EthereumHardfork::Paris)
.active_at_ttd(td, U256::ZERO)
{
return Err(CanonicalError::from(BlockValidationError::BlockPreMerge {
Expand Down
665 changes: 313 additions & 352 deletions crates/chainspec/src/spec.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use reth_beacon_consensus::BeaconEngineMessage;
use reth_chainspec::ChainSpec;
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use reth_engine_primitives::EngineTypes;
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2492,7 +2492,7 @@ mod tests {
use super::*;
use alloy_genesis::Genesis;
use reth_db::test_utils::create_test_static_files_dir;
use reth_primitives::{Hardfork, U256};
use reth_primitives::{EthereumHardfork, U256};
use reth_provider::{
providers::StaticFileProvider, test_utils::blocks::BlockchainTestData,
};
Expand Down Expand Up @@ -2721,9 +2721,9 @@ mod tests {
async fn payload_pre_merge() {
let data = BlockchainTestData::default();
let mut block1 = data.blocks[0].0.block.clone();
block1
.header
.set_difficulty(MAINNET.fork(Hardfork::Paris).ttd().unwrap() - U256::from(1));
block1.header.set_difficulty(
MAINNET.fork(EthereumHardfork::Paris).ttd().unwrap() - U256::from(1),
);
block1 = block1.unseal().seal_slow();
let (block2, exec_result2) = data.blocks[1].clone();
let mut block2 = block2.unseal().block;
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/common/src/calc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use reth_chainspec::{Chain, ChainSpec, Hardfork};
use reth_chainspec::{Chain, ChainSpec, EthereumHardfork};
use reth_primitives::{constants::ETH_TO_WEI, BlockNumber, U256};

/// Calculates the base block reward.
Expand Down Expand Up @@ -26,7 +26,7 @@ pub fn base_block_reward(
block_difficulty: U256,
total_difficulty: U256,
) -> Option<u128> {
if chain_spec.fork(Hardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) ||
if chain_spec.fork(EthereumHardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) ||
chain_spec.chain == Chain::goerli()
{
None
Expand All @@ -39,9 +39,9 @@ pub fn base_block_reward(
///
/// Caution: The caller must ensure that the block number is before the merge.
pub fn base_block_reward_pre_merge(chain_spec: &ChainSpec, block_number: BlockNumber) -> u128 {
if chain_spec.fork(Hardfork::Constantinople).active_at_block(block_number) {
if chain_spec.fork(EthereumHardfork::Constantinople).active_at_block(block_number) {
ETH_TO_WEI * 2
} else if chain_spec.fork(Hardfork::Byzantium).active_at_block(block_number) {
} else if chain_spec.fork(EthereumHardfork::Byzantium).active_at_block(block_number) {
ETH_TO_WEI * 3
} else {
ETH_TO_WEI * 5
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Collection of methods for block validation.

use reth_chainspec::ChainSpec;
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_consensus::ConsensusError;
use reth_primitives::{
constants::{
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
MAXIMUM_EXTRA_DATA_SIZE,
},
eip4844::calculate_excess_blob_gas,
GotExpected, Hardfork, Header, SealedBlock, SealedHeader,
EthereumHardfork, GotExpected, Header, SealedBlock, SealedHeader,
};

/// Gas used needs to be less than gas limit. Gas used is going to be checked after execution.
Expand All @@ -29,7 +29,7 @@ pub fn validate_header_base_fee(
header: &SealedHeader,
chain_spec: &ChainSpec,
) -> Result<(), ConsensusError> {
if chain_spec.fork(Hardfork::London).active_at_block(header.number) &&
if chain_spec.fork(EthereumHardfork::London).active_at_block(header.number) &&
header.base_fee_per_gas.is_none()
{
return Err(ConsensusError::BaseFeeMissing)
Expand Down Expand Up @@ -192,11 +192,11 @@ pub fn validate_against_parent_eip1559_base_fee(
parent: &SealedHeader,
chain_spec: &ChainSpec,
) -> Result<(), ConsensusError> {
if chain_spec.fork(Hardfork::London).active_at_block(header.number) {
if chain_spec.fork(EthereumHardfork::London).active_at_block(header.number) {
let base_fee = header.base_fee_per_gas.ok_or(ConsensusError::BaseFeeMissing)?;

let expected_base_fee =
if chain_spec.fork(Hardfork::London).transitions_at_block(header.number) {
if chain_spec.fork(EthereumHardfork::London).transitions_at_block(header.number) {
reth_primitives::constants::EIP1559_INITIAL_BASE_FEE
} else {
// This BaseFeeMissing will not happen as previous blocks are checked to have
Expand Down
4 changes: 4 additions & 0 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ crc = "3"
# misc
serde = { workspace = true, features = ["derive"], optional = true }
thiserror-no-std = { workspace = true, default-features = false }
once_cell.workspace = true
dyn-clone.workspace = true
rustc-hash.workspace = true

# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
auto_impl.workspace = true

[dev-dependencies]
arbitrary = { workspace = true, features = ["derive"] }
Expand Down
23 changes: 0 additions & 23 deletions crates/ethereum-forks/src/chains/dev.rs

This file was deleted.

94 changes: 0 additions & 94 deletions crates/ethereum-forks/src/chains/ethereum.rs

This file was deleted.

9 changes: 0 additions & 9 deletions crates/ethereum-forks/src/chains/mod.rs

This file was deleted.

105 changes: 0 additions & 105 deletions crates/ethereum-forks/src/chains/optimism.rs

This file was deleted.

Loading

0 comments on commit 50ee497

Please sign in to comment.