Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mempool pruning [release-v0.18] #9226

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/cryptonote_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,14 @@ namespace cryptonote
void tx_memory_pool::prune(size_t bytes)
{
CRITICAL_REGION_LOCAL(m_transactions_lock);

// Nothing to do if already empty
if (m_txs_by_fee_and_receive_time.empty())
return;

if (bytes == 0)
bytes = m_txpool_max_weight;

CRITICAL_REGION_LOCAL1(m_blockchain);
LockedTXN lock(m_blockchain.get_db());
bool changed = false;
Expand Down Expand Up @@ -482,8 +488,13 @@ namespace cryptonote
reduce_txpool_weight(meta.weight);
remove_transaction_keyimages(tx, txid);
MINFO("Pruned tx " << txid << " from txpool: weight: " << meta.weight << ", fee/byte: " << it->first.first);

auto it_prev = it;
--it_prev;

remove_tx_from_transient_lists(it, txid, !meta.matches(relay_category::broadcasted));
it--;
it = it_prev;

changed = true;
}
catch (const std::exception &e)
Expand Down Expand Up @@ -1828,7 +1839,7 @@ namespace cryptonote
auto sorted_it = find_tx_in_sorted_container(txid);
if (sorted_it == m_txs_by_fee_and_receive_time.end())
{
MERROR("Re-adding tx " << txid << " to tx pool, but it was not found in the sorted txs container");
MDEBUG("Re-adding tx " << txid << " to tx pool, but it was not found in the sorted txs container");
}
else
{
Expand Down
11 changes: 6 additions & 5 deletions src/cryptonote_core/tx_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ namespace cryptonote
{
// sort by greatest first, not least
if (a.first.first > b.first.first) return true;
else if (a.first.first < b.first.first) return false;
else if (a.first.second < b.first.second) return true;
else if (a.first.second > b.first.second) return false;
else if (a.second != b.second) return true;
else return false;
if (a.first.first < b.first.first) return false;

if (a.first.second < b.first.second) return true;
if (a.first.second > b.first.second) return false;

return memcmp(a.second.data, b.second.data, sizeof(crypto::hash)) < 0;
}
};

Expand Down