Merge pull request #9225

a01d7cc Fixed mempool pruning (SChernykh)
This commit is contained in:
luigi1111 2024-03-08 20:27:34 -05:00
commit 1bec71279e
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
2 changed files with 19 additions and 7 deletions

View File

@ -435,8 +435,14 @@ namespace cryptonote
void tx_memory_pool::prune(size_t bytes) void tx_memory_pool::prune(size_t bytes)
{ {
CRITICAL_REGION_LOCAL(m_transactions_lock); 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) if (bytes == 0)
bytes = m_txpool_max_weight; bytes = m_txpool_max_weight;
CRITICAL_REGION_LOCAL1(m_blockchain); CRITICAL_REGION_LOCAL1(m_blockchain);
LockedTXN lock(m_blockchain.get_db()); LockedTXN lock(m_blockchain.get_db());
bool changed = false; bool changed = false;
@ -481,8 +487,13 @@ namespace cryptonote
reduce_txpool_weight(meta.weight); reduce_txpool_weight(meta.weight);
remove_transaction_keyimages(tx, txid); remove_transaction_keyimages(tx, txid);
MINFO("Pruned tx " << txid << " from txpool: weight: " << meta.weight << ", fee/byte: " << it->first.first); 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)); remove_tx_from_transient_lists(it, txid, !meta.matches(relay_category::broadcasted));
it--; it = it_prev;
changed = true; changed = true;
} }
catch (const std::exception &e) catch (const std::exception &e)
@ -1827,7 +1838,7 @@ namespace cryptonote
auto sorted_it = find_tx_in_sorted_container(txid); auto sorted_it = find_tx_in_sorted_container(txid);
if (sorted_it == m_txs_by_fee_and_receive_time.end()) 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 else
{ {

View File

@ -69,11 +69,12 @@ namespace cryptonote
{ {
// sort by greatest first, not least // sort by greatest first, not least
if (a.first.first > b.first.first) return true; if (a.first.first > b.first.first) return true;
else if (a.first.first < b.first.first) return false; 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; if (a.first.second < b.first.second) return true;
else if (a.second != b.second) return true; if (a.first.second > b.first.second) return false;
else return false;
return memcmp(a.second.data, b.second.data, sizeof(crypto::hash)) < 0;
} }
}; };