LCOV - code coverage report
Current view: top level - src/active - context.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 54 57 94.7 %
Date: 2026-06-25 07:23:43 Functions: 13 15 86.7 %

          Line data    Source code
       1             : // Copyright (c) 2025 The Dash Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <active/context.h>
       6             : 
       7             : #include <active/masternode.h>
       8             : #include <bls/bls_worker.h>
       9             : #include <chainlock/handler.h>
      10             : #include <chainlock/signing.h>
      11             : #include <evo/deterministicmns.h>
      12             : #include <governance/governance.h>
      13             : #include <governance/signing.h>
      14             : #include <governance/superblock.h>
      15             : #include <instantsend/instantsend.h>
      16             : #include <instantsend/signing.h>
      17             : #include <llmq/debug.h>
      18             : #include <llmq/dkgsessionmgr.h>
      19             : #include <llmq/ehf_signals.h>
      20             : #include <llmq/quorums.h>
      21             : #include <llmq/quorumsman.h>
      22             : #include <llmq/signing_shares.h>
      23             : #include <masternode/sync.h>
      24             : #include <util/check.h>
      25             : #include <validation.h>
      26             : #include <validationinterface.h>
      27             : 
      28        1980 : ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman, CConnman& connman,
      29             :                              CDeterministicMNManager& dmnman, CGovernanceManager& govman,
      30             :                              governance::SuperblockManager& superblocks, CSporkManager& sporkman,
      31             :                              const chainlock::Chainlocks& chainlocks, CTxMemPool& mempool,
      32             :                              chainlock::ChainlockHandler& clhandler, llmq::CInstantSendManager& isman,
      33             :                              llmq::CQuorumManager& qman, llmq::CQuorumSnapshotManager& qsnapman,
      34             :                              llmq::CSigningManager& sigman, const CMasternodeSync& mn_sync,
      35             :                              const CBLSSecretKey& operator_sk, const util::DbWrapperParams& db_params, bool quorums_watch) :
      36         660 :     llmq::QuorumRole{qman},
      37         660 :     m_bls_worker{bls_worker},
      38         660 :     m_quorums_watch{quorums_watch},
      39         660 :     nodeman{std::make_unique<CActiveMasternodeManager>(connman, dmnman, operator_sk)},
      40         660 :     dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
      41         660 :     qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params)},
      42         660 :     shareman{std::make_unique<llmq::CSigSharesManager>(connman, chainman, sigman, *nodeman, qman, sporkman)},
      43         660 :     gov_signer{std::make_unique<GovernanceSigner>(connman, dmnman, govman, superblocks, *nodeman, chainman, mn_sync)},
      44         660 :     ehf_sighandler{std::make_unique<llmq::CEHFSignalsHandler>(chainman, sigman, *shareman, qman)},
      45         660 :     cl_signer{std::make_unique<chainlock::ChainLockSigner>(chainman.ActiveChainstate(), chainlocks, clhandler, isman,
      46         660 :                                                            qman, sigman, *shareman, mn_sync)},
      47         660 :     is_signer{std::make_unique<instantsend::InstantSendSigner>(chainman.ActiveChainstate(), chainlocks, isman, sigman,
      48         660 :                                                                *shareman, qman, sporkman, mempool, mn_sync)}
      49        1980 : {
      50         660 : }
      51             : 
      52        1320 : ActiveContext::~ActiveContext() = default;
      53             : 
      54         660 : void ActiveContext::Start()
      55             : {
      56         660 :     cl_signer->Start();
      57         660 :     cl_signer->RegisterRecoveryInterface();
      58         660 :     is_signer->RegisterRecoveryInterface();
      59         660 :     shareman->RegisterRecoveryInterface();
      60             : 
      61         660 :     RegisterValidationInterface(cl_signer.get());
      62         660 : }
      63             : 
      64         660 : void ActiveContext::Stop()
      65             : {
      66         660 :     UnregisterValidationInterface(cl_signer.get());
      67             : 
      68         660 :     shareman->UnregisterRecoveryInterface();
      69         660 :     is_signer->UnregisterRecoveryInterface();
      70         660 :     cl_signer->UnregisterRecoveryInterface();
      71         660 :     cl_signer->Stop();
      72         660 : }
      73             : 
      74           0 : CCoinJoinServer& ActiveContext::GetCJServer() const
      75             : {
      76           0 :     return *Assert(m_cj_server);
      77             : }
      78             : 
      79         660 : void ActiveContext::SetCJServer(gsl::not_null<CCoinJoinServer*> cj_server)
      80             : {
      81             :     // Prohibit double initialization
      82         660 :     assert(m_cj_server == nullptr);
      83         660 :     m_cj_server = cj_server;
      84         660 : }
      85             : 
      86         660 : void ActiveContext::InitializeCurrentBlockTip(const CBlockIndex* tip, bool ibd)
      87             : {
      88         660 :     UpdatedBlockTip(tip, nullptr, ibd);
      89         660 : }
      90             : 
      91       87081 : void ActiveContext::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
      92             : {
      93       87081 :     if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
      94        5808 :         return;
      95             : 
      96       81273 :     nodeman->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
      97       81273 :     ehf_sighandler->UpdatedBlockTip(pindexNew);
      98       81273 :     gov_signer->UpdatedBlockTip(pindexNew);
      99       81273 :     qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
     100       87081 : }
     101             : 
     102      478961 : bool ActiveContext::IsMasternode() const
     103             : {
     104             :     // We are only initialized if masternode mode is enabled
     105      478961 :     return true;
     106             : }
     107             : 
     108      236324 : bool ActiveContext::IsWatching() const
     109             : {
     110             :     // Watch-only mode can co-exist with masternode mode
     111      236324 :     return m_quorums_watch;
     112             : }
     113             : 
     114      483703 : uint256 ActiveContext::GetProTxHash() const
     115             : {
     116      483703 :     return nodeman->GetProTxHash();
     117             : }
     118             : 
     119        1896 : bool ActiveContext::SetQuorumSecretKeyShare(llmq::CQuorum& quorum, Span<CBLSSecretKey> skContributions) const
     120             : {
     121        1896 :     return quorum.SetSecretKeyShare(m_bls_worker.AggregateSecretKeys(skContributions), nodeman->GetProTxHash());
     122           0 : }

Generated by: LCOV version 1.16