-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: improved initialization of members of LLMQContext and related changes #5150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,108 +20,85 @@ | |
| #include <masternode/sync.h> | ||
|
|
||
| LLMQContext::LLMQContext(CEvoDB& evo_db, CTxMemPool& mempool, CConnman& connman, CSporkManager& sporkman, | ||
| const std::unique_ptr<PeerManager>& peerman, bool unit_tests, bool wipe) { | ||
| Create(evo_db, mempool, connman, sporkman, peerman, unit_tests, wipe); | ||
|
|
||
| /* Context aliases to globals used by the LLMQ system */ | ||
| quorum_block_processor = llmq::quorumBlockProcessor.get(); | ||
| qman = llmq::quorumManager.get(); | ||
| clhandler = llmq::chainLocksHandler.get(); | ||
| isman = llmq::quorumInstantSendManager.get(); | ||
| } | ||
|
|
||
| LLMQContext::~LLMQContext() { | ||
| isman = nullptr; | ||
| clhandler = nullptr; | ||
| qman = nullptr; | ||
| quorum_block_processor = nullptr; | ||
|
|
||
| Destroy(); | ||
| } | ||
|
|
||
| void LLMQContext::Create(CEvoDB& evo_db, CTxMemPool& mempool, CConnman& connman, CSporkManager& sporkman, | ||
| const std::unique_ptr<PeerManager>& peerman, bool unit_tests, bool wipe) { | ||
| bls_worker = std::make_shared<CBLSWorker>(); | ||
|
|
||
| dkg_debugman = std::make_unique<llmq::CDKGDebugManager>(); | ||
| llmq::quorumBlockProcessor = std::make_unique<llmq::CQuorumBlockProcessor>(evo_db, connman, peerman); | ||
| qdkgsman = std::make_unique<llmq::CDKGSessionManager>(connman, *bls_worker, *dkg_debugman, *llmq::quorumBlockProcessor, sporkman, peerman, unit_tests, wipe); | ||
| llmq::quorumManager = std::make_unique<llmq::CQuorumManager>(evo_db, connman, *bls_worker, *llmq::quorumBlockProcessor, *qdkgsman, ::masternodeSync, peerman); | ||
| sigman = std::make_unique<llmq::CSigningManager>(connman, *llmq::quorumManager, peerman, unit_tests, wipe); | ||
| shareman = std::make_unique<llmq::CSigSharesManager>(connman, *llmq::quorumManager, *sigman, peerman); | ||
| llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(mempool, connman, sporkman, *sigman, *shareman, *llmq::quorumManager, *::masternodeSync, peerman); | ||
| llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(mempool, connman, sporkman, *llmq::quorumManager, *sigman, *shareman, *llmq::chainLocksHandler, *::masternodeSync, peerman, unit_tests, wipe); | ||
|
|
||
| const std::unique_ptr<PeerManager>& peerman, bool unit_tests, bool wipe) : | ||
| bls_worker{std::make_shared<CBLSWorker>()}, | ||
| dkg_debugman{std::make_unique<llmq::CDKGDebugManager>()}, | ||
| quorum_block_processor{[&]() -> llmq::CQuorumBlockProcessor* const { | ||
| assert(llmq::quorumBlockProcessor == nullptr); | ||
| llmq::quorumBlockProcessor = std::make_unique<llmq::CQuorumBlockProcessor>(evo_db, connman, peerman); | ||
| return llmq::quorumBlockProcessor.get(); | ||
| }()}, | ||
| qdkgsman{std::make_unique<llmq::CDKGSessionManager>(connman, *bls_worker, *dkg_debugman, *quorum_block_processor, sporkman, peerman, unit_tests, wipe)}, | ||
| qman{[&]() -> llmq::CQuorumManager* const { | ||
| assert(llmq::quorumManager == nullptr); | ||
| llmq::quorumManager = std::make_unique<llmq::CQuorumManager>(evo_db, connman, *bls_worker, *quorum_block_processor, *qdkgsman, ::masternodeSync, peerman); | ||
| return llmq::quorumManager.get(); | ||
| }()}, | ||
| sigman{std::make_unique<llmq::CSigningManager>(connman, *llmq::quorumManager, peerman, unit_tests, wipe)}, | ||
| shareman{std::make_unique<llmq::CSigSharesManager>(connman, *llmq::quorumManager, *sigman, peerman)}, | ||
| clhandler{[&]() -> llmq::CChainLocksHandler* const { | ||
| assert(llmq::chainLocksHandler == nullptr); | ||
| llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(mempool, connman, sporkman, *sigman, *shareman, *llmq::quorumManager, *::masternodeSync, peerman); | ||
| return llmq::chainLocksHandler.get(); | ||
| }()}, | ||
| isman{[&]() -> llmq::CInstantSendManager* const { | ||
| assert(llmq::quorumInstantSendManager == nullptr); | ||
| llmq::quorumInstantSendManager = std::make_unique<llmq::CInstantSendManager>(mempool, connman, sporkman, *llmq::quorumManager, *sigman, *shareman, *llmq::chainLocksHandler, *::masternodeSync, peerman, unit_tests, wipe); | ||
| return llmq::quorumInstantSendManager.get(); | ||
| }()} | ||
| { | ||
| // NOTE: we use this only to wipe the old db, do NOT use it for anything else | ||
| // TODO: remove it in some future version | ||
| auto llmqDbTmp = std::make_unique<CDBWrapper>(unit_tests ? "" : (GetDataDir() / "llmq"), 1 << 20, unit_tests, true); | ||
| } | ||
|
|
||
| void LLMQContext::Destroy() { | ||
| LLMQContext::~LLMQContext() { | ||
| // LLMQContext doesn't own these objects, but still need to care of them for consistancy: | ||
| llmq::quorumInstantSendManager.reset(); | ||
| llmq::chainLocksHandler.reset(); | ||
| shareman.reset(); | ||
| sigman.reset(); | ||
| llmq::quorumManager.reset(); | ||
| qdkgsman.reset(); | ||
| llmq::quorumBlockProcessor.reset(); | ||
| dkg_debugman.reset(); | ||
| bls_worker.reset(); | ||
| { | ||
| LOCK(llmq::cs_llmq_vbc); | ||
| llmq::llmq_versionbitscache.Clear(); | ||
| } | ||
| } | ||
|
|
||
| void LLMQContext::Interrupt() { | ||
| if (shareman != nullptr) { | ||
| shareman->InterruptWorkerThread(); | ||
| } | ||
| if (llmq::quorumInstantSendManager != nullptr) { | ||
| llmq::quorumInstantSendManager->InterruptWorkerThread(); | ||
| } | ||
| shareman->InterruptWorkerThread(); | ||
|
|
||
| assert(isman == llmq::quorumInstantSendManager.get()); | ||
| llmq::quorumInstantSendManager->InterruptWorkerThread(); | ||
| } | ||
|
|
||
| void LLMQContext::Start() { | ||
| if (bls_worker != nullptr) { | ||
| bls_worker->Start(); | ||
| } | ||
| if (qdkgsman != nullptr) { | ||
| qdkgsman->StartThreads(); | ||
| } | ||
| if (llmq::quorumManager != nullptr) { | ||
| llmq::quorumManager->Start(); | ||
| } | ||
| if (shareman != nullptr) { | ||
| shareman->RegisterAsRecoveredSigsListener(); | ||
| shareman->StartWorkerThread(); | ||
| } | ||
| if (llmq::chainLocksHandler != nullptr) { | ||
| llmq::chainLocksHandler->Start(); | ||
| } | ||
| if (llmq::quorumInstantSendManager != nullptr) { | ||
| llmq::quorumInstantSendManager->Start(); | ||
| } | ||
| assert(quorum_block_processor == llmq::quorumBlockProcessor.get()); | ||
| assert(qman == llmq::quorumManager.get()); | ||
| assert(clhandler == llmq::chainLocksHandler.get()); | ||
| assert(isman == llmq::quorumInstantSendManager.get()); | ||
|
Comment on lines
+75
to
+78
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these could still be null which could cause crashes below.. Are we sure these are always non-null? It seems yes as they are assigned in the constructor.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, if |
||
|
|
||
| bls_worker->Start(); | ||
| qdkgsman->StartThreads(); | ||
| qman->Start(); | ||
| shareman->RegisterAsRecoveredSigsListener(); | ||
| shareman->StartWorkerThread(); | ||
|
|
||
| llmq::chainLocksHandler->Start(); | ||
| llmq::quorumInstantSendManager->Start(); | ||
| } | ||
|
|
||
| void LLMQContext::Stop() { | ||
| if (llmq::quorumInstantSendManager != nullptr) { | ||
| llmq::quorumInstantSendManager->Stop(); | ||
| } | ||
| if (llmq::chainLocksHandler != nullptr) { | ||
| llmq::chainLocksHandler->Stop(); | ||
| } | ||
| if (shareman != nullptr) { | ||
| shareman->StopWorkerThread(); | ||
| shareman->UnregisterAsRecoveredSigsListener(); | ||
| } | ||
| if (llmq::quorumManager != nullptr) { | ||
| llmq::quorumManager->Stop(); | ||
| } | ||
| if (qdkgsman != nullptr) { | ||
| qdkgsman->StopThreads(); | ||
| } | ||
| if (bls_worker != nullptr) { | ||
| bls_worker->Stop(); | ||
| } | ||
| assert(quorum_block_processor == llmq::quorumBlockProcessor.get()); | ||
| assert(qman == llmq::quorumManager.get()); | ||
| assert(clhandler == llmq::chainLocksHandler.get()); | ||
| assert(isman == llmq::quorumInstantSendManager.get()); | ||
|
|
||
| llmq::quorumInstantSendManager->Stop(); | ||
| llmq::chainLocksHandler->Stop(); | ||
|
|
||
| shareman->StopWorkerThread(); | ||
| shareman->UnregisterAsRecoveredSigsListener(); | ||
| qman->Stop(); | ||
| qdkgsman->StopThreads(); | ||
| bls_worker->Stop(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UdjinM6, can we drop this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was added ~2 years ago in v18.0 so, yeah, I guess it's safe to drop it in v20