Skip to content

Commit

Permalink
Add tevmmainnet-base and tevmtestnet-base 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 50e0c39 commit 48102e9
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/chainspec/res/genesis/tevmmainnet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"nonce": "0x00",
"nonce": "0x0",
"timestamp": "0x5c114972",
"extraData": "0x00000024796a9998ec49fb788de51614c57276dc6151bd2328305dba5d018897",
"gasLimit": "0x7fffffff",
Expand Down
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"
}
2 changes: 1 addition & 1 deletion crates/chainspec/res/genesis/tevmtestnet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"nonce": "0x00",
"nonce": "0x0",
"timestamp": "0x5d55db93",
"extraData": "0x000000397128c497668c241b27d1521c764156cea50bcac87892fc8916e23b24",
"gasLimit": "0x7fffffff",
Expand Down
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"
}
2 changes: 1 addition & 1 deletion crates/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use spec::{
pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};

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

#[cfg(not(feature = "std"))]
extern crate alloc;
Expand Down
85 changes: 84 additions & 1 deletion crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,73 @@ pub static TEVMTESTNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.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 @@ -494,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 @@ -1221,7 +1292,7 @@ mod tests {
use reth_ethereum_forks::OptimismHardforks;

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

fn test_fork_ids(spec: &ChainSpec, cases: &[(Head, ForkId)]) {
for (block, expected_id) in cases {
Expand Down Expand Up @@ -1898,6 +1969,18 @@ Post-merge hard forks (timestamp based):
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
9 changes: 7 additions & 2 deletions crates/node/core/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{path::PathBuf, sync::Arc};
use reth_chainspec::DEV;

#[cfg(feature = "telos")]
use reth_chainspec::{TEVMMAINNET, TEVMTESTNET};
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 @@ -21,7 +21,8 @@ use reth_chainspec::{HOLESKY, MAINNET, SEPOLIA};
pub const SUPPORTED_CHAINS: &[&str] = &["optimism", "optimism-sepolia", "base", "base-sepolia"];
#[cfg(feature = "telos")]
/// Chains supported by telos-reth
pub const SUPPORTED_CHAINS: &[&str] = &["tevmmainnet", "tevmtestnet"];
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"];
Expand Down Expand Up @@ -56,6 +57,10 @@ pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error>
"tevmmainnet" => TEVMMAINNET.clone(),
#[cfg(feature = "telos")]
"tevmtestnet" => TEVMTESTNET.clone(),
#[cfg(feature = "telos")]
"tevmmainnet-base" => TEVMMAINNET_BASE.clone(),
#[cfg(feature = "telos")]
"tevmtestnet-base" => 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
8 changes: 8 additions & 0 deletions crates/node/core/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ mod tests {
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);

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-base"), "{:?}", path);
}
}

Expand All @@ -404,6 +408,10 @@ mod tests {
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);

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-base"), "{:?}", path);
}
}
}
11 changes: 11 additions & 0 deletions crates/primitives-traits/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ pub const TEVMMAINNET_GENESIS_HASH: B256 =
pub const TEVMTESTNET_GENESIS_HASH: B256 =
b256!("b25034033c9ca7a40e879ddcc29cf69071a22df06688b5fe8cc2d68b4e0528f9");

#[cfg(feature = "telos")]
/// Tevmmainnet base genesis hash.
pub const TEVMMAINNET_BASE_GENESIS_HASH: B256 =
b256!("757720a8e51c63ef1d4f907d6569dacaa965e91c2661345902de18af11f81063");

#[cfg(feature = "telos")]
/// Tevmtestnet base genesis hash.
/// TODO: Block hash not finalized yet, need to modify the parent hash
pub const TEVMTESTNET_BASE_GENESIS_HASH: B256 =
b256!("a6da3143bdeab454a923ac47589700ebe75d734f26e1f9201caa9b7268045d02");

/// Holesky genesis hash: `0xb5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4`
pub const HOLESKY_GENESIS_HASH: B256 =
b256!("b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4");
Expand Down
7 changes: 5 additions & 2 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub use constants::{
MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH,
};
#[cfg(feature = "telos")]
pub use constants::{TEVMMAINNET_GENESIS_HASH, TEVMTESTNET_GENESIS_HASH};
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 @@ -125,7 +128,7 @@ pub use optimism::*;
/// Telos specific re-exports
#[cfg(feature = "telos")]
mod telos {
pub use reth_chainspec::{TEVMMAINNET, TEVMTESTNET};
pub use reth_chainspec::{TEVMMAINNET, TEVMMAINNET_BASE, TEVMTESTNET, TEVMTESTNET_BASE};
}

#[cfg(feature = "telos")]
Expand Down
26 changes: 25 additions & 1 deletion crates/primitives/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mod tests {
use alloy_rlp::Decodable;
use reth_chainspec::{HOLESKY, MAINNET, SEPOLIA};
#[cfg(feature = "telos")]
use reth_chainspec::{TEVMMAINNET, TEVMTESTNET};
use reth_chainspec::{TEVMMAINNET, TEVMMAINNET_BASE, TEVMTESTNET, TEVMTESTNET_BASE};
use reth_trie_common::root::{state_root_ref_unhashed, state_root_unhashed};
use std::collections::HashMap;

Expand Down Expand Up @@ -557,6 +557,30 @@ mod tests {
);
}

#[cfg(feature = "telos")]
{
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"
);
}

#[cfg(feature = "telos")]
{
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"
);
}

#[cfg(feature = "telos")]
{
let expected_tevmtestnet_state_root =
Expand Down
47 changes: 44 additions & 3 deletions crates/storage/db-common/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ 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"))]

provider_rw.save_stage_checkpoint(stage, Default::default())?;
}

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

provider.tx_ref().put::<tables::HeaderNumbers>(block_hash, 0)?;
provider.tx_ref().put::<tables::BlockBodyIndices>(0, Default::default())?;
#[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)?;
}

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

Ok(())
}
Expand Down Expand Up @@ -540,7 +558,8 @@ mod tests {
use reth_primitives::{HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH};
#[cfg(feature = "telos")]
use reth_primitives::{
TEVMMAINNET, TEVMMAINNET_GENESIS_HASH, TEVMTESTNET, TEVMTESTNET_GENESIS_HASH,
TEVMMAINNET, TEVMMAINNET_BASE, TEVMMAINNET_BASE_GENESIS_HASH, TEVMMAINNET_GENESIS_HASH,
TEVMTESTNET, TEVMTESTNET_BASE, TEVMTESTNET_BASE_GENESIS_HASH, TEVMTESTNET_GENESIS_HASH,
};
use reth_primitives_traits::IntegerList;
use reth_provider::test_utils::create_test_provider_factory_with_chain_spec;
Expand Down Expand Up @@ -604,6 +623,28 @@ mod tests {
assert_eq!(genesis_hash, TEVMTESTNET_GENESIS_HASH);
}

#[test]
#[cfg(feature = "telos")]
fn success_init_genesis_tevmmainnet_base() {
let genesis_hash =
init_genesis(create_test_provider_factory_with_chain_spec(TEVMMAINNET_BASE.clone()))
.unwrap();

// actual, expected
assert_eq!(genesis_hash, TEVMMAINNET_BASE_GENESIS_HASH);
}

#[test]
#[cfg(feature = "telos")]
fn success_init_genesis_tevmtestnet_base() {
let genesis_hash =
init_genesis(create_test_provider_factory_with_chain_spec(TEVMTESTNET_BASE.clone()))
.unwrap();

// actual, expected
assert_eq!(genesis_hash, TEVMTESTNET_BASE_GENESIS_HASH);
}

#[test]
fn fail_init_inconsistent_db() {
let factory = create_test_provider_factory_with_chain_spec(SEPOLIA.clone());
Expand Down

0 comments on commit 48102e9

Please sign in to comment.