mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: unify all chains confs (#747)
Co-authored-by: Bjerg <onbjerg@users.noreply.github.com>
This commit is contained in:
@ -6,7 +6,7 @@ use reth_network::{
|
||||
config::{mainnet_nodes, rng_secret_key},
|
||||
NetworkConfig, PeersConfig,
|
||||
};
|
||||
use reth_primitives::{NodeRecord, H256};
|
||||
use reth_primitives::{ChainSpec, NodeRecord};
|
||||
use reth_provider::ProviderImpl;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -26,8 +26,7 @@ impl Config {
|
||||
pub fn network_config<DB: Database>(
|
||||
&self,
|
||||
db: Arc<DB>,
|
||||
chain_id: u64,
|
||||
genesis_hash: H256,
|
||||
chain_spec: ChainSpec,
|
||||
disable_discovery: bool,
|
||||
bootnodes: Option<Vec<NodeRecord>>,
|
||||
) -> NetworkConfig<ProviderImpl<DB>> {
|
||||
@ -37,8 +36,7 @@ impl Config {
|
||||
NetworkConfig::builder(Arc::new(ProviderImpl::new(db)), rng_secret_key())
|
||||
.boot_nodes(bootnodes.unwrap_or_else(mainnet_nodes))
|
||||
.peer_config(peer_config)
|
||||
.genesis_hash(genesis_hash)
|
||||
.chain_id(chain_id)
|
||||
.chain_spec(chain_spec)
|
||||
.set_discovery(disable_discovery)
|
||||
.build()
|
||||
}
|
||||
|
||||
@ -5,11 +5,7 @@ use crate::{
|
||||
config::Config,
|
||||
dirs::{ConfigPath, DbPath, PlatformPath},
|
||||
prometheus_exporter,
|
||||
utils::{
|
||||
chainspec::{chain_spec_value_parser, ChainSpecification},
|
||||
init::{init_db, init_genesis},
|
||||
parse_socket_address,
|
||||
},
|
||||
utils::{chainspec::chain_spec_value_parser, init::init_db, parse_socket_address},
|
||||
NetworkOpts,
|
||||
};
|
||||
use clap::{crate_version, Parser};
|
||||
@ -18,11 +14,10 @@ use fdlimit::raise_fd_limit;
|
||||
use futures::{stream::select as stream_select, Stream, StreamExt};
|
||||
use reth_consensus::BeaconConsensus;
|
||||
use reth_downloaders::{bodies, headers};
|
||||
use reth_executor::Config as ExecutorConfig;
|
||||
use reth_interfaces::consensus::ForkchoiceState;
|
||||
use reth_network::NetworkEvent;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{BlockNumber, NodeRecord, H256};
|
||||
use reth_primitives::{BlockNumber, ChainSpec, NodeRecord, H256};
|
||||
use reth_stages::{
|
||||
metrics::HeaderMetrics,
|
||||
stages::{
|
||||
@ -68,7 +63,7 @@ pub struct Command {
|
||||
default_value = "mainnet",
|
||||
value_parser = chain_spec_value_parser
|
||||
)]
|
||||
chain: ChainSpecification,
|
||||
chain: ChainSpec,
|
||||
|
||||
/// Enable Prometheus metrics.
|
||||
///
|
||||
@ -119,15 +114,12 @@ impl Command {
|
||||
HeaderMetrics::describe();
|
||||
}
|
||||
|
||||
let chain_id = self.chain.consensus.chain_id;
|
||||
let consensus = Arc::new(BeaconConsensus::new(self.chain.consensus.clone()));
|
||||
let genesis_hash = init_genesis(db.clone(), self.chain.genesis.clone())?;
|
||||
let consensus: Arc<BeaconConsensus> = Arc::new(BeaconConsensus::new(self.chain.clone()));
|
||||
|
||||
let network = config
|
||||
.network_config(
|
||||
db.clone(),
|
||||
chain_id,
|
||||
genesis_hash,
|
||||
self.chain.clone(),
|
||||
self.network.disable_discovery,
|
||||
self.bootnodes.clone(),
|
||||
)
|
||||
@ -178,7 +170,7 @@ impl Command {
|
||||
commit_threshold: config.stages.sender_recovery.commit_threshold,
|
||||
})
|
||||
.push(ExecutionStage {
|
||||
config: ExecutorConfig::new_ethereum(),
|
||||
chain_spec: self.chain.clone(),
|
||||
commit_threshold: config.stages.execution.commit_threshold,
|
||||
});
|
||||
|
||||
|
||||
@ -2,10 +2,7 @@
|
||||
use crate::{
|
||||
config::Config,
|
||||
dirs::{ConfigPath, PlatformPath},
|
||||
utils::{
|
||||
chainspec::{chain_spec_value_parser, ChainSpecification},
|
||||
hash_or_num_value_parser,
|
||||
},
|
||||
utils::{chainspec::chain_spec_value_parser, hash_or_num_value_parser},
|
||||
};
|
||||
use backon::{ConstantBackoff, Retryable};
|
||||
use clap::{Parser, Subcommand};
|
||||
@ -15,7 +12,7 @@ use reth_interfaces::p2p::{
|
||||
headers::client::{HeadersClient, HeadersRequest},
|
||||
};
|
||||
use reth_network::FetchClient;
|
||||
use reth_primitives::{BlockHashOrNumber, Header, NodeRecord, SealedHeader};
|
||||
use reth_primitives::{BlockHashOrNumber, ChainSpec, NodeRecord, SealedHeader};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// `reth p2p` command
|
||||
@ -40,7 +37,7 @@ pub struct Command {
|
||||
default_value = "mainnet",
|
||||
value_parser = chain_spec_value_parser
|
||||
)]
|
||||
chain: ChainSpecification,
|
||||
chain: ChainSpec,
|
||||
|
||||
/// Disable the discovery service.
|
||||
#[arg(short, long)]
|
||||
@ -86,10 +83,6 @@ impl Command {
|
||||
|
||||
let mut config: Config = confy::load_path(&self.config).unwrap_or_default();
|
||||
|
||||
let chain_id = self.chain.consensus.chain_id;
|
||||
let genesis: Header = self.chain.genesis.clone().into();
|
||||
let genesis_hash = genesis.hash_slow();
|
||||
|
||||
if let Some(peer) = self.trusted_peer {
|
||||
config.peers.trusted_nodes.insert(peer);
|
||||
}
|
||||
@ -101,7 +94,7 @@ impl Command {
|
||||
config.peers.connect_trusted_nodes_only = self.trusted_only;
|
||||
|
||||
let network = config
|
||||
.network_config(noop_db, chain_id, genesis_hash, self.disable_discovery, None)
|
||||
.network_config(noop_db, self.chain.clone(), self.disable_discovery, None)
|
||||
.start_network()
|
||||
.await?;
|
||||
|
||||
|
||||
@ -5,15 +5,13 @@ use crate::{
|
||||
config::Config,
|
||||
dirs::{ConfigPath, DbPath, PlatformPath},
|
||||
prometheus_exporter,
|
||||
utils::{
|
||||
chainspec::{chain_spec_value_parser, ChainSpecification},
|
||||
init::{init_db, init_genesis},
|
||||
},
|
||||
utils::{chainspec::chain_spec_value_parser, init::init_db},
|
||||
NetworkOpts,
|
||||
};
|
||||
use reth_consensus::BeaconConsensus;
|
||||
use reth_downloaders::bodies::concurrent::ConcurrentDownloader;
|
||||
use reth_executor::Config as ExecutorConfig;
|
||||
|
||||
use reth_primitives::ChainSpec;
|
||||
use reth_stages::{
|
||||
metrics::HeaderMetrics,
|
||||
stages::{bodies::BodyStage, execution::ExecutionStage, sender_recovery::SenderRecoveryStage},
|
||||
@ -56,7 +54,7 @@ pub struct Command {
|
||||
default_value = "mainnet",
|
||||
value_parser = chain_spec_value_parser
|
||||
)]
|
||||
chain: ChainSpecification,
|
||||
chain: ChainSpec,
|
||||
|
||||
/// Enable Prometheus metrics.
|
||||
///
|
||||
@ -126,9 +124,8 @@ impl Command {
|
||||
|
||||
match self.stage {
|
||||
StageEnum::Bodies => {
|
||||
let chain_id = self.chain.consensus.chain_id;
|
||||
let consensus = Arc::new(BeaconConsensus::new(self.chain.consensus.clone()));
|
||||
let genesis_hash = init_genesis(db.clone(), self.chain.genesis.clone())?;
|
||||
let consensus: Arc<BeaconConsensus> =
|
||||
Arc::new(BeaconConsensus::new(self.chain.clone()));
|
||||
|
||||
let mut config = config;
|
||||
config.peers.connect_trusted_nodes_only = self.network.trusted_only;
|
||||
@ -141,8 +138,7 @@ impl Command {
|
||||
let network = config
|
||||
.network_config(
|
||||
db.clone(),
|
||||
chain_id,
|
||||
genesis_hash,
|
||||
self.chain.clone(),
|
||||
self.network.disable_discovery,
|
||||
None,
|
||||
)
|
||||
@ -179,10 +175,8 @@ impl Command {
|
||||
stage.execute(&mut tx, input).await?;
|
||||
}
|
||||
StageEnum::Execution => {
|
||||
let mut stage = ExecutionStage {
|
||||
config: ExecutorConfig::new_ethereum(),
|
||||
commit_threshold: num_blocks,
|
||||
};
|
||||
let mut stage =
|
||||
ExecutionStage { chain_spec: self.chain.clone(), commit_threshold: num_blocks };
|
||||
if !self.skip_unwind {
|
||||
stage.unwind(&mut tx, unwind).await?;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use reth_primitives::{
|
||||
Address, BigEndianHash, Bloom, Bytes, Header as RethHeader, JsonU256, SealedHeader, H160, H256,
|
||||
H64,
|
||||
Address, BigEndianHash, Bloom, Bytes, ChainSpec, ChainSpecBuilder, Header as RethHeader,
|
||||
JsonU256, SealedHeader, H160, H256, H64,
|
||||
};
|
||||
use serde::{self, Deserialize};
|
||||
use std::collections::BTreeMap;
|
||||
@ -209,28 +209,30 @@ pub enum ForkSpec {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<ForkSpec> for reth_executor::SpecUpgrades {
|
||||
impl From<ForkSpec> for ChainSpec {
|
||||
fn from(fork_spec: ForkSpec) -> Self {
|
||||
let spec_builder = ChainSpecBuilder::mainnet();
|
||||
|
||||
match fork_spec {
|
||||
ForkSpec::Frontier => Self::new_frontier_activated(),
|
||||
ForkSpec::Frontier => spec_builder.frontier_activated(),
|
||||
ForkSpec::Homestead | ForkSpec::FrontierToHomesteadAt5 => {
|
||||
Self::new_homestead_activated()
|
||||
spec_builder.homestead_activated()
|
||||
}
|
||||
ForkSpec::EIP150 | ForkSpec::HomesteadToDaoAt5 | ForkSpec::HomesteadToEIP150At5 => {
|
||||
Self::new_tangerine_whistle_activated()
|
||||
spec_builder.tangerine_whistle_activated()
|
||||
}
|
||||
ForkSpec::EIP158 => Self::new_spurious_dragon_activated(),
|
||||
ForkSpec::EIP158 => spec_builder.spurious_dragon_activated(),
|
||||
ForkSpec::Byzantium |
|
||||
ForkSpec::EIP158ToByzantiumAt5 |
|
||||
ForkSpec::ConstantinopleFix |
|
||||
ForkSpec::ByzantiumToConstantinopleFixAt5 => Self::new_byzantium_activated(),
|
||||
ForkSpec::Istanbul => Self::new_istanbul_activated(),
|
||||
ForkSpec::Berlin => Self::new_berlin_activated(),
|
||||
ForkSpec::London | ForkSpec::BerlinToLondonAt5 => Self::new_london_activated(),
|
||||
ForkSpec::Merge => Self::new_paris_activated(),
|
||||
ForkSpec::MergeEOF => Self::new_paris_activated(),
|
||||
ForkSpec::MergeMeterInitCode => Self::new_paris_activated(),
|
||||
ForkSpec::MergePush0 => Self::new_paris_activated(),
|
||||
ForkSpec::ByzantiumToConstantinopleFixAt5 => spec_builder.byzantium_activated(),
|
||||
ForkSpec::Istanbul => spec_builder.istanbul_activated(),
|
||||
ForkSpec::Berlin => spec_builder.berlin_activated(),
|
||||
ForkSpec::London | ForkSpec::BerlinToLondonAt5 => spec_builder.london_activated(),
|
||||
ForkSpec::Merge => spec_builder.paris_activated(),
|
||||
ForkSpec::MergeEOF => spec_builder.paris_activated(),
|
||||
ForkSpec::MergeMeterInitCode => spec_builder.paris_activated(),
|
||||
ForkSpec::MergePush0 => spec_builder.paris_activated(),
|
||||
ForkSpec::Shanghai => {
|
||||
panic!("Not supported")
|
||||
}
|
||||
@ -241,6 +243,7 @@ impl From<ForkSpec> for reth_executor::SpecUpgrades {
|
||||
panic!("Unknown fork");
|
||||
}
|
||||
}
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,10 +9,9 @@ use reth_db::{
|
||||
transaction::{DbTx, DbTxMut},
|
||||
Error as DbError,
|
||||
};
|
||||
use reth_executor::SpecUpgrades;
|
||||
use reth_primitives::{
|
||||
keccak256, Account as RethAccount, Address, JsonU256, SealedBlock, SealedHeader, StorageEntry,
|
||||
H256, U256,
|
||||
keccak256, Account as RethAccount, Address, ChainSpec, JsonU256, SealedBlock, SealedHeader,
|
||||
StorageEntry, H256, U256,
|
||||
};
|
||||
use reth_rlp::Decodable;
|
||||
use reth_stages::{stages::execution::ExecutionStage, ExecInput, Stage, StageId, Transaction};
|
||||
@ -124,9 +123,9 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<TestOutcome> {
|
||||
|
||||
debug!(target: "reth::cli", name, network = ?suite.network, "Running test");
|
||||
|
||||
let spec_upgrades: SpecUpgrades = suite.network.into();
|
||||
let chain_spec: ChainSpec = suite.network.into();
|
||||
// if paris aka merge is not activated we dont have block rewards;
|
||||
let has_block_reward = spec_upgrades.paris != 0;
|
||||
let has_block_reward = chain_spec.paris_status().block_number().is_some();
|
||||
|
||||
// Create db and acquire transaction
|
||||
let db = create_test_rw_db::<WriteMap>();
|
||||
@ -189,10 +188,7 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<TestOutcome> {
|
||||
|
||||
// Initialize the execution stage
|
||||
// Hardcode the chain_id to Ethereum 1.
|
||||
let mut stage = ExecutionStage::new(
|
||||
reth_executor::Config { chain_id: U256::from(1), spec_upgrades },
|
||||
1000,
|
||||
);
|
||||
let mut stage = ExecutionStage::new(chain_spec, 1000);
|
||||
|
||||
// Call execution stage
|
||||
let input = ExecInput {
|
||||
|
||||
Reference in New Issue
Block a user