diff --git a/Cargo.lock b/Cargo.lock index 391a4285f8c6..671fd7b3aac3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4190,6 +4190,32 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "parse-display" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddcac6cdc2aaa03a89780c6681ffb46ac5b4b7dbade8d2a20a6a501f6fd363a8" +dependencies = [ + "once_cell", + "parse-display-derive", + "regex", +] + +[[package]] +name = "parse-display-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e503280f7d6dbf7566bc63d903c3b0f595fc11553a7e1f87f81adb8fcbca983" +dependencies = [ + "once_cell", + "proc-macro2 1.0.60", + "quote 1.0.28", + "regex", + "regex-syntax 0.6.29", + "structmeta", + "syn 2.0.18", +] + [[package]] name = "paste" version = "1.0.11" @@ -4951,6 +4977,7 @@ dependencies = [ "metrics-exporter-prometheus", "metrics-process", "metrics-util", + "parse-display", "pin-project", "pretty_assertions", "proptest", @@ -5285,6 +5312,7 @@ dependencies = [ "serde", "smol_str", "snap", + "symphony-primitives", "test-fuzz", "thiserror", "tokio", @@ -5517,6 +5545,7 @@ dependencies = [ "impl-serde", "modular-bitfield", "once_cell", + "parse-display", "plain_hasher", "pprof", "proptest", @@ -5533,6 +5562,7 @@ dependencies = [ "serde_with", "strum", "sucds", + "symphony-primitives", "test-fuzz", "thiserror", "tiny-keccak", @@ -6802,6 +6832,29 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "structmeta" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" +dependencies = [ + "proc-macro2 1.0.60", + "quote 1.0.28", + "structmeta-derive", + "syn 2.0.18", +] + +[[package]] +name = "structmeta-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" +dependencies = [ + "proc-macro2 1.0.60", + "quote 1.0.28", + "syn 2.0.18", +] + [[package]] name = "strum" version = "0.24.1" @@ -6888,6 +6941,12 @@ dependencies = [ [[package]] name = "symphony-primitives" version = "0.1.0-alpha.1" +dependencies = [ + "parse-display", + "serde", + "serde_json", + "thiserror", +] [[package]] name = "syn" diff --git a/Cargo.toml b/Cargo.toml index 65f45d52d14e..2fcf531789f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,6 +108,7 @@ thiserror = "1.0.37" serde_json = "1.0.94" serde = { version = "1.0", default-features = false } rand = "0.8.5" +parse-display = "0.8.1" ## tokio diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index d9955fa8910d..18c65d607580 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -86,6 +86,7 @@ hex = "0.4" thiserror = { workspace = true } pretty_assertions = "1.3.0" humantime = "2.1.0" +parse-display = { workspace = true } [features] jemalloc = ["dep:jemallocator", "dep:jemalloc-ctl"] diff --git a/bin/reth/src/args/utils.rs b/bin/reth/src/args/utils.rs index 031b457d2ef4..52c65077f458 100644 --- a/bin/reth/src/args/utils.rs +++ b/bin/reth/src/args/utils.rs @@ -1,6 +1,6 @@ //! Clap parser utilities -use reth_primitives::{AllGenesisFormats, BlockHashOrNumber, ChainSpec, GOERLI, MAINNET, SEPOLIA}; +use reth_primitives::{AllGenesisFormats, BlockHashOrNumber, ChainSpec, TESTNET_SPEC, MAINNET_SPEC, DEVNET_SPEC}; use reth_revm::primitives::B256 as H256; use std::{ net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, @@ -20,9 +20,9 @@ pub fn parse_duration_from_secs(arg: &str) -> eyre::Result eyre::Result, eyre::Error> { Ok(match s { - "mainnet" => MAINNET.clone(), - "goerli" => GOERLI.clone(), - "sepolia" => SEPOLIA.clone(), + "mainnet" => MAINNET_SPEC.clone(), + "testnet" => TESTNET_SPEC.clone(), + "devnet" => DEVNET_SPEC.clone(), _ => { let raw = std::fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?; serde_json::from_str(&raw)? @@ -34,9 +34,9 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result, eyre::Er /// to a custom one. pub fn genesis_value_parser(s: &str) -> eyre::Result, eyre::Error> { Ok(match s { - "mainnet" => MAINNET.clone(), - "goerli" => GOERLI.clone(), - "sepolia" => SEPOLIA.clone(), + "mainnet" => MAINNET_SPEC.clone(), + "testnet" => TESTNET_SPEC.clone(), + "devnet" => DEVNET_SPEC.clone(), _ => { let raw = std::fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned()))?; let genesis: AllGenesisFormats = serde_json::from_str(&raw)?; diff --git a/bin/reth/src/dirs.rs b/bin/reth/src/dirs.rs index 796377b6a164..67cc42eb6b0c 100644 --- a/bin/reth/src/dirs.rs +++ b/bin/reth/src/dirs.rs @@ -12,10 +12,10 @@ use std::{ pub fn config_path_prefix(chain: Chain) -> String { if chain == Chain::mainnet() { "mainnet".to_string() - } else if chain == Chain::goerli() { - "goerli".to_string() - } else if chain == Chain::sepolia() { - "sepolia".to_string() + } else if chain == Chain::devnet() { + "devnet".to_string() + } else if chain == Chain::testnet() { + "testnet".to_string() } else { chain.id().to_string() } diff --git a/crates/consensus/beacon/src/beacon_consensus.rs b/crates/consensus/beacon/src/beacon_consensus.rs index 449d46845c76..762fa65bde23 100644 --- a/crates/consensus/beacon/src/beacon_consensus.rs +++ b/crates/consensus/beacon/src/beacon_consensus.rs @@ -72,7 +72,7 @@ impl Consensus for BeaconConsensus { // Goerli exception: // * If the network is goerli pre-merge, ignore the extradata check, since we do not // support clique. - if self.chain_spec.chain != Chain::goerli() { + if self.chain_spec.chain != Chain::devnet() { validate_header_extradata(header)?; } } diff --git a/crates/consensus/common/src/calc.rs b/crates/consensus/common/src/calc.rs index 304a081e5ce2..f687adece23e 100644 --- a/crates/consensus/common/src/calc.rs +++ b/crates/consensus/common/src/calc.rs @@ -25,7 +25,7 @@ pub fn base_block_reward( block_difficulty: U256, total_difficulty: U256, ) -> Option { - if chain_spec.chain == Chain::goerli() || + if chain_spec.chain == Chain::devnet() || chain_spec.fork(Hardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) { None diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index de43afd7130b..ac360263640d 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -13,6 +13,9 @@ bytes.workspace = true thiserror = { workspace = true } serde = { workspace = true, optional = true } +#symphony +symphony-primitives = { workspace = true } + # reth reth-codecs = { path = "../../storage/codecs" } reth-primitives = { workspace = true } diff --git a/crates/net/eth-wire/src/types/status.rs b/crates/net/eth-wire/src/types/status.rs index a29af1894147..ca6264c637b5 100644 --- a/crates/net/eth-wire/src/types/status.rs +++ b/crates/net/eth-wire/src/types/status.rs @@ -2,9 +2,10 @@ use crate::{EthVersion, StatusBuilder}; use reth_codecs::derive_arbitrary; use reth_primitives::{ - hex, Chain, ChainSpec, ForkId, Genesis, Hardfork, Head, H256, MAINNET, U256, + hex, Chain, ChainSpec, ForkId, Genesis, Hardfork, Head, H256, MAINNET_SPEC, U256, }; use reth_rlp::{RlpDecodable, RlpEncodable}; +use symphony_primitives::SymphonyChains; use std::fmt::{Debug, Display}; #[cfg(feature = "serde")] @@ -132,15 +133,15 @@ impl Debug for Status { // impl Default for Status { fn default() -> Self { - let mainnet_genesis = MAINNET.genesis_hash(); + let mainnet_genesis = MAINNET_SPEC.genesis_hash(); Status { version: EthVersion::Eth68 as u8, - chain: Chain::Named(ethers_core::types::Chain::Mainnet), + chain: Chain::Named(SymphonyChains::Mainnet), total_difficulty: U256::from(17_179_869_184u64), blockhash: mainnet_genesis, genesis: mainnet_genesis, forkid: Hardfork::Frontier - .fork_id(&MAINNET) + .fork_id(&MAINNET_SPEC) .expect("The Frontier hardfork should always exist"), } } diff --git a/crates/net/network/src/config.rs b/crates/net/network/src/config.rs index dbfc570873a5..08aebf243ed0 100644 --- a/crates/net/network/src/config.rs +++ b/crates/net/network/src/config.rs @@ -11,7 +11,7 @@ use reth_discv4::{Discv4Config, Discv4ConfigBuilder, DEFAULT_DISCOVERY_PORT}; use reth_dns_discovery::DnsDiscoveryConfig; use reth_ecies::util::pk2id; use reth_eth_wire::{HelloMessage, Status}; -use reth_primitives::{ChainSpec, ForkFilter, Head, NodeRecord, PeerId, MAINNET}; +use reth_primitives::{ChainSpec, ForkFilter, Head, NodeRecord, PeerId, MAINNET_SPEC}; use reth_provider::{BlockReader, HeaderProvider}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use secp256k1::SECP256K1; @@ -160,7 +160,7 @@ impl NetworkConfigBuilder { listener_addr: None, peers_config: None, sessions_config: None, - chain_spec: MAINNET.clone(), + chain_spec: MAINNET_SPEC.clone(), network_mode: Default::default(), executor: None, hello_message: None, @@ -456,7 +456,7 @@ mod tests { #[test] fn test_network_fork_filter_default() { - let mut chain_spec = Arc::clone(&MAINNET); + let mut chain_spec = Arc::clone(&MAINNET_SPEC); // remove any `next` fields we would have by removing all hardforks Arc::make_mut(&mut chain_spec).hardforks = BTreeMap::new(); diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 12822404dde0..9662dd6130eb 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -9,6 +9,9 @@ repository.workspace = true description = "Commonly used types in reth." [dependencies] +#symphony +symphony-primitives = { workspace = true } + # reth reth-rlp = { workspace = true, features = ["std", "derive", "ethereum-types"] } reth-rlp-derive = { path = "../rlp/rlp-derive" } @@ -56,6 +59,7 @@ url = "2.3" impl-serde = "0.4.0" once_cell = "1.17.0" zstd = { version = "0.12", features = ["experimental"] } +parse-display = { workspace = true } # proof related triehash = "0.8" diff --git a/crates/primitives/src/chain/mod.rs b/crates/primitives/src/chain/mod.rs index 43f4647a8c99..0a2fbc43e81c 100644 --- a/crates/primitives/src/chain/mod.rs +++ b/crates/primitives/src/chain/mod.rs @@ -1,17 +1,17 @@ use crate::{ - net::{goerli_nodes, mainnet_nodes, sepolia_nodes}, NodeRecord, U256, U64, }; use reth_codecs::add_arbitrary_tests; use reth_rlp::{Decodable, Encodable}; use serde::{Deserialize, Serialize}; +use symphony_primitives::{SymphonyChains}; use std::{fmt, str::FromStr}; // The chain spec module. mod spec; pub use spec::{ AllGenesisFormats, ChainSpec, ChainSpecBuilder, DisplayHardforks, ForkCondition, - ForkTimestamps, GOERLI, MAINNET, SEPOLIA, + ForkTimestamps, TESTNET_SPEC, MAINNET_SPEC, DEVNET_SPEC, }; // The chain info module. @@ -19,11 +19,11 @@ mod info; pub use info::ChainInfo; /// Either a named or chain id or the actual id value -#[add_arbitrary_tests(rlp)] +// #[add_arbitrary_tests(rlp)] // FIXME: what do we need to do to add this back? #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Chain { /// Contains a known chain - Named(ethers_core::types::Chain), + Named(SymphonyChains), /// Contains the id of a chain Id(u64), } @@ -31,17 +31,17 @@ pub enum Chain { impl Chain { /// Returns the mainnet chain. pub const fn mainnet() -> Self { - Chain::Named(ethers_core::types::Chain::Mainnet) + Chain::Named(SymphonyChains::Mainnet) } - /// Returns the goerli chain. - pub const fn goerli() -> Self { - Chain::Named(ethers_core::types::Chain::Goerli) + /// Returns the devnet chain. + pub const fn devnet() -> Self { + Chain::Named(SymphonyChains::Devnet) } - /// Returns the sepolia chain. - pub const fn sepolia() -> Self { - Chain::Named(ethers_core::types::Chain::Sepolia) + /// Returns the testnet chain. + pub const fn testnet() -> Self { + Chain::Named(SymphonyChains::Testnet) } /// The id of the chain @@ -52,39 +52,32 @@ impl Chain { } } - /// Helper function for checking if a chainid corresponds to a legacy chainid - /// without eip1559 - pub fn is_legacy(&self) -> bool { - match self { - Chain::Named(c) => c.is_legacy(), - Chain::Id(_) => false, - } - } - /// Returns the address of the public DNS node list for the given chain. /// /// See also pub fn public_dns_network_protocol(self) -> Option { - use ethers_core::types::Chain::*; - const DNS_PREFIX: &str = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@"; + todo!() + // use ethers_core::types::Chain::*; + // const DNS_PREFIX: &str = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@"; - let named: ethers_core::types::Chain = self.try_into().ok()?; + // let named: ethers_core::types::Chain = self.try_into().ok()?; - if matches!(named, Mainnet | Goerli | Sepolia | Ropsten | Rinkeby) { - return Some(format!("{DNS_PREFIX}all.{}.ethdisco.net", named.as_ref().to_lowercase())) - } - None + // if matches!(named, Mainnet | Goerli | Sepolia | Ropsten | Rinkeby) { + // return Some(format!("{DNS_PREFIX}all.{}.ethdisco.net", named.as_ref().to_lowercase())) + // } + // None } - /// Returns bootnodes for the given chain. + /// Returns bootnodes for the given chain. pub fn bootnodes(self) -> Option> { - use ethers_core::types::Chain::*; - match self.try_into().ok()? { - Mainnet => Some(mainnet_nodes()), - Goerli => Some(goerli_nodes()), - Sepolia => Some(sepolia_nodes()), - _ => None, - } + todo!() + // use ethers_core::types::Chain::*; + // match self.try_into().ok()? { + // Mainnet => Some(mainnet_nodes()), + // Goerli => Some(goerli_nodes()), + // Sepolia => Some(sepolia_nodes()), + // _ => None, + // } } } @@ -103,15 +96,15 @@ impl fmt::Display for Chain { } } -impl From for Chain { - fn from(id: ethers_core::types::Chain) -> Self { +impl From for Chain { + fn from(id: SymphonyChains) -> Self { Chain::Named(id) } } impl From for Chain { fn from(id: u64) -> Self { - ethers_core::types::Chain::try_from(id).map(Chain::Named).unwrap_or_else(|_| Chain::Id(id)) + SymphonyChains::try_from(id).map(Chain::Named).unwrap_or_else(|_| Chain::Id(id)) } } @@ -142,22 +135,11 @@ impl From for U256 { } } -impl TryFrom for ethers_core::types::Chain { - type Error = >::Error; - - fn try_from(chain: Chain) -> Result { - match chain { - Chain::Named(chain) => Ok(chain), - Chain::Id(id) => id.try_into(), - } - } -} - impl FromStr for Chain { type Err = String; fn from_str(s: &str) -> Result { - if let Ok(chain) = ethers_core::types::Chain::from_str(s) { + if let Ok(chain) = SymphonyChains::try_from(s) { Ok(Chain::Named(chain)) } else { s.parse::() @@ -170,13 +152,14 @@ impl FromStr for Chain { impl Encodable for Chain { fn encode(&self, out: &mut dyn reth_rlp::BufMut) { match self { - Self::Named(chain) => u64::from(*chain).encode(out), - Self::Id(id) => id.encode(out), - } + Self::Named(chain) => u64::try_from(*chain).unwrap(), + Self::Id(id) => *id, + }.encode(out) } + fn length(&self) -> usize { match self { - Self::Named(chain) => u64::from(*chain).length(), + Self::Named(chain) => u64::try_from(*chain).unwrap().length(), Self::Id(id) => id.length(), } } @@ -190,49 +173,52 @@ impl Decodable for Chain { impl Default for Chain { fn default() -> Self { - ethers_core::types::Chain::Mainnet.into() - } -} - -#[cfg(any(test, feature = "arbitrary"))] -impl<'a> arbitrary::Arbitrary<'a> for Chain { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - if u.ratio(1, 2)? { - let chain = u.int_in_range(0..=(ethers_core::types::Chain::COUNT - 1))?; - - return Ok(Chain::Named(ethers_core::types::Chain::iter().nth(chain).expect("in range"))) - } - - Ok(Self::Id(u64::arbitrary(u)?)) + Chain::Named(SymphonyChains::Mainnet) } } -#[cfg(any(test, feature = "arbitrary"))] -use strum::{EnumCount, IntoEnumIterator}; - -#[cfg(any(test, feature = "arbitrary"))] -use proptest::{ - arbitrary::ParamsFor, - prelude::{any, Strategy}, - sample::Selector, - strategy::BoxedStrategy, -}; - -#[cfg(any(test, feature = "arbitrary"))] -impl proptest::arbitrary::Arbitrary for Chain { - type Parameters = ParamsFor; - fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { - let named = any::() - .prop_map(move |sel| Chain::Named(sel.select(ethers_core::types::Chain::iter()))); - let id = any::().prop_map(Chain::from); - proptest::strategy::Union::new_weighted(vec![(50, named.boxed()), (50, id.boxed())]).boxed() - } - - type Strategy = BoxedStrategy; -} +// FIXME: what does this do? +// #[cfg(any(test, feature = "arbitrary"))] +// impl<'a> arbitrary::Arbitrary<'a> for Chain { +// fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { +// if u.ratio(1, 2)? { +// let chain = u.int_in_range(0..=(ethers_core::types::Chain::COUNT - 1))?; + +// return Ok(Chain::Named(ethers_core::types::Chain::iter().nth(chain).expect("in range"))) +// } + +// Ok(Self::Id(u64::arbitrary(u)?)) +// } +// } + +// #[cfg(any(test, feature = "arbitrary"))] +// use strum::{EnumCount, IntoEnumIterator}; + +// #[cfg(any(test, feature = "arbitrary"))] +// use proptest::{ +// arbitrary::ParamsFor, +// prelude::{any, Strategy}, +// sample::Selector, +// strategy::BoxedStrategy, +// }; + +// #[cfg(any(test, feature = "arbitrary"))] +// impl proptest::arbitrary::Arbitrary for Chain { +// type Parameters = ParamsFor; +// fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { +// let named = any::() +// .prop_map(move |sel| Chain::Named(sel.select(ethers_core::types::Chain::iter()))); +// let id = any::().prop_map(Chain::from); +// proptest::strategy::Union::new_weighted(vec![(50, named.boxed()), (50, id.boxed())]).boxed() +// } + +// type Strategy = BoxedStrategy; +// } #[cfg(test)] mod tests { + use symphony_primitives::constants::DEVNET_ID; + use super::*; #[test] @@ -243,31 +229,13 @@ mod tests { #[test] fn test_named_id() { - let chain = Chain::Named(ethers_core::types::Chain::Goerli); - assert_eq!(chain.id(), 5); - } - - #[test] - fn test_legacy_named_chain() { - let chain = Chain::Named(ethers_core::types::Chain::Optimism); - assert!(chain.is_legacy()); - } - - #[test] - fn test_not_legacy_named_chain() { - let chain = Chain::Named(ethers_core::types::Chain::Mainnet); - assert!(!chain.is_legacy()); - } - - #[test] - fn test_not_legacy_id_chain() { - let chain = Chain::Id(1234); - assert!(!chain.is_legacy()); + let chain = Chain::Named(SymphonyChains::Devnet); + assert_eq!(chain.id(), DEVNET_ID); } #[test] fn test_display_named_chain() { - let chain = Chain::Named(ethers_core::types::Chain::Mainnet); + let chain = Chain::Named(SymphonyChains::Mainnet); assert_eq!(format!("{chain}"), "mainnet"); } @@ -288,9 +256,9 @@ mod tests { #[test] fn test_into_u256() { - let chain = Chain::Named(ethers_core::types::Chain::Goerli); + let chain = Chain::Named(SymphonyChains::Devnet); let n: U256 = chain.into(); - let expected = U256::from(5); + let expected = U256::from(DEVNET_ID); assert_eq!(n, expected); } @@ -298,9 +266,9 @@ mod tests { #[test] #[allow(non_snake_case)] fn test_into_U64() { - let chain = Chain::Named(ethers_core::types::Chain::Goerli); + let chain = Chain::Named(SymphonyChains::Devnet); let n: U64 = chain.into(); - let expected = U64::from(5); + let expected = U64::from(DEVNET_ID); assert_eq!(n, expected); } @@ -308,7 +276,7 @@ mod tests { #[test] fn test_from_str_named_chain() { let result = Chain::from_str("mainnet"); - let expected = Chain::Named(ethers_core::types::Chain::Mainnet); + let expected = Chain::Named(SymphonyChains::Mainnet); assert!(result.is_ok()); assert_eq!(result.unwrap(), expected); @@ -333,7 +301,7 @@ mod tests { #[test] fn test_default() { let default = Chain::default(); - let expected = Chain::Named(ethers_core::types::Chain::Mainnet); + let expected = Chain::Named(SymphonyChains::Mainnet); assert_eq!(default, expected); } @@ -345,10 +313,10 @@ mod tests { assert_eq!(chain.length(), 3); } - #[test] - fn test_dns_network() { - let s = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.mainnet.ethdisco.net"; - let chain: Chain = ethers_core::types::Chain::Mainnet.into(); - assert_eq!(s, chain.public_dns_network_protocol().unwrap().as_str()); - } + // #[test] + // fn test_dns_network() { + // let s = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.mainnet.ethdisco.net"; + // let chain: Chain = ethers_core::types::Chain::Mainnet.into(); + // assert_eq!(s, chain.public_dns_network_protocol().unwrap().as_str()); + // } } diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 4e888a5c10d1..92f8148bee58 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -16,7 +16,7 @@ use std::{ }; /// The Ethereum mainnet spec -pub static MAINNET: Lazy> = Lazy::new(|| { +pub static MAINNET_SPEC: Lazy> = Lazy::new(|| { ChainSpec { chain: Chain::mainnet(), genesis: serde_json::from_str(include_str!("../../res/genesis/mainnet.json")) @@ -58,10 +58,10 @@ pub static MAINNET: Lazy> = Lazy::new(|| { .into() }); -/// The Goerli spec -pub static GOERLI: Lazy> = Lazy::new(|| { +/// The devnet spec +pub static DEVNET_SPEC: Lazy> = Lazy::new(|| { ChainSpec { - chain: Chain::goerli(), + chain: Chain::devnet(), genesis: serde_json::from_str(include_str!("../../res/genesis/goerli.json")) .expect("Can't deserialize Goerli genesis json"), genesis_hash: Some(H256(hex!( @@ -92,10 +92,10 @@ pub static GOERLI: Lazy> = Lazy::new(|| { .into() }); -/// The Sepolia spec -pub static SEPOLIA: Lazy> = Lazy::new(|| { +/// The Testnet spec +pub static TESTNET_SPEC: Lazy> = Lazy::new(|| { ChainSpec { - chain: Chain::sepolia(), + chain: Chain::testnet(), genesis: serde_json::from_str(include_str!("../../res/genesis/sepolia.json")) .expect("Can't deserialize Sepolia genesis json"), genesis_hash: Some(H256(hex!( @@ -444,9 +444,9 @@ impl ChainSpecBuilder { /// Construct a new builder from the mainnet chain spec. pub fn mainnet() -> Self { Self { - chain: Some(MAINNET.chain), - genesis: Some(MAINNET.genesis.clone()), - hardforks: MAINNET.hardforks.clone(), + chain: Some(MAINNET_SPEC.chain), + genesis: Some(MAINNET_SPEC.genesis.clone()), + hardforks: MAINNET_SPEC.hardforks.clone(), } } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 59c12624794a..a2e8d9b792b4 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -59,7 +59,7 @@ pub use block::{ pub use bloom::Bloom; pub use chain::{ AllGenesisFormats, Chain, ChainInfo, ChainSpec, ChainSpecBuilder, DisplayHardforks, - ForkCondition, ForkTimestamps, GOERLI, MAINNET, SEPOLIA, + ForkCondition, ForkTimestamps, TESTNET_SPEC, MAINNET_SPEC, DEVNET_SPEC, }; pub use compression::*; pub use constants::{ diff --git a/crates/revm/revm-primitives/src/env.rs b/crates/revm/revm-primitives/src/env.rs index 4a3ee3239282..0c53a276c43d 100644 --- a/crates/revm/revm-primitives/src/env.rs +++ b/crates/revm/revm-primitives/src/env.rs @@ -77,7 +77,7 @@ pub fn fill_block_env_with_coinbase( /// Return the coinbase address for the given header and chain spec. pub fn block_coinbase(chain_spec: &ChainSpec, header: &Header, after_merge: bool) -> Address { - if chain_spec.chain == Chain::goerli() && !after_merge { + if chain_spec.chain == Chain::devnet() && !after_merge { recover_header_signer(header).expect("failed to recover signer") } else { header.beneficiary diff --git a/crates/symphony-primitives/Cargo.toml b/crates/symphony-primitives/Cargo.toml index 825d0aaac026..3d23f718a067 100644 --- a/crates/symphony-primitives/Cargo.toml +++ b/crates/symphony-primitives/Cargo.toml @@ -8,7 +8,11 @@ homepage.workspace = true repository.workspace = true description = "Symphony specific primitive data types." -# [dependencies] +[dependencies] +thiserror ={ workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +parse-display = { workspace = true } # [dev-dependencies] diff --git a/crates/symphony-primitives/src/chains.rs b/crates/symphony-primitives/src/chains.rs new file mode 100644 index 000000000000..3b3b7f68f769 --- /dev/null +++ b/crates/symphony-primitives/src/chains.rs @@ -0,0 +1,68 @@ +use std::fmt::{Debug, Display}; + +use crate::constants::{ + DEVNET_ID, DEVNET_NAME, MAINNET_ID, MAINNET_NAME, TESTNET_ID, TESTNET_NAME, +}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[repr(u64)] +pub enum SymphonyChains { + Mainnet = MAINNET_ID, + Devnet = DEVNET_ID, + Testnet = TESTNET_ID, +} + +#[derive(Debug)] +pub enum SymphonyChainError { + UnrecognizedChainId, + UnrecognizedStr, +} + +impl TryFrom for SymphonyChains { + type Error = SymphonyChainError; + fn try_from(value: u64) -> Result { + match value { + MAINNET_ID => Ok(Self::Mainnet), + DEVNET_ID => Ok(Self::Devnet), + TESTNET_ID => Ok(Self::Testnet), + _ => Err(SymphonyChainError::UnrecognizedChainId), + } + } +} + +impl From for u64 { + fn from(value: SymphonyChains) -> Self { + match value { + SymphonyChains::Mainnet => MAINNET_ID, + SymphonyChains::Devnet => DEVNET_ID, + SymphonyChains::Testnet => TESTNET_ID, + } + } +} + +impl TryFrom<&str> for SymphonyChains { + type Error = SymphonyChainError; + fn try_from(value: &str) -> Result { + match value.to_uppercase().as_str() { + MAINNET_NAME => Ok(Self::Mainnet), + DEVNET_NAME => Ok(Self::Devnet), + TESTNET_NAME => Ok(Self::Testnet), + _ => Err(SymphonyChainError::UnrecognizedStr), + } + } +} + +impl Display for SymphonyChains { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let chain_name = match self { + SymphonyChains::Mainnet => MAINNET_NAME, + SymphonyChains::Devnet => DEVNET_NAME, + SymphonyChains::Testnet => TESTNET_NAME, + }; + + let chain_name = chain_name.to_lowercase(); + + write!(f, "symphony-{chain_name}") + } +} diff --git a/crates/symphony-primitives/src/constants.rs b/crates/symphony-primitives/src/constants.rs new file mode 100644 index 000000000000..7bc030c1c0b6 --- /dev/null +++ b/crates/symphony-primitives/src/constants.rs @@ -0,0 +1,7 @@ +pub const MAINNET_NAME: &str = "MAINNET"; +pub const DEVNET_NAME: &str = "DEVNET"; +pub const TESTNET_NAME: &str = "TESTNET"; + +pub const MAINNET_ID: u64 = 70047; +pub const DEVNET_ID: u64 = 70048; +pub const TESTNET_ID: u64 = 70049; diff --git a/crates/symphony-primitives/src/lib.rs b/crates/symphony-primitives/src/lib.rs index e69de29bb2d1..4c7001e6091c 100644 --- a/crates/symphony-primitives/src/lib.rs +++ b/crates/symphony-primitives/src/lib.rs @@ -0,0 +1,4 @@ +pub mod chains; +pub mod constants; + +pub use chains::{SymphonyChainError, SymphonyChains};