Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
feat: activate prague always (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg authored Sep 16, 2024
1 parent 9441e6b commit 1610d9b
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 168 deletions.
297 changes: 150 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,40 @@ alloy-signer-local = { version = "0.3", features = ["mnemonic"] }
tokio = { version = "1.21", default-features = false }

# reth
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-optimism-rpc = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-optimism-rpc = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb", features = [
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
"optimism",
] }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "c1b5fbb" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }

# misc
clap = "4"
eyre = "0.6.12"
tracing = "0.1.0"
serde_json = "1"
once_cell = "1.19"

# misc-testing
rstest = "0.18.2"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ COPY LICENSE-* ./
ADD etc/alphanet-genesis.json ./etc/alphanet-genesis.json

EXPOSE 30303 30303/udp 9001 8545 9000 8546
ENTRYPOINT ["/usr/local/bin/alphanet", "--chain", "./etc/alphanet-genesis.json"]
ENTRYPOINT ["/usr/local/bin/alphanet"]
6 changes: 3 additions & 3 deletions bin/alphanet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
//! - `min-debug-logs`: Disables all logs below `debug` level.
//! - `min-trace-logs`: Disables all logs below `trace` level.
use alphanet_node::node::AlphaNetNode;
use alphanet_node::{chainspec::AlphanetChainSpecParser, node::AlphaNetNode};
use clap::Parser;
use reth_node_optimism::args::RollupArgs;
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_cli::Cli;
use reth_optimism_rpc::eth::rpc::SequencerClient;

// We use jemalloc for performance reasons.
Expand All @@ -45,7 +45,7 @@ fn main() {
}

if let Err(err) =
Cli::<OpChainSpecParser, RollupArgs>::parse().run(|builder, rollup_args| async move {
Cli::<AlphanetChainSpecParser, RollupArgs>::parse().run(|builder, rollup_args| async move {
let node = builder
.node(AlphaNetNode::new(rollup_args.clone()))
.extend_rpc_modules(move |ctx| {
Expand Down
4 changes: 4 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ categories.workspace = true

[dependencies]
alphanet-precompile.workspace = true
once_cell.workspace = true
reth-cli.workspace = true
reth-node-api.workspace = true
reth-node-builder.workspace = true
reth-node-core.workspace = true
reth-node-optimism.workspace = true
reth-chainspec.workspace = true
reth-primitives.workspace = true
reth-revm.workspace = true
serde_json.workspace = true

eyre.workspace = true

Expand Down
135 changes: 135 additions & 0 deletions crates/node/src/chainspec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//! Alphanet chainspec parsing logic.
use once_cell::sync::Lazy;
use reth_chainspec::{
BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec, EthereumHardfork,
ForkCondition, OptimismHardfork,
};
use reth_cli::chainspec::ChainSpecParser;
use reth_node_core::args::utils::parse_custom_chain_spec;
use reth_primitives::{b256, constants::ETHEREUM_BLOCK_GAS_LIMIT, U256};
use std::sync::Arc;

/// Alphanet forks.
pub static ALPHANET_FORKS: Lazy<ChainHardforks> = Lazy::new(|| {
ChainHardforks::new(vec![
(EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Homestead.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Dao.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Tangerine.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::SpuriousDragon.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Byzantium.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Constantinople.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Petersburg.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Istanbul.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::Berlin.boxed(), ForkCondition::Block(0)),
(EthereumHardfork::London.boxed(), ForkCondition::Block(0)),
(
EthereumHardfork::Paris.boxed(),
ForkCondition::TTD { fork_block: None, total_difficulty: U256::ZERO },
),
(EthereumHardfork::Shanghai.boxed(), ForkCondition::Timestamp(0)),
(EthereumHardfork::Cancun.boxed(), ForkCondition::Timestamp(0)),
(OptimismHardfork::Regolith.boxed(), ForkCondition::Timestamp(0)),
(OptimismHardfork::Bedrock.boxed(), ForkCondition::Block(0)),
(OptimismHardfork::Ecotone.boxed(), ForkCondition::Timestamp(0)),
(OptimismHardfork::Canyon.boxed(), ForkCondition::Timestamp(0)),
(EthereumHardfork::Prague.boxed(), ForkCondition::Timestamp(0)),
])
});

/// Alphanet dev testnet specification.
pub static ALPHANET_DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::dev(),
genesis: serde_json::from_str(include_str!("../../../etc/alphanet-genesis.json"))
.expect("Can't deserialize alphanet genesis json"),
genesis_hash: Some(b256!(
"2f980576711e3617a5e4d83dd539548ec0f7792007d505a3d2e9674833af2d7c"
)),
paris_block_and_final_difficulty: Some((0, U256::from(0))),
hardforks: ALPHANET_FORKS.clone(),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
deposit_contract: None,
..Default::default()
}
.into()
});

/// Alphanet main chain specification.
pub static ALPHANET_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::optimism_mainnet(),
// genesis contains empty alloc field because state at first bedrock block is imported
// manually from trusted source
genesis: serde_json::from_str(include_str!("../../../etc/alphanet-genesis.json"))
.expect("Can't deserialize alphanet genesis json"),
genesis_hash: Some(b256!(
"2f980576711e3617a5e4d83dd539548ec0f7792007d505a3d2e9674833af2d7c"
)),
paris_block_and_final_difficulty: Some((0, U256::from(0))),
hardforks: ALPHANET_FORKS.clone(),
base_fee_params: BaseFeeParamsKind::Variable(
vec![
(EthereumHardfork::London.boxed(), BaseFeeParams::optimism()),
(OptimismHardfork::Canyon.boxed(), BaseFeeParams::optimism_canyon()),
]
.into(),
),
max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
prune_delete_limit: 10000,
..Default::default()
}
.into()
});

/// Alphanet chain specification parser.
#[derive(Debug, Clone, Default)]
pub struct AlphanetChainSpecParser;

impl ChainSpecParser for AlphanetChainSpecParser {
type ChainSpec = ChainSpec;

const SUPPORTED_CHAINS: &'static [&'static str] = &["alphanet", "dev"];

fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
Ok(match s {
"alphanet" => ALPHANET_MAINNET.clone(),
"dev" => ALPHANET_DEV.clone(),
s => {
let mut chainspec = parse_custom_chain_spec(s)?;

// NOTE(onbjerg): This is a temporary workaround until we figure out a better way to
// activate Prague based on a custom fork name. Currently there does not seem to be
// a good way to do it.
chainspec.hardforks.insert(EthereumHardfork::Prague, ForkCondition::Timestamp(0));

Arc::new(chainspec)
}
})
}
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use reth_chainspec::EthereumHardforks;
use reth_cli::chainspec::ChainSpecParser;

use super::AlphanetChainSpecParser;

#[test]
fn chainspec_parser_adds_prague() {
let mut chainspec_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
chainspec_path.push("../../etc/alphanet-genesis.json");

let chain_spec = AlphanetChainSpecParser::parse(&chainspec_path.to_string_lossy())
.expect("could not parse chainspec");

assert!(
chain_spec.is_prague_active_at_timestamp(0),
"prague should be active at timestamp 0"
);
}
}
2 changes: 1 addition & 1 deletion crates/node/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use reth_revm::{
use std::sync::Arc;

/// Custom EVM configuration
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct AlphaNetEvmConfig {
chain_spec: Arc<ChainSpec>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![warn(unused_crate_dependencies)]

pub mod chainspec;
pub mod evm;
pub mod node;
2 changes: 1 addition & 1 deletion crates/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
ctx: &BuilderContext<Node>,
) -> eyre::Result<(Self::EVM, Self::Executor)> {
let chain_spec = ctx.chain_spec();
let evm_config = AlphaNetEvmConfig::default();
let evm_config = AlphaNetEvmConfig::new(chain_spec.clone());
let executor = OpExecutorProvider::new(chain_spec, evm_config.clone());

Ok((evm_config, executor))
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ categories.workspace = true

[dependencies]
reth-revm.workspace = true

p256 = { version = "0.13.2", features = ["ecdsa"] }

[dev-dependencies]
reth-node-api.workspace = true
reth-chainspec.workspace = true
reth-primitives.workspace = true
eyre.workspace = true
rstest.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/precompile/src/secp256r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! The precompile can be inserted in a custom EVM like this:
//! ```
//! use alphanet_precompile::secp256r1;
//! use reth_chainspec::ChainSpec;
//! use reth_node_api::{ConfigureEvm, ConfigureEvmEnv};
//! use reth_primitives::{TransactionSigned, U256};
//! use reth_revm::{
Expand Down
1 change: 0 additions & 1 deletion crates/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ alloy-network.workspace = true
alloy-signer-local = { workspace = true, features = ["mnemonic"] }

reth = { workspace = true }
reth-chainspec.workspace = true
reth-node-core = { workspace = true }
reth-node-builder = { workspace = true, features = ["test-utils"] }
reth-primitives.workspace = true
Expand Down

0 comments on commit 1610d9b

Please sign in to comment.