Skip to content

Commit

Permalink
feat(primitives): naive chain metadata replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
dereksione committed Jun 29, 2023
1 parent 6955cd6 commit 1d7577d
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 41 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions bin/reth/src/args/utils.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -20,9 +20,9 @@ pub fn parse_duration_from_secs(arg: &str) -> eyre::Result<Duration, std::num::P
/// to a custom one.
pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, 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)?
Expand All @@ -34,9 +34,9 @@ pub fn chain_spec_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Er
/// to a custom one.
pub fn genesis_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, 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)?;
Expand Down
8 changes: 4 additions & 4 deletions bin/reth/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/beacon/src/beacon_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/common/src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn base_block_reward(
block_difficulty: U256,
total_difficulty: U256,
) -> Option<u128> {
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
Expand Down
9 changes: 5 additions & 4 deletions crates/net/eth-wire/src/types/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -132,15 +133,15 @@ impl Debug for Status {
// <https://etherscan.io/block/0>
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"),
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 11 additions & 9 deletions crates/primitives/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{fmt, str::FromStr};
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.
Expand Down Expand Up @@ -53,10 +53,11 @@ impl Chain {
}
}

// Returns the address of the public DNS node list for the given chain.
//
// See also <https://github.com/ethereum/discv4-dns-lists>
// pub fn public_dns_network_protocol(self) -> Option<String> {
/// Returns the address of the public DNS node list for the given chain.
///
/// See also <https://github.com/ethereum/discv4-dns-lists>
pub fn public_dns_network_protocol(self) -> Option<String> {
todo!()
// use ethers_core::types::Chain::*;
// const DNS_PREFIX: &str = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@";

Expand All @@ -66,18 +67,19 @@ impl Chain {
// return Some(format!("{DNS_PREFIX}all.{}.ethdisco.net", named.as_ref().to_lowercase()))
// }
// None
// }
}

// Returns bootnodes for the given chain.
// pub fn bootnodes(self) -> Option<Vec<NodeRecord>> {
/// Returns bootnodes for the given chain.
pub fn bootnodes(self) -> Option<Vec<NodeRecord>> {
todo!()
// use ethers_core::types::Chain::*;
// match self.try_into().ok()? {
// Mainnet => Some(mainnet_nodes()),
// Goerli => Some(goerli_nodes()),
// Sepolia => Some(sepolia_nodes()),
// _ => None,
// }
// }
}
}

impl fmt::Display for Chain {
Expand Down
20 changes: 10 additions & 10 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
};

/// The Ethereum mainnet spec
pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
pub static MAINNET_SPEC: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: Chain::mainnet(),
genesis: serde_json::from_str(include_str!("../../res/genesis/mainnet.json"))
Expand Down Expand Up @@ -58,10 +58,10 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

/// The Goerli spec
pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
/// The devnet spec
pub static DEVNET_SPEC: Lazy<Arc<ChainSpec>> = 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!(
Expand Down Expand Up @@ -92,10 +92,10 @@ pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

/// The Sepolia spec
pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
/// The Testnet spec
pub static TESTNET_SPEC: Lazy<Arc<ChainSpec>> = 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!(
Expand Down Expand Up @@ -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(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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::{
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/revm-primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d7577d

Please sign in to comment.