From 95935668022ebd9a034b6289eb70ba837af3ca93 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 20:32:11 +0700 Subject: [PATCH] refactor: move pQuorumBaseBlockIndex from Init() to constructor in CDKGSession --- src/llmq/dkgsession.cpp | 3 +-- src/llmq/dkgsession.h | 9 +++++---- src/llmq/dkgsessionhandler.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index da21ea977e..fe7ae64411 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -68,9 +68,8 @@ CDKGMember::CDKGMember(const CDeterministicMNCPtr& _dmn, size_t _idx) : } -bool CDKGSession::Init(gsl::not_null _pQuorumBaseBlockIndex, Span mns, const uint256& _myProTxHash, int _quorumIndex) +bool CDKGSession::Init(Span mns, const uint256& _myProTxHash, int _quorumIndex) { - m_quorum_base_block_index = _pQuorumBaseBlockIndex; quorumIndex = _quorumIndex; members.resize(mns.size()); memberIds.resize(members.size()); diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index 3f18fc892b..61e8467374 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -288,7 +288,7 @@ private: const CActiveMasternodeManager* const m_mn_activeman; const CSporkManager& m_sporkman; - const CBlockIndex* m_quorum_base_block_index{nullptr}; + const CBlockIndex* const m_quorum_base_block_index; int quorumIndex{0}; private: @@ -326,16 +326,17 @@ private: std::set validCommitments GUARDED_BY(invCs); public: - CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CConnman& _connman, + CDKGSession(const CBlockIndex* pQuorumBaseBlockIndex, const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CConnman& _connman, CDeterministicMNManager& dmnman, CDKGSessionManager& _dkgManager, CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman) : params(_params), blsWorker(_blsWorker), cache(_blsWorker), connman(_connman), m_dmnman(dmnman), dkgManager(_dkgManager), - dkgDebugManager(_dkgDebugManager), m_mn_metaman(mn_metaman), m_mn_activeman(mn_activeman), m_sporkman(sporkman) + dkgDebugManager(_dkgDebugManager), m_mn_metaman(mn_metaman), m_mn_activeman(mn_activeman), m_sporkman(sporkman), + m_quorum_base_block_index{pQuorumBaseBlockIndex} {} // TODO: remove Init completely - bool Init(gsl::not_null pQuorumBaseBlockIndex, Span mns, const uint256& _myProTxHash, int _quorumIndex); + bool Init(Span mns, const uint256& _myProTxHash, int _quorumIndex); [[nodiscard]] std::optional GetMyMemberIndex() const { return myIdx; } diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 6a5f85493b..1895a2b3cb 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -41,7 +41,7 @@ CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chai m_peerman(peerman), params(_params), quorumIndex(_quorumIndex), - curSession(std::make_unique(_params, _blsWorker, _connman, dmnman, _dkgManager, _dkgDebugManager, m_mn_metaman, m_mn_activeman, sporkman)), + curSession(std::make_unique(nullptr, _params, _blsWorker, _connman, dmnman, _dkgManager, _dkgDebugManager, m_mn_metaman, m_mn_activeman, sporkman)), pendingContributions((size_t)_params.size * 2, MSG_QUORUM_CONTRIB), // we allow size*2 messages as we need to make sure we see bad behavior (double messages) pendingComplaints((size_t)_params.size * 2, MSG_QUORUM_COMPLAINT), pendingJustifications((size_t)_params.size * 2, MSG_QUORUM_JUSTIFICATION), @@ -194,10 +194,10 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) return false; } - curSession = std::make_unique(params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); - auto mns = utils::GetAllQuorumMembers(params.type, m_dmnman, pQuorumBaseBlockIndex); - if (!curSession->Init(pQuorumBaseBlockIndex, mns, m_mn_activeman->GetProTxHash(), quorumIndex)) { + curSession = std::make_unique(pQuorumBaseBlockIndex, params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); + + if (!curSession->Init(mns, m_mn_activeman->GetProTxHash(), quorumIndex)) { LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size()); return false; }