Skip to content

Commit d7c35d0

Browse files
committed
refactor: remove llmq::CQuorumManager global, move to LLMQContext
1 parent 5b86df6 commit d7c35d0

File tree

6 files changed

+10
-21
lines changed

6 files changed

+10
-21
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
19751975
node.llmq_ctx = std::make_unique<LLMQContext>(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman,
19761976
*node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, /* unit_tests = */ false, /* wipe = */ fReset || fReindexChainState);
19771977
// Enable CMNHFManager::{Process, Undo}Block
1978-
node.mnhf_manager->ConnectManagers(node.llmq_ctx->qman);
1978+
node.mnhf_manager->ConnectManagers(node.llmq_ctx->qman.get());
19791979
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
19801980
node.llmq_ctx->Start();
19811981

src/llmq/context.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,20 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis
2626
dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()},
2727
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainstate, dmnman, evo_db, peerman)},
2828
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainstate, connman, dmnman, *dkg_debugman, mn_metaman, *quorum_block_processor, mn_activeman, sporkman, peerman, unit_tests, wipe)},
29-
qman{[&]() -> llmq::CQuorumManager* const {
30-
assert(llmq::quorumManager == nullptr);
31-
llmq::quorumManager = std::make_unique<llmq::CQuorumManager>(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman);
32-
return llmq::quorumManager.get();
33-
}()},
34-
sigman{std::make_unique<llmq::CSigningManager>(connman, mn_activeman, *llmq::quorumManager, peerman, unit_tests, wipe)},
35-
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *llmq::quorumManager, sporkman, peerman)},
29+
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman)},
30+
sigman{std::make_unique<llmq::CSigningManager>(connman, mn_activeman, *qman, peerman, unit_tests, wipe)},
31+
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *qman, sporkman, peerman)},
3632
clhandler{[&]() -> llmq::CChainLocksHandler* const {
3733
assert(llmq::chainLocksHandler == nullptr);
38-
llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode);
34+
llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode);
3935
return llmq::chainLocksHandler.get();
4036
}()},
4137
isman{[&]() -> llmq::CInstantSendManager* const {
4238
assert(llmq::quorumInstantSendManager == nullptr);
43-
llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(*llmq::chainLocksHandler, chainstate, connman, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode, unit_tests, wipe);
39+
llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(*llmq::chainLocksHandler, chainstate, connman, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode, unit_tests, wipe);
4440
return llmq::quorumInstantSendManager.get();
4541
}()},
46-
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *llmq::quorumManager, sporkman, peerman)}
42+
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *qman, sporkman, peerman)}
4743
{
4844
// NOTE: we use this only to wipe the old db, do NOT use it for anything else
4945
// TODO: remove it in some future version
@@ -54,7 +50,6 @@ LLMQContext::~LLMQContext() {
5450
// LLMQContext doesn't own these objects, but still need to care of them for consistency:
5551
llmq::quorumInstantSendManager.reset();
5652
llmq::chainLocksHandler.reset();
57-
llmq::quorumManager.reset();
5853
}
5954

6055
void LLMQContext::Interrupt() {
@@ -66,7 +61,6 @@ void LLMQContext::Interrupt() {
6661
}
6762

6863
void LLMQContext::Start() {
69-
assert(qman == llmq::quorumManager.get());
7064
assert(clhandler == llmq::chainLocksHandler.get());
7165
assert(isman == llmq::quorumInstantSendManager.get());
7266

@@ -84,7 +78,6 @@ void LLMQContext::Start() {
8478
}
8579

8680
void LLMQContext::Stop() {
87-
assert(qman == llmq::quorumManager.get());
8881
assert(clhandler == llmq::chainLocksHandler.get());
8982
assert(isman == llmq::quorumInstantSendManager.get());
9083

src/llmq/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct LLMQContext {
5454
*
5555
* Please note, that members here should not be re-ordered, because initialization
5656
* some of them requires other member initialized.
57-
* For example, constructor `quorumManager` requires `bls_worker`.
57+
* For example, constructor `qman` requires `bls_worker`.
5858
*
5959
* Some objects are still global variables and their de-globalization is not trivial
6060
* at this point. LLMQContext keeps just a pointer to them and doesn't own these objects,
@@ -64,7 +64,7 @@ struct LLMQContext {
6464
const std::unique_ptr<llmq::CDKGDebugManager> dkg_debugman;
6565
const std::unique_ptr<llmq::CQuorumBlockProcessor> quorum_block_processor;
6666
const std::unique_ptr<llmq::CDKGSessionManager> qdkgsman;
67-
llmq::CQuorumManager* const qman;
67+
const std::unique_ptr<llmq::CQuorumManager> qman;
6868
const std::unique_ptr<llmq::CSigningManager> sigman;
6969
const std::unique_ptr<llmq::CSigSharesManager> shareman;
7070
llmq::CChainLocksHandler* const clhandler;

src/llmq/quorums.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ namespace llmq
3333
static const std::string DB_QUORUM_SK_SHARE = "q_Qsk";
3434
static const std::string DB_QUORUM_QUORUM_VVEC = "q_Qqvvec";
3535

36-
std::unique_ptr<CQuorumManager> quorumManager;
37-
3836
RecursiveMutex cs_data_requests;
3937
static std::unordered_map<CQuorumDataRequestKey, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests GUARDED_BY(cs_data_requests);
4038

src/llmq/quorums.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ class CQuorumManager
289289
void StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const;
290290
};
291291

292-
extern std::unique_ptr<CQuorumManager> quorumManager;
293-
294292
// when selecting a quorum for signing and verification, we use CQuorumManager::SelectQuorum with this offset as
295293
// starting height for scanning. This is because otherwise the resulting signatures would not be verifiable by nodes
296294
// which are not 100% at the chain tip.

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
119119
#endif // ENABLE_WALLET
120120
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
121121
/* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false);
122-
Assert(node.mnhf_manager)->ConnectManagers(node.llmq_ctx->qman);
122+
Assert(node.mnhf_manager)->ConnectManagers(node.llmq_ctx->qman.get());
123123
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
124124
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
125125
}

0 commit comments

Comments
 (0)