Skip to content

Commit

Permalink
refactor: remove llmq::CQuorumManager global, move to LLMQContext
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed May 29, 2024
1 parent 5b86df6 commit d7c35d0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
node.llmq_ctx = std::make_unique<LLMQContext>(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman,
*node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, /* unit_tests = */ false, /* wipe = */ fReset || fReindexChainState);
// Enable CMNHFManager::{Process, Undo}Block
node.mnhf_manager->ConnectManagers(node.llmq_ctx->qman);
node.mnhf_manager->ConnectManagers(node.llmq_ctx->qman.get());
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
node.llmq_ctx->Start();

Expand Down
19 changes: 6 additions & 13 deletions src/llmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,20 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis
dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()},
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainstate, dmnman, evo_db, peerman)},
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)},
qman{[&]() -> llmq::CQuorumManager* const {
assert(llmq::quorumManager == nullptr);
llmq::quorumManager = std::make_unique<llmq::CQuorumManager>(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman);
return llmq::quorumManager.get();
}()},
sigman{std::make_unique<llmq::CSigningManager>(connman, mn_activeman, *llmq::quorumManager, peerman, unit_tests, wipe)},
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *llmq::quorumManager, sporkman, peerman)},
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainstate, connman, dmnman, *qdkgsman, evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman)},
sigman{std::make_unique<llmq::CSigningManager>(connman, mn_activeman, *qman, peerman, unit_tests, wipe)},
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *qman, sporkman, peerman)},
clhandler{[&]() -> llmq::CChainLocksHandler* const {
assert(llmq::chainLocksHandler == nullptr);
llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *llmq::quorumManager, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode);
llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode);
return llmq::chainLocksHandler.get();
}()},
isman{[&]() -> llmq::CInstantSendManager* const {
assert(llmq::quorumInstantSendManager == nullptr);
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);
llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(*llmq::chainLocksHandler, chainstate, connman, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, peerman, is_masternode, unit_tests, wipe);
return llmq::quorumInstantSendManager.get();
}()},
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *llmq::quorumManager, sporkman, peerman)}
ehfSignalsHandler{std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *qman, sporkman, peerman)}
{
// NOTE: we use this only to wipe the old db, do NOT use it for anything else
// TODO: remove it in some future version
Expand All @@ -54,7 +50,6 @@ LLMQContext::~LLMQContext() {
// LLMQContext doesn't own these objects, but still need to care of them for consistency:
llmq::quorumInstantSendManager.reset();
llmq::chainLocksHandler.reset();
llmq::quorumManager.reset();
}

void LLMQContext::Interrupt() {
Expand All @@ -66,7 +61,6 @@ void LLMQContext::Interrupt() {
}

void LLMQContext::Start() {
assert(qman == llmq::quorumManager.get());
assert(clhandler == llmq::chainLocksHandler.get());
assert(isman == llmq::quorumInstantSendManager.get());

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

void LLMQContext::Stop() {
assert(qman == llmq::quorumManager.get());
assert(clhandler == llmq::chainLocksHandler.get());
assert(isman == llmq::quorumInstantSendManager.get());

Expand Down
4 changes: 2 additions & 2 deletions src/llmq/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct LLMQContext {
*
* Please note, that members here should not be re-ordered, because initialization
* some of them requires other member initialized.
* For example, constructor `quorumManager` requires `bls_worker`.
* For example, constructor `qman` requires `bls_worker`.
*
* Some objects are still global variables and their de-globalization is not trivial
* at this point. LLMQContext keeps just a pointer to them and doesn't own these objects,
Expand All @@ -64,7 +64,7 @@ struct LLMQContext {
const std::unique_ptr<llmq::CDKGDebugManager> dkg_debugman;
const std::unique_ptr<llmq::CQuorumBlockProcessor> quorum_block_processor;
const std::unique_ptr<llmq::CDKGSessionManager> qdkgsman;
llmq::CQuorumManager* const qman;
const std::unique_ptr<llmq::CQuorumManager> qman;
const std::unique_ptr<llmq::CSigningManager> sigman;
const std::unique_ptr<llmq::CSigSharesManager> shareman;
llmq::CChainLocksHandler* const clhandler;
Expand Down
2 changes: 0 additions & 2 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace llmq
static const std::string DB_QUORUM_SK_SHARE = "q_Qsk";
static const std::string DB_QUORUM_QUORUM_VVEC = "q_Qqvvec";

std::unique_ptr<CQuorumManager> quorumManager;

RecursiveMutex cs_data_requests;
static std::unordered_map<CQuorumDataRequestKey, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests GUARDED_BY(cs_data_requests);

Expand Down
2 changes: 0 additions & 2 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ class CQuorumManager
void StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex) const;
};

extern std::unique_ptr<CQuorumManager> quorumManager;

// when selecting a quorum for signing and verification, we use CQuorumManager::SelectQuorum with this offset as
// starting height for scanning. This is because otherwise the resulting signatures would not be verifiable by nodes
// which are not 100% at the chain tip.
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
#endif // ENABLE_WALLET
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
/* mn_activeman = */ nullptr, *node.mn_sync, node.peerman, /* unit_tests = */ true, /* wipe = */ false);
Assert(node.mnhf_manager)->ConnectManagers(node.llmq_ctx->qman);
Assert(node.mnhf_manager)->ConnectManagers(node.llmq_ctx->qman.get());
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor),
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
}
Expand Down

0 comments on commit d7c35d0

Please sign in to comment.