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

5b3406094f2679dfb3763de4414257268565b943 net_processing: Boost inv trickle rate (Anthony Towns)
228e9201efb5574b1b96bb924de1d2e8dd1317f3 txmempool: have CompareDepthAndScore sort missing txs first (Anthony Towns)

Pull request description:

  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

ACKs for top commit:
  willcl-ark:
    ACK 5b34060
  instagibbs:
    ACK 5b3406094f
  darosior:
    utACK 5b3406094f2679dfb3763de4414257268565b943
  glozow:
    code review ACK 5b3406094f2679dfb3763de4414257268565b943
  dergoegge:
    utACK 5b3406094f2679dfb3763de4414257268565b943

Tree-SHA512: 155cd3b5d150ba3417c1cd126f2be734497742e85358a19c9d365f4f97c555ff9e846405bbeada13c3575b3713c3a7eb2f780879a828cbbf032ad9a6e5416b30
This commit is contained in:
fanquake 2023-05-11 14:02:14 +01:00 committed by Konstantin Akimov
parent 37e026a038
commit 489b44c647
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
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) {