feat: add pooled_transaction_max (#1971)

This commit is contained in:
chirag-bgh
2023-03-24 23:39:02 +05:30
committed by GitHub
parent 099f241b90
commit ea4b4f77e9
3 changed files with 27 additions and 4 deletions

View File

@@ -368,15 +368,14 @@ where
let mut msg_builder = PooledTransactionsHashesBuilder::new(version);
let pooled_txs = self.pool.pooled_transactions();
let pooled_txs =
self.pool.pooled_transactions_max(NEW_POOLED_TRANSACTION_HASHES_SOFT_LIMIT);
if pooled_txs.is_empty() {
// do not send a message if there are no transactions in the pool
return
}
for pooled_tx in
pooled_txs.into_iter().take(NEW_POOLED_TRANSACTION_HASHES_SOFT_LIMIT)
{
for pooled_tx in pooled_txs.into_iter() {
peer.transactions.insert(*pooled_tx.hash());
msg_builder.push_pooled(pooled_tx);
}

View File

@@ -283,6 +283,17 @@ where
self.pool.pooled_transactions()
}
fn pooled_transaction_hashes_max(&self, max: usize) -> Vec<TxHash> {
self.pooled_transaction_hashes().into_iter().take(max).collect()
}
fn pooled_transactions_max(
&self,
max: usize,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pooled_transactions().into_iter().take(max).collect()
}
fn best_transactions(
&self,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {

View File

@@ -79,6 +79,11 @@ pub trait TransactionPool: Send + Sync + Clone {
/// Consumer: P2P
fn pooled_transaction_hashes(&self) -> Vec<TxHash>;
/// Returns only the first `max` hashes of transactions in the pool.
///
/// Consumer: P2P
fn pooled_transaction_hashes_max(&self, max: usize) -> Vec<TxHash>;
/// Returns the _full_ transaction objects all transactions in the pool.
///
/// Note: This returns a `Vec` but should guarantee that all transactions are unique.
@@ -86,6 +91,14 @@ pub trait TransactionPool: Send + Sync + Clone {
/// Consumer: P2P
fn pooled_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns only the first `max` transactions in the pool.
///
/// Consumer: P2P
fn pooled_transactions_max(
&self,
max: usize,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
/// Returns an iterator that yields transactions that are ready for block production.
///
/// Consumer: Block production