Skip to content

Commit 3fba3d5

Browse files
committed
[refactor] Make signals optional in mempool and chainman
This is done in preparation for the next two commits, where the CMainSignals are de-globalized. This avoids adding new constructor arguments to the ChainstateManager and CTxMemPool classes over the next two commits. This could also allow future tests that are only interested in the internal behaviour of the classes to forgo instantiating the signals.
1 parent 7143d43 commit 3fba3d5

11 files changed

+72
-39
lines changed

contrib/devtools/test_deterministic_coverage.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ NON_DETERMINISTIC_TESTS=(
1717
"blockfilter_index_tests/blockfilter_index_initial_sync" # src/checkqueue.h: In CCheckQueue::Loop(): while (queue.empty()) { ... }
1818
"coinselector_tests/knapsack_solver_test" # coinselector_tests.cpp: if (equal_sets(setCoinsRet, setCoinsRet2))
1919
"fs_tests/fsbridge_fstream" # deterministic test failure?
20-
"miner_tests/CreateNewBlock_validity" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
20+
"miner_tests/CreateNewBlock_validity" # validation.cpp: if (signals.CallbacksPending() > 10)
2121
"scheduler_tests/manythreads" # scheduler.cpp: CScheduler::serviceQueue()
2222
"scheduler_tests/singlethreadedscheduler_ordered" # scheduler.cpp: CScheduler::serviceQueue()
23-
"txvalidationcache_tests/checkinputs_test" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
24-
"txvalidationcache_tests/tx_mempool_block_doublespend" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
25-
"txindex_tests/txindex_initial_sync" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
26-
"txvalidation_tests/tx_mempool_reject_coinbase" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
27-
"validation_block_tests/processnewblock_signals_ordering" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
28-
"wallet_tests/coin_mark_dirty_immature_credit" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
29-
"wallet_tests/dummy_input_size_test" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
30-
"wallet_tests/importmulti_rescan" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
31-
"wallet_tests/importwallet_rescan" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
32-
"wallet_tests/ListCoins" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
33-
"wallet_tests/scan_for_wallet_transactions" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
34-
"wallet_tests/wallet_disableprivkeys" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
23+
"txvalidationcache_tests/checkinputs_test" # validation.cpp: if (signals.CallbacksPending() > 10)
24+
"txvalidationcache_tests/tx_mempool_block_doublespend" # validation.cpp: if (signals.CallbacksPending() > 10)
25+
"txindex_tests/txindex_initial_sync" # validation.cpp: if (signals.CallbacksPending() > 10)
26+
"txvalidation_tests/tx_mempool_reject_coinbase" # validation.cpp: if (signals.CallbacksPending() > 10)
27+
"validation_block_tests/processnewblock_signals_ordering" # validation.cpp: if (signals.CallbacksPending() > 10)
28+
"wallet_tests/coin_mark_dirty_immature_credit" # validation.cpp: if (signals.CallbacksPending() > 10)
29+
"wallet_tests/dummy_input_size_test" # validation.cpp: if (signals.CallbacksPending() > 10)
30+
"wallet_tests/importmulti_rescan" # validation.cpp: if (signals.CallbacksPending() > 10)
31+
"wallet_tests/importwallet_rescan" # validation.cpp: if (signals.CallbacksPending() > 10)
32+
"wallet_tests/ListCoins" # validation.cpp: if (signals.CallbacksPending() > 10)
33+
"wallet_tests/scan_for_wallet_transactions" # validation.cpp: if (signals.CallbacksPending() > 10)
34+
"wallet_tests/wallet_disableprivkeys" # validation.cpp: if (signals.CallbacksPending() > 10)
3535
)
3636

3737
TEST_BITCOIN_BINARY="src/test/test_bitcoin"

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ int main(int argc, char* argv[])
118118
.chainparams = *chainparams,
119119
.datadir = abs_datadir,
120120
.notifications = *notifications,
121+
.signals = &GetMainSignals(),
121122
};
122123
const node::BlockManager::Options blockman_opts{
123124
.chainparams = chainman_opts.chainparams,

src/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14491449
.chainparams = chainparams,
14501450
.datadir = args.GetDataDirNet(),
14511451
.notifications = *node.notifications,
1452+
.signals = &GetMainSignals(),
14521453
};
14531454
Assert(ApplyArgsManOptions(args, chainman_opts)); // no error can happen, already checked in AppInitParameterInteraction
14541455

@@ -1478,6 +1479,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14781479

14791480
CTxMemPool::Options mempool_opts{
14801481
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0,
1482+
.signals = &GetMainSignals(),
14811483
};
14821484
auto result{ApplyArgsManOptions(args, chainparams, mempool_opts)};
14831485
if (!result) {

src/kernel/chainstatemanager_opts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <optional>
1919

2020
class CChainParams;
21+
class CMainSignals;
2122

2223
static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true};
2324
static constexpr auto DEFAULT_MAX_TIP_AGE{24h};
@@ -44,6 +45,7 @@ struct ChainstateManagerOpts {
4445
DBOptions coins_db{};
4546
CoinsViewOptions coins_view{};
4647
Notifications& notifications;
48+
CMainSignals* signals{nullptr};
4749
//! Number of script check worker threads. Zero means no parallel verification.
4850
int worker_threads_num{0};
4951
};

src/kernel/mempool_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <cstdint>
1414
#include <optional>
1515

16+
class CMainSignals;
17+
1618
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
1719
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
1820
/** Default for -maxmempool when blocksonly is set */
@@ -56,6 +58,8 @@ struct MemPoolOptions {
5658
bool full_rbf{DEFAULT_MEMPOOL_FULL_RBF};
5759
bool persist_v1_dat{DEFAULT_PERSIST_V1_DAT};
5860
MemPoolLimits limits{};
61+
62+
CMainSignals* signals{nullptr};
5963
};
6064
} // namespace kernel
6165

src/test/util/setup_common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
185185
.datadir = m_args.GetDataDirNet(),
186186
.check_block_index = true,
187187
.notifications = *m_node.notifications,
188+
.signals = &GetMainSignals(),
188189
.worker_threads_num = 2,
189190
};
190191
const BlockManager::Options blockman_opts{

src/test/util/txmempool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <util/time.h>
1414
#include <util/translation.h>
1515
#include <validation.h>
16+
#include <validationinterface.h>
1617

1718
using node::NodeContext;
1819

@@ -22,6 +23,7 @@ CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node)
2223
// Default to always checking mempool regardless of
2324
// chainparams.DefaultConsistencyChecks for tests
2425
.check_ratio = 1,
26+
.signals = &GetMainSignals(),
2527
};
2628
const auto result{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)};
2729
Assert(result);

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ struct SnapshotTestSetup : TestChain100Setup {
383383
.chainparams = ::Params(),
384384
.datadir = chainman.m_options.datadir,
385385
.notifications = *m_node.notifications,
386+
.signals = &GetMainSignals(),
386387
};
387388
const BlockManager::Options blockman_opts{
388389
.chainparams = chainman_opts.chainparams,

src/txmempool.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ CTxMemPool::CTxMemPool(const Options& opts)
406406
m_require_standard{opts.require_standard},
407407
m_full_rbf{opts.full_rbf},
408408
m_persist_v1_dat{opts.persist_v1_dat},
409-
m_limits{opts.limits}
409+
m_limits{opts.limits},
410+
m_signals{opts.signals}
410411
{
411412
}
412413

@@ -487,12 +488,12 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
487488
// even if not directly reported below.
488489
uint64_t mempool_sequence = GetAndIncrementSequence();
489490

490-
if (reason != MemPoolRemovalReason::BLOCK) {
491+
if (reason != MemPoolRemovalReason::BLOCK && m_signals) {
491492
// Notify clients that a transaction has been removed from the mempool
492493
// for any reason except being included in a block. Clients interested
493494
// in transactions included in blocks can subscribe to the BlockConnected
494495
// notification.
495-
GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
496+
m_signals->TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
496497
}
497498
TRACE5(mempool, removed,
498499
it->GetTx().GetHash().data(),
@@ -643,7 +644,9 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
643644
removeConflicts(*tx);
644645
ClearPrioritisation(tx->GetHash());
645646
}
646-
GetMainSignals().MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);
647+
if (m_signals) {
648+
m_signals->MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);
649+
}
647650
lastRollingFeeUpdate = GetTime();
648651
blockSinceLastRollingFeeBump = true;
649652
}

src/txmempool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <vector>
4141

4242
class CChain;
43+
class CMainSignals;
4344

4445
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
4546
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
@@ -447,6 +448,8 @@ class CTxMemPool
447448

448449
const Limits m_limits;
449450

451+
CMainSignals* const m_signals;
452+
450453
/** Create a new CTxMemPool.
451454
* Sanity checks will be off by default for performance, because otherwise
452455
* accepting transactions becomes O(N^2) where N is the number of transactions

0 commit comments

Comments
 (0)