From 48e503480bca6f7a7378aeb048bbcd8bce46417d Mon Sep 17 00:00:00 2001 From: Coa Date: Sun, 18 Aug 2024 17:34:57 +0200 Subject: [PATCH] Minimize telos chain config changes --- bin/reth/src/main.rs | 2 +- crates/chainspec/Cargo.toml | 4 +-- crates/chainspec/src/spec.rs | 8 ----- crates/net/network/src/config.rs | 16 ---------- crates/node/core/Cargo.toml | 1 + crates/node/core/src/args/utils.rs | 17 +++++------ crates/primitives/src/lib.rs | 9 +++--- crates/primitives/src/proofs.rs | 41 ++++++++++++++++++++++++++ crates/storage/db-common/Cargo.toml | 2 +- crates/storage/db-common/src/init.rs | 23 +++++---------- crates/telos/node/src/node.rs | 2 ++ crates/telos/node/tests/integration.rs | 8 ++--- 12 files changed, 69 insertions(+), 64 deletions(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index ebd9215231804..fee6493a9833f 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -8,7 +8,7 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; #[cfg(all(feature = "optimism", not(test)))] compile_error!("Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you mean to build `op-reth`?"); -#[cfg(all(not(feature = "optimism"), not(feature = "telos")))] +#[cfg(not(feature = "optimism"))] /// clap [Args] for Engine related arguments. use clap::Args; diff --git a/crates/chainspec/Cargo.toml b/crates/chainspec/Cargo.toml index 8f273338f3c37..20bdfdb392ca4 100644 --- a/crates/chainspec/Cargo.toml +++ b/crates/chainspec/Cargo.toml @@ -52,9 +52,7 @@ optimism = [ "serde", "dep:op-alloy-rpc-types", ] -telos = [ - "reth-network-peers/telos" -] +telos = [] std = [] arbitrary = [ "alloy-chains/arbitrary" diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index b02b41876e0ab..a56a096ecbb72 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -30,8 +30,6 @@ use reth_network_peers::{ base_nodes, base_testnet_nodes, holesky_nodes, mainnet_nodes, op_nodes, op_testnet_nodes, sepolia_nodes, }; -#[cfg(feature = "telos")] -use reth_network_peers::{tevmmainnet_nodes, tevmtestnet_nodes}; /// The Ethereum mainnet spec pub static MAINNET: Lazy> = Lazy::new(|| { @@ -824,12 +822,6 @@ impl ChainSpec { pub fn bootnodes(&self) -> Option> { use NamedChain as C; let chain = self.chain; - #[cfg(feature = "telos")] - match chain.id() { - 40 => Some(tevmmainnet_nodes()), - 41 => Some(tevmtestnet_nodes()), - _ => None, - }; match chain.try_into().ok()? { C::Mainnet => Some(mainnet_nodes()), C::Sepolia => Some(sepolia_nodes()), diff --git a/crates/net/network/src/config.rs b/crates/net/network/src/config.rs index 812bcf4605d81..546d9f1821332 100644 --- a/crates/net/network/src/config.rs +++ b/crates/net/network/src/config.rs @@ -13,10 +13,6 @@ use reth_primitives::{ForkFilter, Head}; use reth_storage_api::{BlockNumReader, BlockReader, HeaderProvider}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use secp256k1::SECP256K1; -#[cfg(feature = "telos")] -use reth_network_peers::{ - tevmmainnet_nodes, tevmtestnet_nodes, -}; use crate::{ error::NetworkError, @@ -390,18 +386,6 @@ impl NetworkConfigBuilder { self.boot_nodes(sepolia_nodes()) } - #[cfg(feature = "telos")] - /// Convenience function for setting [Self::boot_nodes] to the tevmmainnet boot nodes. - pub fn tevmmainnet_boot_nodes(self) -> Self { - self.boot_nodes(tevmmainnet_nodes()) - } - - #[cfg(feature = "telos")] - /// Convenience function for setting [Self::boot_nodes] to the tevmtestnet boot nodes. - pub fn tevmtestnet_boot_nodes(self) -> Self { - self.boot_nodes(tevmtestnet_nodes()) - } - /// Sets the boot nodes to use to bootstrap the configured discovery services (discv4 + discv5). pub fn boot_nodes>(mut self, nodes: impl IntoIterator) -> Self { self.boot_nodes = nodes.into_iter().map(Into::into).collect(); diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index 492d5b086f5a3..0c606a5f8104b 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -86,6 +86,7 @@ optimism = [ "reth-rpc-eth-api/optimism", ] telos = ["reth-chainspec/telos"] +default = ["telos"] # Features for vergen to generate correct env vars jemalloc = [] diff --git a/crates/node/core/src/args/utils.rs b/crates/node/core/src/args/utils.rs index 1375918456e47..199e220cb341e 100644 --- a/crates/node/core/src/args/utils.rs +++ b/crates/node/core/src/args/utils.rs @@ -7,9 +7,6 @@ use std::{path::PathBuf, sync::Arc}; use reth_chainspec::DEV; -#[cfg(feature = "telos")] -use reth_chainspec::{TEVMMAINNET, TEVMMAINNET_BASE, TEVMTESTNET, TEVMTESTNET_BASE}; - #[cfg(feature = "optimism")] use reth_chainspec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA}; @@ -19,13 +16,13 @@ use reth_chainspec::{HOLESKY, MAINNET, SEPOLIA}; #[cfg(feature = "optimism")] /// Chains supported by op-reth. First value should be used as the default. pub const SUPPORTED_CHAINS: &[&str] = &["optimism", "optimism-sepolia", "base", "base-sepolia"]; +#[cfg(all(not(feature = "optimism"), not(feature = "telos")))] +/// Chains supported by reth. First value should be used as the default. +pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "holesky", "dev"]; #[cfg(feature = "telos")] /// Chains supported by telos-reth pub const SUPPORTED_CHAINS: &[&str] = &["tevmmainnet", "tevmtestnet", "tevmmainnet-base", "tevmtestnet-base"]; -#[cfg(all(not(feature = "optimism"), not(feature = "telos")))] -/// Chains supported by reth. First value should be used as the default. -pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "holesky", "dev"]; /// The help info for the --chain flag pub fn chain_help() -> String { @@ -54,13 +51,13 @@ pub fn chain_value_parser(s: &str) -> eyre::Result, eyre::Error> #[cfg(feature = "optimism")] "base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(), #[cfg(feature = "telos")] - "tevmmainnet" => TEVMMAINNET.clone(), + "tevmmainnet" => reth_chainspec::TEVMMAINNET.clone(), #[cfg(feature = "telos")] - "tevmtestnet" => TEVMTESTNET.clone(), + "tevmtestnet" => reth_chainspec::TEVMTESTNET.clone(), #[cfg(feature = "telos")] - "tevmmainnet-base" => TEVMMAINNET_BASE.clone(), + "tevmmainnet-base" => reth_chainspec::TEVMMAINNET_BASE.clone(), #[cfg(feature = "telos")] - "tevmtestnet-base" => TEVMTESTNET_BASE.clone(), + "tevmtestnet-base" => reth_chainspec::TEVMTESTNET_BASE.clone(), _ => { // try to read json from path first let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) { diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 50b85f06ebf7c..e7ed0a80c8db9 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -48,11 +48,6 @@ pub use constants::{ DEV_GENESIS_HASH, EMPTY_OMMER_ROOT_HASH, HOLESKY_GENESIS_HASH, KECCAK_EMPTY, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, }; -#[cfg(feature = "telos")] -pub use constants::{ - TEVMMAINNET_BASE_GENESIS_HASH, TEVMMAINNET_GENESIS_HASH, TEVMTESTNET_BASE_GENESIS_HASH, - TEVMTESTNET_GENESIS_HASH, -}; pub use genesis::{ChainConfig, Genesis, GenesisAccount}; pub use receipt::{ gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts, @@ -129,6 +124,10 @@ pub use optimism::*; #[cfg(feature = "telos")] mod telos { pub use reth_chainspec::{TEVMMAINNET, TEVMMAINNET_BASE, TEVMTESTNET, TEVMTESTNET_BASE}; + pub use reth_primitives_traits::constants::{ + TEVMMAINNET_BASE_GENESIS_HASH, TEVMMAINNET_GENESIS_HASH, TEVMTESTNET_BASE_GENESIS_HASH, + TEVMTESTNET_GENESIS_HASH, + }; } #[cfg(feature = "telos")] diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index 72660d13f8338..ac5cbc7dbb366 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -600,5 +600,46 @@ mod tests { expected_holesky_state_root, calculated_holesky_state_root, "holesky state root mismatch" ); + + #[cfg(feature = "telos")] + { + use reth_chainspec::{TEVMMAINNET, TEVMMAINNET_BASE, TEVMTESTNET, TEVMTESTNET_BASE}; + + let expected_tevmmainnet_state_root = + b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); + let calculated_tevmmainnet_state_root = + state_root_ref_unhashed(&TEVMMAINNET.genesis.alloc); + assert_eq!( + expected_tevmmainnet_state_root, calculated_tevmmainnet_state_root, + "tevmmainnet state root mismatch" + ); + + let expected_tevmmainnet_base_state_root = + b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); + let calculated_tevmmainnet_base_state_root = + state_root_ref_unhashed(&TEVMMAINNET_BASE.genesis.alloc); + assert_eq!( + expected_tevmmainnet_base_state_root, calculated_tevmmainnet_base_state_root, + "tevmmainnet-base state root mismatch" + ); + + let expected_tevmtestnet_base_state_root = + b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); + let calculated_tevmtestnet_base_state_root = + state_root_ref_unhashed(&TEVMTESTNET_BASE.genesis.alloc); + assert_eq!( + expected_tevmtestnet_base_state_root, calculated_tevmtestnet_base_state_root, + "tevmtestnet-base state root mismatch" + ); + + let expected_tevmtestnet_state_root = + b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); + let calculated_tevmtestnet_state_root = + state_root_ref_unhashed(&TEVMTESTNET.genesis.alloc); + assert_eq!( + expected_tevmtestnet_state_root, calculated_tevmtestnet_state_root, + "tevmtestnet state root mismatch" + ); + } } } diff --git a/crates/storage/db-common/Cargo.toml b/crates/storage/db-common/Cargo.toml index 4b93c567d8583..2dc5c6561818d 100644 --- a/crates/storage/db-common/Cargo.toml +++ b/crates/storage/db-common/Cargo.toml @@ -44,4 +44,4 @@ reth-primitives-traits.workspace = true workspace = true [features] -telos = [] \ No newline at end of file +telos = ["reth-primitives/telos"] \ No newline at end of file diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 99d55f3faaa70..eff09930df8d0 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -121,11 +121,9 @@ pub fn init_genesis(factory: ProviderFactory) -> Result(stage.to_string(), reth_primitives::stage::StageCheckpoint::new(genesis.number.unwrap_or_default()))?; - // #[cfg(not(feature = "telos"))] - + #[cfg(feature = "telos")] + provider_rw.save_stage_checkpoint(stage, StageCheckpoint::new(genesis.number.unwrap_or_default()))?; + #[cfg(not(feature = "telos"))] provider_rw.save_stage_checkpoint(stage, Default::default())?; } @@ -304,21 +302,14 @@ pub fn insert_genesis_header( Err(e) => return Err(e), } - #[cfg(feature = "telos")] - { + if cfg!(feature = "telos") { provider.tx_ref().put::(block_hash, header.number)?; provider.tx_ref().put::(header.number, Default::default())?; - // TODO: What to do with other tables: - // tx.put::(header.number, block_hash)?; - // tx.put::(header.number, header.difficulty.into())?; - // tx.put::(header.number, header)?; + return Ok(()) } - #[cfg(not(feature = "telos"))] - { - provider.tx_ref().put::(block_hash, 0)?; - provider.tx_ref().put::(0, Default::default())?; - } + provider.tx_ref().put::(block_hash, 0)?; + provider.tx_ref().put::(0, Default::default())?; Ok(()) } diff --git a/crates/telos/node/src/node.rs b/crates/telos/node/src/node.rs index 27034db4e6cf0..fa44cd76afa32 100644 --- a/crates/telos/node/src/node.rs +++ b/crates/telos/node/src/node.rs @@ -1,3 +1,5 @@ +//! Telos node implementation + use crate::args::TelosArgs; use reth_ethereum_engine_primitives::{ EthBuiltPayload, EthEngineTypes, EthPayloadAttributes, EthPayloadBuilderAttributes, diff --git a/crates/telos/node/tests/integration.rs b/crates/telos/node/tests/integration.rs index 5c59fbd5e3d68..ff5e373abee19 100644 --- a/crates/telos/node/tests/integration.rs +++ b/crates/telos/node/tests/integration.rs @@ -100,8 +100,7 @@ async fn start_consensus(reth_handle: TelosRethNodeHandle, ship_port: u16, chain }; let mut client_under_test = ConsensusClient::new(config).await; - let run_result = client_under_test.run().await; - run_result + client_under_test.run().await } #[tokio::test] @@ -131,6 +130,7 @@ async fn testing_chain_sync() { _ = NodeTestContext::new(node_handle.node.clone()).await.unwrap(); info!("Started Reth!"); - let consensus_result = start_consensus(reth_handle, ship_port, chain_port).await; - assert!(consensus_result.is_ok(), "Error with consensus client: {:?}", consensus_result.err().unwrap()); + if let Err(error) = start_consensus(reth_handle, ship_port, chain_port).await { + panic!("Error with consensus client: {error:?}"); + } }