Skip to content

chore: replaced anvil hardforks with alloy hardforks #10612

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

Merged
merged 19 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ alloy-transport = { version = "1.0.7", default-features = false }
alloy-transport-http = { version = "1.0.7", default-features = false }
alloy-transport-ipc = { version = "1.0.7", default-features = false }
alloy-transport-ws = { version = "1.0.7", default-features = false }
alloy-hardforks = { version = "0.2.6", default-features = false }
alloy-op-hardforks = { version = "0.2.6", default-features = false }

## alloy-core
alloy-dyn-abi = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ alloy-transport.workspace = true
alloy-chains.workspace = true
alloy-genesis.workspace = true
alloy-trie.workspace = true
alloy-hardforks.workspace = true
alloy-op-hardforks.workspace = true
op-alloy-consensus = { workspace = true, features = ["serde"] }

# revm
Expand Down
7 changes: 4 additions & 3 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
config::{ForkChoice, DEFAULT_MNEMONIC},
eth::{backend::db::SerializableState, pool::transactions::TransactionOrder, EthApi},
AccountGenerator, EthereumHardfork, NodeConfig, OptimismHardfork, CHAIN_ID,
AccountGenerator, EthereumHardfork, NodeConfig, CHAIN_ID,
};
use alloy_genesis::Genesis;
use alloy_op_hardforks::OpHardfork;
use alloy_primitives::{utils::Unit, B256, U256};
use alloy_signer_local::coins_bip39::{English, Mnemonic};
use anvil_server::ServerConfig;
Expand Down Expand Up @@ -218,7 +219,7 @@ impl NodeArgs {
let hardfork = match &self.hardfork {
Some(hf) => {
if self.evm.optimism {
Some(OptimismHardfork::from_str(hf)?.into())
Some(OpHardfork::from_str(hf)?.into())
} else {
Some(EthereumHardfork::from_str(hf)?.into())
}
Expand Down Expand Up @@ -836,7 +837,7 @@ mod tests {
let args: NodeArgs =
NodeArgs::parse_from(["anvil", "--optimism", "--hardfork", "Regolith"]);
let config = args.into_node_config().unwrap();
assert_eq!(config.hardfork, Some(OptimismHardfork::Regolith.into()));
assert_eq!(config.hardfork, Some(OpHardfork::Regolith.into()));
}

#[test]
Expand Down
15 changes: 9 additions & 6 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ use crate::{
fees::{INITIAL_BASE_FEE, INITIAL_GAS_PRICE},
pool::transactions::{PoolTransaction, TransactionOrder},
},
hardfork::ChainHardfork,
hardfork::{ethereum_hardfork_from_block_tag, spec_id_from_ethereum_hardfork, ChainHardfork},
mem::{self, in_memory_db::MemDb},
EthereumHardfork, FeeManager, OptimismHardfork, PrecompileFactory,
EthereumHardfork, FeeManager, PrecompileFactory,
};
use alloy_consensus::BlockHeader;
use alloy_genesis::Genesis;
use alloy_network::{AnyNetwork, TransactionResponse};
use alloy_op_hardforks::OpHardfork;
use alloy_primitives::{hex, map::HashMap, utils::Unit, BlockNumber, TxHash, U256};
use alloy_provider::Provider;
use alloy_rpc_types::{Block, BlockNumberOrTag};
Expand Down Expand Up @@ -530,9 +531,9 @@ impl NodeConfig {
return hardfork;
}
if self.enable_optimism {
return OptimismHardfork::default().into();
return OpHardfork::Isthmus.into();
}
EthereumHardfork::default().into()
EthereumHardfork::Cancun.into()
}

/// Sets a custom code size limit
Expand Down Expand Up @@ -1186,8 +1187,10 @@ impl NodeConfig {
let chain_id =
provider.get_chain_id().await.wrap_err("failed to fetch network chain ID")?;
if alloy_chains::NamedChain::Mainnet == chain_id {
let hardfork: EthereumHardfork = fork_block_number.into();
env.evm_env.cfg_env.spec = hardfork.into();
let hardfork: EthereumHardfork =
ethereum_hardfork_from_block_tag(fork_block_number);

env.evm_env.cfg_env.spec = spec_id_from_ethereum_hardfork(hardfork);
self.hardfork = Some(ChainHardfork::Ethereum(hardfork));
}
Some(U256::from(chain_id))
Expand Down
Loading
Loading