Support soft limit in NewPooledTransactions (#1577)

This commit is contained in:
Tirth Patel
2023-03-03 05:06:01 -03:30
committed by GitHub
parent 161795945b
commit fbfec26a36

View File

@@ -36,6 +36,9 @@ use tracing::trace;
/// Cache limit of transactions to keep track of for a single peer.
const PEER_TRANSACTION_CACHE_LIMIT: usize = 1024 * 10;
/// Soft limit for NewPooledTransactions
const NEW_POOLED_TRANSACTION_HASHES_SOFT_LIMT: usize = 4096;
/// The future for inserting a function into the pool
pub type PoolImportFuture = Pin<Box<dyn Future<Output = PoolResult<TxHash>> + Send + 'static>>;
@@ -352,7 +355,23 @@ where
// Send a `NewPooledTransactionHashes` to the peer with _all_ transactions in the
// pool
if !self.network.is_syncing() {
todo!("get access to full tx");
let mut hashes = PooledTransactionsHashesBuilder::new(version);
let to_propogate = self.pool.pooled_transactions().into_iter().map(|tx| {
let tx = Arc::new(tx.transaction.to_recovered_transaction().into_signed());
PropagateTransaction::new(tx)
});
for tx in to_propogate.take(NEW_POOLED_TRANSACTION_HASHES_SOFT_LIMT) {
let peer = self.peers.get_mut(&peer_id).unwrap();
if peer.transactions.insert(tx.hash()) {
hashes.push(&tx);
}
}
let hashes = hashes.build();
self.network.send_transactions_hashes(peer_id, hashes);
// let msg = NewPooledTransactionHashes66(self.pool.pooled_transactions());
// self.network.send_message(NetworkHandleMessage::SendPooledTransactionHashes {
// peer_id,