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 0 : 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 0 : llmq::QuorumRole{qman},
37 0 : m_bls_worker{bls_worker},
38 0 : m_quorums_watch{quorums_watch},
39 0 : nodeman{std::make_unique<CActiveMasternodeManager>(connman, dmnman, operator_sk)},
40 0 : dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
41 0 : qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params)},
42 0 : shareman{std::make_unique<llmq::CSigSharesManager>(connman, chainman, sigman, *nodeman, qman, sporkman)},
43 0 : gov_signer{std::make_unique<GovernanceSigner>(connman, dmnman, govman, superblocks, *nodeman, chainman, mn_sync)},
44 0 : ehf_sighandler{std::make_unique<llmq::CEHFSignalsHandler>(chainman, sigman, *shareman, qman)},
45 0 : cl_signer{std::make_unique<chainlock::ChainLockSigner>(chainman.ActiveChainstate(), chainlocks, clhandler, isman,
46 0 : qman, sigman, *shareman, mn_sync)},
47 0 : is_signer{std::make_unique<instantsend::InstantSendSigner>(chainman.ActiveChainstate(), chainlocks, isman, sigman,
48 0 : *shareman, qman, sporkman, mempool, mn_sync)}
49 0 : {
50 0 : }
51 :
52 0 : ActiveContext::~ActiveContext() = default;
53 :
54 0 : void ActiveContext::Start()
55 : {
56 0 : cl_signer->Start();
57 0 : cl_signer->RegisterRecoveryInterface();
58 0 : is_signer->RegisterRecoveryInterface();
59 0 : shareman->RegisterRecoveryInterface();
60 :
61 0 : RegisterValidationInterface(cl_signer.get());
62 0 : }
63 :
64 0 : void ActiveContext::Stop()
65 : {
66 0 : UnregisterValidationInterface(cl_signer.get());
67 :
68 0 : shareman->UnregisterRecoveryInterface();
69 0 : is_signer->UnregisterRecoveryInterface();
70 0 : cl_signer->UnregisterRecoveryInterface();
71 0 : cl_signer->Stop();
72 0 : }
73 :
74 0 : CCoinJoinServer& ActiveContext::GetCJServer() const
75 : {
76 0 : return *Assert(m_cj_server);
77 : }
78 :
79 0 : void ActiveContext::SetCJServer(gsl::not_null<CCoinJoinServer*> cj_server)
80 : {
81 : // Prohibit double initialization
82 0 : assert(m_cj_server == nullptr);
83 0 : m_cj_server = cj_server;
84 0 : }
85 :
86 0 : void ActiveContext::InitializeCurrentBlockTip(const CBlockIndex* tip, bool ibd)
87 : {
88 0 : UpdatedBlockTip(tip, nullptr, ibd);
89 0 : }
90 :
91 0 : void ActiveContext::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload)
92 : {
93 0 : if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones
94 0 : return;
95 :
96 0 : nodeman->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
97 0 : ehf_sighandler->UpdatedBlockTip(pindexNew);
98 0 : gov_signer->UpdatedBlockTip(pindexNew);
99 0 : qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
100 0 : }
101 :
102 0 : bool ActiveContext::IsMasternode() const
103 : {
104 : // We are only initialized if masternode mode is enabled
105 0 : return true;
106 : }
107 :
108 0 : bool ActiveContext::IsWatching() const
109 : {
110 : // Watch-only mode can co-exist with masternode mode
111 0 : return m_quorums_watch;
112 : }
113 :
114 0 : uint256 ActiveContext::GetProTxHash() const
115 : {
116 0 : return nodeman->GetProTxHash();
117 : }
118 :
119 0 : bool ActiveContext::SetQuorumSecretKeyShare(llmq::CQuorum& quorum, Span<CBLSSecretKey> skContributions) const
120 : {
121 0 : return quorum.SetSecretKeyShare(m_bls_worker.AggregateSecretKeys(skContributions), nodeman->GetProTxHash());
122 0 : }
|