Merge #6086: backport: bitcoin/bitcoin#27610: Improve performance of p2p inv to send queues

489b44c647 Merge bitcoin/bitcoin#27610: Improve performance of p2p inv to send queues (fanquake)

Pull request description:

  ## Issue being fixed or feature implemented
  Couple of performance improvements when draining the inventory-to-send queue:

     * drop txs that have already been evicted from the mempool (or included in a block) immediately, rather than at the end of processing
     * marginally increase outgoing trickle rate during spikes in tx volume

  ## What was done?
  Backport bitcoin#27610

  ## How Has This Been Tested?
  Run unit/functional tests

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  UdjinM6:
    utACK 489b44c647
  PastaPastaPasta:
    utACK 489b44c647

Tree-SHA512: 4afca4705b0f9680d147f0bef006fb82a6fd9692fef898dd50aede8570d02b6fece367ec30ab2caa973279df28d90348006a1f78b550dd8b0f7e72dbcb1bba5b
This commit is contained in:
pasta 2024-06-29 14:44:46 -05:00
commit 3e342d797e
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 12 additions and 4 deletions

View File

@ -5736,7 +5736,10 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// No reason to drain out at many times the network's capacity,
// especially since we have many peers and some will draw much shorter delays.
unsigned int nRelayedTransactions = 0;
while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX_PER_1MB_BLOCK * MaxBlockSize() / 1000000) {
size_t broadcast_max{INVENTORY_BROADCAST_MAX_PER_1MB_BLOCK * MaxBlockSize() / 1000000 + (peer->m_tx_relay->m_tx_inventory_to_send.size()/1000)*5};
broadcast_max = std::min<size_t>(1000, broadcast_max);
while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) {
// Fetch the top element from the heap
std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
std::set<uint256>::iterator it = vInvTx.back();

View File

@ -1171,11 +1171,16 @@ void CTxMemPool::check(CChainState& active_chainstate) const
bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb)
{
/* Return `true` if hasha should be considered sooner than hashb. Namely when:
* a is not in the mempool, but b is
* both are in the mempool and a has fewer ancestors than b
* both are in the mempool and a has a higher score than b
*/
LOCK(cs);
indexed_transaction_set::const_iterator i = mapTx.find(hasha);
if (i == mapTx.end()) return false;
indexed_transaction_set::const_iterator j = mapTx.find(hashb);
if (j == mapTx.end()) return true;
if (j == mapTx.end()) return false;
indexed_transaction_set::const_iterator i = mapTx.find(hasha);
if (i == mapTx.end()) return true;
uint64_t counta = i->GetCountWithAncestors();
uint64_t countb = j->GetCountWithAncestors();
if (counta == countb) {