mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: use network primitives pooled transaction AT (#12718)
This commit is contained in:
@ -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.
|
||||
///
|
||||
@ -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));
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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},
|
||||
@ -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 {
|
||||
@ -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.
|
||||
|
||||
@ -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()
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
@ -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();
|
||||
@ -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.
|
||||
@ -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`].
|
||||
|
||||
Reference in New Issue
Block a user