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() {