refactor: extract init from node-core (#8373)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
William Law
2024-05-25 03:20:04 -07:00
committed by GitHub
parent 0056f2f097
commit 7dd787707c
17 changed files with 80 additions and 21 deletions

24
Cargo.lock generated
View File

@ -6391,6 +6391,7 @@ dependencies = [
"reth-consensus",
"reth-consensus-common",
"reth-db",
"reth-db-common",
"reth-discv4",
"reth-discv5",
"reth-downloaders",
@ -6659,6 +6660,25 @@ dependencies = [
"thiserror",
]
[[package]]
name = "reth-db-common"
version = "0.2.0-beta.7"
dependencies = [
"eyre",
"reth-codecs",
"reth-config",
"reth-db",
"reth-etl",
"reth-interfaces",
"reth-primitives",
"reth-provider",
"reth-trie",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "reth-discv4"
version = "0.2.0-beta.7"
@ -7310,6 +7330,7 @@ dependencies = [
"reth-config",
"reth-consensus",
"reth-db",
"reth-db-common",
"reth-downloaders",
"reth-evm",
"reth-exex",
@ -7361,14 +7382,12 @@ dependencies = [
"proptest",
"rand 0.8.5",
"reth-beacon-consensus",
"reth-codecs",
"reth-config",
"reth-consensus-common",
"reth-db",
"reth-discv4",
"reth-discv5",
"reth-engine-primitives",
"reth-etl",
"reth-evm",
"reth-fs-util",
"reth-interfaces",
@ -7388,7 +7407,6 @@ dependencies = [
"reth-tasks",
"reth-tracing",
"reth-transaction-pool",
"reth-trie",
"secp256k1 0.28.2",
"serde",
"serde_json",

View File

@ -66,6 +66,7 @@ members = [
"crates/storage/codecs/",
"crates/storage/codecs/derive/",
"crates/storage/db/",
"crates/storage/db-common",
"crates/storage/errors/",
"crates/storage/libmdbx-rs/",
"crates/storage/libmdbx-rs/mdbx-sys/",
@ -222,6 +223,7 @@ reth-config = { path = "crates/config" }
reth-consensus = { path = "crates/consensus/consensus" }
reth-consensus-common = { path = "crates/consensus/common" }
reth-db = { path = "crates/storage/db" }
reth-db-common = { path = "crates/storage/db-common" }
reth-discv4 = { path = "crates/net/discv4" }
reth-discv5 = { path = "crates/net/discv5" }
reth-dns-discovery = { path = "crates/net/dns" }

View File

@ -54,6 +54,7 @@ reth-node-optimism = { workspace = true, optional = true, features = [
"optimism",
] }
reth-node-core.workspace = true
reth-db-common.workspace = true
reth-node-builder.workspace = true
reth-node-events.workspace = true
reth-consensus.workspace = true

View File

@ -17,6 +17,7 @@ use reth_cli_runner::CliContext;
use reth_config::{config::EtlConfig, Config};
use reth_consensus::Consensus;
use reth_db::{database::Database, init_db, DatabaseEnv};
use reth_db_common::init::init_genesis;
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
headers::reverse_headers::ReverseHeadersDownloaderBuilder,
@ -26,7 +27,6 @@ use reth_fs_util as fs;
use reth_interfaces::p2p::{bodies::client::BodiesClient, headers::client::HeadersClient};
use reth_network::{NetworkEvents, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_core::init::init_genesis;
use reth_primitives::{
stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, PruneModes, B256,
};
@ -187,7 +187,7 @@ impl Command {
match get_single_header(&client, BlockHashOrNumber::Number(block)).await {
Ok(tip_header) => {
info!(target: "reth::cli", ?block, "Successfully fetched block");
return Ok(tip_header.hash())
return Ok(tip_header.hash());
}
Err(error) => {
error!(target: "reth::cli", ?block, %error, "Failed to fetch the block. Retrying...");
@ -255,7 +255,7 @@ impl Command {
provider.get_stage_checkpoint(StageId::Finish)?.map(|ch| ch.block_number);
if latest_block_number.unwrap_or_default() >= self.to {
info!(target: "reth::cli", latest = latest_block_number, "Nothing to run");
return Ok(())
return Ok(());
}
let pipeline_events = pipeline.events();

View File

@ -16,6 +16,7 @@ use reth_beacon_consensus::EthBeaconConsensus;
use reth_config::{config::EtlConfig, Config};
use reth_consensus::Consensus;
use reth_db::{database::Database, init_db, tables, transaction::DbTx};
use reth_db_common::init::init_genesis;
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
file_client::{ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE},
@ -25,7 +26,6 @@ use reth_interfaces::p2p::{
bodies::downloader::BodyDownloader,
headers::downloader::{HeaderDownloader, SyncTarget},
};
use reth_node_core::init::init_genesis;
use reth_node_events::node::NodeEvent;
use reth_primitives::{stage::StageId, ChainSpec, PruneModes, B256};
use reth_provider::{

View File

@ -13,19 +13,15 @@ use crate::{
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_config::{config::EtlConfig, Config};
use reth_db::{init_db, tables, transaction::DbTx};
use reth_db_common::init::init_genesis;
use reth_downloaders::file_client::{
ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE,
};
use reth_node_core::init::init_genesis;
use reth_primitives::{op_mainnet::is_dup_tx, stage::StageId, PruneModes};
use reth_provider::{ProviderFactory, StageCheckpointReader, StaticFileProviderFactory};
use reth_static_file::StaticFileProducer;
use std::{path::PathBuf, sync::Arc};
use tracing::{debug, error, info};
/// Syncs RLP encoded blocks from a file.

View File

@ -9,7 +9,7 @@ use crate::{
};
use clap::Parser;
use reth_db::init_db;
use reth_node_core::init::init_genesis;
use reth_db_common::init::init_genesis;
use reth_primitives::ChainSpec;
use reth_provider::ProviderFactory;
use std::sync::Arc;

View File

@ -10,7 +10,7 @@ use crate::{
use clap::Parser;
use reth_config::config::EtlConfig;
use reth_db::{database::Database, init_db};
use reth_node_core::init::init_from_state_dump;
use reth_db_common::init::init_from_state_dump;
use reth_primitives::{ChainSpec, B256};
use reth_provider::ProviderFactory;

View File

@ -9,7 +9,8 @@ use reth_db::{
init_db, tables,
transaction::DbTx,
};
use reth_node_core::{args::DatabaseArgs, init::init_genesis};
use reth_db_common::init::init_genesis;
use reth_node_core::args::DatabaseArgs;
use reth_primitives::ChainSpec;
use reth_provider::{BlockNumReader, HeaderProvider, ProviderError, ProviderFactory};
use reth_trie::StateRoot;

View File

@ -11,8 +11,8 @@ use crate::{
use clap::Parser;
use itertools::Itertools;
use reth_db::{open_db, static_file::iter_static_files, tables, transaction::DbTxMut, DatabaseEnv};
use reth_db_common::init::{insert_genesis_header, insert_genesis_history, insert_genesis_state};
use reth_fs_util as fs;
use reth_node_core::init::{insert_genesis_header, insert_genesis_history, insert_genesis_state};
use reth_primitives::{
stage::StageId, static_file::find_fixed_range, ChainSpec, StaticFileSegment,
};

View File

@ -35,11 +35,8 @@ reth-network-api.workspace = true
reth-evm.workspace = true
reth-engine-primitives.workspace = true
reth-tasks.workspace = true
reth-trie.workspace = true
reth-consensus-common.workspace = true
reth-beacon-consensus.workspace = true
reth-etl.workspace = true
reth-codecs.workspace = true
# ethereum
discv5.workspace = true

View File

@ -13,7 +13,6 @@ pub mod cli;
pub mod dirs;
pub mod engine;
pub mod exit;
pub mod init;
pub mod metrics;
pub mod node_config;
pub mod utils;

View File

@ -16,6 +16,7 @@ workspace = true
reth-auto-seal-consensus.workspace = true
reth-beacon-consensus.workspace = true
reth-blockchain-tree.workspace = true
reth-db-common.workspace = true
reth-exex.workspace = true
reth-evm.workspace = true
reth-provider.workspace = true

View File

@ -9,11 +9,11 @@ use tokio::sync::mpsc::Receiver;
use reth_auto_seal_consensus::MiningMode;
use reth_config::{config::EtlConfig, PruneConfig};
use reth_db::{database::Database, database_metrics::DatabaseMetrics};
use reth_db_common::init::{init_genesis, InitDatabaseError};
use reth_interfaces::p2p::headers::client::HeadersClient;
use reth_node_core::{
cli::config::RethRpcConfig,
dirs::{ChainPath, DataDirPath},
init::{init_genesis, InitDatabaseError},
node_config::NodeConfig,
};
use reth_primitives::{BlockNumber, Chain, ChainSpec, Head, PruneModes, B256};

View File

@ -0,0 +1,33 @@
[package]
name = "reth-db-common"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
[dependencies]
# reth
reth-primitives.workspace = true
reth-db = { workspace = true, features = ["mdbx"] }
reth-interfaces = { workspace = true, features = ["clap"] }
reth-provider.workspace = true
reth-config.workspace = true
reth-trie.workspace = true
reth-etl.workspace = true
reth-codecs.workspace = true
# misc
eyre.workspace = true
thiserror.workspace = true
# io
serde.workspace = true
serde_json.workspace = true
# tracing
tracing.workspace = true
[lints]
workspace = true

View File

@ -0,0 +1,11 @@
//! Common db operations
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
pub mod init;