chore: relax cli bounds (#13543)

This commit is contained in:
Arsenii Kulikov
2024-12-24 20:43:52 +04:00
committed by GitHub
parent c822337fd6
commit 41283d3db0
18 changed files with 69 additions and 78 deletions

View File

@ -15,7 +15,6 @@ use reth_node_core::{
args::{DatabaseArgs, DatadirArgs},
dirs::{ChainPath, DataDirPath},
};
use reth_primitives::EthPrimitives;
use reth_provider::{
providers::{NodeTypesForProvider, StaticFileProvider},
ProviderFactory, StaticFileProviderFactory,
@ -198,11 +197,5 @@ impl AccessRights {
/// Helper trait with a common set of requirements for the
/// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI.
pub trait CliNodeTypes:
NodeTypesWithEngine + NodeTypesForProvider<Primitives = EthPrimitives>
{
}
impl<N> CliNodeTypes for N where
N: NodeTypesWithEngine + NodeTypesForProvider<Primitives = EthPrimitives>
{
}
pub trait CliNodeTypes: NodeTypesWithEngine + NodeTypesForProvider {}
impl<N> CliNodeTypes for N where N: NodeTypesWithEngine + NodeTypesForProvider {}

View File

@ -20,6 +20,7 @@ use reth_network_p2p::{
bodies::downloader::BodyDownloader,
headers::downloader::{HeaderDownloader, SyncTarget},
};
use reth_node_api::{BlockTy, BodyTy, HeaderTy};
use reth_node_core::version::SHORT_VERSION;
use reth_node_events::node::NodeEvent;
use reth_provider::{
@ -86,7 +87,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> ImportComm
let mut total_decoded_blocks = 0;
let mut total_decoded_txns = 0;
while let Some(file_client) = reader.next_chunk::<FileClient>().await? {
while let Some(file_client) = reader.next_chunk::<FileClient<_>>().await? {
// create a new FileClient from chunk read from file
info!(target: "reth::cli",
"Importing chain file chunk"
@ -161,14 +162,14 @@ pub fn build_import_pipeline<N, C, E>(
config: &Config,
provider_factory: ProviderFactory<N>,
consensus: &Arc<C>,
file_client: Arc<FileClient>,
file_client: Arc<FileClient<BlockTy<N>>>,
static_file_producer: StaticFileProducer<ProviderFactory<N>>,
disable_exec: bool,
executor: E,
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent<N::Primitives>>)>
where
N: ProviderNodeTypes + CliNodeTypes,
C: Consensus + 'static,
C: Consensus<HeaderTy<N>, BodyTy<N>> + 'static,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
if !file_client.has_canonical_blocks() {

View File

@ -6,11 +6,11 @@ use clap::Parser;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_db_common::init::init_from_state_dump;
use reth_node_api::NodePrimitives;
use reth_primitives::SealedHeader;
use reth_provider::{
BlockNumReader, DatabaseProviderFactory, StaticFileProviderFactory, StaticFileWriter,
};
use std::{io::BufReader, path::PathBuf, str::FromStr};
use tracing::info;
@ -67,7 +67,13 @@ pub struct InitStateCommand<C: ChainSpecParser> {
impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateCommand<C> {
/// Execute the `init` command
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec>>(self) -> eyre::Result<()> {
pub async fn execute<N>(self) -> eyre::Result<()>
where
N: CliNodeTypes<
ChainSpec = C::ChainSpec,
Primitives: NodePrimitives<BlockHeader = alloy_consensus::Header>,
>,
{
info!(target: "reth::cli", "Reth init-state starting");
let Environment { config, provider_factory, .. } = self.env.init::<N>(AccessRights::RW)?;

View File

@ -1,4 +1,5 @@
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use alloy_consensus::BlockHeader;
use clap::Parser;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
@ -51,10 +52,10 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
}
let state_root = StateRoot::from_tx(tx_mut).root()?;
if state_root != best_header.state_root {
if state_root != best_header.state_root() {
eyre::bail!(
"Recovery failed. Incorrect state root. Expected: {:?}. Received: {:?}",
best_header.state_root,
best_header.state_root(),
state_root
);
}

View File

@ -7,7 +7,6 @@ use reth_db_api::{
};
use reth_db_common::DbTool;
use reth_evm::{execute::BlockExecutorProvider, noop::NoopBlockExecutorProvider};
use reth_node_api::NodePrimitives;
use reth_node_builder::NodeTypesWithDB;
use reth_node_core::dirs::{ChainPath, DataDirPath};
use reth_provider::{
@ -26,14 +25,7 @@ pub(crate) async fn dump_execution_stage<N, E>(
executor: E,
) -> eyre::Result<()>
where
N: ProviderNodeTypes<
DB = Arc<DatabaseEnv>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header,
>,
>,
N: ProviderNodeTypes<DB = Arc<DatabaseEnv>>,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
let (output_db, tip_block_number) = setup(from, to, &output_datadir.db(), db_tool)?;
@ -139,9 +131,7 @@ fn import_tables_with_range<N: NodeTypesWithDB>(
/// Dry-run an unwind to FROM block, so we can get the `PlainStorageState` and
/// `PlainAccountState` safely. There might be some state dependency from an address
/// which hasn't been changed in the given range.
fn unwind_and_copy<
N: ProviderNodeTypes<Primitives: NodePrimitives<BlockHeader = reth_primitives::Header>>,
>(
fn unwind_and_copy<N: ProviderNodeTypes>(
db_tool: &DbTool<N>,
from: u64,
tip_block_number: u64,
@ -179,13 +169,7 @@ fn dry_run<N, E>(
executor: E,
) -> eyre::Result<()>
where
N: ProviderNodeTypes<
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header,
>,
>,
N: ProviderNodeTypes,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
info!(target: "reth::cli", "Executing stage. [dry-run]");

View File

@ -9,7 +9,6 @@ use reth_db_api::{database::Database, table::TableImporter};
use reth_db_common::DbTool;
use reth_evm::noop::NoopBlockExecutorProvider;
use reth_exex::ExExManagerHandle;
use reth_node_api::NodePrimitives;
use reth_node_core::dirs::{ChainPath, DataDirPath};
use reth_provider::{
providers::{ProviderNodeTypes, StaticFileProvider},
@ -33,14 +32,7 @@ pub(crate) async fn dump_merkle_stage<N>(
should_run: bool,
) -> Result<()>
where
N: ProviderNodeTypes<
DB = Arc<DatabaseEnv>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header,
>,
>,
N: ProviderNodeTypes<DB = Arc<DatabaseEnv>>,
{
let (output_db, tip_block_number) = setup(from, to, &output_datadir.db(), db_tool)?;
@ -78,15 +70,7 @@ where
}
/// Dry-run an unwind to FROM block and copy the necessary table data to the new database.
fn unwind_and_copy<
N: ProviderNodeTypes<
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header,
>,
>,
>(
fn unwind_and_copy<N: ProviderNodeTypes>(
db_tool: &DbTool<N>,
range: (u64, u64),
tip_block_number: u64,
@ -166,7 +150,7 @@ fn unwind_and_copy<
/// Try to re-execute the stage straight away
fn dry_run<N>(output_provider_factory: ProviderFactory<N>, to: u64, from: u64) -> eyre::Result<()>
where
N: ProviderNodeTypes<Primitives: NodePrimitives<BlockHeader = reth_primitives::Header>>,
N: ProviderNodeTypes,
{
info!(target: "reth::cli", "Executing stage.");
let provider = output_provider_factory.database_provider_rw()?;

View File

@ -4,6 +4,7 @@
use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::Sealable;
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::{EthChainSpec, EthereumHardforks};