Skip to content

Commit 65650a6

Browse files
chore: replaced anvil hardforks with alloy hardforks (#10612)
* chore: replaced anvil hardforks with alloy hardforks * fixes * fixes * fixes * removed redundant op and alloy hardforks enum * fixes * fixes * bumped alloy hardforks and kept default to prague and isthmus * bumped alloy-hardforks and fixes --------- Co-authored-by: zerosnacks <[email protected]>
1 parent 3e45ccb commit 65650a6

18 files changed

+126
-218
lines changed

Cargo.lock

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ alloy-transport = { version = "1.0.7", default-features = false }
230230
alloy-transport-http = { version = "1.0.7", default-features = false }
231231
alloy-transport-ipc = { version = "1.0.7", default-features = false }
232232
alloy-transport-ws = { version = "1.0.7", default-features = false }
233+
alloy-hardforks = { version = "0.2.6", default-features = false }
234+
alloy-op-hardforks = { version = "0.2.6", default-features = false }
233235

234236
## alloy-core
235237
alloy-dyn-abi = "1.0"

crates/anvil/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ alloy-transport.workspace = true
5555
alloy-chains.workspace = true
5656
alloy-genesis.workspace = true
5757
alloy-trie.workspace = true
58+
alloy-hardforks.workspace = true
59+
alloy-op-hardforks.workspace = true
5860
op-alloy-consensus = { workspace = true, features = ["serde"] }
5961

6062
# revm

crates/anvil/src/cmd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::{
22
config::{ForkChoice, DEFAULT_MNEMONIC},
33
eth::{backend::db::SerializableState, pool::transactions::TransactionOrder, EthApi},
4-
AccountGenerator, EthereumHardfork, NodeConfig, OptimismHardfork, CHAIN_ID,
4+
AccountGenerator, EthereumHardfork, NodeConfig, CHAIN_ID,
55
};
66
use alloy_genesis::Genesis;
7+
use alloy_op_hardforks::OpHardfork;
78
use alloy_primitives::{utils::Unit, B256, U256};
89
use alloy_signer_local::coins_bip39::{English, Mnemonic};
910
use anvil_server::ServerConfig;
@@ -218,7 +219,7 @@ impl NodeArgs {
218219
let hardfork = match &self.hardfork {
219220
Some(hf) => {
220221
if self.evm.optimism {
221-
Some(OptimismHardfork::from_str(hf)?.into())
222+
Some(OpHardfork::from_str(hf)?.into())
222223
} else {
223224
Some(EthereumHardfork::from_str(hf)?.into())
224225
}
@@ -836,7 +837,7 @@ mod tests {
836837
let args: NodeArgs =
837838
NodeArgs::parse_from(["anvil", "--optimism", "--hardfork", "Regolith"]);
838839
let config = args.into_node_config().unwrap();
839-
assert_eq!(config.hardfork, Some(OptimismHardfork::Regolith.into()));
840+
assert_eq!(config.hardfork, Some(OpHardfork::Regolith.into()));
840841
}
841842

842843
#[test]

crates/anvil/src/config.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ use crate::{
1111
fees::{INITIAL_BASE_FEE, INITIAL_GAS_PRICE},
1212
pool::transactions::{PoolTransaction, TransactionOrder},
1313
},
14-
hardfork::ChainHardfork,
14+
hardfork::{ethereum_hardfork_from_block_tag, spec_id_from_ethereum_hardfork, ChainHardfork},
1515
mem::{self, in_memory_db::MemDb},
16-
EthereumHardfork, FeeManager, OptimismHardfork, PrecompileFactory,
16+
EthereumHardfork, FeeManager, PrecompileFactory,
1717
};
1818
use alloy_consensus::BlockHeader;
1919
use alloy_genesis::Genesis;
2020
use alloy_network::{AnyNetwork, TransactionResponse};
21+
use alloy_op_hardforks::OpHardfork;
2122
use alloy_primitives::{hex, map::HashMap, utils::Unit, BlockNumber, TxHash, U256};
2223
use alloy_provider::Provider;
2324
use alloy_rpc_types::{Block, BlockNumberOrTag};
@@ -530,9 +531,9 @@ impl NodeConfig {
530531
return hardfork;
531532
}
532533
if self.enable_optimism {
533-
return OptimismHardfork::default().into();
534+
return OpHardfork::Isthmus.into();
534535
}
535-
EthereumHardfork::default().into()
536+
EthereumHardfork::Cancun.into()
536537
}
537538

538539
/// Sets a custom code size limit
@@ -1186,8 +1187,10 @@ impl NodeConfig {
11861187
let chain_id =
11871188
provider.get_chain_id().await.wrap_err("failed to fetch network chain ID")?;
11881189
if alloy_chains::NamedChain::Mainnet == chain_id {
1189-
let hardfork: EthereumHardfork = fork_block_number.into();
1190-
env.evm_env.cfg_env.spec = hardfork.into();
1190+
let hardfork: EthereumHardfork =
1191+
ethereum_hardfork_from_block_tag(fork_block_number);
1192+
1193+
env.evm_env.cfg_env.spec = spec_id_from_ethereum_hardfork(hardfork);
11911194
self.hardfork = Some(ChainHardfork::Ethereum(hardfork));
11921195
}
11931196
Some(U256::from(chain_id))

0 commit comments

Comments
 (0)