Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward txns over p2p #116

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions bin/odyssey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use eyre::Context;
use odyssey_node::{
broadcaster::periodic_broadcaster,
chainspec::OdysseyChainSpecParser,
forwarder::forward_raw_transactions,
node::OdysseyNode,
rpc::{EthApiExt, EthApiOverrideServer},
};
Expand Down Expand Up @@ -60,7 +61,7 @@ fn main() {
.as_ref()
.map(<EthereumWallet as NetworkWallet<Ethereum>>::default_signer_address);

let node = builder
let handle = builder
.with_types_and_provider::<OdysseyNode, BlockchainProvider2<_>>()
.with_components(OdysseyNode::components(&rollup_args))
.with_add_ons(
Expand Down Expand Up @@ -124,7 +125,13 @@ fn main() {
})
.await?;

node.wait_for_node_exit().await
// spawn raw transaction forwarding
let txhandle = handle.node.network.transactions_handle().await.unwrap();
let 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)));

handle.wait_for_node_exit().await
})
{
eprintln!("Error: {err:?}");
Expand Down
6 changes: 3 additions & 3 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions crates/node/src/forwarder.rs
Original file line number Diff line number Diff line change
@@ -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<N: NetworkPrimitives>(
txn: TransactionsHandle<N>,
mut raw_txs: Receiver<Bytes>,
) {
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));
}
}
}
}
1 change: 1 addition & 0 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
pub mod broadcaster;
pub mod chainspec;
pub mod evm;
pub mod forwarder;
pub mod node;
pub mod rpc;
4 changes: 2 additions & 2 deletions crates/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading