From 59f9b13eeb90b2673f2be29c7446489eb25feae7 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 19 Dec 2024 15:33:22 +0100 Subject: [PATCH 1/2] feat: forward txns over p2p --- Cargo.lock | 1 + bin/odyssey/src/main.rs | 7 +++++++ crates/node/Cargo.toml | 6 +++--- crates/node/src/forwarder.rs | 23 +++++++++++++++++++++++ crates/node/src/lib.rs | 1 + crates/node/src/node.rs | 4 ++-- 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 crates/node/src/forwarder.rs diff --git a/Cargo.lock b/Cargo.lock index 11fcea5..18c1e72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4460,6 +4460,7 @@ dependencies = [ "reth-optimism-primitives", "reth-payload-builder", "reth-primitives", + "reth-primitives-traits", "reth-revm", "reth-rpc-eth-api", "reth-rpc-eth-types", diff --git a/bin/odyssey/src/main.rs b/bin/odyssey/src/main.rs index 084ed1b..e20ee82 100644 --- a/bin/odyssey/src/main.rs +++ b/bin/odyssey/src/main.rs @@ -30,6 +30,7 @@ use eyre::Context; use odyssey_node::{ broadcaster::periodic_broadcaster, chainspec::OdysseyChainSpecParser, + forwarder::forward_raw_transactions, node::OdysseyNode, rpc::{EthApiExt, EthApiOverrideServer}, }; @@ -124,6 +125,12 @@ fn main() { }) .await?; + // spawn raw transaction forwarding + let txhandle = node.node.network.transactions_handle().await.unwrap(); + let raw_txs = + node.node.add_ons_handle.eth_api().eth_api().subscribe_to_raw_transactions(); + node.node.task_executor.spawn(Box::pin(forward_raw_transactions(txhandle, raw_txs))); + node.wait_for_node_exit().await }) { diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 9772e49..2f19e15 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -12,9 +12,7 @@ categories.workspace = true [dependencies] odyssey-common.workspace = true -revm-precompile.workspace = true -revm-primitives.workspace = true - +reth-primitives-traits.workspace = true reth-cli.workspace = true reth-errors.workspace = true reth-node-api.workspace = true @@ -44,6 +42,8 @@ alloy-rpc-types-eth.workspace = true op-alloy-consensus.workspace = true +revm-precompile.workspace = true +revm-primitives.workspace = true serde_json.workspace = true tokio.workspace = true diff --git a/crates/node/src/forwarder.rs b/crates/node/src/forwarder.rs new file mode 100644 index 0000000..06e52f3 --- /dev/null +++ b/crates/node/src/forwarder.rs @@ -0,0 +1,23 @@ +//! P2P transaction forwarding + +use alloy_eips::eip2718::Decodable2718; +use alloy_primitives::Bytes; +use reth_network::{transactions::TransactionsHandle, NetworkPrimitives}; +use reth_primitives_traits::transaction::signed::SignedTransaction; +use tokio::sync::broadcast::Receiver; +use tracing::trace; + +/// Forwards raw transactions to the network. +pub async fn forward_raw_transactions( + txn: TransactionsHandle, + mut raw_txs: Receiver, +) { + loop { + if let Ok(raw_tx) = raw_txs.recv().await { + if let Ok(tx) = N::BroadcastedTransaction::decode_2718(&mut raw_tx.as_ref()) { + trace!(target: "rpc::rpc", tx=%tx.tx_hash(), "Forwarding raw transaction over p2p"); + txn.broadcast_transactions(Some(tx)); + } + } + } +} diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index c10c76c..fe707ea 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -18,5 +18,6 @@ pub mod broadcaster; pub mod chainspec; pub mod evm; +pub mod forwarder; pub mod node; pub mod rpc; diff --git a/crates/node/src/node.rs b/crates/node/src/node.rs index b90b243..0d62d74 100644 --- a/crates/node/src/node.rs +++ b/crates/node/src/node.rs @@ -235,8 +235,8 @@ where network_config.peers_config.backoff_durations.medium = Duration::from_secs(5); network_config.peers_config.backoff_durations.high = Duration::from_secs(5); network_config.peers_config.max_backoff_count = u8::MAX; - network_config.sessions_config.session_command_buffer = 500; - network_config.sessions_config.session_event_buffer = 500; + network_config.sessions_config.session_command_buffer = 750; + network_config.sessions_config.session_event_buffer = 750; let txconfig = TransactionsManagerConfig { propagation_mode: TransactionPropagationMode::All, From 9c2bac8e31008d4dca19ab3946515bdafa2cb6a3 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 19 Dec 2024 15:45:51 +0100 Subject: [PATCH 2/2] rename variable --- bin/odyssey/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/odyssey/src/main.rs b/bin/odyssey/src/main.rs index e20ee82..ea3e031 100644 --- a/bin/odyssey/src/main.rs +++ b/bin/odyssey/src/main.rs @@ -61,7 +61,7 @@ fn main() { .as_ref() .map(>::default_signer_address); - let node = builder + let handle = builder .with_types_and_provider::>() .with_components(OdysseyNode::components(&rollup_args)) .with_add_ons( @@ -126,12 +126,12 @@ fn main() { .await?; // spawn raw transaction forwarding - let txhandle = node.node.network.transactions_handle().await.unwrap(); + let txhandle = handle.node.network.transactions_handle().await.unwrap(); let raw_txs = - node.node.add_ons_handle.eth_api().eth_api().subscribe_to_raw_transactions(); - node.node.task_executor.spawn(Box::pin(forward_raw_transactions(txhandle, raw_txs))); + handle.node.add_ons_handle.eth_api().eth_api().subscribe_to_raw_transactions(); + handle.node.task_executor.spawn(Box::pin(forward_raw_transactions(txhandle, raw_txs))); - node.wait_for_node_exit().await + handle.wait_for_node_exit().await }) { eprintln!("Error: {err:?}");