Skip to content

Commit

Permalink
Minimize telos chain config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coa-telos committed Aug 21, 2024
1 parent 1ae6019 commit 48e5034
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ optimism = [
"serde",
"dep:op-alloy-rpc-types",
]
telos = [
"reth-network-peers/telos"
]
telos = []
std = []
arbitrary = [
"alloy-chains/arbitrary"
Expand Down
8 changes: 0 additions & 8 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<ChainSpec>> = Lazy::new(|| {
Expand Down Expand Up @@ -824,12 +822,6 @@ impl ChainSpec {
pub fn bootnodes(&self) -> Option<Vec<NodeRecord>> {
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()),
Expand Down
16 changes: 0 additions & 16 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<T: Into<TrustedPeer>>(mut self, nodes: impl IntoIterator<Item = T>) -> Self {
self.boot_nodes = nodes.into_iter().map(Into::into).collect();
Expand Down
1 change: 1 addition & 0 deletions crates/node/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
17 changes: 7 additions & 10 deletions crates/node/core/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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 {
Expand Down Expand Up @@ -54,13 +51,13 @@ pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, 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())) {
Expand Down
9 changes: 4 additions & 5 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
Expand Down
41 changes: 41 additions & 0 deletions crates/primitives/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
}
2 changes: 1 addition & 1 deletion crates/storage/db-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ reth-primitives-traits.workspace = true
workspace = true

[features]
telos = []
telos = ["reth-primitives/telos"]
23 changes: 7 additions & 16 deletions crates/storage/db-common/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ pub fn init_genesis<DB: Database>(factory: ProviderFactory<DB>) -> Result<B256,

// insert sync stage
for stage in StageId::ALL {
// TODO: Does this still apply
// #[cfg(feature = "telos")]
// tx.put::<tables::SyncStage>(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())?;
}

Expand Down Expand Up @@ -304,21 +302,14 @@ pub fn insert_genesis_header<DB: Database>(
Err(e) => return Err(e),
}

#[cfg(feature = "telos")]
{
if cfg!(feature = "telos") {
provider.tx_ref().put::<tables::HeaderNumbers>(block_hash, header.number)?;
provider.tx_ref().put::<tables::BlockBodyIndices>(header.number, Default::default())?;
// TODO: What to do with other tables:
// tx.put::<tables::CanonicalHeaders>(header.number, block_hash)?;
// tx.put::<tables::HeaderTD>(header.number, header.difficulty.into())?;
// tx.put::<tables::Headers>(header.number, header)?;
return Ok(())
}

#[cfg(not(feature = "telos"))]
{
provider.tx_ref().put::<tables::HeaderNumbers>(block_hash, 0)?;
provider.tx_ref().put::<tables::BlockBodyIndices>(0, Default::default())?;
}
provider.tx_ref().put::<tables::HeaderNumbers>(block_hash, 0)?;
provider.tx_ref().put::<tables::BlockBodyIndices>(0, Default::default())?;

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions crates/telos/node/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Telos node implementation
use crate::args::TelosArgs;
use reth_ethereum_engine_primitives::{
EthBuiltPayload, EthEngineTypes, EthPayloadAttributes, EthPayloadBuilderAttributes,
Expand Down
8 changes: 4 additions & 4 deletions crates/telos/node/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:?}");
}
}

0 comments on commit 48e5034

Please sign in to comment.