Skip to content

Commit

Permalink
feat: use network primitives pooled transaction AT (paradigmxyz#12718)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 20, 2024
1 parent 8df9045 commit a0d7503
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
6 changes: 5 additions & 1 deletion crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ pub enum EthMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a `GetPooledTransactions` request-response pair.
GetPooledTransactions(RequestPair<GetPooledTransactions>),
/// Represents a `PooledTransactions` request-response pair.
PooledTransactions(RequestPair<PooledTransactions>),
#[cfg_attr(
feature = "serde",
serde(bound = "N::PooledTransaction: serde::Serialize + serde::de::DeserializeOwned")
)]
PooledTransactions(RequestPair<PooledTransactions<N::PooledTransaction>>),
/// Represents a `GetNodeData` request-response pair.
GetNodeData(RequestPair<GetNodeData>),
/// Represents a `NodeData` request-response pair.
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network-api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub enum PeerRequest<N: NetworkPrimitives = EthNetworkPrimitives> {
/// The request for pooled transactions.
request: GetPooledTransactions,
/// The channel to send the response for pooled transactions.
response: oneshot::Sender<RequestResult<PooledTransactions>>,
response: oneshot::Sender<RequestResult<PooledTransactions<N::PooledTransaction>>>,
},
/// Requests `NodeData` from the peer.
///
Expand Down
6 changes: 3 additions & 3 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub struct NetworkManager<N: NetworkPrimitives = EthNetworkPrimitives> {
event_sender: EventSender<NetworkEvent<PeerRequest<N>>>,
/// Sender half to send events to the
/// [`TransactionsManager`](crate::transactions::TransactionsManager) task, if configured.
to_transactions_manager: Option<UnboundedMeteredSender<NetworkTransactionEvent>>,
to_transactions_manager: Option<UnboundedMeteredSender<NetworkTransactionEvent<N>>>,
/// Sender half to send events to the
/// [`EthRequestHandler`](crate::eth_requests::EthRequestHandler) task, if configured.
///
Expand Down Expand Up @@ -120,7 +120,7 @@ pub struct NetworkManager<N: NetworkPrimitives = EthNetworkPrimitives> {
impl<N: NetworkPrimitives> NetworkManager<N> {
/// Sets the dedicated channel for events indented for the
/// [`TransactionsManager`](crate::transactions::TransactionsManager).
pub fn set_transactions(&mut self, tx: mpsc::UnboundedSender<NetworkTransactionEvent>) {
pub fn set_transactions(&mut self, tx: mpsc::UnboundedSender<NetworkTransactionEvent<N>>) {
self.to_transactions_manager =
Some(UnboundedMeteredSender::new(tx, NETWORK_POOL_TRANSACTIONS_SCOPE));
}
Expand Down Expand Up @@ -409,7 +409,7 @@ impl<N: NetworkPrimitives> NetworkManager<N> {

/// Sends an event to the [`TransactionsManager`](crate::transactions::TransactionsManager) if
/// configured.
fn notify_tx_manager(&self, event: NetworkTransactionEvent) {
fn notify_tx_manager(&self, event: NetworkTransactionEvent<N>) {
if let Some(ref tx) = self.to_transactions_manager {
let _ = tx.send(event);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/net/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reth_eth_wire::{
};
use reth_network_api::PeerRequest;
use reth_network_p2p::error::{RequestError, RequestResult};
use reth_primitives::{PooledTransactionsElement, ReceiptWithBloom};
use reth_primitives::ReceiptWithBloom;
use std::{
sync::Arc,
task::{ready, Context, Poll},
Expand Down Expand Up @@ -89,7 +89,7 @@ pub enum PeerResponse<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a response to a request for pooled transactions.
PooledTransactions {
/// The receiver channel for the response to a pooled transactions request.
response: oneshot::Receiver<RequestResult<PooledTransactions>>,
response: oneshot::Receiver<RequestResult<PooledTransactions<N::PooledTransaction>>>,
},
/// Represents a response to a request for `NodeData`.
NodeData {
Expand Down Expand Up @@ -146,7 +146,7 @@ pub enum PeerResponseResult<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a result containing block bodies or an error.
BlockBodies(RequestResult<Vec<N::BlockBody>>),
/// Represents a result containing pooled transactions or an error.
PooledTransactions(RequestResult<Vec<PooledTransactionsElement>>),
PooledTransactions(RequestResult<Vec<N::PooledTransaction>>),
/// Represents a result containing node data or an error.
NodeData(RequestResult<Vec<Bytes>>),
/// Represents a result containing receipts or an error.
Expand Down
4 changes: 2 additions & 2 deletions crates/net/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<N: NetworkPrimitives> NetworkHandle<N> {
/// Send message to get the [`TransactionsHandle`].
///
/// Returns `None` if no transaction task is installed.
pub async fn transactions_handle(&self) -> Option<TransactionsHandle> {
pub async fn transactions_handle(&self) -> Option<TransactionsHandle<N>> {
let (tx, rx) = oneshot::channel();
let _ = self.manager().send(NetworkHandleMessage::GetTransactionsHandle(tx));
rx.await.unwrap()
Expand Down Expand Up @@ -504,7 +504,7 @@ pub(crate) enum NetworkHandleMessage<N: NetworkPrimitives = EthNetworkPrimitives
/// Gets the reputation for a specific peer via a oneshot sender.
GetReputationById(PeerId, oneshot::Sender<Option<Reputation>>),
/// Retrieves the `TransactionsHandle` via a oneshot sender.
GetTransactionsHandle(oneshot::Sender<Option<TransactionsHandle>>),
GetTransactionsHandle(oneshot::Sender<Option<TransactionsHandle<N>>>),
/// Initiates a graceful shutdown of the network via a oneshot sender.
Shutdown(oneshot::Sender<()>),
/// Sets the network state between hibernation and active.
Expand Down
10 changes: 4 additions & 6 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ impl<N: NetworkPrimitives> TransactionsHandle<N> {
let res = self.get_transaction_hashes(vec![peer]).await?;
Ok(res.into_values().next().unwrap_or_default())
}
}

impl TransactionsHandle {
/// Requests the transactions directly from the given peer.
///
/// Returns `None` if the peer is not connected.
Expand All @@ -173,7 +171,7 @@ impl TransactionsHandle {
&self,
peer_id: PeerId,
hashes: Vec<B256>,
) -> Result<Option<Vec<PooledTransactionsElement>>, RequestError> {
) -> Result<Option<Vec<N::PooledTransaction>>, RequestError> {
let Some(peer) = self.peer_handle(peer_id).await? else { return Ok(None) };

let (tx, rx) = oneshot::channel();
Expand Down Expand Up @@ -1762,7 +1760,7 @@ enum TransactionsCommand<N: NetworkPrimitives = EthNetworkPrimitives> {

/// All events related to transactions emitted by the network.
#[derive(Debug)]
pub enum NetworkTransactionEvent {
pub enum NetworkTransactionEvent<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents the event of receiving a list of transactions from a peer.
///
/// This indicates transactions that were broadcasted to us from the peer.
Expand All @@ -1786,10 +1784,10 @@ pub enum NetworkTransactionEvent {
/// The received `GetPooledTransactions` request.
request: GetPooledTransactions,
/// The sender for responding to the request with a result of `PooledTransactions`.
response: oneshot::Sender<RequestResult<PooledTransactions>>,
response: oneshot::Sender<RequestResult<PooledTransactions<N::PooledTransaction>>>,
},
/// Represents the event of receiving a `GetTransactionsHandle` request.
GetTransactionsHandle(oneshot::Sender<Option<TransactionsHandle>>),
GetTransactionsHandle(oneshot::Sender<Option<TransactionsHandle<N>>>),
}

/// Tracks stats about the [`TransactionsManager`].
Expand Down

0 comments on commit a0d7503

Please sign in to comment.