Line data Source code
1 : // Copyright (c) 2018-2021 The Dash Core developers 2 : // Copyright (c) 2022 The PIVX Core developers 3 : // Distributed under the MIT/X11 software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #include "llmq/quorums_init.h" 7 : 8 : #include "bls/bls_worker.h" 9 : #include "dbwrapper.h" 10 : #include "llmq/quorums.h" 11 : #include "llmq/quorums_blockprocessor.h" 12 : #include "llmq/quorums_debug.h" 13 : #include "llmq/quorums_dkgsessionmgr.h" 14 : #include "quorums_chainlocks.h" 15 : #include "quorums_signing.h" 16 : #include "quorums_signing_shares.h" 17 : 18 : namespace llmq 19 : { 20 : 21 : CBLSWorker* blsWorker; 22 : CDBWrapper* llmqDb; 23 : 24 413 : void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests) 25 : { 26 1121 : llmqDb = new CDBWrapper(unitTests ? "" : (GetDataDir() / "llmq"), 1 << 20, unitTests, false, CLIENT_VERSION | ADDRV2_FORMAT); 27 413 : blsWorker = new CBLSWorker(); 28 : 29 413 : quorumDKGDebugManager.reset(new CDKGDebugManager()); 30 413 : quorumBlockProcessor.reset(new CQuorumBlockProcessor(evoDb)); 31 413 : quorumDKGSessionManager.reset(new CDKGSessionManager(*llmqDb, *blsWorker)); 32 413 : quorumManager.reset(new CQuorumManager(evoDb, *blsWorker, *quorumDKGSessionManager)); 33 413 : quorumSigSharesManager.reset(new CSigSharesManager()); 34 413 : quorumSigningManager.reset(new CSigningManager(*llmqDb, unitTests)); 35 413 : chainLocksHandler.reset(new CChainLocksHandler(scheduler)); 36 413 : } 37 : 38 433 : void DestroyLLMQSystem() 39 : { 40 433 : chainLocksHandler.reset(); 41 433 : quorumSigningManager.reset(); 42 433 : quorumSigSharesManager.reset(); 43 433 : quorumDKGSessionManager.reset(); 44 433 : quorumBlockProcessor.reset(); 45 433 : quorumDKGDebugManager.reset(); 46 433 : quorumManager.reset(); 47 433 : delete blsWorker; 48 433 : blsWorker = nullptr; 49 433 : delete llmqDb; 50 433 : llmqDb = nullptr; 51 433 : } 52 : 53 285 : void StartLLMQSystem() 54 : { 55 285 : if (blsWorker) { 56 285 : blsWorker->Start(); 57 : } 58 285 : if (quorumDKGSessionManager) { 59 285 : quorumDKGSessionManager->StartThreads(); 60 : } 61 285 : if (quorumSigSharesManager) { 62 285 : quorumSigSharesManager->RegisterAsRecoveredSigsListener(); 63 285 : quorumSigSharesManager->StartWorkerThread(); 64 : } 65 285 : if (chainLocksHandler) { 66 285 : chainLocksHandler->Start(); 67 : } 68 285 : } 69 : 70 315 : void StopLLMQSystem() 71 : { 72 315 : if (chainLocksHandler) { 73 295 : chainLocksHandler->Stop(); 74 : } 75 315 : if (quorumSigSharesManager) { 76 295 : quorumSigSharesManager->StopWorkerThread(); 77 295 : quorumSigSharesManager->UnregisterAsRecoveredSigsListener(); 78 : } 79 315 : if (quorumDKGSessionManager) { 80 295 : quorumDKGSessionManager->StopThreads(); 81 : } 82 315 : if (blsWorker) { 83 295 : blsWorker->Stop(); 84 : } 85 315 : } 86 : 87 433 : void InterruptLLMQSystem() 88 : { 89 433 : if (quorumSigSharesManager) { 90 413 : quorumSigSharesManager->Interrupt(); 91 : } 92 433 : } 93 : 94 : } // namespace llmq