Skip to content

Commit

Permalink
chore(cli): unify trait bounds (paradigmxyz#12604)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
klkvr and mattsse authored Nov 16, 2024
1 parent dda1906 commit 735eb4b
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 129 deletions.
15 changes: 7 additions & 8 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ use reth_blockchain_tree::{
};
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_consensus::Consensus;
use reth_errors::RethResult;
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_fs_util as fs;
use reth_node_api::{
EngineApiMessageVersion, NodeTypesWithDB, NodeTypesWithEngine, PayloadBuilderAttributes,
};
use reth_node_api::{EngineApiMessageVersion, PayloadBuilderAttributes};
use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider};
use reth_primitives::{
BlobTransaction, PooledTransactionsElement, SealedBlock, SealedBlockWithSenders, SealedHeader,
Transaction, TransactionSigned,
};
use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider,
ProviderFactory, StageCheckpointReader, StateProviderFactory,
providers::{BlockchainProvider, ProviderNodeTypes},
BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, ProviderFactory,
StageCheckpointReader, StateProviderFactory,
};
use reth_revm::{
cached::CachedReads,
Expand Down Expand Up @@ -88,7 +87,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Fetches the best block block from the database.
///
/// If the database is empty, returns the genesis block.
fn lookup_best_block<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
fn lookup_best_block<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
factory: ProviderFactory<N>,
) -> RethResult<Arc<SealedBlock>> {
Expand Down Expand Up @@ -123,7 +122,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}

/// Execute `debug in-memory-merkle` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
13 changes: 7 additions & 6 deletions bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures::{stream::select as stream_select, StreamExt};
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
Expand All @@ -22,10 +22,11 @@ use reth_exex::ExExManagerHandle;
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_network_p2p::{headers::client::HeadersClient, EthBlockClient};
use reth_node_api::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_api::NodeTypesWithDBAdapter;
use reth_node_ethereum::EthExecutorProvider;
use reth_provider::{
BlockExecutionWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader,
providers::ProviderNodeTypes, BlockExecutionWriter, ChainSpecProvider, ProviderFactory,
StageCheckpointReader,
};
use reth_prune::PruneModes;
use reth_stages::{
Expand Down Expand Up @@ -58,7 +59,7 @@ pub struct Command<C: ChainSpecParser> {
}

impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
fn build_pipeline<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>, Client>(
fn build_pipeline<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>, Client>(
&self,
config: &Config,
client: Client,
Expand Down Expand Up @@ -116,7 +117,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
Ok(pipeline)
}

async fn build_network<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
async fn build_network<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
Expand Down Expand Up @@ -160,7 +161,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}

/// Execute `execution-debug` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
13 changes: 6 additions & 7 deletions bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
Expand All @@ -19,12 +19,11 @@ use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_provider::{
writer::UnifiedStorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter,
HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory,
StageCheckpointReader, StateWriter, StorageReader,
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, AccountExtReader,
ChainSpecProvider, HashingWriter, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown,
ProviderFactory, StageCheckpointReader, StateWriter, StorageReader,
};
use reth_revm::database::StateProviderDatabase;
use reth_stages::StageId;
Expand Down Expand Up @@ -56,7 +55,7 @@ pub struct Command<C: ChainSpecParser> {
}

impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
async fn build_network<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
Expand All @@ -78,7 +77,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}

/// Execute `debug in-memory-merkle` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
13 changes: 6 additions & 7 deletions bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
Expand All @@ -17,12 +17,11 @@ use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_network_p2p::full_block::FullBlockClient;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_provider::{
writer::UnifiedStorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider,
DatabaseProviderFactory, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown,
ProviderError, ProviderFactory, StateWriter,
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, BlockNumReader, BlockWriter,
ChainSpecProvider, DatabaseProviderFactory, HeaderProvider, LatestStateProviderRef,
OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter,
};
use reth_revm::database::StateProviderDatabase;
use reth_stages::{
Expand Down Expand Up @@ -56,7 +55,7 @@ pub struct Command<C: ChainSpecParser> {
}

impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
async fn build_network<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
Expand All @@ -78,7 +77,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}

/// Execute `merkle-debug` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions bin/reth/src/commands/debug_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use clap::{Parser, Subcommand};
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::CliNodeTypes;
use reth_cli_runner::CliContext;
use reth_node_api::NodeTypesWithEngine;
use reth_node_ethereum::EthEngineTypes;

mod build_block;
Expand Down Expand Up @@ -37,9 +37,7 @@ pub enum Subcommands<C: ChainSpecParser> {

impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Execute `debug` command
pub async fn execute<
N: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>,
>(
pub async fn execute<N: CliNodeTypes<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
15 changes: 6 additions & 9 deletions bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reth_blockchain_tree::{
};
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
Expand All @@ -18,13 +18,12 @@ use reth_engine_util::engine_store::{EngineMessageStore, StoredEngineApiMessage}
use reth_fs_util as fs;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{
EngineApiMessageVersion, NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine,
};
use reth_node_api::{EngineApiMessageVersion, NodeTypesWithDBAdapter};
use reth_node_ethereum::{EthEngineTypes, EthEvmConfig, EthExecutorProvider};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::{
providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
providers::{BlockchainProvider, ProviderNodeTypes},
CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
};
use reth_prune::PruneModes;
use reth_stages::Pipeline;
Expand Down Expand Up @@ -56,7 +55,7 @@ pub struct Command<C: ChainSpecParser> {
}

impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
async fn build_network<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
Expand All @@ -78,9 +77,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}

/// Execute `debug replay-engine` command
pub async fn execute<
N: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>,
>(
pub async fn execute<N: CliNodeTypes<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
Expand Down
9 changes: 7 additions & 2 deletions crates/cli/commands/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct EnvironmentArgs<C: ChainSpecParser> {
impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> EnvironmentArgs<C> {
/// Initializes environment according to [`AccessRights`] and returns an instance of
/// [`Environment`].
pub fn init<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
pub fn init<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
access: AccessRights,
) -> eyre::Result<Environment<N>> {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Environmen
/// If it's a read-write environment and an issue is found, it will attempt to heal (including a
/// pipeline unwind). Otherwise, it will print out an warning, advising the user to restart the
/// node to heal.
fn create_provider_factory<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
fn create_provider_factory<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
db: Arc<DatabaseEnv>,
Expand Down Expand Up @@ -188,3 +188,8 @@ impl AccessRights {
matches!(self, Self::RW)
}
}

/// Helper trait with a common set of requirements for the
/// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI.
pub trait CliNodeTypes: NodeTypesWithEngine<ChainSpec: EthereumHardforks> {}
impl<N> CliNodeTypes for N where N: NodeTypesWithEngine<ChainSpec: EthereumHardforks> {}
9 changes: 6 additions & 3 deletions crates/cli/commands/src/db/checksum.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::db::get::{maybe_json_value_parser, table_key};
use crate::{
common::CliNodeTypes,
db::get::{maybe_json_value_parser, table_key},
};
use ahash::RandomState;
use clap::Parser;
use reth_chainspec::EthereumHardforks;
use reth_db::{DatabaseEnv, RawKey, RawTable, RawValue, TableViewer, Tables};
use reth_db_api::{cursor::DbCursorRO, table::Table, transaction::DbTx};
use reth_db_common::DbTool;
use reth_node_builder::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_builder::{NodeTypesWithDB, NodeTypesWithDBAdapter};
use reth_provider::{providers::ProviderNodeTypes, DBProvider};
use std::{
hash::{BuildHasher, Hasher},
Expand Down Expand Up @@ -36,7 +39,7 @@ pub struct Command {

impl Command {
/// Execute `db checksum` command
pub fn execute<N: NodeTypesWithEngine<ChainSpec: EthereumHardforks>>(
pub fn execute<N: CliNodeTypes<ChainSpec: EthereumHardforks>>(
self,
tool: &DbTool<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>,
) -> eyre::Result<()> {
Expand Down
7 changes: 2 additions & 5 deletions crates/cli/commands/src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::common::{AccessRights, Environment, EnvironmentArgs};
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use clap::{Parser, Subcommand};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_db::version::{get_db_version, DatabaseVersionError, DB_VERSION};
use reth_db_common::DbTool;
use reth_node_builder::NodeTypesWithEngine;
use std::io::{self, Write};

mod checksum;
Expand Down Expand Up @@ -65,9 +64,7 @@ macro_rules! db_ro_exec {

impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C> {
/// Execute `db` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
) -> eyre::Result<()> {
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(self) -> eyre::Result<()> {
let data_dir = self.env.datadir.clone().resolve_datadir(self.env.chain.chain());
let db_path = data_dir.db();
let static_files_path = data_dir.static_files();
Expand Down
8 changes: 3 additions & 5 deletions crates/cli/commands/src/db/stats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::db::checksum::ChecksumViewer;
use crate::{common::CliNodeTypes, db::checksum::ChecksumViewer};
use clap::Parser;
use comfy_table::{Cell, Row, Table as ComfyTable};
use eyre::WrapErr;
Expand All @@ -9,9 +9,7 @@ use reth_db::{mdbx, static_file::iter_static_files, DatabaseEnv, TableViewer, Ta
use reth_db_api::database::Database;
use reth_db_common::DbTool;
use reth_fs_util as fs;
use reth_node_builder::{
NodePrimitives, NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine,
};
use reth_node_builder::{NodePrimitives, NodeTypesWithDB, NodeTypesWithDBAdapter};
use reth_node_core::dirs::{ChainPath, DataDirPath};
use reth_provider::providers::{ProviderNodeTypes, StaticFileProvider};
use reth_static_file_types::SegmentRangeInclusive;
Expand Down Expand Up @@ -40,7 +38,7 @@ pub struct Command {

impl Command {
/// Execute `db stats` command
pub fn execute<N: NodeTypesWithEngine<ChainSpec: EthereumHardforks>>(
pub fn execute<N: CliNodeTypes<ChainSpec: EthereumHardforks>>(
self,
data_dir: ChainPath<DataDirPath>,
tool: &DbTool<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>,
Expand Down
5 changes: 2 additions & 3 deletions crates/cli/commands/src/import.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Command that initializes the node by importing a chain from a file.
use crate::common::{AccessRights, Environment, EnvironmentArgs};
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use alloy_primitives::B256;
use clap::Parser;
use futures::{Stream, StreamExt};
Expand All @@ -20,7 +20,6 @@ use reth_network_p2p::{
bodies::downloader::BodyDownloader,
headers::downloader::{HeaderDownloader, SyncTarget},
};
use reth_node_builder::NodeTypesWithEngine;
use reth_node_core::version::SHORT_VERSION;
use reth_node_events::node::NodeEvent;
use reth_provider::{
Expand Down Expand Up @@ -60,7 +59,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> ImportComm
/// Execute `import` command
pub async fn execute<N, E, F>(self, executor: F) -> eyre::Result<()>
where
N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>,
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
E: BlockExecutorProvider,
F: FnOnce(Arc<N::ChainSpec>) -> E,
{
Expand Down
7 changes: 2 additions & 5 deletions crates/cli/commands/src/init_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Command that initializes the node from a genesis file.
use crate::common::{AccessRights, Environment, EnvironmentArgs};
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use clap::Parser;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_node_builder::NodeTypesWithEngine;
use reth_provider::BlockHashReader;
use tracing::info;

Expand All @@ -17,9 +16,7 @@ pub struct InitCommand<C: ChainSpecParser> {

impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitCommand<C> {
/// Execute the `init` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
) -> eyre::Result<()> {
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(self) -> eyre::Result<()> {
info!(target: "reth::cli", "reth init starting");

let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RW)?;
Expand Down
Loading

0 comments on commit 735eb4b

Please sign in to comment.