From 76c0d71a8672d7c73631d9f8b6b5e9cb898ef3d6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 23 Aug 2023 17:05:13 +0200 Subject: [PATCH] feat: use get_pooled_transaction_elements in network manager --- crates/net/network/src/transactions.rs | 22 +++++++++++----------- crates/transaction-pool/src/lib.rs | 11 ++++------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/crates/net/network/src/transactions.rs b/crates/net/network/src/transactions.rs index e03d466676a1..17318aa67d62 100644 --- a/crates/net/network/src/transactions.rs +++ b/crates/net/network/src/transactions.rs @@ -24,8 +24,8 @@ use reth_primitives::{ }; use reth_rlp::Encodable; use reth_transaction_pool::{ - error::PoolResult, PoolTransaction, PropagateKind, PropagatedTransactions, TransactionPool, - ValidPoolTransaction, + error::PoolResult, GetPooledTransactionLimit, PoolTransaction, PropagateKind, + PropagatedTransactions, TransactionPool, ValidPoolTransaction, }; use std::{ collections::{hash_map::Entry, HashMap}, @@ -52,6 +52,10 @@ const MAX_FULL_TRANSACTIONS_PACKET_SIZE: usize = 100 * 1024; /// const GET_POOLED_TRANSACTION_SOFT_LIMIT_NUM_HASHES: usize = 256; +/// Softlimit for the response size of a GetPooledTransactions message (2MB) +const GET_POOLED_TRANSACTION_SOFT_LIMIT_SIZE: GetPooledTransactionLimit = + GetPooledTransactionLimit::SizeSoftLimit(2 * 1024 * 1024); + /// The future for inserting a function into the pool pub type PoolImportFuture = Pin> + Send + 'static>>; @@ -182,19 +186,15 @@ where response: oneshot::Sender>, ) { if let Some(peer) = self.peers.get_mut(&peer_id) { - // TODO softResponseLimit 2 * 1024 * 1024 let transactions = self .pool - .get_all(request.0) - .into_iter() - .map(|tx| tx.transaction.to_recovered_transaction().into_signed()) - .collect::>(); + .get_pooled_transaction_elements(request.0, GET_POOLED_TRANSACTION_SOFT_LIMIT_SIZE); - // we sent a response at which point we assume that the peer is aware of the transaction - peer.transactions.extend(transactions.iter().map(|tx| tx.hash())); + // we sent a response at which point we assume that the peer is aware of the + // transactions + peer.transactions.extend(transactions.iter().map(|tx| *tx.hash())); - // TODO: remove this! this will be different when we introduce the blobpool - let resp = PooledTransactions(transactions.into_iter().map(Into::into).collect()); + let resp = PooledTransactions(transactions); let _ = response.send(Ok(resp)); } } diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index d2b705607ec3..570277656380 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -165,10 +165,7 @@ use std::{ use tokio::sync::mpsc::Receiver; use tracing::{instrument, trace}; -use crate::{ - blobstore::{BlobStore, BlobStoreError}, - traits::GetPooledTransactionLimit, -}; +use crate::blobstore::{BlobStore, BlobStoreError}; pub use crate::{ config::{ PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP, REPLACE_BLOB_PRICE_BUMP, @@ -183,9 +180,9 @@ pub use crate::{ }, traits::{ AllPoolTransactions, BestTransactions, BlockInfo, CanonicalStateUpdate, ChangedAccount, - EthPooledTransaction, NewTransactionEvent, PendingTransactionListenerKind, PoolSize, - PoolTransaction, PropagateKind, PropagatedTransactions, TransactionOrigin, TransactionPool, - TransactionPoolExt, + EthPooledTransaction, GetPooledTransactionLimit, NewTransactionEvent, + PendingTransactionListenerKind, PoolSize, PoolTransaction, PropagateKind, + PropagatedTransactions, TransactionOrigin, TransactionPool, TransactionPoolExt, }, validate::{ EthTransactionValidator, TransactionValidationOutcome, TransactionValidationTaskExecutor,