aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSChernykh <15806605+SChernykh@users.noreply.github.com>2024-03-08 20:58:21 +0100
committerSChernykh <15806605+SChernykh@users.noreply.github.com>2024-03-08 21:04:16 +0100
commita01d7ccbfd2defec5fa5b0ca2de3fcd46f524748 (patch)
tree8422591949032ba9489cf98cd94c53d8f14fc9fb /src
parentMerge pull request #9222 (diff)
downloadmonero-a01d7ccbfd2defec5fa5b0ca2de3fcd46f524748.tar.xz
Fixed mempool pruning
- Fixed undefined behavior after a call to `remove_tx_from_transient_lists` (it used an invalid iterator) - Fixed `txCompare` (it wasn't strictly weak ordered)
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/tx_pool.cpp15
-rw-r--r--src/cryptonote_core/tx_pool.h11
2 files changed, 19 insertions, 7 deletions
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index f70db2b74..4f0501c1d 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -435,8 +435,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;
@@ -481,8 +487,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)
@@ -1827,7 +1838,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
{
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index 3bb96d3a8..3a111ce91 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -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;
}
};