From 7fb62f7db60c7d793828ae45f87bc3f5c63cc989 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Thu, 10 Oct 2024 14:59:23 -0400 Subject: [PATCH] Apply mempool changeset transactions directly into the mempool Rather than individually calling addUnchecked for each transaction added in a changeset (after removing all the to-be-removed transactions), instead we can take advantage of boost::multi_index's splicing features to extract and insert entries directly from the staging multi_index into mapTx. This has the immediate advantage of saving allocation overhead for mempool entries which have already been allocated once. This also means that the memory locations of mempool entries will not change when transactions go from staging to the main mempool. Additionally, eliminate addUnchecked and require all new transactions to enter the mempool via a CTxMemPoolChangeSet. --- src/bench/mempool_ephemeral_spends.cpp | 3 +- src/bench/mempool_eviction.cpp | 3 +- src/bench/mempool_stress.cpp | 3 +- src/bench/rpc_mempool.cpp | 3 +- src/test/blockencodings_tests.cpp | 8 +- src/test/fuzz/mini_miner.cpp | 4 +- src/test/fuzz/partially_downloaded_block.cpp | 2 +- src/test/fuzz/rbf.cpp | 8 +- src/test/mempool_tests.cpp | 92 ++++++++++---------- src/test/miner_tests.cpp | 62 ++++++------- src/test/miniminer_tests.cpp | 42 ++++----- src/test/policyestimator_tests.cpp | 12 +-- src/test/rbf_tests.cpp | 60 ++++++------- src/test/txvalidation_tests.cpp | 24 ++--- src/test/util/setup_common.cpp | 18 ++-- src/test/util/txmempool.cpp | 10 +++ src/test/util/txmempool.h | 4 + src/txmempool.cpp | 76 ++++++++++------ src/txmempool.h | 41 +++++---- src/validation.cpp | 2 +- 20 files changed, 268 insertions(+), 209 deletions(-) diff --git a/src/bench/mempool_ephemeral_spends.cpp b/src/bench/mempool_ephemeral_spends.cpp index e867c61752c..f34664a736b 100644 --- a/src/bench/mempool_ephemeral_spends.cpp +++ b/src/bench/mempool_ephemeral_spends.cpp @@ -11,6 +11,7 @@ #include