Skip to content

Commit 137a98c

Browse files
committed
Merge bitcoin/bitcoin#27610: Improve performance of p2p inv to send queues
5b34060 net_processing: Boost inv trickle rate (Anthony Towns) 228e920 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 bitcoin/bitcoin@5b34060 darosior: utACK 5b34060 glozow: code review ACK 5b34060 dergoegge: utACK 5b34060 Tree-SHA512: 155cd3b5d150ba3417c1cd126f2be734497742e85358a19c9d365f4f97c555ff9e846405bbeada13c3575b3713c3a7eb2f780879a828cbbf032ad9a6e5416b30
2 parents c2f2abd + 5b34060 commit 137a98c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5677,7 +5677,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
56775677
// especially since we have many peers and some will draw much shorter delays.
56785678
unsigned int nRelayedTransactions = 0;
56795679
LOCK(tx_relay->m_bloom_filter_mutex);
5680-
while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX) {
5680+
size_t broadcast_max{INVENTORY_BROADCAST_MAX + (tx_relay->m_tx_inventory_to_send.size()/1000)*5};
5681+
broadcast_max = std::min<size_t>(1000, broadcast_max);
5682+
while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) {
56815683
// Fetch the top element from the heap
56825684
std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
56835685
std::set<uint256>::iterator it = vInvTx.back();

src/txmempool.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,16 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
755755

756756
bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid)
757757
{
758+
/* Return `true` if hasha should be considered sooner than hashb. Namely when:
759+
* a is not in the mempool, but b is
760+
* both are in the mempool and a has fewer ancestors than b
761+
* both are in the mempool and a has a higher score than b
762+
*/
758763
LOCK(cs);
759-
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
760-
if (i == mapTx.end()) return false;
761764
indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
762-
if (j == mapTx.end()) return true;
765+
if (j == mapTx.end()) return false;
766+
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
767+
if (i == mapTx.end()) return true;
763768
uint64_t counta = i->GetCountWithAncestors();
764769
uint64_t countb = j->GetCountWithAncestors();
765770
if (counta == countb) {

0 commit comments

Comments
 (0)