Skip to content

Commit c76d3f2

Browse files
committed
refactor: consolidate Dash-specific chainstate params with DashParams
1 parent 9a13ac0 commit c76d3f2

File tree

9 files changed

+72
-76
lines changed

9 files changed

+72
-76
lines changed

src/init.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
20052005
node.mnhf_manager,
20062006
node.llmq_ctx,
20072007
Assert(node.mempool.get()),
2008-
args.GetDataDirNet(),
20092008
fPruneMode,
20102009
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
20112010
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
@@ -2017,19 +2016,25 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
20172016
cache_sizes.coins,
20182017
/*block_tree_db_in_memory=*/false,
20192018
/*coins_db_in_memory=*/false,
2020-
/*dash_dbs_in_memory=*/false,
2021-
/*bls_threads=*/[&args]() -> int8_t {
2022-
int8_t threads = args.GetIntArg("-parbls", llmq::DEFAULT_BLSCHECK_THREADS);
2023-
if (threads <= 0) {
2024-
// -parbls=0 means autodetect (number of cores - 1 validator threads)
2025-
// -parbls=-n means "leave n cores free" (number of cores - n - 1 validator threads)
2026-
threads += GetNumCores();
2027-
}
2028-
// Subtract 1 because the main thread counts towards the par threads
2029-
return std::clamp<int8_t>(threads - 1, 0, llmq::MAX_BLSCHECK_THREADS);
2030-
}(),
2031-
llmq::DEFAULT_WORKER_COUNT,
2032-
args.GetIntArg("-maxrecsigsage", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE),
2019+
llmq::DashParams{
2020+
.bls_threads = [&args]() -> int8_t {
2021+
int8_t threads = args.GetIntArg("-parbls", llmq::DEFAULT_BLSCHECK_THREADS);
2022+
if (threads <= 0) {
2023+
// -parbls=0 means autodetect (number of cores - 1 validator threads)
2024+
// -parbls=-n means "leave n cores free" (number of cores - n - 1 validator threads)
2025+
threads += GetNumCores();
2026+
}
2027+
// Subtract 1 because the main thread counts towards the par threads
2028+
return std::clamp<int8_t>(threads - 1, 0, llmq::MAX_BLSCHECK_THREADS);
2029+
}(),
2030+
.worker_count = llmq::DEFAULT_WORKER_COUNT,
2031+
.max_recsigs_age = args.GetIntArg("-maxrecsigsage", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE),
2032+
.db_params = util::DbWrapperParams{
2033+
.path = args.GetDataDirNet(),
2034+
.memory = false,
2035+
.wipe = fReset || fReindexChainState,
2036+
},
2037+
},
20332038
/*shutdown_requested=*/ShutdownRequested,
20342039
/*coins_error_cb=*/[]() {
20352040
uiInterface.ThreadSafeMessageBox(

src/llmq/context.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,27 @@
88
#include <chainlock/chainlock.h>
99
#include <instantsend/instantsend.h>
1010
#include <llmq/blockprocessor.h>
11+
#include <llmq/options.h>
1112
#include <llmq/quorumsman.h>
1213
#include <llmq/signing.h>
1314
#include <llmq/snapshot.h>
1415
#include <validation.h>
1516

1617
LLMQContext::LLMQContext(CDeterministicMNManager& dmnman, CEvoDB& evo_db, CSporkManager& sporkman, CTxMemPool& mempool,
17-
const ChainstateManager& chainman, const CMasternodeSync& mn_sync,
18-
const util::DbWrapperParams& db_params, int8_t bls_threads, int8_t worker_count,
19-
int64_t max_recsigs_age) :
18+
const ChainstateManager& chainman, const CMasternodeSync& mn_sync, const llmq::DashParams& params) :
2019
bls_worker{std::make_shared<CBLSWorker>()},
2120
qsnapman{std::make_unique<llmq::CQuorumSnapshotManager>(evo_db)},
2221
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db,
23-
*qsnapman, bls_threads)},
22+
*qsnapman, params.bls_threads)},
2423
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, dmnman, evo_db, *quorum_block_processor, *qsnapman,
25-
chainman, db_params)},
26-
sigman{std::make_unique<llmq::CSigningManager>(*qman, db_params, max_recsigs_age)},
24+
chainman, params.db_params)},
25+
sigman{std::make_unique<llmq::CSigningManager>(*qman, params.db_params, params.max_recsigs_age)},
2726
clhandler{std::make_unique<llmq::CChainLocksHandler>(chainman.ActiveChainstate(), *qman, sporkman, mempool, mn_sync)},
2827
isman{std::make_unique<llmq::CInstantSendManager>(*clhandler, chainman.ActiveChainstate(), *sigman, sporkman,
29-
mempool, mn_sync, db_params)}
28+
mempool, mn_sync, params.db_params)}
3029
{
3130
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
32-
bls_worker->Start(worker_count);
31+
bls_worker->Start(params.worker_count);
3332
}
3433

3534
LLMQContext::~LLMQContext()

src/llmq/context.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@ class CQuorumBlockProcessor;
2626
class CQuorumManager;
2727
class CQuorumSnapshotManager;
2828
class CSigningManager;
29+
struct DashParams;
2930
} // namespace llmq
30-
namespace util {
31-
struct DbWrapperParams;
32-
} // namespace util
3331

3432
struct LLMQContext {
3533
public:
3634
LLMQContext() = delete;
3735
LLMQContext(const LLMQContext&) = delete;
3836
LLMQContext& operator=(const LLMQContext&) = delete;
3937
explicit LLMQContext(CDeterministicMNManager& dmnman, CEvoDB& evo_db, CSporkManager& sporkman, CTxMemPool& mempool,
40-
const ChainstateManager& chainman, const CMasternodeSync& mn_sync,
41-
const util::DbWrapperParams& db_params, int8_t bls_threads, int8_t worker_count,
42-
int64_t max_recsigs_age);
38+
const ChainstateManager& chainman, const CMasternodeSync& mn_sync, const llmq::DashParams& params);
4339
~LLMQContext();
4440

4541
void Start();

src/llmq/options.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BITCOIN_LLMQ_OPTIONS_H
66
#define BITCOIN_LLMQ_OPTIONS_H
77

8+
#include <dbwrapper.h>
9+
810
#include <gsl/pointers.h>
911

1012
#include <map>
@@ -28,6 +30,13 @@ enum class QvvecSyncMode : int8_t {
2830
OnlyIfTypeMember = 1,
2931
};
3032

33+
struct DashParams {
34+
int8_t bls_threads;
35+
int8_t worker_count;
36+
int64_t max_recsigs_age;
37+
util::DbWrapperParams db_params;
38+
};
39+
3140
/** -llmq-data-recovery default */
3241
static constexpr bool DEFAULT_ENABLE_QUORUM_DATA_RECOVERY{true};
3342
/** -watchquorums default, if true, we will connect to all new quorums and watch their communication */

src/node/chainstate.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
4747
std::unique_ptr<CMNHFManager>& mnhf_manager,
4848
std::unique_ptr<LLMQContext>& llmq_ctx,
4949
CTxMemPool* mempool,
50-
const fs::path& data_dir,
5150
bool fPruneMode,
5251
bool is_addrindex_enabled,
5352
bool is_spentindex_enabled,
@@ -59,10 +58,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
5958
int64_t nCoinCacheUsage,
6059
bool block_tree_db_in_memory,
6160
bool coins_db_in_memory,
62-
bool dash_dbs_in_memory,
63-
int8_t bls_threads,
64-
int8_t worker_count,
65-
int64_t max_recsigs_age,
61+
const llmq::DashParams& dash_params,
6662
std::function<bool()> shutdown_requested,
6763
std::function<void()> coins_error_cb)
6864
{
@@ -73,7 +69,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
7369
LOCK(cs_main);
7470

7571
evodb.reset();
76-
evodb = std::make_unique<CEvoDB>(util::DbWrapperParams{.path = data_dir, .memory = dash_dbs_in_memory, .wipe = fReset || fReindexChainState});
72+
evodb = std::make_unique<CEvoDB>(dash_params.db_params);
7773

7874
mnhf_manager.reset();
7975
mnhf_manager = std::make_unique<CMNHFManager>(*evodb, chainman);
@@ -89,9 +85,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
8985
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
9086

9187
DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, chain_helper, cpoolman,
92-
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, data_dir, dash_dbs_in_memory,
93-
/*llmq_dbs_wipe=*/fReset || fReindexChainState, bls_threads, worker_count,
94-
max_recsigs_age, consensus_params);
88+
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, dash_params, consensus_params);
9589

9690
if (fReset) {
9791
pblocktree->WriteReindexing(true);
@@ -223,12 +217,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
223217
std::unique_ptr<CMNHFManager>& mnhf_manager,
224218
std::unique_ptr<LLMQContext>& llmq_ctx,
225219
CTxMemPool* mempool,
226-
const fs::path& data_dir,
227-
bool llmq_dbs_in_memory,
228-
bool llmq_dbs_wipe,
229-
int8_t bls_threads,
230-
int8_t worker_count,
231-
int64_t max_recsigs_age,
220+
const llmq::DashParams& dash_params,
232221
const Consensus::Params& consensus_params)
233222
{
234223
// Same logic as pblocktree
@@ -242,9 +231,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
242231
llmq_ctx->Stop();
243232
}
244233
llmq_ctx.reset();
245-
llmq_ctx = std::make_unique<LLMQContext>(*dmnman, *evodb, sporkman, *mempool, chainman, mn_sync,
246-
util::DbWrapperParams{.path = data_dir, .memory = llmq_dbs_in_memory, .wipe = llmq_dbs_wipe},
247-
bls_threads, worker_count, max_recsigs_age);
234+
llmq_ctx = std::make_unique<LLMQContext>(*dmnman, *evodb, sporkman, *mempool, chainman, mn_sync, dash_params);
248235
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman.get());
249236
// Enable CMNHFManager::{Process, Undo}Block
250237
mnhf_manager->ConnectManagers(llmq_ctx->qman.get());

src/node/chainstate.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ class CMNHFManager;
2424
class CSporkManager;
2525
class CTxMemPool;
2626
struct LLMQContext;
27-
2827
namespace Consensus {
2928
struct Params;
3029
} // namespace Consensus
31-
namespace fs {
32-
class path;
33-
} // namespace fs
30+
namespace llmq {
31+
struct DashParams;
32+
} // namespace util
3433

3534
namespace node {
3635
enum class ChainstateLoadingError {
@@ -91,7 +90,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
9190
std::unique_ptr<CMNHFManager>& mnhf_manager,
9291
std::unique_ptr<LLMQContext>& llmq_ctx,
9392
CTxMemPool* mempool,
94-
const fs::path& data_dir,
9593
bool fPruneMode,
9694
bool is_addrindex_enabled,
9795
bool is_spentindex_enabled,
@@ -103,10 +101,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
103101
int64_t nCoinCacheUsage,
104102
bool block_tree_db_in_memory,
105103
bool coins_db_in_memory,
106-
bool dash_dbs_in_memory,
107-
int8_t bls_threads,
108-
int8_t worker_count,
109-
int64_t max_recsigs_age,
104+
const llmq::DashParams& dash_params,
110105
std::function<bool()> shutdown_requested = nullptr,
111106
std::function<void()> coins_error_cb = nullptr);
112107

@@ -123,12 +118,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
123118
std::unique_ptr<CMNHFManager>& mnhf_manager,
124119
std::unique_ptr<LLMQContext>& llmq_ctx,
125120
CTxMemPool* mempool,
126-
const fs::path& data_dir,
127-
bool llmq_dbs_in_memory,
128-
bool llmq_dbs_wipe,
129-
int8_t bls_threads,
130-
int8_t worker_count,
131-
int64_t max_recsigs_age,
121+
const llmq::DashParams& dash_params,
132122
const Consensus::Params& consensus_params);
133123

134124
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,

src/test/util/setup_common.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,21 @@ std::unique_ptr<PeerManager> MakePeerManager(CConnman& connman,
139139

140140
void DashChainstateSetup(ChainstateManager& chainman,
141141
NodeContext& node,
142-
bool llmq_dbs_in_memory,
143-
bool llmq_dbs_wipe,
144142
const Consensus::Params& consensus_params)
145143
{
146144
DashChainstateSetup(chainman, *Assert(node.govman.get()), *Assert(node.mn_metaman.get()), *Assert(node.mn_sync.get()),
147145
*Assert(node.sporkman.get()), node.chain_helper, node.cpoolman, node.dmnman, node.evodb, node.mnhf_manager,
148-
node.llmq_ctx, Assert(node.mempool.get()), node.args->GetDataDirNet(), llmq_dbs_in_memory, llmq_dbs_wipe,
149-
llmq::DEFAULT_BLSCHECK_THREADS, llmq::DEFAULT_WORKER_COUNT, llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE,
150-
consensus_params);
146+
node.llmq_ctx, Assert(node.mempool.get()),
147+
llmq::DashParams{
148+
.bls_threads = llmq::DEFAULT_BLSCHECK_THREADS,
149+
.worker_count = llmq::DEFAULT_WORKER_COUNT,
150+
.max_recsigs_age = llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE,
151+
.db_params = util::DbWrapperParams{
152+
.path = node.args->GetDataDirNet(),
153+
.memory = true,
154+
.wipe = false,
155+
},
156+
}, consensus_params);
151157
}
152158

153159
void DashChainstateSetupClose(NodeContext& node)
@@ -318,6 +324,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
318324
// instead of unit tests, but for now we need these here.
319325
RegisterAllCoreRPCCommands(tableRPC);
320326

327+
const bool fReindexChainState{m_args.GetBoolArg("-reindex-chainstate", false)};
321328
auto maybe_load_error = LoadChainstate(fReindex.load(),
322329
*Assert(m_node.chainman.get()),
323330
*Assert(m_node.govman.get()),
@@ -331,22 +338,27 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
331338
m_node.mnhf_manager,
332339
m_node.llmq_ctx,
333340
Assert(m_node.mempool.get()),
334-
Assert(m_node.args)->GetDataDirNet(),
335341
fPruneMode,
336342
m_args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
337343
m_args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
338344
m_args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
339345
chainparams.GetConsensus(),
340-
m_args.GetBoolArg("-reindex-chainstate", false),
346+
fReindexChainState,
341347
m_cache_sizes.block_tree_db,
342348
m_cache_sizes.coins_db,
343349
m_cache_sizes.coins,
344350
/*block_tree_db_in_memory=*/true,
345351
/*coins_db_in_memory=*/true,
346-
/*dash_dbs_in_memory=*/true,
347-
llmq::DEFAULT_BLSCHECK_THREADS,
348-
llmq::DEFAULT_WORKER_COUNT,
349-
llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE);
352+
llmq::DashParams{
353+
.bls_threads = llmq::DEFAULT_BLSCHECK_THREADS,
354+
.worker_count = llmq::DEFAULT_WORKER_COUNT,
355+
.max_recsigs_age = llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE,
356+
.db_params = util::DbWrapperParams{
357+
.path = Assert(m_node.args)->GetDataDirNet(),
358+
.memory = true,
359+
.wipe = fReindex.load() || fReindexChainState,
360+
},
361+
});
350362
assert(!maybe_load_error.has_value());
351363

352364
auto maybe_verify_error = VerifyLoadedChainstate(

src/test/util/setup_common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ std::unique_ptr<PeerManager> MakePeerManager(CConnman& connman,
9393
bool ignore_incoming_txs);
9494
void DashChainstateSetup(ChainstateManager& chainman,
9595
node::NodeContext& node,
96-
bool llmq_dbs_in_memory,
97-
bool llmq_dbs_wipe,
9896
const Consensus::Params& consensus_params);
9997
void DashChainstateSetupClose(node::NodeContext& node);
10098

0 commit comments

Comments
 (0)