mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-01 02:25:24 -05:00
feat: NetworkHandle get access to TransactionsHandle (#6780)
This commit is contained in:
@@ -593,6 +593,13 @@ where
|
||||
let _ = tx.send(self.swarm.sessions().get_peer_infos_by_ids(peers));
|
||||
}
|
||||
NetworkHandleMessage::AddRlpxSubProtocol(proto) => self.add_rlpx_sub_protocol(proto),
|
||||
NetworkHandleMessage::GetTransactionsHandle(tx) => {
|
||||
if let Some(ref tx_inner) = self.to_transactions_manager {
|
||||
let _ = tx_inner.send(NetworkTransactionEvent::GetTransactionsHandle(tx));
|
||||
} else {
|
||||
let _ = tx.send(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
config::NetworkMode, discovery::DiscoveryEvent, manager::NetworkEvent, message::PeerRequest,
|
||||
peers::PeersHandle, protocol::RlpxSubProtocol, swarm::NetworkConnectionState, FetchClient,
|
||||
peers::PeersHandle, protocol::RlpxSubProtocol, swarm::NetworkConnectionState,
|
||||
transactions::TransactionsHandle, FetchClient,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions};
|
||||
@@ -136,6 +137,15 @@ impl NetworkHandle {
|
||||
})
|
||||
}
|
||||
|
||||
/// Send message to get the [`TransactionsHandle`].
|
||||
///
|
||||
/// Returns `None` if no transaction task is installed.
|
||||
pub async fn transactions_handle(&self) -> Option<TransactionsHandle> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.manager().send(NetworkHandleMessage::GetTransactionsHandle(tx));
|
||||
rx.await.unwrap()
|
||||
}
|
||||
|
||||
/// Provides a shareable reference to the [`BandwidthMeter`] stored on the `NetworkInner`.
|
||||
pub fn bandwidth_meter(&self) -> &BandwidthMeter {
|
||||
&self.inner.bandwidth_meter
|
||||
@@ -446,6 +456,8 @@ pub(crate) enum NetworkHandleMessage {
|
||||
GetPeerInfosByPeerKind(PeerKind, oneshot::Sender<Vec<PeerInfo>>),
|
||||
/// 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>>),
|
||||
/// Initiates a graceful shutdown of the network via a oneshot sender.
|
||||
Shutdown(oneshot::Sender<()>),
|
||||
/// Sets the network state between hibernation and active.
|
||||
|
||||
@@ -869,6 +869,9 @@ where
|
||||
NetworkTransactionEvent::GetPooledTransactions { peer_id, request, response } => {
|
||||
self.on_get_pooled_transactions(peer_id, request, response)
|
||||
}
|
||||
NetworkTransactionEvent::GetTransactionsHandle(response) => {
|
||||
let _ = response.send(Some(self.handle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1561,6 +1564,8 @@ pub enum NetworkTransactionEvent {
|
||||
/// The sender for responding to the request with a result of `PooledTransactions`.
|
||||
response: oneshot::Sender<RequestResult<PooledTransactions>>,
|
||||
},
|
||||
/// Represents the event of receiving a `GetTransactionsHandle` request.
|
||||
GetTransactionsHandle(oneshot::Sender<Option<TransactionsHandle>>),
|
||||
}
|
||||
|
||||
/// Tracks stats about the [`TransactionsManager`].
|
||||
|
||||
Reference in New Issue
Block a user