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

feat: use new ChainHardforks type on ChainSpec #9065

Merged
merged 41 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2331726
wip
joshieDo Jun 21, 2024
57f4262
add fn boxed to Hardfork and OptimismHardfork
joshieDo Jun 21, 2024
8722500
renaming
joshieDo Jun 24, 2024
b78ee32
use mainnet chains to order genesis chainspec forks
joshieDo Jun 24, 2024
912c41e
compile
joshieDo Jun 24, 2024
750cb08
fixes and ChainForks reimpl
joshieDo Jun 24, 2024
03431ca
insert replaces if possible
joshieDo Jun 24, 2024
cfe5abf
split optimism helper traits
joshieDo Jun 24, 2024
fb7d8ab
move helper methods to hardforks mod
joshieDo Jun 24, 2024
273a3dc
add EthereumActivations
joshieDo Jun 24, 2024
e2f27bf
fix cargo docs
joshieDo Jun 24, 2024
c901a77
fix from_str
joshieDo Jun 24, 2024
26e4d7d
fmt
joshieDo Jun 24, 2024
bd9bf75
fix dev_hardforks
joshieDo Jun 24, 2024
77fedda
remove import
joshieDo Jun 24, 2024
413e303
use dyn-clone instead
joshieDo Jun 25, 2024
a54a8e2
add Clone restriction
joshieDo Jun 26, 2024
7e5b49f
move to macros.rs
joshieDo Jun 26, 2024
20ac993
impl hash for dyn hardfork
joshieDo Jun 26, 2024
3cb5c5e
add map to ChainHardforks
joshieDo Jun 26, 2024
cadec17
Merge remote-tracking branch 'origin/main' into joshie/dyn-forks
joshieDo Jun 26, 2024
8891405
fix insert
joshieDo Jun 26, 2024
500197c
change fn new
joshieDo Jun 26, 2024
7338ccd
various smol review changes
joshieDo Jun 27, 2024
9814243
move chain hardfork lists to enum impl
joshieDo Jun 27, 2024
e107703
rm/move activation traits to hardfork type
joshieDo Jun 27, 2024
9d10116
fix import
joshieDo Jun 27, 2024
2f17230
Merge remote-tracking branch 'origin/main' into joshie/dyn-forks
joshieDo Jun 27, 2024
2ea7c00
rm non_exhaustive
joshieDo Jun 27, 2024
26e820c
make etherem forks fn const without type erasure
joshieDo Jun 27, 2024
fb37cfb
use FxHashMap instead
joshieDo Jun 27, 2024
8f5767b
clippy
joshieDo Jun 27, 2024
2f75f07
add doc to OptimismHardfork
joshieDo Jun 27, 2024
96574f3
fix debug impl
joshieDo Jun 27, 2024
11e2e31
Merge remote-tracking branch 'origin/main' into joshie/dyn-forks
joshieDo Jun 27, 2024
1c692fb
use condition instead of clone
joshieDo Jun 27, 2024
8d54154
Merge remote-tracking branch 'origin/main' into joshie/dyn-forks
joshieDo Jun 27, 2024
fc9bbb9
just clone hardforks
joshieDo Jun 27, 2024
b025ba7
rm box from forks_iter
joshieDo Jun 27, 2024
b327d74
clippy
joshieDo Jun 27, 2024
7c061df
Merge remote-tracking branch 'origin/main' into joshie/dyn-forks
joshieDo Jun 27, 2024
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
2 changes: 2 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
668 changes: 315 additions & 353 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
2 changes: 2 additions & 0 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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

# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
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