Skip to content

Commit

Permalink
Add Telos mainnet/testnet genesis blocks to the supported chains
Browse files Browse the repository at this point in the history
  • Loading branch information
coa-telos committed Aug 14, 2024
1 parent 13a283f commit 59df97d
Show file tree
Hide file tree
Showing 27 changed files with 287 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ ethereum = []
telos = [
"dep:reth-node-telos",
"dep:reth-telos-rpc",
"reth-node-core/telos",

]

[[bin]]
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ mod tests {
/// Tests that the log directory is parsed correctly. It's always tied to the specific chain's
/// name
#[test]
#[cfg(not(feature = "telos"))]
// NOTE: Test is disable since chan names are defined in the alloy,
// and telos chains fallbacks to the id, causing paths to end with 40 and 41
fn parse_logs_path() {
let mut reth = Cli::try_parse_args_from(["reth", "node"]).unwrap();
reth.logs.log_file_directory =
Expand Down
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
2 changes: 1 addition & 1 deletion bin/reth/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::sync::Arc;
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
compile_error!("Cannot build the `op-reth` binary with the `optimism` feature flag disabled. Did you mean to build `reth`?");

#[cfg(feature = "optimism")]
Expand Down
3 changes: 3 additions & 0 deletions crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ optimism = [
"serde",
"dep:op-alloy-rpc-types",
]
telos = [
"reth-network-peers/telos"
]
std = []
arbitrary = [
"alloy-chains/arbitrary"
Expand Down
13 changes: 13 additions & 0 deletions crates/chainspec/res/genesis/tevmmainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x00",
"timestamp": "0x5c114972",
"extraData": "0x00000024796a9998ec49fb788de51614c57276dc6151bd2328305dba5d018897",
"gasLimit": "0x0",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
13 changes: 13 additions & 0 deletions crates/chainspec/res/genesis/tevmtestnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x00",
"timestamp": "0x5d55db93",
"extraData": "0x000000397128c497668c241b27d1521c764156cea50bcac87892fc8916e23b24",
"gasLimit": "0x0",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
3 changes: 3 additions & 0 deletions crates/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub use spec::{
#[cfg(feature = "optimism")]
pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};

#[cfg(feature = "telos")]
pub use spec::{TEVMMAINNET, TEVMTESTNET};

#[cfg(not(feature = "std"))]
extern crate alloc;

Expand Down
90 changes: 90 additions & 0 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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 @@ -229,6 +231,72 @@ pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

#[cfg(feature = "telos")]
/// The Tevmmainnet spec
pub static TEVMMAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::from_id(40),
genesis: serde_json::from_str(include_str!("../res/genesis/tevmmainnet.json"))
.expect("Can't deserialize Tevmmainnet genesis json"),
genesis_hash: Some(b256!(
"13f28fe4d164354cbcb0b9d8d43dff5d8e4b180e440579a55505a5fc96831c6b"
)),
hardforks: ChainHardforks::new(
vec![
(EthereumHardfork::Frontier, ForkCondition::Block(0)),
(EthereumHardfork::Homestead, ForkCondition::Block(0)),
(EthereumHardfork::Dao, ForkCondition::Block(0)),
(EthereumHardfork::Tangerine, ForkCondition::Block(0)),
(EthereumHardfork::SpuriousDragon, ForkCondition::Block(0)),
(EthereumHardfork::Byzantium, ForkCondition::Block(0)),
(EthereumHardfork::Constantinople, ForkCondition::Block(0)),
(EthereumHardfork::Petersburg, ForkCondition::Block(0)),
(EthereumHardfork::Istanbul, ForkCondition::Block(0)),
(EthereumHardfork::MuirGlacier, ForkCondition::Block(0)),
(EthereumHardfork::Berlin, ForkCondition::Block(0)),
]
.into_iter()
.map(|(a, b)| (a.boxed(), b))
.collect(),
),
..Default::default()
}
.into()
});

#[cfg(feature = "telos")]
/// The Tevmtestnet spec
pub static TEVMTESTNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::from_id(41),
genesis: serde_json::from_str(include_str!("../res/genesis/tevmtestnet.json"))
.expect("Can't deserialize Tevmtestnet genesis json"),
genesis_hash: Some(b256!(
"f5488543e19d3441f652d76cbd52014f9807d0f09bfa25422568b1cf3e30da1a"
)),
hardforks: ChainHardforks::new(
vec![
(EthereumHardfork::Frontier, ForkCondition::Block(0)),
(EthereumHardfork::Homestead, ForkCondition::Block(0)),
(EthereumHardfork::Dao, ForkCondition::Block(0)),
(EthereumHardfork::Tangerine, ForkCondition::Block(0)),
(EthereumHardfork::SpuriousDragon, ForkCondition::Block(0)),
(EthereumHardfork::Byzantium, ForkCondition::Block(0)),
(EthereumHardfork::Constantinople, ForkCondition::Block(0)),
(EthereumHardfork::Petersburg, ForkCondition::Block(0)),
(EthereumHardfork::Istanbul, ForkCondition::Block(0)),
(EthereumHardfork::MuirGlacier, ForkCondition::Block(0)),
(EthereumHardfork::Berlin, ForkCondition::Block(0)),
]
.into_iter()
.map(|(a, b)| (a.boxed(), b))
.collect(),
),
..Default::default()
}
.into()
});

/// A wrapper around [`BaseFeeParams`] that allows for specifying constant or dynamic EIP-1559
/// parameters based on the active [Hardfork].
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -685,6 +753,12 @@ 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 All @@ -693,6 +767,7 @@ impl ChainSpec {
C::Optimism => Some(op_nodes()),
C::BaseGoerli | C::BaseSepolia => Some(base_testnet_nodes()),
C::OptimismSepolia | C::OptimismGoerli | C::OptimismKovan => Some(op_testnet_nodes()),

_ => None,
}
}
Expand Down Expand Up @@ -1145,6 +1220,9 @@ mod tests {
#[cfg(feature = "optimism")]
use reth_ethereum_forks::OptimismHardforks;

#[cfg(feature = "telos")]
use crate::{TEVMMAINNET, TEVMTESTNET};

fn test_fork_ids(spec: &ChainSpec, cases: &[(Head, ForkId)]) {
for (block, expected_id) in cases {
let computed_id = spec.fork_id(block);
Expand Down Expand Up @@ -1808,6 +1886,18 @@ Post-merge hard forks (timestamp based):
);
}

#[test]
#[cfg(feature = "telos")]
fn tevmmainnet_forkids() {
test_fork_ids(&TEVMMAINNET, &[]);
}

#[test]
#[cfg(feature = "telos")]
fn tevmtestnet_forkids() {
test_fork_ids(&TEVMTESTNET, &[]);
}

#[test]
fn dev_forkids() {
test_fork_ids(
Expand Down
1 change: 1 addition & 0 deletions crates/net/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ default = ["serde"]
geth-tests = []
serde = ["dep:serde", "secp256k1/serde", "enr/serde", "reth-network-types/serde"]
test-utils = ["dep:reth-provider", "reth-provider?/test-utils", "dep:tempfile", "reth-transaction-pool/test-utils", "reth-network-types/test-utils"]
telos = ["reth-network-peers/telos"]

[[bench]]
name = "bench"
Expand Down
16 changes: 16 additions & 0 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ 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 @@ -386,6 +390,18 @@ 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/net/peers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tokio = { workspace = true, features = ["net", "macros", "rt"] }
[features]
secp256k1 = ["dep:secp256k1", "enr/secp256k1"]
net = ["dep:tokio", "tokio?/net"]
telos = []
17 changes: 17 additions & 0 deletions crates/net/peers/src/bootnodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ pub use ethereum::*;
mod optimism;
pub use optimism::*;

#[cfg(feature = "telos")]
mod telos;
#[cfg(feature = "telos")]
pub use telos::*;

/// Returns parsed mainnet nodes
pub fn mainnet_nodes() -> Vec<NodeRecord> {
parse_nodes(&MAINNET_BOOTNODES[..])
Expand Down Expand Up @@ -47,3 +52,15 @@ pub fn base_testnet_nodes() -> Vec<NodeRecord> {
pub fn parse_nodes(nodes: impl IntoIterator<Item = impl AsRef<str>>) -> Vec<NodeRecord> {
nodes.into_iter().map(|s| s.as_ref().parse().unwrap()).collect()
}

#[cfg(feature = "telos")]
/// Returns parsed tevmmainnet nodes
pub fn tevmmainnet_nodes() -> Vec<NodeRecord> {
parse_nodes(&TEVMMAINNET_BOOTNODES[..])
}

#[cfg(feature = "telos")]
/// Returns parsed tevmtestnet nodes
pub fn tevmtestnet_nodes() -> Vec<NodeRecord> {
parse_nodes(&TEVMTESTNET_BOOTNODES[..])
}
7 changes: 7 additions & 0 deletions crates/net/peers/src/bootnodes/telos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Telos bootnodes
/// Ethereum Foundation TEVMMAINNET BOOTNODES
pub static TEVMMAINNET_BOOTNODES: [&str; 0] = [];

/// Ethereum Foundation TEVMTESTNET BOOTNODES
pub static TEVMTESTNET_BOOTNODES: [&str; 0] = [];
2 changes: 2 additions & 0 deletions crates/node/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ optimism = [
"reth-rpc-types-compat/optimism",
"reth-rpc-eth-api/optimism",
]
telos = ["reth-chainspec/telos"]

# Features for vergen to generate correct env vars
jemalloc = []
asm-keccak = []
Expand Down
20 changes: 15 additions & 5 deletions crates/node/core/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ use std::{path::PathBuf, sync::Arc};

use reth_chainspec::DEV;

#[cfg(feature = "telos")]
use reth_chainspec::{TEVMMAINNET, TEVMTESTNET};

#[cfg(feature = "optimism")]
use reth_chainspec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};

#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
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(not(feature = "optimism"))]
#[cfg(feature = "telos")]
/// Chains supported by telos-reth
pub const SUPPORTED_CHAINS: &[&str] = &["tevmmainnet", "tevmtestnet"];
#[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"];

Expand All @@ -31,11 +37,11 @@ pub fn chain_help() -> String {
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
Ok(match s {
#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
"mainnet" => MAINNET.clone(),
#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
"sepolia" => SEPOLIA.clone(),
#[cfg(not(feature = "optimism"))]
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
"holesky" => HOLESKY.clone(),
"dev" => DEV.clone(),
#[cfg(feature = "optimism")]
Expand All @@ -46,6 +52,10 @@ pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error>
"base" => BASE_MAINNET.clone(),
#[cfg(feature = "optimism")]
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
#[cfg(feature = "telos")]
"tevmmainnet" => TEVMMAINNET.clone(),
#[cfg(feature = "telos")]
"tevmtestnet" => TEVMTESTNET.clone(),
_ => {
// try to read json from path first
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
Expand Down
15 changes: 15 additions & 0 deletions crates/node/core/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ mod tests {
let path = MaybePlatformPath::<DataDirPath>::from_str("my/path/to/datadir").unwrap();
let path = path.unwrap_or_chain_default(Chain::mainnet(), DatadirArgs::default());
assert!(path.as_ref().ends_with("my/path/to/datadir"), "{path:?}");

#[cfg(feature = "telos")]
{
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::from_id(40), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/tevmmainnet"), "{:?}", path);
}
}

#[test]
Expand All @@ -389,6 +396,14 @@ mod tests {

let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::sepolia(), DatadirArgs::default());

assert!(path.as_ref().ends_with("reth/sepolia"), "{path:?}");

#[cfg(feature = "telos")]
{
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::from_id(41), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/tevmtestnet"), "{:?}", path);
}
}
}
1 change: 1 addition & 0 deletions crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ arbitrary = [
"dep:proptest-arbitrary-interop",
]
alloy-compat = ["alloy-rpc-types-eth"]
telos = []
Loading

0 comments on commit 59df97d

Please sign in to comment.