-
Notifications
You must be signed in to change notification settings - Fork 62
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not unless we want to replace the wrapped |
||
node.node.task_executor.spawn(Box::pin(forward_raw_transactions(txhandle, raw_txs))); | ||
|
||
node.wait_for_node_exit().await | ||
}) | ||
{ | ||
|
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)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ | |
pub mod broadcaster; | ||
pub mod chainspec; | ||
pub mod evm; | ||
pub mod forwarder; | ||
pub mod node; | ||
pub mod rpc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wish we coudl get rid of
node.node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can rename the variable