mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: use OpChainSpec in OptimismNode and its components (#11304)
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_node_core::args::utils::parse_custom_chain_spec;
|
||||
use reth_optimism_chainspec::{
|
||||
@ -27,7 +26,7 @@ fn chain_value_parser(s: &str) -> eyre::Result<Arc<OpChainSpec>, eyre::Error> {
|
||||
pub struct OpChainSpecParser;
|
||||
|
||||
impl ChainSpecParser for OpChainSpecParser {
|
||||
type ChainSpec = ChainSpec;
|
||||
type ChainSpec = OpChainSpec;
|
||||
|
||||
const SUPPORTED_CHAINS: &'static [&'static str] = &[
|
||||
"dev",
|
||||
@ -40,7 +39,7 @@ impl ChainSpecParser for OpChainSpecParser {
|
||||
];
|
||||
|
||||
fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
|
||||
chain_value_parser(s).map(|s| Arc::new(Arc::unwrap_or_clone(s).inner))
|
||||
chain_value_parser(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use alloy_primitives::B256;
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_config::Config;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_downloaders::{
|
||||
@ -14,6 +13,7 @@ use reth_network_p2p::{
|
||||
};
|
||||
use reth_node_builder::NodeTypesWithDB;
|
||||
use reth_node_events::node::NodeEvent;
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_evm::OpExecutorProvider;
|
||||
use reth_provider::{BlockNumReader, ChainSpecProvider, HeaderProvider, ProviderFactory};
|
||||
use reth_prune::PruneModes;
|
||||
@ -36,7 +36,7 @@ pub(crate) async fn build_import_pipeline<N, C>(
|
||||
disable_exec: bool,
|
||||
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
|
||||
where
|
||||
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
||||
N: NodeTypesWithDB<ChainSpec = OpChainSpec>,
|
||||
C: Consensus + 'static,
|
||||
{
|
||||
if !file_client.has_canonical_blocks() {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
//! Command that initializes the node by importing OP Mainnet chain segment below Bedrock, from a
|
||||
//! file.
|
||||
use clap::Parser;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
|
||||
use reth_consensus::noop::NoopConsensus;
|
||||
@ -12,6 +11,7 @@ use reth_downloaders::file_client::{
|
||||
};
|
||||
use reth_node_builder::NodeTypesWithEngine;
|
||||
use reth_node_core::version::SHORT_VERSION;
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_primitives::bedrock::is_dup_tx;
|
||||
use reth_provider::StageCheckpointReader;
|
||||
use reth_prune::PruneModes;
|
||||
@ -40,7 +40,7 @@ pub struct ImportOpCommand<C: ChainSpecParser> {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> ImportOpCommand<C> {
|
||||
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportOpCommand<C> {
|
||||
/// Execute `import` command
|
||||
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
|
||||
self,
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
|
||||
use reth_db::tables;
|
||||
@ -15,12 +14,13 @@ use reth_downloaders::{
|
||||
use reth_execution_types::ExecutionOutcome;
|
||||
use reth_node_builder::{NodeTypesWithDB, NodeTypesWithEngine};
|
||||
use reth_node_core::version::SHORT_VERSION;
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_primitives::bedrock::is_dup_tx;
|
||||
use reth_primitives::Receipts;
|
||||
use reth_provider::{
|
||||
writer::UnifiedStorageWriter, DatabaseProviderFactory, OriginalValuesKnown, ProviderFactory,
|
||||
StageCheckpointReader, StageCheckpointWriter, StateWriter, StaticFileProviderFactory,
|
||||
StaticFileWriter, StatsReader,
|
||||
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory,
|
||||
OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter,
|
||||
StateWriter, StaticFileProviderFactory, StaticFileWriter, StatsReader,
|
||||
};
|
||||
use reth_stages::{StageCheckpoint, StageId};
|
||||
use reth_static_file_types::StaticFileSegment;
|
||||
@ -46,7 +46,7 @@ pub struct ImportReceiptsOpCommand<C: ChainSpecParser> {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> ImportReceiptsOpCommand<C> {
|
||||
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportReceiptsOpCommand<C> {
|
||||
/// Execute `import` command
|
||||
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
|
||||
self,
|
||||
@ -88,7 +88,7 @@ pub async fn import_receipts_from_file<N, P, F>(
|
||||
filter: F,
|
||||
) -> eyre::Result<()>
|
||||
where
|
||||
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
||||
N: NodeTypesWithDB<ChainSpec = OpChainSpec>,
|
||||
P: AsRef<Path>,
|
||||
F: FnMut(u64, &mut Receipts) -> usize,
|
||||
{
|
||||
@ -126,7 +126,7 @@ pub async fn import_receipts_from_reader<N, F>(
|
||||
mut filter: F,
|
||||
) -> eyre::Result<ImportReceiptsResult>
|
||||
where
|
||||
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
|
||||
N: ProviderNodeTypes,
|
||||
F: FnMut(u64, &mut Receipts) -> usize,
|
||||
{
|
||||
let static_file_provider = provider_factory.static_file_provider();
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
//! Command that initializes the node from a genesis file.
|
||||
|
||||
use clap::Parser;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::common::{AccessRights, Environment};
|
||||
use reth_db_common::init::init_from_state_dump;
|
||||
use reth_node_builder::NodeTypesWithEngine;
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_primitives::bedrock::BEDROCK_HEADER;
|
||||
use reth_provider::{
|
||||
BlockNumReader, ChainSpecProvider, DatabaseProviderFactory, StaticFileProviderFactory,
|
||||
@ -35,7 +35,7 @@ pub struct InitStateCommandOp<C: ChainSpecParser> {
|
||||
without_ovm: bool,
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> InitStateCommandOp<C> {
|
||||
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> InitStateCommandOp<C> {
|
||||
/// Execute the `init` command
|
||||
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
|
||||
self,
|
||||
|
||||
@ -2,7 +2,6 @@ use crate::chainspec::OpChainSpecParser;
|
||||
use clap::Subcommand;
|
||||
use import::ImportOpCommand;
|
||||
use import_receipts::ImportReceiptsOpCommand;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::{
|
||||
config_cmd, db, dump_genesis, init_cmd,
|
||||
@ -19,10 +18,8 @@ pub mod init_state;
|
||||
|
||||
/// Commands to be executed
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands<
|
||||
Spec: ChainSpecParser<ChainSpec = ChainSpec> = OpChainSpecParser,
|
||||
Ext: clap::Args + fmt::Debug = NoArgs,
|
||||
> {
|
||||
pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
|
||||
{
|
||||
/// Start the node
|
||||
#[command(name = "node")]
|
||||
Node(Box<node::NodeCommand<Spec, Ext>>),
|
||||
|
||||
@ -28,6 +28,7 @@ pub mod commands;
|
||||
pub mod receipt_file_codec;
|
||||
|
||||
pub use commands::{import::ImportOpCommand, import_receipts::ImportReceiptsOpCommand};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
|
||||
use std::{ffi::OsString, fmt, sync::Arc};
|
||||
|
||||
@ -35,7 +36,7 @@ use chainspec::OpChainSpecParser;
|
||||
use clap::{command, value_parser, Parser};
|
||||
use commands::Commands;
|
||||
use futures_util::Future;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::node::NoArgs;
|
||||
use reth_cli_runner::CliRunner;
|
||||
@ -55,10 +56,7 @@ use tracing::info;
|
||||
/// This is the entrypoint to the executable.
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
|
||||
pub struct Cli<
|
||||
Spec: ChainSpecParser<ChainSpec = ChainSpec> = OpChainSpecParser,
|
||||
Ext: clap::Args + fmt::Debug = NoArgs,
|
||||
> {
|
||||
pub struct Cli<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs> {
|
||||
/// The command to run
|
||||
#[command(subcommand)]
|
||||
command: Commands<Spec, Ext>,
|
||||
@ -112,9 +110,9 @@ impl Cli {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Spec, Ext> Cli<Spec, Ext>
|
||||
impl<C, Ext> Cli<C, Ext>
|
||||
where
|
||||
Spec: ChainSpecParser<ChainSpec = ChainSpec>,
|
||||
C: ChainSpecParser<ChainSpec = OpChainSpec>,
|
||||
Ext: clap::Args + fmt::Debug,
|
||||
{
|
||||
/// Execute the configured cli command.
|
||||
@ -123,12 +121,12 @@ where
|
||||
/// [`NodeCommand`](reth_cli_commands::node::NodeCommand).
|
||||
pub fn run<L, Fut>(mut self, launcher: L) -> eyre::Result<()>
|
||||
where
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, ChainSpec>>, Ext) -> Fut,
|
||||
L: FnOnce(WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>, C::ChainSpec>>, Ext) -> Fut,
|
||||
Fut: Future<Output = eyre::Result<()>>,
|
||||
{
|
||||
// add network name to logs dir
|
||||
self.logs.log_file_directory =
|
||||
self.logs.log_file_directory.join(self.chain.chain.to_string());
|
||||
self.logs.log_file_directory.join(self.chain.chain().to_string());
|
||||
|
||||
let _guard = self.init_tracing()?;
|
||||
info!(target: "reth::cli", "Initialized tracing, debug log directory: {}", self.logs.log_file_directory);
|
||||
|
||||
Reference in New Issue
Block a user