From f34ab3f65aeeb0857926178c3392655eb4a2ee27 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 18 Dec 2024 12:56:08 +0000 Subject: [PATCH 1/4] Add txpool --- Cargo.lock | 1 + crates/reth-rbuilder/Cargo.toml | 2 ++ crates/reth-rbuilder/src/main.rs | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46b598fd..3caa1560 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10098,6 +10098,7 @@ version = "0.1.0" dependencies = [ "clap 4.5.21", "eyre", + "futures-util", "libc", "rbuilder", "reth", diff --git a/crates/reth-rbuilder/Cargo.toml b/crates/reth-rbuilder/Cargo.toml index 70bfea36..fa2dec15 100644 --- a/crates/reth-rbuilder/Cargo.toml +++ b/crates/reth-rbuilder/Cargo.toml @@ -6,6 +6,8 @@ edition.workspace = true [dependencies] rbuilder = { path = "../rbuilder" } +futures-util = "0.3.31" + reth.workspace = true reth-node-builder.workspace = true reth-node-ethereum.workspace = true diff --git a/crates/reth-rbuilder/src/main.rs b/crates/reth-rbuilder/src/main.rs index 1e0b2f20..962f60bb 100644 --- a/crates/reth-rbuilder/src/main.rs +++ b/crates/reth-rbuilder/src/main.rs @@ -6,11 +6,13 @@ //! See for more information. use clap::{Args, Parser}; +use futures_util::StreamExt; use rbuilder::{ live_builder::{base_config::load_config_toml_and_env, cli::LiveBuilderConfig, config::Config}, telemetry, }; -use reth::{chainspec::EthereumChainSpecParser, cli::Cli}; +use reth::transaction_pool::TransactionPool; +use reth::{builder::NodeHandle, chainspec::EthereumChainSpecParser, cli::Cli}; use reth_db_api::Database; use reth_node_builder::{ engine_tree_config::{ @@ -78,7 +80,7 @@ fn main() { let engine_tree_config = TreeConfig::default() .with_persistence_threshold(extra_args.persistence_threshold) .with_memory_block_buffer_target(extra_args.memory_block_buffer_target); - let handle = builder + let NodeHandle{node_exit_future, node} = builder .with_types_and_provider::>() .with_components(EthereumNode::components()) .with_add_ons(EthereumAddOns::default()) @@ -95,7 +97,16 @@ fn main() { builder.launch_with(launcher) }) .await?; - handle.node_exit_future.await + + let mut pending_transactions = node.pool.new_pending_pool_transactions_listener(); + + node.task_executor.spawn(Box::pin(async move { + while let Some(event) = pending_transactions.next().await { + println!("Pending transaction: {:?}", event); + } + })); + + node_exit_future.await } true => { info!(target: "reth::cli", "Running with legacy engine"); From 4c86731e4130583f165ca5b4ed993c2ec0123862 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 18 Dec 2024 15:51:10 +0000 Subject: [PATCH 2/4] Try it --- Cargo.lock | 1 + crates/rbuilder/src/live_builder/mod.rs | 2 ++ crates/reth-rbuilder/Cargo.toml | 1 + crates/reth-rbuilder/src/main.rs | 3 +++ 4 files changed, 7 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3caa1560..7d6a5d48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10107,6 +10107,7 @@ dependencies = [ "reth-node-builder", "reth-node-ethereum", "reth-provider", + "reth-transaction-pool", "tikv-jemallocator", "tokio", "tracing", diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index 5b7c78e2..c6f7dbbc 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -284,6 +284,8 @@ where Ok(()) } + pub fn add_transaction() {} + // Currently we only need two timings config, depending on whether rbuilder is being // used in the optimism context. If further customisation is required in the future // this should be improved on. diff --git a/crates/reth-rbuilder/Cargo.toml b/crates/reth-rbuilder/Cargo.toml index fa2dec15..43e1c769 100644 --- a/crates/reth-rbuilder/Cargo.toml +++ b/crates/reth-rbuilder/Cargo.toml @@ -14,6 +14,7 @@ reth-node-ethereum.workspace = true reth-provider.workspace = true reth-cli-util.workspace = true reth-db-api.workspace = true +reth-transaction-pool.workspace = true tokio.workspace = true clap.workspace = true diff --git a/crates/reth-rbuilder/src/main.rs b/crates/reth-rbuilder/src/main.rs index 962f60bb..dd728afc 100644 --- a/crates/reth-rbuilder/src/main.rs +++ b/crates/reth-rbuilder/src/main.rs @@ -25,6 +25,7 @@ use reth_provider::{ providers::{BlockchainProvider, BlockchainProvider2}, BlockReader, DatabaseProviderFactory, HeaderProvider, StateProviderFactory, }; +use reth_transaction_pool::NewTransactionEvent; use std::{path::PathBuf, process}; use tokio::task; use tracing::{error, info, warn}; @@ -103,6 +104,8 @@ fn main() { node.task_executor.spawn(Box::pin(async move { while let Some(event) = pending_transactions.next().await { println!("Pending transaction: {:?}", event); + let tx = event.transaction; + panic!("Pending transaction"); } })); From e0d81f65664a709bc6621eec7e32e5fb5c00d7ff Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 18 Dec 2024 16:20:27 +0000 Subject: [PATCH 3/4] Last fix --- crates/reth-rbuilder/src/main.rs | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/reth-rbuilder/src/main.rs b/crates/reth-rbuilder/src/main.rs index dd728afc..3dc978b5 100644 --- a/crates/reth-rbuilder/src/main.rs +++ b/crates/reth-rbuilder/src/main.rs @@ -6,13 +6,12 @@ //! See for more information. use clap::{Args, Parser}; -use futures_util::StreamExt; use rbuilder::{ live_builder::{base_config::load_config_toml_and_env, cli::LiveBuilderConfig, config::Config}, telemetry, }; -use reth::transaction_pool::TransactionPool; -use reth::{builder::NodeHandle, chainspec::EthereumChainSpecParser, cli::Cli}; +use reth::rpc::builder::config::RethRpcServerConfig; +use reth::{chainspec::EthereumChainSpecParser, cli::Cli}; use reth_db_api::Database; use reth_node_builder::{ engine_tree_config::{ @@ -25,7 +24,6 @@ use reth_provider::{ providers::{BlockchainProvider, BlockchainProvider2}, BlockReader, DatabaseProviderFactory, HeaderProvider, StateProviderFactory, }; -use reth_transaction_pool::NewTransactionEvent; use std::{path::PathBuf, process}; use tokio::task; use tracing::{error, info, warn}; @@ -81,12 +79,17 @@ fn main() { let engine_tree_config = TreeConfig::default() .with_persistence_threshold(extra_args.persistence_threshold) .with_memory_block_buffer_target(extra_args.memory_block_buffer_target); - let NodeHandle{node_exit_future, node} = builder + let handle = builder .with_types_and_provider::>() .with_components(EthereumNode::components()) .with_add_ons(EthereumAddOns::default()) .on_rpc_started(move |ctx, _| { - spawn_rbuilder(ctx.provider().clone(), extra_args.rbuilder_config); + let ipc_path = if ctx.config().rpc.is_ipc_enabled() { + Some(PathBuf::from(ctx.config().rpc.ipc_path())) + } else { + None + }; + spawn_rbuilder(ctx.provider().clone(), extra_args.rbuilder_config, ipc_path); Ok(()) }) .launch_with_fn(|builder| { @@ -99,17 +102,7 @@ fn main() { }) .await?; - let mut pending_transactions = node.pool.new_pending_pool_transactions_listener(); - - node.task_executor.spawn(Box::pin(async move { - while let Some(event) = pending_transactions.next().await { - println!("Pending transaction: {:?}", event); - let tx = event.transaction; - panic!("Pending transaction"); - } - })); - - node_exit_future.await + handle.node_exit_future.await } true => { info!(target: "reth::cli", "Running with legacy engine"); @@ -118,7 +111,13 @@ fn main() { .with_components(EthereumNode::components()) .with_add_ons::>(Default::default()) .on_rpc_started(move |ctx, _| { - spawn_rbuilder(ctx.provider().clone(), extra_args.rbuilder_config); + let ipc_path = if ctx.config().rpc.is_ipc_enabled() { + Some(PathBuf::from(ctx.config().rpc.ipc_path())) + } else { + None + }; + + spawn_rbuilder(ctx.provider().clone(), extra_args.rbuilder_config, ipc_path); Ok(()) }) .launch().await?; @@ -135,7 +134,7 @@ fn main() { /// Spawns a tokio rbuilder task. /// /// Takes down the entire process if the rbuilder errors or stops. -fn spawn_rbuilder(provider: P, config_path: PathBuf) +fn spawn_rbuilder(provider: P, config_path: PathBuf, ipc_path: Option) where DB: Database + Clone + 'static, P: DatabaseProviderFactory @@ -146,7 +145,10 @@ where { let _handle = task::spawn(async move { let result = async { - let config: Config = load_config_toml_and_env(config_path)?; + let mut config: Config = load_config_toml_and_env(config_path)?; + if let Some(ipc_path) = ipc_path { + config.base_config.el_node_ipc_path = ipc_path; + } // Spawn redacted server that is safe for tdx builders to expose telemetry::servers::redacted::spawn( From 9060ba6415e1da082724a2eee4640f8df52ae45f Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 18 Dec 2024 16:22:48 +0000 Subject: [PATCH 4/4] Update --- Cargo.lock | 2 -- crates/rbuilder/src/live_builder/mod.rs | 2 -- crates/reth-rbuilder/Cargo.toml | 3 --- 3 files changed, 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d6a5d48..46b598fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10098,7 +10098,6 @@ version = "0.1.0" dependencies = [ "clap 4.5.21", "eyre", - "futures-util", "libc", "rbuilder", "reth", @@ -10107,7 +10106,6 @@ dependencies = [ "reth-node-builder", "reth-node-ethereum", "reth-provider", - "reth-transaction-pool", "tikv-jemallocator", "tokio", "tracing", diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index c6f7dbbc..5b7c78e2 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -284,8 +284,6 @@ where Ok(()) } - pub fn add_transaction() {} - // Currently we only need two timings config, depending on whether rbuilder is being // used in the optimism context. If further customisation is required in the future // this should be improved on. diff --git a/crates/reth-rbuilder/Cargo.toml b/crates/reth-rbuilder/Cargo.toml index 43e1c769..70bfea36 100644 --- a/crates/reth-rbuilder/Cargo.toml +++ b/crates/reth-rbuilder/Cargo.toml @@ -6,15 +6,12 @@ edition.workspace = true [dependencies] rbuilder = { path = "../rbuilder" } -futures-util = "0.3.31" - reth.workspace = true reth-node-builder.workspace = true reth-node-ethereum.workspace = true reth-provider.workspace = true reth-cli-util.workspace = true reth-db-api.workspace = true -reth-transaction-pool.workspace = true tokio.workspace = true clap.workspace = true