Skip to content

Commit ef3e18b

Browse files
committed
Merge pull request #9226
b5b72ae Fixed mempool pruning (SChernykh)
2 parents 5eb3fc2 + b5b72ae commit ef3e18b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/cryptonote_core/tx_pool.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,14 @@ namespace cryptonote
436436
void tx_memory_pool::prune(size_t bytes)
437437
{
438438
CRITICAL_REGION_LOCAL(m_transactions_lock);
439+
440+
// Nothing to do if already empty
441+
if (m_txs_by_fee_and_receive_time.empty())
442+
return;
443+
439444
if (bytes == 0)
440445
bytes = m_txpool_max_weight;
446+
441447
CRITICAL_REGION_LOCAL1(m_blockchain);
442448
LockedTXN lock(m_blockchain.get_db());
443449
bool changed = false;
@@ -482,8 +488,13 @@ namespace cryptonote
482488
reduce_txpool_weight(meta.weight);
483489
remove_transaction_keyimages(tx, txid);
484490
MINFO("Pruned tx " << txid << " from txpool: weight: " << meta.weight << ", fee/byte: " << it->first.first);
491+
492+
auto it_prev = it;
493+
--it_prev;
494+
485495
remove_tx_from_transient_lists(it, txid, !meta.matches(relay_category::broadcasted));
486-
it--;
496+
it = it_prev;
497+
487498
changed = true;
488499
}
489500
catch (const std::exception &e)
@@ -1828,7 +1839,7 @@ namespace cryptonote
18281839
auto sorted_it = find_tx_in_sorted_container(txid);
18291840
if (sorted_it == m_txs_by_fee_and_receive_time.end())
18301841
{
1831-
MERROR("Re-adding tx " << txid << " to tx pool, but it was not found in the sorted txs container");
1842+
MDEBUG("Re-adding tx " << txid << " to tx pool, but it was not found in the sorted txs container");
18321843
}
18331844
else
18341845
{

src/cryptonote_core/tx_pool.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ namespace cryptonote
6969
{
7070
// sort by greatest first, not least
7171
if (a.first.first > b.first.first) return true;
72-
else if (a.first.first < b.first.first) return false;
73-
else if (a.first.second < b.first.second) return true;
74-
else if (a.first.second > b.first.second) return false;
75-
else if (a.second != b.second) return true;
76-
else return false;
72+
if (a.first.first < b.first.first) return false;
73+
74+
if (a.first.second < b.first.second) return true;
75+
if (a.first.second > b.first.second) return false;
76+
77+
return memcmp(a.second.data, b.second.data, sizeof(crypto::hash)) < 0;
7778
}
7879
};
7980

0 commit comments

Comments
 (0)