From 6f7068ef425bd3dd2f7fa023cc7baff393d65c72 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 18 Sep 2024 21:05:38 +0700 Subject: [PATCH 01/11] refactor: remove exceeding evodb.h from headers --- src/evo/creditpool.cpp | 1 + src/evo/creditpool.h | 2 +- src/evo/deterministicmns.cpp | 1 + src/evo/deterministicmns.h | 3 ++- src/evo/mnhftx.cpp | 1 + src/init.cpp | 1 + src/llmq/quorums.cpp | 7 +++++++ src/llmq/quorums.h | 6 ++++-- src/llmq/snapshot.cpp | 1 + src/llmq/snapshot.h | 2 +- 10 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 876b9bfb3a..374f45792c 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index 479cc77879..9f3034cbcf 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ class BlockManager; class CBlockIndex; class BlockValidationState; +class CEvoDB; class TxValidationState; namespace Consensus { struct Params; diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 158de1ad78..9ad5253e97 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 7d035fc2eb..ac27530526 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -8,10 +8,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -30,6 +30,7 @@ class CBlock; class CBlockIndex; class CChainState; class CConnman; +class CEvoDB; class TxValidationState; extern RecursiveMutex cs_main; diff --git a/src/evo/mnhftx.cpp b/src/evo/mnhftx.cpp index 22b95062b1..d495def879 100644 --- a/src/evo/mnhftx.cpp +++ b/src/evo/mnhftx.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/init.cpp b/src/init.cpp index 18decacf04..f7a7feed72 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -90,6 +90,7 @@ #include #include +#include #include #include #include diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 6fc79b82a1..6ce748c8da 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -11,10 +11,12 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -230,6 +232,11 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, MigrateOldQuorumDB(_evoDb); } +CQuorumManager::~CQuorumManager() +{ + Stop(); +} + void CQuorumManager::Start() { int workerCount = std::thread::hardware_concurrency() / 2; diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index be377e357f..4756011e14 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -26,8 +25,11 @@ class CActiveMasternodeManager; class CBlockIndex; class CChainState; class CConnman; +class CDataStream; class CDeterministicMN; class CDeterministicMNManager; +class CDBWrapper; +class CEvoDB; class CMasternodeSync; class CNode; class CSporkManager; @@ -258,7 +260,7 @@ public: CDKGSessionManager& _dkgManager, CEvoDB& _evoDb, CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync, const CSporkManager& sporkman, bool unit_tests, bool wipe); - ~CQuorumManager() { Stop(); }; + ~CQuorumManager(); void Start(); void Stop(); diff --git a/src/llmq/snapshot.cpp b/src/llmq/snapshot.cpp index 1224eae2d7..7b349fb31d 100644 --- a/src/llmq/snapshot.cpp +++ b/src/llmq/snapshot.cpp @@ -4,6 +4,7 @@ #include +#include #include #include diff --git a/src/llmq/snapshot.h b/src/llmq/snapshot.h index b108e3f8ff..4113e255cc 100644 --- a/src/llmq/snapshot.h +++ b/src/llmq/snapshot.h @@ -5,7 +5,6 @@ #ifndef BITCOIN_LLMQ_SNAPSHOT_H #define BITCOIN_LLMQ_SNAPSHOT_H -#include #include #include #include @@ -20,6 +19,7 @@ class CBlockIndex; class CDeterministicMN; class CDeterministicMNList; +class CEvoDb; namespace llmq { class CQuorumBlockProcessor; From e77aeb321b5e3c05c0462191f48084739e5c10d6 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 13:09:48 +0700 Subject: [PATCH 02/11] refactor: removed including quorums.h from chainlocks.h --- src/evo/cbtx.cpp | 1 + src/llmq/chainlocks.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 29a9999965..80bde9d0a7 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/src/llmq/chainlocks.h b/src/llmq/chainlocks.h index f229f5b608..79f96ccb68 100644 --- a/src/llmq/chainlocks.h +++ b/src/llmq/chainlocks.h @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -36,6 +35,7 @@ namespace llmq { class CSigningManager; class CSigSharesManager; +enum class VerifyRecSigStatus; class CChainLocksHandler : public CRecoveredSigsListener { From d361b11e5b9aee282b5bde44e015d36487a662a9 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 13:10:24 +0700 Subject: [PATCH 03/11] refactor: moved including llmq/dkgsession.h from dkgsessionmgr.h to cpp file --- src/llmq/dkgsessionmgr.cpp | 3 +++ src/llmq/dkgsessionmgr.h | 8 ++++++-- src/net_processing.cpp | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index eefaeaef18..d614e69b59 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -56,6 +57,8 @@ CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chai } } +CDKGSessionManager::~CDKGSessionManager() = default; + void CDKGSessionManager::MigrateDKG() { if (!db->IsEmpty()) return; diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index 92094063a8..3affac23f6 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -6,8 +6,8 @@ #define BITCOIN_LLMQ_DKGSESSIONMGR_H #include -#include #include +#include #include #include @@ -23,6 +23,10 @@ class CDKGDebugManager; class CMasternodeMetaMan; class CSporkManager; class PeerManager; +class CDKGContribution; +class CDKGComplaint; +class CDKGJustification; +class CDKGPrematureCommitment; class UniValue; @@ -71,7 +75,7 @@ public: CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman, const std::unique_ptr& peerman, bool unitTests, bool fWipe); - ~CDKGSessionManager() = default; + ~CDKGSessionManager(); void StartThreads(); void StopThreads(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 542679c6df..43649407cc 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include From d26d4ab0bc73df4cb1c4a2acd00c5aae73317347 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 13:39:30 +0700 Subject: [PATCH 04/11] 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" From fb78b0cc94c7ea5b637b79b4c24f7fd8dc9550c9 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 15:36:35 +0700 Subject: [PATCH 05/11] refactor: remove retBan flag from ReceiveMessage --- src/llmq/dkgsession.cpp | 16 ++++------------ src/llmq/dkgsession.h | 8 ++++---- src/llmq/dkgsessionhandler.cpp | 8 +------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index b5f393d4d2..c3416df3fa 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -259,12 +259,10 @@ bool CDKGSession::PreVerifyMessage(const CDKGContribution& qc, bool& retBan) con return true; } -void CDKGSession::ReceiveMessage(const CDKGContribution& qc, bool& retBan) +void CDKGSession::ReceiveMessage(const CDKGContribution& qc) { CDKGLogger logger(*this, __func__, __LINE__); - retBan = false; - auto* member = GetMember(qc.proTxHash); cxxtimer::Timer t1(true); @@ -569,12 +567,10 @@ bool CDKGSession::PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const return true; } -void CDKGSession::ReceiveMessage(const CDKGComplaint& qc, bool& retBan) +void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) { CDKGLogger logger(*this, __func__, __LINE__); - retBan = false; - logger.Batch("received complaint from %s", qc.proTxHash.ToString()); auto* member = GetMember(qc.proTxHash); @@ -780,12 +776,10 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co return true; } -void CDKGSession::ReceiveMessage(const CDKGJustification& qj, bool& retBan) +void CDKGSession::ReceiveMessage(const CDKGJustification& qj) { CDKGLogger logger(*this, __func__, __LINE__); - retBan = false; - logger.Batch("received justification from %s", qj.proTxHash.ToString()); auto* member = GetMember(qj.proTxHash); @@ -1095,12 +1089,10 @@ bool CDKGSession::PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retB return true; } -void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc, bool& retBan) +void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc) { CDKGLogger logger(*this, __func__, __LINE__); - retBan = false; - cxxtimer::Timer t1(true); logger.Batch("received premature commitment from %s. validMembers=%d", qc.proTxHash.ToString(), qc.CountValidMembers()); diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index c16a741874..8a874f555d 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -350,7 +350,7 @@ public: void Contribute(CDKGPendingMessages& pendingMessages); void SendContributions(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGContribution& qc, bool& retBan) const; - void ReceiveMessage(const CDKGContribution& qc, bool& retBan); + void ReceiveMessage(const CDKGContribution& qc); void VerifyPendingContributions() EXCLUSIVE_LOCKS_REQUIRED(cs_pending); // Phase 2: complaint @@ -358,19 +358,19 @@ public: void VerifyConnectionAndMinProtoVersions() const; void SendComplaint(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const; - void ReceiveMessage(const CDKGComplaint& qc, bool& retBan); + void ReceiveMessage(const CDKGComplaint& qc); // Phase 3: justification void VerifyAndJustify(CDKGPendingMessages& pendingMessages); void SendJustification(CDKGPendingMessages& pendingMessages, const std::set& forMembers); bool PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const; - void ReceiveMessage(const CDKGJustification& qj, bool& retBan); + void ReceiveMessage(const CDKGJustification& qj); // Phase 4: commit void VerifyAndCommit(CDKGPendingMessages& pendingMessages); void SendCommitment(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retBan) const; - void ReceiveMessage(const CDKGPrematureCommitment& qc, bool& retBan); + void ReceiveMessage(const CDKGPrematureCommitment& qc); // Phase 5: aggregate/finalize std::vector FinalizeCommitments(); diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 0df07a1653..c68cf8758a 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -489,13 +489,7 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi if (badNodes.count(nodeId)) { continue; } - bool ban = false; - session.ReceiveMessage(*p.second, ban); - if (ban) { - LogPrint(BCLog::LLMQ_DKG, "%s -- banning node after ReceiveMessage failed, peer=%d\n", __func__, nodeId); - pendingMessages.Misbehaving(nodeId, 100); - badNodes.emplace(nodeId); - } + session.ReceiveMessage(*p.second); } return true; From c82672af94034ce894cc507be53ba79f324e0ffd Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 13:53:38 +0700 Subject: [PATCH 06/11] refactor: remove dependency of CDKGSession on PeerManager --- src/llmq/dkgsession.cpp | 96 ++++++++----------------- src/llmq/dkgsession.h | 37 ++++++---- src/llmq/dkgsessionhandler.cpp | 56 ++++++++++++--- test/lint/lint-circular-dependencies.sh | 1 - 4 files changed, 101 insertions(+), 89 deletions(-) diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index c3416df3fa..201d015714 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -33,14 +32,15 @@ namespace llmq { -class CDKGLogger : public CBatchedLogger +CDKGLogger::CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line) : + CDKGLogger(_quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->GetBlockHash(), _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember(), _func, source_line) { -public: - CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line) : - CDKGLogger(_quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->GetBlockHash(), _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember(), _func, source_line){}; - CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line) : - CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _llmqTypeName, _quorumIndex, _height, _areWeMember), __FILE__, source_line){}; -}; +} + +CDKGLogger::CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line) : + CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _llmqTypeName, _quorumIndex, _height, _areWeMember), __FILE__, source_line) +{ +} static std::array, ToUnderlying(DKGError::type::_COUNT)> simDkgErrorMap{}; @@ -259,7 +259,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGContribution& qc, bool& retBan) con return true; } -void CDKGSession::ReceiveMessage(const CDKGContribution& qc) +std::optional CDKGSession::ReceiveMessage(const CDKGContribution& qc) { CDKGLogger logger(*this, __func__, __LINE__); @@ -273,7 +273,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) if (member->contributions.size() >= 2) { // only relay up to 2 contributions, that's enough to let the other members know about his bad behavior - return; + return std::nullopt; } const uint256 hash = ::SerializeHash(qc); @@ -281,7 +281,6 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) member->contributions.emplace(hash); CInv inv(MSG_QUORUM_CONTRIB, hash); - RelayInvToParticipants(inv); dkgDebugManager.UpdateLocalMemberStatus(params.type, quorumIndex, member->idx, [&](CDKGDebugMemberStatus& status) { status.statusBits.receivedContribution = true; @@ -293,7 +292,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) // so others know about his bad behavior MarkBadMember(member->idx); logger.Batch("%s did send multiple contributions", member->dmn->proTxHash.ToString()); - return; + return inv; } receivedVvecs[member->idx] = qc.vvec; @@ -306,7 +305,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) if (!AreWeMember()) { // can't further validate - return; + return inv; } dkgManager.WriteVerifiedVvecContribution(params.type, m_quorum_base_block_index, qc.proTxHash, qc.vvec); @@ -327,7 +326,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) status.statusBits.weComplain = true; return true; }); - return; + return inv; } logger.Batch("decrypted our contribution share. time=%d", t2.count()); @@ -339,6 +338,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc) if (pendingContributionVerifications.size() >= 32) { VerifyPendingContributions(); } + return inv; } // Verifies all pending secret key contributions in one batch @@ -567,7 +567,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const return true; } -void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) +std::optional CDKGSession::ReceiveMessage(const CDKGComplaint& qc) { CDKGLogger logger(*this, __func__, __LINE__); @@ -577,7 +577,7 @@ void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) if (member->complaints.size() >= 2) { // only relay up to 2 complaints, that's enough to let the other members know about his bad behavior - return; + return std::nullopt; } const uint256 hash = ::SerializeHash(qc); @@ -585,7 +585,6 @@ void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) member->complaints.emplace(hash); CInv inv(MSG_QUORUM_COMPLAINT, hash); - RelayInvToParticipants(inv); dkgDebugManager.UpdateLocalMemberStatus(params.type, quorumIndex, member->idx, [&](CDKGDebugMemberStatus& status) { status.statusBits.receivedComplaint = true; @@ -597,7 +596,7 @@ void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) // so others know about his bad behavior MarkBadMember(member->idx); logger.Batch("%s did send multiple complaints", member->dmn->proTxHash.ToString()); - return; + return inv; } int receivedCount = 0; @@ -626,6 +625,7 @@ void CDKGSession::ReceiveMessage(const CDKGComplaint& qc) } logger.Batch("received and relayed complaint. received=%d", receivedCount); + return inv; } void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages) @@ -776,7 +776,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co return true; } -void CDKGSession::ReceiveMessage(const CDKGJustification& qj) +std::optional CDKGSession::ReceiveMessage(const CDKGJustification& qj) { CDKGLogger logger(*this, __func__, __LINE__); @@ -786,7 +786,7 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj) if (member->justifications.size() >= 2) { // only relay up to 2 justifications, that's enough to let the other members know about his bad behavior - return; + return std::nullopt; } const uint256 hash = ::SerializeHash(qj); @@ -795,7 +795,6 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj) // we always relay, even if further verification fails CInv inv(MSG_QUORUM_JUSTIFICATION, hash); - RelayInvToParticipants(inv); dkgDebugManager.UpdateLocalMemberStatus(params.type, quorumIndex, member->idx, [&](CDKGDebugMemberStatus& status) { status.statusBits.receivedJustification = true; @@ -807,13 +806,13 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj) // so others know about his bad behavior logger.Batch("%s did send multiple justifications", member->dmn->proTxHash.ToString()); MarkBadMember(member->idx); - return; + return inv; } if (member->bad) { // we locally determined him to be bad (sent none or more then one contributions) // don't give him a second chance (but we relay the justification in case other members disagree) - return; + return inv; } for (const auto& p : qj.contributions) { @@ -826,7 +825,7 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj) } } if (member->bad) { - return; + return inv; } cxxtimer::Timer t1(true); @@ -866,6 +865,7 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj) }); logger.Batch("verified justification: received=%d/%d time=%d", receivedCount, expectedCount, t1.count()); + return inv; } void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages) @@ -1089,7 +1089,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retB return true; } -void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc) +std::optional CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc) { CDKGLogger logger(*this, __func__, __LINE__); @@ -1129,30 +1129,29 @@ void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc) if ((*quorumVvec)[0] != qc.quorumPublicKey) { logger.Batch("calculated quorum public key does not match"); - return; + return std::nullopt; } uint256 vvecHash = ::SerializeHash(*quorumVvec); if (qc.quorumVvecHash != vvecHash) { logger.Batch("calculated quorum vvec hash does not match"); - return; + return std::nullopt; } CBLSPublicKey pubKeyShare = cache.BuildPubKeyShare(::SerializeHash(std::make_pair(memberIndexes, member->id)), quorumVvec, member->id); if (!pubKeyShare.IsValid()) { logger.Batch("failed to calculate public key share"); - return; + return std::nullopt; } if (!qc.quorumSig.VerifyInsecure(pubKeyShare, qc.GetSignHash())) { logger.Batch("failed to verify quorumSig"); - return; + return std::nullopt; } } WITH_LOCK(invCs, validCommitments.emplace(hash)); CInv inv(MSG_QUORUM_PREMATURE_COMMITMENT, hash); - RelayInvToParticipants(inv); dkgDebugManager.UpdateLocalMemberStatus(params.type, quorumIndex, member->idx, [&](CDKGDebugMemberStatus& status) { status.statusBits.receivedPrematureCommitment = true; @@ -1164,6 +1163,7 @@ void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc) t1.stop(); logger.Batch("verified premature commitment. received=%d/%d, time=%d", receivedCount, members.size(), t1.count()); + return inv; } std::vector CDKGSession::FinalizeCommitments() @@ -1296,41 +1296,5 @@ void CDKGSession::MarkBadMember(size_t idx) member->bad = true; } -void CDKGSession::RelayInvToParticipants(const CInv& inv) const -{ - CDKGLogger logger(*this, __func__, __LINE__); - std::stringstream ss; - for (const auto& r : relayMembers) { - ss << r.ToString().substr(0, 4) << " | "; - } - logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]", - inv.ToString(), - relayMembers.size(), - connman.GetNodeCount(ConnectionDirection::Both), - connman.GetNetworkActive(), - connman.HasMasternodeQuorumNodes(params.type, m_quorum_base_block_index->GetBlockHash()), - m_quorum_base_block_index->GetBlockHash().ToString(), - myProTxHash.ToString().substr(0, 4), ss.str()); - - std::stringstream ss2; - connman.ForEachNode([&](const CNode* pnode) { - if (pnode->qwatch || - (!pnode->GetVerifiedProRegTxHash().IsNull() && (relayMembers.count(pnode->GetVerifiedProRegTxHash()) != 0))) { - Assert(m_peerman)->PushInventory(pnode->GetId(), inv); - } - - if (pnode->GetVerifiedProRegTxHash().IsNull()) { - logger.Batch("node[%d:%s] not mn", - pnode->GetId(), - pnode->m_addr_name); - } else if (relayMembers.count(pnode->GetVerifiedProRegTxHash()) == 0) { - ss2 << pnode->GetVerifiedProRegTxHash().ToString().substr(0, 4) << " | "; - } - }); - logger.Batch("forMember[%s] NOTrelayMembers[%s]", - myProTxHash.ToString().substr(0, 4), - ss2.str()); - logger.Flush(); -} } // namespace llmq diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index 8a874f555d..b47854f4fb 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -5,13 +5,14 @@ #ifndef BITCOIN_LLMQ_DKGSESSION_H #define BITCOIN_LLMQ_DKGSESSION_H +#include + +#include #include #include #include - -#include -#include #include +#include #include @@ -22,7 +23,6 @@ class CDeterministicMN; class CMasternodeMetaMan; class CSporkManager; class UniValue; -class PeerManager; using CDeterministicMNCPtr = std::shared_ptr; @@ -249,6 +249,13 @@ public: } }; +class CDKGLogger : public CBatchedLogger +{ +public: + CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line); + CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line); +}; + /** * The DKG session is a single instance of the DKG process. It is owned and called by CDKGSessionHandler, which passes * received DKG messages to the session. The session is not persistent and will loose it's state (the whole object is @@ -281,7 +288,6 @@ private: CMasternodeMetaMan& m_mn_metaman; const CActiveMasternodeManager* const m_mn_activeman; const CSporkManager& m_sporkman; - const std::unique_ptr& m_peerman; const CBlockIndex* m_quorum_base_block_index{nullptr}; int quorumIndex{0}; @@ -324,11 +330,12 @@ public: CDKGSession(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, const std::unique_ptr& peerman) : + 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), - m_peerman(peerman) {} + dkgDebugManager(_dkgDebugManager), m_mn_metaman(mn_metaman), m_mn_activeman(mn_activeman), m_sporkman(sporkman) + {} + // TODO: remove Init completely bool Init(gsl::not_null pQuorumBaseBlockIndex, Span mns, const uint256& _myProTxHash, int _quorumIndex); [[nodiscard]] std::optional GetMyMemberIndex() const { return myIdx; } @@ -350,7 +357,7 @@ public: void Contribute(CDKGPendingMessages& pendingMessages); void SendContributions(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGContribution& qc, bool& retBan) const; - void ReceiveMessage(const CDKGContribution& qc); + std::optional ReceiveMessage(const CDKGContribution& qc); void VerifyPendingContributions() EXCLUSIVE_LOCKS_REQUIRED(cs_pending); // Phase 2: complaint @@ -358,19 +365,19 @@ public: void VerifyConnectionAndMinProtoVersions() const; void SendComplaint(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const; - void ReceiveMessage(const CDKGComplaint& qc); + std::optional ReceiveMessage(const CDKGComplaint& qc); // Phase 3: justification void VerifyAndJustify(CDKGPendingMessages& pendingMessages); void SendJustification(CDKGPendingMessages& pendingMessages, const std::set& forMembers); bool PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const; - void ReceiveMessage(const CDKGJustification& qj); + std::optional ReceiveMessage(const CDKGJustification& qj); // Phase 4: commit void VerifyAndCommit(CDKGPendingMessages& pendingMessages); void SendCommitment(CDKGPendingMessages& pendingMessages); bool PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retBan) const; - void ReceiveMessage(const CDKGPrematureCommitment& qc); + std::optional ReceiveMessage(const CDKGPrematureCommitment& qc); // Phase 5: aggregate/finalize std::vector FinalizeCommitments(); @@ -378,10 +385,12 @@ public: [[nodiscard]] bool AreWeMember() const { return !myProTxHash.IsNull(); } void MarkBadMember(size_t idx); - void RelayInvToParticipants(const CInv& inv) const; - public: [[nodiscard]] CDKGMember* GetMember(const uint256& proTxHash) const; + [[nodiscard]] const std::set& RelayMembers() const { return relayMembers; } + [[nodiscard]] const CBlockIndex* BlockIndex() const { return m_quorum_base_block_index; } + [[nodiscard]] const uint256& ProTx() const { return myProTxHash; } + [[nodiscard]] const Consensus::LLMQParams GetParams() const { return params; } private: [[nodiscard]] bool ShouldSimulateError(DKGError::type type) const; diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index c68cf8758a..f5dc6d9152 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, peerman)), + curSession(std::make_unique(_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), @@ -190,7 +190,7 @@ void CDKGSessionHandler::StopThread() bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) { - curSession = std::make_unique(params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman, m_peerman); + curSession = std::make_unique(params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) { return false; @@ -438,8 +438,45 @@ std::set BatchVerifyMessageSigs(CDKGSession& session, const std::vector< return ret; } +static void RelayInvToParticipants(const CDKGSession& session, CConnman& connman, PeerManager& peerman, const CInv& inv) +{ + CDKGLogger logger(session, __func__, __LINE__); + std::stringstream ss; + const auto& relayMembers = session.RelayMembers(); + for (const auto& r : relayMembers) { + ss << r.ToString().substr(0, 4) << " | "; + } + logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]", + inv.ToString(), + relayMembers.size(), + connman.GetNodeCount(ConnectionDirection::Both), + connman.GetNetworkActive(), + connman.HasMasternodeQuorumNodes(session.GetParams().type, session.BlockIndex()->GetBlockHash()), + session.BlockIndex()->GetBlockHash().ToString(), + session.ProTx().ToString().substr(0, 4), ss.str()); + + std::stringstream ss2; + connman.ForEachNode([&](const CNode* pnode) { + if (pnode->qwatch || + (!pnode->GetVerifiedProRegTxHash().IsNull() && (relayMembers.count(pnode->GetVerifiedProRegTxHash()) != 0))) { + peerman.PushInventory(pnode->GetId(), inv); + } + + if (pnode->GetVerifiedProRegTxHash().IsNull()) { + logger.Batch("node[%d:%s] not mn", + pnode->GetId(), + pnode->m_addr_name); + } else if (relayMembers.count(pnode->GetVerifiedProRegTxHash()) == 0) { + ss2 << pnode->GetVerifiedProRegTxHash().ToString().substr(0, 4) << " | "; + } + }); + logger.Batch("forMember[%s] NOTrelayMembers[%s]", + session.ProTx().ToString().substr(0, 4), + ss2.str()); + logger.Flush(); +} template -bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendingMessages, size_t maxCount) +bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSession& session, CDKGPendingMessages& pendingMessages, size_t maxCount) { auto msgs = pendingMessages.PopAndDeserializeMessages(maxCount); if (msgs.empty()) { @@ -489,7 +526,10 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi if (badNodes.count(nodeId)) { continue; } - session.ReceiveMessage(*p.second); + const std::optional inv = session.ReceiveMessage(*p.second); + if (inv && peerman) { + RelayInvToParticipants(session, connman, *peerman, *inv); + } } return true; @@ -532,7 +572,7 @@ void CDKGSessionHandler::HandleDKGRound() curSession->Contribute(pendingContributions); }; auto fContributeWait = [this] { - return ProcessPendingMessageBatch(*curSession, pendingContributions, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingContributions, 8); }; HandlePhase(QuorumPhase::Contribute, QuorumPhase::Complain, curQuorumHash, 0.05, fContributeStart, fContributeWait); @@ -541,7 +581,7 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndComplain(pendingComplaints); }; auto fComplainWait = [this] { - return ProcessPendingMessageBatch(*curSession, pendingComplaints, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingComplaints, 8); }; HandlePhase(QuorumPhase::Complain, QuorumPhase::Justify, curQuorumHash, 0.05, fComplainStart, fComplainWait); @@ -550,7 +590,7 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndJustify(pendingJustifications); }; auto fJustifyWait = [this] { - return ProcessPendingMessageBatch(*curSession, pendingJustifications, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingJustifications, 8); }; HandlePhase(QuorumPhase::Justify, QuorumPhase::Commit, curQuorumHash, 0.05, fJustifyStart, fJustifyWait); @@ -559,7 +599,7 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndCommit(pendingPrematureCommitments); }; auto fCommitWait = [this] { - return ProcessPendingMessageBatch(*curSession, pendingPrematureCommitments, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingPrematureCommitments, 8); }; HandlePhase(QuorumPhase::Commit, QuorumPhase::Finalize, curQuorumHash, 0.1, fCommitStart, fCommitWait); diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index f2f6a4365c..90417d9138 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -93,7 +93,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "llmq/context -> llmq/ehf_signals -> net_processing -> llmq/context" "llmq/blockprocessor -> net_processing -> llmq/blockprocessor" "llmq/chainlocks -> net_processing -> llmq/chainlocks" - "llmq/dkgsession -> net_processing -> llmq/quorums -> llmq/dkgsession" "net_processing -> spork -> net_processing" "evo/simplifiedmns -> llmq/blockprocessor -> net_processing -> evo/simplifiedmns" "governance/governance -> net_processing -> governance/governance" From 7f815cb5017bd223e7aec0645645d9ceeaf956d8 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 16:47:09 +0700 Subject: [PATCH 07/11] refactor: remove unused constructor of CDKGLogger --- src/llmq/dkgsession.cpp | 7 +------ src/llmq/dkgsession.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index 201d015714..da21ea977e 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -33,12 +33,7 @@ namespace llmq { CDKGLogger::CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line) : - CDKGLogger(_quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->GetBlockHash(), _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember(), _func, source_line) -{ -} - -CDKGLogger::CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line) : - CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _llmqTypeName, _quorumIndex, _height, _areWeMember), __FILE__, source_line) + CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember()), __FILE__, source_line) { } diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index b47854f4fb..3f18fc892b 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -253,7 +253,6 @@ class CDKGLogger : public CBatchedLogger { public: CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line); - CDKGLogger(std::string_view _llmqTypeName, int _quorumIndex, const uint256& _quorumHash, int _height, bool _areWeMember, std::string_view _func, int source_line); }; /** From 9f3eb6bbb80e6536f29ee6c2379969d2b8903a30 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 18:52:29 +0700 Subject: [PATCH 08/11] perf: check DIP0003 before CDKGSession initialization --- src/llmq/dkgsessionhandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index f5dc6d9152..6a5f85493b 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -190,12 +190,12 @@ void CDKGSessionHandler::StopThread() bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) { - curSession = std::make_unique(params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); - if (!DeploymentDIP0003Enforced(pQuorumBaseBlockIndex->nHeight, Params().GetConsensus())) { 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)) { LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size()); From 95935668022ebd9a034b6289eb70ba837af3ca93 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 20:32:11 +0700 Subject: [PATCH 09/11] 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; } From db9798f5e44d3957e90bc13a1e55e9951f9621fe Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 20 Sep 2024 20:54:24 +0700 Subject: [PATCH 10/11] refactor: move call GetQuorumMembers inside Init() --- src/llmq/dkgsession.cpp | 13 ++++++++++++- src/llmq/dkgsession.h | 8 ++------ src/llmq/dkgsessionhandler.cpp | 5 ++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index fe7ae64411..6d6767d7c0 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -68,8 +68,19 @@ CDKGMember::CDKGMember(const CDeterministicMNCPtr& _dmn, size_t _idx) : } -bool CDKGSession::Init(Span mns, const uint256& _myProTxHash, int _quorumIndex) +CDKGSession::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), + m_quorum_base_block_index{pQuorumBaseBlockIndex} { +} + +bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex) +{ + const auto mns = utils::GetAllQuorumMembers(params.type, m_dmnman, m_quorum_base_block_index); quorumIndex = _quorumIndex; members.resize(mns.size()); memberIds.resize(members.size()); diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index 61e8467374..c31068ae26 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -329,14 +329,10 @@ public: 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), - m_quorum_base_block_index{pQuorumBaseBlockIndex} - {} + const CSporkManager& sporkman); // TODO: remove Init completely - bool Init(Span mns, const uint256& _myProTxHash, int _quorumIndex); + bool Init(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 1895a2b3cb..43a37251ba 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -194,11 +194,10 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) return false; } - auto mns = utils::GetAllQuorumMembers(params.type, m_dmnman, pQuorumBaseBlockIndex); 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()); + if (!curSession->Init(m_mn_activeman->GetProTxHash(), quorumIndex)) { + LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex); return false; } From 74a5a9f98448ab59204296b4082c3598912b15ff Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 24 Sep 2024 01:15:27 +0700 Subject: [PATCH 11/11] style: apply clang-format --- src/evo/cbtx.cpp | 6 +-- src/evo/deterministicmns.cpp | 2 +- src/evo/deterministicmns.h | 2 +- src/evo/mnhftx.cpp | 2 +- src/llmq/dkgsession.cpp | 22 ++++++-- src/llmq/dkgsession.h | 8 +-- src/llmq/dkgsessionhandler.cpp | 94 ++++++++++++++++++---------------- src/llmq/dkgsessionmgr.h | 2 +- src/llmq/quorums.cpp | 7 +-- 9 files changed, 81 insertions(+), 64 deletions(-) diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 80bde9d0a7..a5f8d6b1cd 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -2,17 +2,17 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include +#include +#include #include #include #include #include #include #include -#include -#include -#include #include #include diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 9ad5253e97..ac167a298b 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -2,10 +2,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include #include #include #include +#include #include #include #include diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index ac27530526..3dcbdd33a4 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -13,10 +13,10 @@ #include #include #include +#include #include #include #include -#include #include diff --git a/src/evo/mnhftx.cpp b/src/evo/mnhftx.cpp index d495def879..a7a953db58 100644 --- a/src/evo/mnhftx.cpp +++ b/src/evo/mnhftx.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index 6d6767d7c0..d59e7defee 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -33,7 +33,10 @@ namespace llmq { CDKGLogger::CDKGLogger(const CDKGSession& _quorumDkg, std::string_view _func, int source_line) : - CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _quorumDkg.params.name, _quorumDkg.quorumIndex, _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember()), __FILE__, source_line) + CBatchedLogger(BCLog::LLMQ_DKG, + strprintf("QuorumDKG(type=%s, qIndex=%d, h=%d, member=%d)", _quorumDkg.params.name, _quorumDkg.quorumIndex, + _quorumDkg.m_quorum_base_block_index->nHeight, _quorumDkg.AreWeMember()), + __FILE__, source_line) { } @@ -68,12 +71,21 @@ CDKGMember::CDKGMember(const CDeterministicMNCPtr& _dmn, size_t _idx) : } -CDKGSession::CDKGSession(const CBlockIndex* pQuorumBaseBlockIndex, const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CConnman& _connman, - CDeterministicMNManager& dmnman, CDKGSessionManager& _dkgManager, CDKGDebugManager& _dkgDebugManager, +CDKGSession::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), + 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), m_quorum_base_block_index{pQuorumBaseBlockIndex} { } diff --git a/src/llmq/dkgsession.h b/src/llmq/dkgsession.h index c31068ae26..72cf7f714b 100644 --- a/src/llmq/dkgsession.h +++ b/src/llmq/dkgsession.h @@ -326,10 +326,10 @@ private: std::set validCommitments GUARDED_BY(invCs); public: - 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); + 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); // TODO: remove Init completely bool Init(const uint256& _myProTxHash, int _quorumIndex); diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 43a37251ba..661cafdcad 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -24,28 +24,34 @@ namespace llmq { -CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman, - 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) : - blsWorker(_blsWorker), - m_chainstate(chainstate), - connman(_connman), - m_dmnman(dmnman), - dkgDebugManager(_dkgDebugManager), - dkgManager(_dkgManager), - m_mn_metaman(mn_metaman), - quorumBlockProcessor(_quorumBlockProcessor), - m_mn_activeman(mn_activeman), - m_sporkman(sporkman), - m_peerman(peerman), - params(_params), - quorumIndex(_quorumIndex), - 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), - pendingPrematureCommitments((size_t)_params.size * 2, MSG_QUORUM_PREMATURE_COMMITMENT) +CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, + CDeterministicMNManager& dmnman, 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) : + blsWorker(_blsWorker), + m_chainstate(chainstate), + connman(_connman), + m_dmnman(dmnman), + dkgDebugManager(_dkgDebugManager), + dkgManager(_dkgManager), + m_mn_metaman(mn_metaman), + quorumBlockProcessor(_quorumBlockProcessor), + m_mn_activeman(mn_activeman), + m_sporkman(sporkman), + m_peerman(peerman), + params(_params), + quorumIndex(_quorumIndex), + 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), + pendingPrematureCommitments((size_t)_params.size * 2, MSG_QUORUM_PREMATURE_COMMITMENT) { if (params.type == Consensus::LLMQType::LLMQ_NONE) { throw std::runtime_error("Can't initialize CDKGSessionHandler with LLMQ_NONE type."); @@ -194,10 +200,12 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) return false; } - curSession = std::make_unique(pQuorumBaseBlockIndex, params, blsWorker, connman, m_dmnman, dkgManager, dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); + curSession = std::make_unique(pQuorumBaseBlockIndex, params, blsWorker, connman, m_dmnman, dkgManager, + dkgDebugManager, m_mn_metaman, m_mn_activeman, m_sporkman); if (!curSession->Init(m_mn_activeman->GetProTxHash(), quorumIndex)) { - LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex); + LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d]\n", __func__, + pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex); return false; } @@ -445,37 +453,32 @@ static void RelayInvToParticipants(const CDKGSession& session, CConnman& connman for (const auto& r : relayMembers) { ss << r.ToString().substr(0, 4) << " | "; } - logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]", - inv.ToString(), - relayMembers.size(), - connman.GetNodeCount(ConnectionDirection::Both), + logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] " + "HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]", + inv.ToString(), relayMembers.size(), connman.GetNodeCount(ConnectionDirection::Both), connman.GetNetworkActive(), connman.HasMasternodeQuorumNodes(session.GetParams().type, session.BlockIndex()->GetBlockHash()), - session.BlockIndex()->GetBlockHash().ToString(), - session.ProTx().ToString().substr(0, 4), ss.str()); + session.BlockIndex()->GetBlockHash().ToString(), session.ProTx().ToString().substr(0, 4), ss.str()); std::stringstream ss2; connman.ForEachNode([&](const CNode* pnode) { if (pnode->qwatch || - (!pnode->GetVerifiedProRegTxHash().IsNull() && (relayMembers.count(pnode->GetVerifiedProRegTxHash()) != 0))) { + (!pnode->GetVerifiedProRegTxHash().IsNull() && (relayMembers.count(pnode->GetVerifiedProRegTxHash()) != 0))) { peerman.PushInventory(pnode->GetId(), inv); } if (pnode->GetVerifiedProRegTxHash().IsNull()) { - logger.Batch("node[%d:%s] not mn", - pnode->GetId(), - pnode->m_addr_name); + logger.Batch("node[%d:%s] not mn", pnode->GetId(), pnode->m_addr_name); } else if (relayMembers.count(pnode->GetVerifiedProRegTxHash()) == 0) { ss2 << pnode->GetVerifiedProRegTxHash().ToString().substr(0, 4) << " | "; } }); - logger.Batch("forMember[%s] NOTrelayMembers[%s]", - session.ProTx().ToString().substr(0, 4), - ss2.str()); + logger.Batch("forMember[%s] NOTrelayMembers[%s]", session.ProTx().ToString().substr(0, 4), ss2.str()); logger.Flush(); } -template -bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSession& session, CDKGPendingMessages& pendingMessages, size_t maxCount) +template +bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSession& session, + CDKGPendingMessages& pendingMessages, size_t maxCount) { auto msgs = pendingMessages.PopAndDeserializeMessages(maxCount); if (msgs.empty()) { @@ -571,7 +574,8 @@ void CDKGSessionHandler::HandleDKGRound() curSession->Contribute(pendingContributions); }; auto fContributeWait = [this] { - return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingContributions, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, + pendingContributions, 8); }; HandlePhase(QuorumPhase::Contribute, QuorumPhase::Complain, curQuorumHash, 0.05, fContributeStart, fContributeWait); @@ -580,7 +584,8 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndComplain(pendingComplaints); }; auto fComplainWait = [this] { - return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingComplaints, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, + pendingComplaints, 8); }; HandlePhase(QuorumPhase::Complain, QuorumPhase::Justify, curQuorumHash, 0.05, fComplainStart, fComplainWait); @@ -589,7 +594,9 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndJustify(pendingJustifications); }; auto fJustifyWait = [this] { - return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingJustifications, 8); + return ProcessPendingMessageBatch(connman, m_peerman.get(), + *curSession, + pendingJustifications, 8); }; HandlePhase(QuorumPhase::Justify, QuorumPhase::Commit, curQuorumHash, 0.05, fJustifyStart, fJustifyWait); @@ -598,7 +605,8 @@ void CDKGSessionHandler::HandleDKGRound() curSession->VerifyAndCommit(pendingPrematureCommitments); }; auto fCommitWait = [this] { - return ProcessPendingMessageBatch(connman, m_peerman.get(), *curSession, pendingPrematureCommitments, 8); + return ProcessPendingMessageBatch( + connman, m_peerman.get(), *curSession, pendingPrematureCommitments, 8); }; HandlePhase(QuorumPhase::Commit, QuorumPhase::Finalize, curQuorumHash, 0.1, fCommitStart, fCommitWait); diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index 3affac23f6..8c1ddea339 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -5,10 +5,10 @@ #ifndef BITCOIN_LLMQ_DKGSESSIONMGR_H #define BITCOIN_LLMQ_DKGSESSIONMGR_H -#include #include #include #include +#include #include #include diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 6ce748c8da..ada778def1 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -11,9 +11,9 @@ #include #include +#include #include #include -#include #include #include @@ -232,10 +232,7 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate, MigrateOldQuorumDB(_evoDb); } -CQuorumManager::~CQuorumManager() -{ - Stop(); -} +CQuorumManager::~CQuorumManager() { Stop(); } void CQuorumManager::Start() {