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 475 : void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests) 25 : { 26 1307 : llmqDb = new CDBWrapper(unitTests ? "" : (GetDataDir() / "llmq"), 1 << 20, unitTests, false, CLIENT_VERSION | ADDRV2_FORMAT); 27 475 : blsWorker = new CBLSWorker(); 28 : 29 475 : quorumDKGDebugManager.reset(new CDKGDebugManager()); 30 475 : quorumBlockProcessor.reset(new CQuorumBlockProcessor(evoDb)); 31 475 : quorumDKGSessionManager.reset(new CDKGSessionManager(*llmqDb, *blsWorker)); 32 475 : quorumManager.reset(new CQuorumManager(evoDb, *blsWorker, *quorumDKGSessionManager)); 33 475 : quorumSigSharesManager.reset(new CSigSharesManager()); 34 475 : quorumSigningManager.reset(new CSigningManager(*llmqDb, unitTests)); 35 475 : chainLocksHandler.reset(new CChainLocksHandler(scheduler)); 36 475 : } 37 : 38 496 : void DestroyLLMQSystem() 39 : { 40 496 : chainLocksHandler.reset(); 41 496 : quorumSigningManager.reset(); 42 496 : quorumSigSharesManager.reset(); 43 496 : quorumDKGSessionManager.reset(); 44 496 : quorumBlockProcessor.reset(); 45 496 : quorumDKGDebugManager.reset(); 46 496 : quorumManager.reset(); 47 496 : delete blsWorker; 48 496 : blsWorker = nullptr; 49 496 : delete llmqDb; 50 496 : llmqDb = nullptr; 51 496 : } 52 : 53 347 : void StartLLMQSystem() 54 : { 55 347 : if (blsWorker) { 56 347 : blsWorker->Start(); 57 : } 58 347 : if (quorumDKGSessionManager) { 59 347 : quorumDKGSessionManager->StartThreads(); 60 : } 61 347 : if (quorumSigSharesManager) { 62 347 : quorumSigSharesManager->RegisterAsRecoveredSigsListener(); 63 347 : quorumSigSharesManager->StartWorkerThread(); 64 : } 65 347 : if (chainLocksHandler) { 66 347 : chainLocksHandler->Start(); 67 : } 68 347 : } 69 : 70 378 : void StopLLMQSystem() 71 : { 72 378 : if (chainLocksHandler) { 73 357 : chainLocksHandler->Stop(); 74 : } 75 378 : if (quorumSigSharesManager) { 76 357 : quorumSigSharesManager->StopWorkerThread(); 77 357 : quorumSigSharesManager->UnregisterAsRecoveredSigsListener(); 78 : } 79 378 : if (quorumDKGSessionManager) { 80 357 : quorumDKGSessionManager->StopThreads(); 81 : } 82 378 : if (blsWorker) { 83 357 : blsWorker->Stop(); 84 : } 85 378 : } 86 : 87 496 : void InterruptLLMQSystem() 88 : { 89 496 : if (quorumSigSharesManager) { 90 475 : quorumSigSharesManager->Interrupt(); 91 : } 92 496 : } 93 : 94 : } // namespace llmq