Skip to content

Commit

Permalink
Add Telos mainnet/testnet chainspecs/genesis to the supported chains
Browse files Browse the repository at this point in the history
  • Loading branch information
coa-telos authored and poplexity committed Aug 17, 2024
1 parent 66469d3 commit 52a0454
Show file tree
Hide file tree
Showing 33 changed files with 676 additions and 199 deletions.
352 changes: 165 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ ethereum = []
telos = [
"dep:reth-node-telos",
"dep:reth-telos-rpc",
"reth-chainspec/telos",
"reth-basic-payload-builder/telos",
"reth-ethereum-payload-builder/telos",
"reth-evm/telos",
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
4 changes: 4 additions & 0 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ 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`?");

<<<<<<< Updated upstream
#[cfg(all(not(feature = "optimism"), not(feature = "telos")))]
=======
#[cfg(not(feature = "optimism"))]
>>>>>>> Stashed changes
/// 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 bin/reth/src/telos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ compile_error!("Cannot build the `telos-reth` binary with the `optimism` feature

#[cfg(feature = "telos")]
fn main() {
<<<<<<< Updated upstream
use reth::cli::Cli;
=======
>>>>>>> Stashed changes

reth_cli_util::sigsegv_handler::install();

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": "0x0",
"timestamp": "0x5c114972",
"extraData": "0x00000024796a9998ec49fb788de51614c57276dc6151bd2328305dba5d018897",
"gasLimit": "0x7fffffff",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
13 changes: 13 additions & 0 deletions crates/chainspec/res/genesis/tevmmainnet_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x0",
"timestamp": "0x61782354",
"extraData": "0x0ac53eebcfa1cf139272bf58540d6dc53f0d22785f9e3d74cb9bc333b597e1bf",
"gasLimit": "0x7fffffff",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"number": "0xac53ec7",
"gasUsed": "0x0",
"parentHash": "0x87bb009caefe5447b3c4beafb6cc168d031a73eb9c6bb0718b5b5972448908c2"
}
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": "0x0",
"timestamp": "0x5d55db93",
"extraData": "0x000000397128c497668c241b27d1521c764156cea50bcac87892fc8916e23b24",
"gasLimit": "0x7fffffff",
"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_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x0",
"timestamp": "0x6170fef7",
"extraData": "0x0821345567cd66541778157d3936896f62a5b3fa134bb34d9708aa52f0c8c713",
"gasLimit": "0x7fffffff",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"stateRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"number": "0x821341c",
"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, TEVMMAINNET_BASE, TEVMTESTNET_BASE};

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

Expand Down
173 changes: 173 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,139 @@ 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!(
"36fe7024b760365e3970b7b403e161811c1e626edd68460272fcdfa276272563"
)),
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!(
"b25034033c9ca7a40e879ddcc29cf69071a22df06688b5fe8cc2d68b4e0528f9"
)),
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 Tevmmainnet-base spec
pub static TEVMMAINNET_BASE: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::from_id(40),
genesis: serde_json::from_str(include_str!("../res/genesis/tevmmainnet_base.json"))
.expect("Can't deserialize Tevmmainnet-base genesis json"),
genesis_hash: Some(b256!(
"757720a8e51c63ef1d4f907d6569dacaa965e91c2661345902de18af11f81063"
)),
hardforks: ChainHardforks::new(
vec![
(EthereumHardfork::Frontier, ForkCondition::Block(180698823)),
(EthereumHardfork::Homestead, ForkCondition::Block(180698823)),
(EthereumHardfork::Dao, ForkCondition::Block(180698823)),
(EthereumHardfork::Tangerine, ForkCondition::Block(180698823)),
(EthereumHardfork::SpuriousDragon, ForkCondition::Block(180698823)),
(EthereumHardfork::Byzantium, ForkCondition::Block(180698823)),
(EthereumHardfork::Constantinople, ForkCondition::Block(180698823)),
(EthereumHardfork::Petersburg, ForkCondition::Block(180698823)),
(EthereumHardfork::Istanbul, ForkCondition::Block(180698823)),
(EthereumHardfork::MuirGlacier, ForkCondition::Block(180698823)),
(EthereumHardfork::Berlin, ForkCondition::Block(180698823)),
]
.into_iter()
.map(|(a, b)| (a.boxed(), b))
.collect(),
),
..Default::default()
}
.into()
});

#[cfg(feature = "telos")]
/// The Tevmtestnet-base spec
/// TODO: Block hash not finalized yet, need to modify the parent hash
pub static TEVMTESTNET_BASE: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::from_id(41),
genesis: serde_json::from_str(include_str!("../res/genesis/tevmtestnet_base.json"))
.expect("Can't deserialize Tevmtestnet-base genesis json"),
genesis_hash: Some(b256!(
"a6da3143bdeab454a923ac47589700ebe75d734f26e1f9201caa9b7268045d02"
)),
hardforks: ChainHardforks::new(
vec![
(EthereumHardfork::Frontier, ForkCondition::Block(136393756)),
(EthereumHardfork::Homestead, ForkCondition::Block(136393756)),
(EthereumHardfork::Dao, ForkCondition::Block(136393756)),
(EthereumHardfork::Tangerine, ForkCondition::Block(136393756)),
(EthereumHardfork::SpuriousDragon, ForkCondition::Block(136393756)),
(EthereumHardfork::Byzantium, ForkCondition::Block(136393756)),
(EthereumHardfork::Constantinople, ForkCondition::Block(136393756)),
(EthereumHardfork::Petersburg, ForkCondition::Block(136393756)),
(EthereumHardfork::Istanbul, ForkCondition::Block(136393756)),
(EthereumHardfork::MuirGlacier, ForkCondition::Block(136393756)),
(EthereumHardfork::Berlin, ForkCondition::Block(136393756)),
]
.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 @@ -426,6 +561,10 @@ impl ChainSpec {
blob_gas_used,
excess_blob_gas,
requests_root,
#[cfg(feature = "telos")]
number: self.genesis.number.unwrap_or_default(),
#[cfg(not(feature = "telos"))]
number: 0,
..Default::default()
}
}
Expand Down Expand Up @@ -685,6 +824,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 +838,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 +1291,9 @@ mod tests {
#[cfg(feature = "optimism")]
use reth_ethereum_forks::OptimismHardforks;

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

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 +1957,30 @@ 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]
#[cfg(feature = "telos")]
fn tevmmainnet_base_forkids() {
test_fork_ids(&TEVMMAINNET_BASE, &[]);
}

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

#[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 = []
Loading

0 comments on commit 52a0454

Please sign in to comment.