Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pooled_transaction_max #1971

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>>> {
Expand Down
13 changes: 13 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,26 @@ 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.
///
/// 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
Expand Down