v30.3-roots.1 · Commit 51: [PATCH 51/68] mempool: synchronize dynamic dust fee publication
src/test/mempool_tests.cpp
Before: src/test/mempool_tests.cpp · After: src/test/mempool_tests.cpp
File metadata
index 1d9ef4949e40927c5d126cd8b3e3a01299a31c9d..313c9725b3c6027a5428db4d2da91790fdc2cb4e 100644
Download original patch · Release notes
Diff rows 1–58 of 58. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/test/mempool_tests.cpp
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
|
| 5 |
#include <common/system.h>
|
| 6 |
#include <policy/policy.h>
|
|
|
|
| 7 |
#include <test/util/txmempool.h>
|
| 8 |
#include <txmempool.h>
|
| 9 |
#include <util/time.h>
|
|
@@ -13,12 +14,51 @@
|
|
| 13 |
#include <boost/test/unit_test.hpp>
|
| 14 |
#include <array>
|
| 15 |
#include <limits>
|
|
|
|
| 16 |
#include <vector>
|
| 17 |
|
| 18 |
BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup)
|
| 19 |
|
| 20 |
static constexpr auto REMOVAL_REASON_DUMMY = MemPoolRemovalReason::REPLACED;
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
BOOST_AUTO_TEST_CASE(MempoolExtraWeightBoundary)
|
| 23 |
{
|
| 24 |
CMutableTransaction tx;
|
|
|
|
| 4 |
|
| 5 |
#include <common/system.h>
|
| 6 |
#include <policy/policy.h>
|
| 7 |
+
#include <scheduler.h>
|
| 8 |
#include <test/util/txmempool.h>
|
| 9 |
#include <txmempool.h>
|
| 10 |
#include <util/time.h>
|
|
|
|
| 14 |
#include <boost/test/unit_test.hpp>
|
| 15 |
#include <array>
|
| 16 |
#include <limits>
|
| 17 |
+
#include <thread>
|
| 18 |
#include <vector>
|
| 19 |
|
| 20 |
BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup)
|
| 21 |
|
| 22 |
static constexpr auto REMOVAL_REASON_DUMMY = MemPoolRemovalReason::REPLACED;
|
| 23 |
|
| 24 |
+
BOOST_AUTO_TEST_CASE(DynamicDustFeePublication)
|
| 25 |
+
{
|
| 26 |
+
CScheduler scheduler;
|
| 27 |
+
auto opts{MemPoolOptionsForTest(m_node)};
|
| 28 |
+
opts.scheduler = &scheduler;
|
| 29 |
+
opts.dust_relay_target = 1;
|
| 30 |
+
opts.dust_relay_multiplier = 1000;
|
| 31 |
+
opts.dust_relay_feerate = CFeeRate{3000};
|
| 32 |
+
bilingual_str error;
|
| 33 |
+
CTxMemPool pool{opts, error};
|
| 34 |
+
BOOST_REQUIRE(error.empty());
|
| 35 |
+
CMutableTransaction tx;
|
| 36 |
+
tx.vin.resize(1);
|
| 37 |
+
tx.vout.emplace_back(COIN, CScript{} << std::vector<unsigned char>(1100, 0));
|
| 38 |
+
const auto txref{MakeTransactionRef(tx)};
|
| 39 |
+
const CAmount fee{100000};
|
| 40 |
+
AddToMempool(pool, TestMemPoolEntryHelper{}.Fee(fee).FromTx(txref));
|
| 41 |
+
const auto vsize{WITH_LOCK(pool.cs, return pool.GetEntry(txref->GetHash())->GetTxSize())};
|
| 42 |
+
const CFeeRate expected{fee * 1000 / vsize};
|
| 43 |
+
BOOST_CHECK(pool.GetDustRelayFee() == opts.dust_relay_feerate);
|
| 44 |
+
pool.UpdateDynamicDustFeerate();
|
| 45 |
+
BOOST_CHECK_EQUAL(pool.GetDustRelayFee().GetFeePerK(), expected.GetFeePerK());
|
| 46 |
+
|
| 47 |
+
// Exercise the scheduler's writer concurrently with the public snapshot
|
| 48 |
+
// reader. The guarded state also exposes unsynchronized access to Clang's
|
| 49 |
+
// thread-safety analysis and race-detecting builds.
|
| 50 |
+
std::thread updater{[&] {
|
| 51 |
+
for (int i{0}; i < 1000; ++i) pool.UpdateDynamicDustFeerate();
|
| 52 |
+
}};
|
| 53 |
+
bool consistent{true};
|
| 54 |
+
for (int i{0}; i < 1000; ++i) consistent &= pool.GetDustRelayFee() == expected;
|
| 55 |
+
updater.join();
|
| 56 |
+
BOOST_CHECK(consistent);
|
| 57 |
+
WITH_LOCK(pool.cs, pool.removeRecursive(*txref, MemPoolRemovalReason::EXPIRY));
|
| 58 |
+
pool.UpdateDynamicDustFeerate();
|
| 59 |
+
BOOST_CHECK(pool.GetDustRelayFee() == opts.dust_relay_feerate);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
BOOST_AUTO_TEST_CASE(MempoolExtraWeightBoundary)
|
| 63 |
{
|
| 64 |
CMutableTransaction tx;
|