diff --git a/Cargo.lock b/Cargo.lock index 784f629e5..33c431f6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6401,7 +6401,6 @@ dependencies = [ "futures", "reth-basic-payload-builder", "reth-beacon-consensus", - "reth-blockchain-tree", "reth-chainspec", "reth-cli", "reth-cli-commands", @@ -6413,7 +6412,6 @@ dependencies = [ "reth-db", "reth-db-api", "reth-downloaders", - "reth-engine-util", "reth-errors", "reth-ethereum-cli", "reth-ethereum-payload-builder", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index fb86a8ced..9730c1804 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -36,7 +36,6 @@ reth-cli-runner.workspace = true reth-cli-commands.workspace = true reth-cli-util.workspace = true reth-consensus-common.workspace = true -reth-blockchain-tree.workspace = true reth-rpc-builder.workspace = true reth-rpc.workspace = true reth-rpc-types-compat.workspace = true @@ -64,7 +63,6 @@ reth-node-builder.workspace = true reth-node-events.workspace = true reth-node-metrics.workspace = true reth-consensus.workspace = true -reth-engine-util.workspace = true reth-prune.workspace = true # crypto diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 55082c1c3..1fd437697 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -13,9 +13,6 @@ use reth_basic_payload_builder::{ BuildArguments, BuildOutcome, Cancelled, PayloadBuilder, PayloadConfig, }; use reth_beacon_consensus::EthBeaconConsensus; -use reth_blockchain_tree::{ - BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, -}; use reth_chainspec::ChainSpec; use reth_cli::chainspec::ChainSpecParser; use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs}; @@ -33,7 +30,7 @@ use reth_primitives::{ TransactionSigned, }; use reth_provider::{ - providers::{BlockchainProvider, ProviderNodeTypes}, + providers::{BlockchainProvider2, ProviderNodeTypes}, BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader, StateProviderFactory, }; @@ -131,21 +128,12 @@ impl> Command { let consensus: Arc> = Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); - let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); - - // configure blockchain tree - let tree_externals = - TreeExternals::new(provider_factory.clone(), Arc::clone(&consensus), executor); - let tree = BlockchainTree::new(tree_externals, BlockchainTreeConfig::default())?; - let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree)); - // fetch the best block from the database let best_block = self .lookup_best_block(provider_factory.clone()) .wrap_err("the head block is missing")?; - let blockchain_db = - BlockchainProvider::new(provider_factory.clone(), blockchain_tree.clone())?; + let blockchain_db = BlockchainProvider2::new(provider_factory.clone())?; let blob_store = InMemoryBlobStore::default(); let validator = diff --git a/bin/reth/src/commands/debug_cmd/mod.rs b/bin/reth/src/commands/debug_cmd/mod.rs index 4aaa1b1c8..26077a127 100644 --- a/bin/reth/src/commands/debug_cmd/mod.rs +++ b/bin/reth/src/commands/debug_cmd/mod.rs @@ -12,7 +12,6 @@ mod build_block; mod execution; mod in_memory_merkle; mod merkle; -mod replay_engine; /// `reth debug` command #[derive(Debug, Parser)] @@ -32,8 +31,6 @@ pub enum Subcommands { InMemoryMerkle(in_memory_merkle::Command), /// Debug block building. BuildBlock(build_block::Command), - /// Debug engine API by replaying stored messages. - ReplayEngine(replay_engine::Command), } impl> Command { @@ -49,7 +46,6 @@ impl> Command { Subcommands::Merkle(command) => command.execute::(ctx).await, Subcommands::InMemoryMerkle(command) => command.execute::(ctx).await, Subcommands::BuildBlock(command) => command.execute::(ctx).await, - Subcommands::ReplayEngine(command) => command.execute::(ctx).await, } } } diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs deleted file mode 100644 index 80d60cfb3..000000000 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ /dev/null @@ -1,212 +0,0 @@ -use crate::args::NetworkArgs; -use clap::Parser; -use eyre::Context; -use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; -use reth_beacon_consensus::{hooks::EngineHooks, BeaconConsensusEngine, EthBeaconConsensus}; -use reth_blockchain_tree::{ - BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, -}; -use reth_chainspec::ChainSpec; -use reth_cli::chainspec::ChainSpecParser; -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; -use reth_consensus::{ConsensusError, FullConsensus}; -use reth_db::DatabaseEnv; -use reth_engine_util::engine_store::{EngineMessageStore, StoredEngineApiMessage}; -use reth_ethereum_payload_builder::EthereumBuilderConfig; -use reth_fs_util as fs; -use reth_network::{BlockDownloaderProvider, NetworkHandle}; -use reth_network_api::NetworkInfo; -use reth_node_api::{EngineApiMessageVersion, NodePrimitives, NodeTypesWithDBAdapter}; -use reth_node_ethereum::{EthEngineTypes, EthEvmConfig, EthExecutorProvider}; -use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; -use reth_primitives::EthPrimitives; -use reth_provider::{ - providers::{BlockchainProvider, ProviderNodeTypes}, - CanonStateSubscriptions, ChainSpecProvider, ProviderFactory, -}; -use reth_prune::PruneModes; -use reth_stages::Pipeline; -use reth_static_file::StaticFileProducer; -use reth_tasks::TaskExecutor; -use reth_transaction_pool::noop::NoopTransactionPool; -use std::{path::PathBuf, sync::Arc, time::Duration}; -use tokio::sync::oneshot; -use tracing::*; - -/// `reth debug replay-engine` command -/// This script will read stored engine API messages and replay them by the timestamp. -/// It does not require -#[derive(Debug, Parser)] -pub struct Command { - #[command(flatten)] - env: EnvironmentArgs, - - #[command(flatten)] - network: NetworkArgs, - - /// The path to read engine API messages from. - #[arg(long = "engine-api-store", value_name = "PATH")] - engine_api_store: PathBuf, - - /// The number of milliseconds between Engine API messages. - #[arg(long = "interval", default_value_t = 1_000)] - interval: u64, -} - -impl> Command { - async fn build_network< - N: ProviderNodeTypes< - ChainSpec = C::ChainSpec, - Primitives: NodePrimitives< - Block = reth_primitives::Block, - Receipt = reth_primitives::Receipt, - BlockHeader = reth_primitives::Header, - >, - >, - >( - &self, - config: &Config, - task_executor: TaskExecutor, - provider_factory: ProviderFactory, - network_secret_path: PathBuf, - default_peers_path: PathBuf, - ) -> eyre::Result { - let secret_key = get_secret_key(&network_secret_path)?; - let network = self - .network - .network_config(config, provider_factory.chain_spec(), secret_key, default_peers_path) - .with_task_executor(Box::new(task_executor)) - .build(provider_factory) - .start_network() - .await?; - info!(target: "reth::cli", peer_id = %network.peer_id(), local_addr = %network.local_addr(), "Connected to P2P network"); - debug!(target: "reth::cli", peer_id = ?network.peer_id(), "Full peer ID"); - Ok(network) - } - - /// Execute `debug replay-engine` command - pub async fn execute< - N: CliNodeTypes, - >( - self, - ctx: CliContext, - ) -> eyre::Result<()> { - let Environment { provider_factory, config, data_dir } = - self.env.init::(AccessRights::RW)?; - - let consensus: Arc> = - Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); - - let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); - - // Configure blockchain tree - let tree_externals = - TreeExternals::new(provider_factory.clone(), Arc::clone(&consensus), executor); - let tree = BlockchainTree::new(tree_externals, BlockchainTreeConfig::default())?; - let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree)); - - // Set up the blockchain provider - let blockchain_db = BlockchainProvider::new(provider_factory.clone(), blockchain_tree)?; - - // Set up network - let network_secret_path = - self.network.p2p_secret_key.clone().unwrap_or_else(|| data_dir.p2p_secret()); - let network = self - .build_network( - &config, - ctx.task_executor.clone(), - provider_factory.clone(), - network_secret_path, - data_dir.known_peers(), - ) - .await?; - - // Set up payload builder - let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new( - EthEvmConfig::new(provider_factory.chain_spec()), - EthereumBuilderConfig::new(Default::default()), - ); - - let payload_generator = BasicPayloadJobGenerator::with_builder( - blockchain_db.clone(), - NoopTransactionPool::default(), - ctx.task_executor.clone(), - BasicPayloadJobGeneratorConfig::default(), - payload_builder, - ); - - let (payload_service, payload_builder): (_, PayloadBuilderHandle) = - PayloadBuilderService::new(payload_generator, blockchain_db.canonical_state_stream()); - - ctx.task_executor.spawn_critical("payload builder service", payload_service); - - // Configure the consensus engine - let network_client = network.fetch_client().await?; - let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::new( - network_client, - Pipeline::>>::builder().build( - provider_factory.clone(), - StaticFileProducer::new(provider_factory.clone(), PruneModes::none()), - ), - blockchain_db.clone(), - Box::new(ctx.task_executor.clone()), - Box::new(network), - None, - payload_builder, - None, - u64::MAX, - EngineHooks::new(), - )?; - info!(target: "reth::cli", "Consensus engine initialized"); - - // Run consensus engine to completion - let (tx, rx) = oneshot::channel(); - info!(target: "reth::cli", "Starting consensus engine"); - ctx.task_executor.spawn_critical_blocking("consensus engine", async move { - let res = beacon_consensus_engine.await; - let _ = tx.send(res); - }); - - let engine_api_store = EngineMessageStore::new(self.engine_api_store.clone()); - for filepath in engine_api_store.engine_messages_iter()? { - let contents = - fs::read(&filepath).wrap_err(format!("failed to read: {}", filepath.display()))?; - let message = serde_json::from_slice(&contents) - .wrap_err(format!("failed to parse: {}", filepath.display()))?; - debug!(target: "reth::cli", filepath = %filepath.display(), ?message, "Forwarding Engine API message"); - match message { - StoredEngineApiMessage::ForkchoiceUpdated { state, payload_attrs } => { - let response = beacon_engine_handle - .fork_choice_updated( - state, - payload_attrs, - EngineApiMessageVersion::default(), - ) - .await?; - debug!(target: "reth::cli", ?response, "Received for forkchoice updated"); - } - StoredEngineApiMessage::NewPayload { payload, sidecar } => { - let response = beacon_engine_handle.new_payload(payload, sidecar).await?; - debug!(target: "reth::cli", ?response, "Received for new payload"); - } - }; - - // Pause before next message - tokio::time::sleep(Duration::from_millis(self.interval)).await; - } - - info!(target: "reth::cli", "Finished replaying engine API messages"); - - match rx.await? { - Ok(()) => info!("Beacon consensus engine exited successfully"), - Err(error) => { - error!(target: "reth::cli", %error, "Beacon consensus engine exited with an error") - } - }; - - Ok(()) - } -} diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 53c592063..1c55669be 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -107,10 +107,6 @@ pub mod primitives { pub mod beacon_consensus { pub use reth_beacon_consensus::*; } -/// Re-exported from `reth_blockchain_tree`. -pub mod blockchain_tree { - pub use reth_blockchain_tree::*; -} /// Re-exported from `reth_consensus`. pub mod consensus { diff --git a/book/SUMMARY.md b/book/SUMMARY.md index f93daeaba..666f4e4ca 100644 --- a/book/SUMMARY.md +++ b/book/SUMMARY.md @@ -70,7 +70,6 @@ - [`reth debug merkle`](./cli/reth/debug/merkle.md) - [`reth debug in-memory-merkle`](./cli/reth/debug/in-memory-merkle.md) - [`reth debug build-block`](./cli/reth/debug/build-block.md) - - [`reth debug replay-engine`](./cli/reth/debug/replay-engine.md) - [`reth recover`](./cli/reth/recover.md) - [`reth recover storage-tries`](./cli/reth/recover/storage-tries.md) - [`reth prune`](./cli/reth/prune.md) diff --git a/book/cli/SUMMARY.md b/book/cli/SUMMARY.md index 5f338a0d1..6a18ff0cd 100644 --- a/book/cli/SUMMARY.md +++ b/book/cli/SUMMARY.md @@ -40,7 +40,6 @@ - [`reth debug merkle`](./reth/debug/merkle.md) - [`reth debug in-memory-merkle`](./reth/debug/in-memory-merkle.md) - [`reth debug build-block`](./reth/debug/build-block.md) - - [`reth debug replay-engine`](./reth/debug/replay-engine.md) - [`reth recover`](./reth/recover.md) - [`reth recover storage-tries`](./reth/recover/storage-tries.md) - [`reth prune`](./reth/prune.md) diff --git a/book/cli/reth/debug.md b/book/cli/reth/debug.md index ab016d631..c3f98e145 100644 --- a/book/cli/reth/debug.md +++ b/book/cli/reth/debug.md @@ -13,7 +13,6 @@ Commands: merkle Debug the clean & incremental state root calculations in-memory-merkle Debug in-memory state root calculation build-block Debug block building - replay-engine Debug engine API by replaying stored messages help Print this message or the help of the given subcommand(s) Options: diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index cde891036..1af1d3e5e 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -18,7 +18,7 @@ use reth::{ api::NodeTypesWithDBAdapter, beacon_consensus::EthBeaconConsensus, providers::{ - providers::{BlockchainProvider, StaticFileProvider}, + providers::{BlockchainProvider2, StaticFileProvider}, ProviderFactory, }, rpc::eth::EthApi, @@ -33,7 +33,7 @@ use reth::rpc::builder::{ }; // Configuring the network parts, ideally also wouldn't need to think about this. use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; -use reth::{blockchain_tree::noop::NoopBlockchainTree, tasks::TokioTaskExecutor}; +use reth::tasks::TokioTaskExecutor; use reth_node_ethereum::{ node::EthereumEngineValidator, EthEvmConfig, EthExecutorProvider, EthereumNode, }; @@ -61,7 +61,7 @@ async fn main() -> eyre::Result<()> { // 2. Setup the blockchain provider using only the database provider and a noop for the tree to // satisfy trait bounds. Tree is not used in this example since we are only operating on the // disk and don't handle new blocks/live sync etc, which is done by the blockchain tree. - let provider = BlockchainProvider::new(factory, Arc::new(NoopBlockchainTree::default()))?; + let provider = BlockchainProvider2::new(factory)?; let rpc_builder = RpcModuleBuilder::default() .with_provider(provider.clone())