diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0694c92fe2..6511ed614b 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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(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::iterator it = vInvTx.back(); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a9b9a09360..ef089a2a38 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -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) {