From d26d4ab0bc73df4cb1c4a2acd00c5aae73317347 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 13:39:30 +0700 Subject: [PATCH] refactor: remove dependency of dkgsessionmgr on dkgsession --- src/llmq/dkgsessionhandler.cpp | 46 +++++++++++++++++++++++++ src/llmq/dkgsessionhandler.h | 11 +++++- src/llmq/dkgsessionmgr.cpp | 21 +++-------- test/lint/lint-circular-dependencies.sh | 1 - 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 7b4b8c4ab2..0df07a1653 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -52,6 +52,8 @@ CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chai } } +CDKGSessionHandler::~CDKGSessionHandler() = default; + void CDKGPendingMessages::PushPendingMessage(NodeId from, PeerManager* peerman, CDataStream& vRecv) { // if peer is not -1 we should always pass valid peerman @@ -589,4 +591,48 @@ void CDKGSessionHandler::PhaseHandlerThread() } } +bool CDKGSessionHandler::GetContribution(const uint256& hash, CDKGContribution& ret) const +{ + LOCK(curSession->invCs); + auto it = curSession->contributions.find(hash); + if (it != curSession->contributions.end()) { + ret = it->second; + return true; + } + return false; +} + +bool CDKGSessionHandler::GetComplaint(const uint256& hash, CDKGComplaint& ret) const +{ + LOCK(curSession->invCs); + auto it = curSession->complaints.find(hash); + if (it != curSession->complaints.end()) { + ret = it->second; + return true; + } + return false; +} + +bool CDKGSessionHandler::GetJustification(const uint256& hash, CDKGJustification& ret) const +{ + LOCK(curSession->invCs); + auto it = curSession->justifications.find(hash); + if (it != curSession->justifications.end()) { + ret = it->second; + return true; + } + return false; +} + +bool CDKGSessionHandler::GetPrematureCommitment(const uint256& hash, CDKGPrematureCommitment& ret) const +{ + LOCK(curSession->invCs); + auto it = curSession->prematureCommitments.find(hash); + if (it != curSession->prematureCommitments.end() && curSession->validCommitments.count(hash)) { + ret = it->second; + return true; + } + return false; +} + } // namespace llmq diff --git a/src/llmq/dkgsessionhandler.h b/src/llmq/dkgsessionhandler.h index 3ffedf0d6f..9abd982efe 100644 --- a/src/llmq/dkgsessionhandler.h +++ b/src/llmq/dkgsessionhandler.h @@ -25,6 +25,10 @@ class PeerManager; namespace llmq { +class CDKGContribution; +class CDKGComplaint; +class CDKGJustification; +class CDKGPrematureCommitment; class CDKGDebugManager; class CDKGSession; class CDKGSessionManager; @@ -153,7 +157,7 @@ public: CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, const std::unique_ptr& peerman, const Consensus::LLMQParams& _params, int _quorumIndex); - ~CDKGSessionHandler() = default; + ~CDKGSessionHandler(); void UpdatedBlockTip(const CBlockIndex *pindexNew); void ProcessMessage(const CNode& pfrom, gsl::not_null peerman, const std::string& msg_type, CDataStream& vRecv); @@ -161,6 +165,11 @@ public: void StartThread(); void StopThread(); + bool GetContribution(const uint256& hash, CDKGContribution& ret) const; + bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const; + bool GetJustification(const uint256& hash, CDKGJustification& ret) const; + bool GetPrematureCommitment(const uint256& hash, CDKGPrematureCommitment& ret) const; + private: bool InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex); diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index d614e69b59..1743f0376c 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include #include #include @@ -300,10 +299,7 @@ bool CDKGSessionManager::GetContribution(const uint256& hash, CDKGContribution& if (dkgType.phase < QuorumPhase::Initialized || dkgType.phase > QuorumPhase::Contribute) { continue; } - LOCK(dkgType.curSession->invCs); - auto it = dkgType.curSession->contributions.find(hash); - if (it != dkgType.curSession->contributions.end()) { - ret = it->second; + if (dkgType.GetContribution(hash, ret)) { return true; } } @@ -321,10 +317,7 @@ bool CDKGSessionManager::GetComplaint(const uint256& hash, CDKGComplaint& ret) c if (dkgType.phase < QuorumPhase::Contribute || dkgType.phase > QuorumPhase::Complain) { continue; } - LOCK(dkgType.curSession->invCs); - auto it = dkgType.curSession->complaints.find(hash); - if (it != dkgType.curSession->complaints.end()) { - ret = it->second; + if (dkgType.GetComplaint(hash, ret)) { return true; } } @@ -342,10 +335,7 @@ bool CDKGSessionManager::GetJustification(const uint256& hash, CDKGJustification if (dkgType.phase < QuorumPhase::Complain || dkgType.phase > QuorumPhase::Justify) { continue; } - LOCK(dkgType.curSession->invCs); - auto it = dkgType.curSession->justifications.find(hash); - if (it != dkgType.curSession->justifications.end()) { - ret = it->second; + if (dkgType.GetJustification(hash, ret)) { return true; } } @@ -363,10 +353,7 @@ bool CDKGSessionManager::GetPrematureCommitment(const uint256& hash, CDKGPrematu if (dkgType.phase < QuorumPhase::Justify || dkgType.phase > QuorumPhase::Commit) { continue; } - LOCK(dkgType.curSession->invCs); - auto it = dkgType.curSession->prematureCommitments.find(hash); - if (it != dkgType.curSession->prematureCommitments.end() && dkgType.curSession->validCommitments.count(hash)) { - ret = it->second; + if (dkgType.GetPrematureCommitment(hash, ret)) { return true; } } diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index 603f79baf9..f2f6a4365c 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -62,7 +62,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "banman -> bloom -> evo/assetlocktx -> llmq/quorums -> net -> banman" "banman -> bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> banman" - "llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsession" "llmq/chainlocks -> validation -> llmq/chainlocks" "coinjoin/coinjoin -> llmq/chainlocks -> net -> coinjoin/coinjoin" "evo/deterministicmns -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns -> evo/deterministicmns"