From a4e0327c29de0edc66b664f570b8dea023608ee0 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Thu, 19 Jan 2023 17:33:10 +0000 Subject: [PATCH] refactor: pass CNode by reference for ProcessMessage functions --- src/llmq/chainlocks.cpp | 4 +- src/llmq/chainlocks.h | 2 +- src/llmq/dkgsessionhandler.cpp | 10 ++--- src/llmq/dkgsessionhandler.h | 2 +- src/llmq/dkgsessionmgr.cpp | 16 ++++---- src/llmq/dkgsessionmgr.h | 2 +- src/llmq/instantsend.cpp | 16 ++++---- src/llmq/instantsend.h | 4 +- src/llmq/quorums.cpp | 38 +++++++++---------- src/llmq/quorums.h | 4 +- src/llmq/signing.cpp | 14 +++---- src/llmq/signing.h | 4 +- src/llmq/signing_shares.cpp | 68 +++++++++++++++++----------------- src/llmq/signing_shares.h | 10 ++--- src/net_processing.cpp | 12 +++--- 15 files changed, 103 insertions(+), 103 deletions(-) diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index 517bb6b13e..3a13aa6454 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -79,7 +79,7 @@ CChainLockSig CChainLocksHandler::GetBestChainLock() const return bestChainLock; } -void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) +void CChainLocksHandler::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) { if (!AreChainLocksEnabled(spork_manager)) { return; @@ -89,7 +89,7 @@ void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& msg_typ CChainLockSig clsig; vRecv >> clsig; - ProcessNewChainLock(pfrom->GetId(), clsig, ::SerializeHash(clsig)); + ProcessNewChainLock(pfrom.GetId(), clsig, ::SerializeHash(clsig)); } } diff --git a/src/llmq/chainlocks.h b/src/llmq/chainlocks.h index 98c3918c2f..0264940af2 100644 --- a/src/llmq/chainlocks.h +++ b/src/llmq/chainlocks.h @@ -89,7 +89,7 @@ public: bool GetChainLockByHash(const uint256& hash, CChainLockSig& ret) const; CChainLockSig GetBestChainLock() const; - void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv); void ProcessNewChainLock(NodeId from, const CChainLockSig& clsig, const uint256& hash); void AcceptedBlockHeader(const CBlockIndex* pindexNew); void UpdatedBlockTip(); diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index a81fb8635a..2bed14be38 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -107,17 +107,17 @@ void CDKGSessionHandler::UpdatedBlockTip(const CBlockIndex* pindexNew) params.name, quorumIndex, currentHeight, pQuorumBaseBlockIndex->nHeight, int(oldPhase), int(phase)); } -void CDKGSessionHandler::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) +void CDKGSessionHandler::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) { // We don't handle messages in the calling thread as deserialization/processing of these would block everything if (msg_type == NetMsgType::QCONTRIB) { - pendingContributions.PushPendingMessage(pfrom->GetId(), vRecv); + pendingContributions.PushPendingMessage(pfrom.GetId(), vRecv); } else if (msg_type == NetMsgType::QCOMPLAINT) { - pendingComplaints.PushPendingMessage(pfrom->GetId(), vRecv); + pendingComplaints.PushPendingMessage(pfrom.GetId(), vRecv); } else if (msg_type == NetMsgType::QJUSTIFICATION) { - pendingJustifications.PushPendingMessage(pfrom->GetId(), vRecv); + pendingJustifications.PushPendingMessage(pfrom.GetId(), vRecv); } else if (msg_type == NetMsgType::QPCOMMITMENT) { - pendingPrematureCommitments.PushPendingMessage(pfrom->GetId(), vRecv); + pendingPrematureCommitments.PushPendingMessage(pfrom.GetId(), vRecv); } } diff --git a/src/llmq/dkgsessionhandler.h b/src/llmq/dkgsessionhandler.h index 3b7b337049..d93a49be1b 100644 --- a/src/llmq/dkgsessionhandler.h +++ b/src/llmq/dkgsessionhandler.h @@ -153,7 +153,7 @@ public: ~CDKGSessionHandler() = default; void UpdatedBlockTip(const CBlockIndex *pindexNew); - void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv); void StartThread(); void StopThread(); diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index 0852c8683d..e222b783eb 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -162,7 +162,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni } } -void CDKGSessionManager::ProcessMessage(CNode* pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv) +void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv) { static Mutex cs_indexedQuorumsCache; static std::map> indexedQuorumsCache GUARDED_BY(cs_indexedQuorumsCache); @@ -179,13 +179,13 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const CQuorumManager& quor } if (msg_type == NetMsgType::QWATCH) { - pfrom->qwatch = true; + pfrom.qwatch = true; return; } if (vRecv.empty()) { LOCK(cs_main); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } @@ -199,7 +199,7 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const CQuorumManager& quor if (!Params().HasLLMQ(llmqType)) { LOCK(cs_main); LogPrintf("CDKGSessionManager -- invalid llmqType [%d]\n", uint8_t(llmqType)); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } @@ -221,14 +221,14 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const CQuorumManager& quor LOCK(cs_main); LogPrintf("CDKGSessionManager -- unknown quorumHash %s\n", quorumHash.ToString()); // NOTE: do not insta-ban for this, we might be lagging behind - Misbehaving(pfrom->GetId(), 10); + Misbehaving(pfrom.GetId(), 10); return; } if (!utils::IsQuorumTypeEnabled(llmqType, quorum_manager, pQuorumBaseBlockIndex->pprev)) { LOCK(cs_main); LogPrintf("CDKGSessionManager -- llmqType [%d] quorums aren't active\n", uint8_t(llmqType)); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } @@ -240,14 +240,14 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const CQuorumManager& quor if (quorumIndex > quorumIndexMax) { LOCK(cs_main); LogPrintf("CDKGSessionManager -- invalid quorumHash %s\n", quorumHash.ToString()); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } if (!dkgSessionHandlers.count(std::make_pair(llmqType, quorumIndex))) { LOCK(cs_main); LogPrintf("CDKGSessionManager -- no session handlers for quorumIndex [%d]\n", quorumIndex); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } } diff --git a/src/llmq/dkgsessionmgr.h b/src/llmq/dkgsessionmgr.h index 21be69054b..c239c62049 100644 --- a/src/llmq/dkgsessionmgr.h +++ b/src/llmq/dkgsessionmgr.h @@ -62,7 +62,7 @@ public: void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload); - void ProcessMessage(CNode* pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv); bool AlreadyHave(const CInv& inv) const; bool GetContribution(const uint256& hash, CDKGContribution& ret) const; bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const; diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index 9cd86f2b9a..1162d95898 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -762,7 +762,7 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco pendingInstantSendLocks.emplace(hash, std::make_pair(-1, islock)); } -void CInstantSendManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) +void CInstantSendManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) { if (!IsInstantSendEnabled()) { return; @@ -776,20 +776,20 @@ void CInstantSendManager::ProcessMessage(CNode* pfrom, const std::string& msg_ty } } -void CInstantSendManager::ProcessMessageInstantSendLock(const CNode* pfrom, const llmq::CInstantSendLockPtr& islock) +void CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom, const llmq::CInstantSendLockPtr& islock) { auto hash = ::SerializeHash(*islock); bool fDIP0024IsActive = false; { LOCK(cs_main); - EraseObjectRequest(pfrom->GetId(), CInv(islock->IsDeterministic() ? MSG_ISDLOCK : MSG_ISLOCK, hash)); + EraseObjectRequest(pfrom.GetId(), CInv(islock->IsDeterministic() ? MSG_ISDLOCK : MSG_ISLOCK, hash)); fDIP0024IsActive = utils::IsDIP0024Active(::ChainActive().Tip()); } if (!islock->TriviallyValid()) { LOCK(cs_main); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); return; } @@ -798,14 +798,14 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode* pfrom, cons const auto blockIndex = WITH_LOCK(cs_main, return LookupBlockIndex(islock->cycleHash)); if (blockIndex == nullptr) { // Maybe we don't have the block yet or maybe some peer spams invalid values for cycleHash - WITH_LOCK(cs_main, Misbehaving(pfrom->GetId(), 1)); + WITH_LOCK(cs_main, Misbehaving(pfrom.GetId(), 1)); return; } // Deterministic islocks MUST use rotation based llmq auto llmqType = Params().GetConsensus().llmqTypeDIP0024InstantSend; if (blockIndex->nHeight % GetLLMQParams(llmqType).dkgInterval != 0) { - WITH_LOCK(cs_main, Misbehaving(pfrom->GetId(), 100)); + WITH_LOCK(cs_main, Misbehaving(pfrom.GetId(), 100)); return; } } @@ -822,10 +822,10 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode* pfrom, cons } LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: received islock, peer=%d\n", __func__, - islock->txid.ToString(), hash.ToString(), pfrom->GetId()); + islock->txid.ToString(), hash.ToString(), pfrom.GetId()); LOCK(cs_pendingLocks); - pendingInstantSendLocks.emplace(hash, std::make_pair(pfrom->GetId(), islock)); + pendingInstantSendLocks.emplace(hash, std::make_pair(pfrom.GetId(), islock)); } /** diff --git a/src/llmq/instantsend.h b/src/llmq/instantsend.h index c9a01c9bcc..bae37026c1 100644 --- a/src/llmq/instantsend.h +++ b/src/llmq/instantsend.h @@ -283,7 +283,7 @@ private: bool TrySignInputLocks(const CTransaction& tx, bool allowResigning, Consensus::LLMQType llmqType, const Consensus::Params& params) LOCKS_EXCLUDED(cs_inputReqests); void TrySignInstantSendLock(const CTransaction& tx) LOCKS_EXCLUDED(cs_creating); - void ProcessMessageInstantSendLock(const CNode* pfrom, const CInstantSendLockPtr& islock); + void ProcessMessageInstantSendLock(const CNode& pfrom, const CInstantSendLockPtr& islock); bool ProcessPendingInstantSendLocks(); bool ProcessPendingInstantSendLocks(bool deterministic) LOCKS_EXCLUDED(cs_pendingLocks); @@ -316,7 +316,7 @@ public: void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override LOCKS_EXCLUDED(cs_inputReqests, cs_creating); - void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv); void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_pendingLocks); void TransactionRemovedFromMempool(const CTransactionRef& tx); diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 64f89d4578..946df17e60 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -437,18 +437,18 @@ bool CQuorumManager::HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockP return quorum_block_processor.HasMinedCommitment(llmqType, quorumHash); } -bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash) const +bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash) const { - if (pFrom == nullptr) { - LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid pFrom: nullptr\n", __func__); + if (pfrom == nullptr) { + LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid pfrom: nullptr\n", __func__); return false; } - if (pFrom->nVersion < LLMQ_DATA_MESSAGES_VERSION) { + if (pfrom->nVersion < LLMQ_DATA_MESSAGES_VERSION) { LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Version must be %d or greater.\n", __func__, LLMQ_DATA_MESSAGES_VERSION); return false; } - if (pFrom->GetVerifiedProRegTxHash().IsNull() && !pFrom->qwatch) { - LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- pFrom is neither a verified masternode nor a qwatch connection\n", __func__); + if (pfrom->GetVerifiedProRegTxHash().IsNull() && !pfrom->qwatch) { + LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- pfrom is neither a verified masternode nor a qwatch connection\n", __func__); return false; } if (!Params().HasLLMQ(llmqType)) { @@ -466,7 +466,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp LOCK(cs_data_requests); CQuorumDataRequestKey key; - key.proRegTx = pFrom->GetVerifiedProRegTxHash(); + key.proRegTx = pfrom->GetVerifiedProRegTxHash(); key.flag = true; key.quorumHash = pQuorumBaseBlockIndex->GetBlockHash(); key.llmqType = llmqType; @@ -476,8 +476,8 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp return false; } - CNetMsgMaker msgMaker(pFrom->GetSendVersion()); - connman.PushMessage(pFrom, msgMaker.Make(NetMsgType::QGETDATA, it.first->second)); + CNetMsgMaker msgMaker(pfrom->GetSendVersion()); + connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::QGETDATA, it.first->second)); return true; } @@ -604,20 +604,20 @@ size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, c return nIndex % pQuorum->qc->validMembers.size(); } -void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, CDataStream& vRecv) +void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) { auto strFunc = __func__; auto errorHandler = [&](const std::string& strError, int nScore = 10) { - LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: %s, from peer=%d\n", strFunc, msg_type, strError, pFrom->GetId()); + LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: %s, from peer=%d\n", strFunc, msg_type, strError, pfrom.GetId()); if (nScore > 0) { LOCK(cs_main); - Misbehaving(pFrom->GetId(), nScore); + Misbehaving(pfrom.GetId(), nScore); } }; if (msg_type == NetMsgType::QGETDATA) { - if (!fMasternodeMode || pFrom == nullptr || (pFrom->GetVerifiedProRegTxHash().IsNull() && !pFrom->qwatch)) { + if (!fMasternodeMode || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) { errorHandler("Not a verified masternode or a qwatch connection"); return; } @@ -628,14 +628,14 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C auto sendQDATA = [&](CQuorumDataRequest::Errors nError = CQuorumDataRequest::Errors::UNDEFINED, const CDataStream& body = CDataStream(SER_NETWORK, PROTOCOL_VERSION)) { request.SetError(nError); - CDataStream ssResponse(SER_NETWORK, pFrom->GetSendVersion(), request, body); - connman.PushMessage(pFrom, CNetMsgMaker(pFrom->GetSendVersion()).Make(NetMsgType::QDATA, ssResponse)); + CDataStream ssResponse(SER_NETWORK, pfrom.GetSendVersion(), request, body); + connman.PushMessage(&pfrom, CNetMsgMaker(pfrom.GetSendVersion()).Make(NetMsgType::QDATA, ssResponse)); }; { LOCK2(cs_main, cs_data_requests); CQuorumDataRequestKey key; - key.proRegTx = pFrom->GetVerifiedProRegTxHash(); + key.proRegTx = pfrom.GetVerifiedProRegTxHash(); key.flag = false; key.quorumHash = request.GetQuorumHash(); key.llmqType = request.GetLLMQType(); @@ -666,7 +666,7 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C return; } - CDataStream ssResponseData(SER_NETWORK, pFrom->GetSendVersion()); + CDataStream ssResponseData(SER_NETWORK, pfrom.GetSendVersion()); // Check if request wants QUORUM_VERIFICATION_VECTOR data if (request.GetDataMask() & CQuorumDataRequest::QUORUM_VERIFICATION_VECTOR) { @@ -701,7 +701,7 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C } if (msg_type == NetMsgType::QDATA) { - if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || pFrom == nullptr || (pFrom->GetVerifiedProRegTxHash().IsNull() && !pFrom->qwatch)) { + if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) { errorHandler("Not a verified masternode or a qwatch connection"); return; } @@ -712,7 +712,7 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C { LOCK2(cs_main, cs_data_requests); CQuorumDataRequestKey key; - key.proRegTx = pFrom->GetVerifiedProRegTxHash(); + key.proRegTx = pfrom.GetVerifiedProRegTxHash(); key.flag = true; key.quorumHash = request.GetQuorumHash(); key.llmqType = request.GetLLMQType(); diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 98e16e037b..4ac9e4060f 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -232,11 +232,11 @@ public: void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload) const; - void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv); static bool HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockProcessor& quorum_block_processor, const uint256& quorumHash); - bool RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash = uint256()) const; + bool RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, const uint256& proTxHash = uint256()) const; // all these methods will lock cs_main for a short period of time CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256& quorumHash) const; diff --git a/src/llmq/signing.cpp b/src/llmq/signing.cpp index 8421a69644..6c90897771 100644 --- a/src/llmq/signing.cpp +++ b/src/llmq/signing.cpp @@ -557,7 +557,7 @@ bool CSigningManager::GetRecoveredSigForGetData(const uint256& hash, CRecoveredS return true; } -void CSigningManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) +void CSigningManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) { if (msg_type == NetMsgType::QSIGREC) { auto recoveredSig = std::make_shared(); @@ -566,18 +566,18 @@ void CSigningManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, } } -void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const std::shared_ptr& recoveredSig) +void CSigningManager::ProcessMessageRecoveredSig(CNode& pfrom, const std::shared_ptr& recoveredSig) { { LOCK(cs_main); - EraseObjectRequest(pfrom->GetId(), CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig->GetHash())); + EraseObjectRequest(pfrom.GetId(), CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig->GetHash())); } bool ban = false; if (!PreVerifyRecoveredSig(qman, *recoveredSig, ban)) { if (ban) { LOCK(cs_main); - Misbehaving(pfrom->GetId(), 100); + Misbehaving(pfrom.GetId(), 100); } return; } @@ -589,16 +589,16 @@ void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const std::shared } LogPrint(BCLog::LLMQ, "CSigningManager::%s -- signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__, - recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom->GetId()); + recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom.GetId()); LOCK(cs); if (pendingReconstructedRecoveredSigs.count(recoveredSig->GetHash())) { // no need to perform full verification LogPrint(BCLog::LLMQ, "CSigningManager::%s -- already pending reconstructed sig, signHash=%s, id=%s, msgHash=%s, node=%d\n", __func__, - recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom->GetId()); + recoveredSig->buildSignHash().ToString(), recoveredSig->getId().ToString(), recoveredSig->getMsgHash().ToString(), pfrom.GetId()); return; } - pendingRecoveredSigs[pfrom->GetId()].emplace_back(recoveredSig); + pendingRecoveredSigs[pfrom.GetId()].emplace_back(recoveredSig); } bool CSigningManager::PreVerifyRecoveredSig(const CQuorumManager& quorum_manager, const CRecoveredSig& recoveredSig, bool& retBan) diff --git a/src/llmq/signing.h b/src/llmq/signing.h index 58d96afa20..e5e5d08a35 100644 --- a/src/llmq/signing.h +++ b/src/llmq/signing.h @@ -184,7 +184,7 @@ public: bool AlreadyHave(const CInv& inv) const; bool GetRecoveredSigForGetData(const uint256& hash, CRecoveredSig& ret) const; - void ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStream& vRecv); + void ProcessMessage(CNode& pnode, const std::string& msg_type, CDataStream& vRecv); // This is called when a recovered signature was was reconstructed from another P2P message and is known to be valid // This is the case for example when a signature appears as part of InstantSend or ChainLocks @@ -197,7 +197,7 @@ public: void TruncateRecoveredSig(Consensus::LLMQType llmqType, const uint256& id); private: - void ProcessMessageRecoveredSig(CNode* pfrom, const std::shared_ptr& recoveredSig); + void ProcessMessageRecoveredSig(CNode& pfrom, const std::shared_ptr& recoveredSig); static bool PreVerifyRecoveredSig(const CQuorumManager& quorum_manager, const CRecoveredSig& recoveredSig, bool& retBan); void CollectPendingRecoveredSigsToVerify(size_t maxUniqueSessions, diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index ded7db3f3e..1ceb50ec90 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -212,7 +212,7 @@ void CSigSharesManager::InterruptWorkerThread() workInterrupt(); } -void CSigSharesManager::ProcessMessage(const CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, const CSporkManager& sporkManager) +void CSigSharesManager::ProcessMessage(const CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, const CSporkManager& sporkManager) { // non-masternodes are not interested in sigshares if (!fMasternodeMode || WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash.IsNull())) { @@ -224,13 +224,13 @@ void CSigSharesManager::ProcessMessage(const CNode* pfrom, const std::string& ms vRecv >> receivedSigShares; if (receivedSigShares.size() > MAX_MSGS_SIG_SHARES) { - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sigs in QSIGSHARE message. cnt=%d, max=%d, node=%d\n", __func__, receivedSigShares.size(), MAX_MSGS_SIG_SHARES, pfrom->GetId()); - BanNode(pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sigs in QSIGSHARE message. cnt=%d, max=%d, node=%d\n", __func__, receivedSigShares.size(), MAX_MSGS_SIG_SHARES, pfrom.GetId()); + BanNode(pfrom.GetId()); return; } for (const auto& sigShare : receivedSigShares) { - ProcessMessageSigShare(pfrom->GetId(), sigShare); + ProcessMessageSigShare(pfrom.GetId(), sigShare); } } @@ -238,39 +238,39 @@ void CSigSharesManager::ProcessMessage(const CNode* pfrom, const std::string& ms std::vector msgs; vRecv >> msgs; if (msgs.size() > MAX_MSGS_CNT_QSIGSESANN) { - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many announcements in QSIGSESANN message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QSIGSESANN, pfrom->GetId()); - BanNode(pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many announcements in QSIGSESANN message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QSIGSESANN, pfrom.GetId()); + BanNode(pfrom.GetId()); return; } if (!ranges::all_of(msgs, [this, &pfrom](const auto& ann){ return ProcessMessageSigSesAnn(pfrom, ann); })) { - BanNode(pfrom->GetId()); + BanNode(pfrom.GetId()); return; } } else if (msg_type == NetMsgType::QSIGSHARESINV) { std::vector msgs; vRecv >> msgs; if (msgs.size() > MAX_MSGS_CNT_QSIGSHARESINV) { - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many invs in QSIGSHARESINV message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QSIGSHARESINV, pfrom->GetId()); - BanNode(pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many invs in QSIGSHARESINV message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QSIGSHARESINV, pfrom.GetId()); + BanNode(pfrom.GetId()); return; } if (!ranges::all_of(msgs, [this, &pfrom](const auto& inv){ return ProcessMessageSigSharesInv(pfrom, inv); })) { - BanNode(pfrom->GetId()); + BanNode(pfrom.GetId()); return; } } else if (msg_type == NetMsgType::QGETSIGSHARES) { std::vector msgs; vRecv >> msgs; if (msgs.size() > MAX_MSGS_CNT_QGETSIGSHARES) { - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many invs in QGETSIGSHARES message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QGETSIGSHARES, pfrom->GetId()); - BanNode(pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many invs in QGETSIGSHARES message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_CNT_QGETSIGSHARES, pfrom.GetId()); + BanNode(pfrom.GetId()); return; } if (!ranges::all_of(msgs, [this, &pfrom](const auto& inv){ return ProcessMessageGetSigShares(pfrom, inv); })) { - BanNode(pfrom->GetId()); + BanNode(pfrom.GetId()); return; } } else if (msg_type == NetMsgType::QBSIGSHARES) { @@ -281,19 +281,19 @@ void CSigSharesManager::ProcessMessage(const CNode* pfrom, const std::string& ms totalSigsCount += bs.sigShares.size(); } if (totalSigsCount > MAX_MSGS_TOTAL_BATCHED_SIGS) { - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sigs in QBSIGSHARES message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_TOTAL_BATCHED_SIGS, pfrom->GetId()); - BanNode(pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sigs in QBSIGSHARES message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_TOTAL_BATCHED_SIGS, pfrom.GetId()); + BanNode(pfrom.GetId()); return; } if (!ranges::all_of(msgs, [this, &pfrom](const auto& bs){ return ProcessMessageBatchedSigShares(pfrom, bs); })) { - BanNode(pfrom->GetId()); + BanNode(pfrom.GetId()); return; } } } -bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode* pfrom, const CSigSesAnn& ann) +bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode& pfrom, const CSigSesAnn& ann) { auto llmqType = ann.getLlmqType(); if (!Params().HasLLMQ(llmqType)) { @@ -303,18 +303,18 @@ bool CSigSharesManager::ProcessMessageSigSesAnn(const CNode* pfrom, const CSigSe return false; } - LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- ann={%s}, node=%d\n", __func__, ann.ToString(), pfrom->GetId()); + LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- ann={%s}, node=%d\n", __func__, ann.ToString(), pfrom.GetId()); auto quorum = qman.GetQuorum(llmqType, ann.getQuorumHash()); if (!quorum) { // TODO should we ban here? LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- quorum %s not found, node=%d\n", __func__, - ann.getQuorumHash().ToString(), pfrom->GetId()); + ann.getQuorumHash().ToString(), pfrom.GetId()); return true; // let's still try other announcements from the same message } LOCK(cs); - auto& nodeState = nodeStates[pfrom->GetId()]; + auto& nodeState = nodeStates[pfrom.GetId()]; auto& session = nodeState.GetOrCreateSessionFromAnn(ann); nodeState.sessionByRecvId.erase(session.recvSessionId); nodeState.sessionByRecvId.erase(ann.getSessionId()); @@ -330,10 +330,10 @@ bool CSigSharesManager::VerifySigSharesInv(Consensus::LLMQType llmqType, const C return inv.inv.size() == size_t(GetLLMQParams(llmqType).size); } -bool CSigSharesManager::ProcessMessageSigSharesInv(const CNode* pfrom, const CSigSharesInv& inv) +bool CSigSharesManager::ProcessMessageSigSharesInv(const CNode& pfrom, const CSigSharesInv& inv) { CSigSharesNodeState::SessionInfo sessionInfo; - if (!GetSessionInfoByRecvId(pfrom->GetId(), inv.sessionId, sessionInfo)) { + if (!GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId, sessionInfo)) { return true; } @@ -347,17 +347,17 @@ bool CSigSharesManager::ProcessMessageSigSharesInv(const CNode* pfrom, const CSi } LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n", __func__, - sessionInfo.signHash.ToString(), inv.ToString(), pfrom->GetId()); + sessionInfo.signHash.ToString(), inv.ToString(), pfrom.GetId()); if (!sessionInfo.quorum->HasVerificationVector()) { // TODO we should allow to ask other nodes for the quorum vvec if we missed it in the DKG LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- we don't have the quorum vvec for %s, not requesting sig shares. node=%d\n", __func__, - sessionInfo.quorumHash.ToString(), pfrom->GetId()); + sessionInfo.quorumHash.ToString(), pfrom.GetId()); return true; } LOCK(cs); - auto& nodeState = nodeStates[pfrom->GetId()]; + auto& nodeState = nodeStates[pfrom.GetId()]; auto* session = nodeState.GetSessionByRecvId(inv.sessionId); if (session == nullptr) { return true; @@ -367,10 +367,10 @@ bool CSigSharesManager::ProcessMessageSigSharesInv(const CNode* pfrom, const CSi return true; } -bool CSigSharesManager::ProcessMessageGetSigShares(const CNode* pfrom, const CSigSharesInv& inv) +bool CSigSharesManager::ProcessMessageGetSigShares(const CNode& pfrom, const CSigSharesInv& inv) { CSigSharesNodeState::SessionInfo sessionInfo; - if (!GetSessionInfoByRecvId(pfrom->GetId(), inv.sessionId, sessionInfo)) { + if (!GetSessionInfoByRecvId(pfrom.GetId(), inv.sessionId, sessionInfo)) { return true; } @@ -384,10 +384,10 @@ bool CSigSharesManager::ProcessMessageGetSigShares(const CNode* pfrom, const CSi } LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signHash=%s, inv={%s}, node=%d\n", __func__, - sessionInfo.signHash.ToString(), inv.ToString(), pfrom->GetId()); + sessionInfo.signHash.ToString(), inv.ToString(), pfrom.GetId()); LOCK(cs); - auto& nodeState = nodeStates[pfrom->GetId()]; + auto& nodeState = nodeStates[pfrom.GetId()]; auto* session = nodeState.GetSessionByRecvId(inv.sessionId); if (session == nullptr) { return true; @@ -397,10 +397,10 @@ bool CSigSharesManager::ProcessMessageGetSigShares(const CNode* pfrom, const CSi return true; } -bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode* pfrom, const CBatchedSigShares& batchedSigShares) +bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode& pfrom, const CBatchedSigShares& batchedSigShares) { CSigSharesNodeState::SessionInfo sessionInfo; - if (!GetSessionInfoByRecvId(pfrom->GetId(), batchedSigShares.sessionId, sessionInfo)) { + if (!GetSessionInfoByRecvId(pfrom.GetId(), batchedSigShares.sessionId, sessionInfo)) { return true; } @@ -413,7 +413,7 @@ bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode* pfrom, const { LOCK(cs); - auto& nodeState = nodeStates[pfrom->GetId()]; + auto& nodeState = nodeStates[pfrom.GetId()]; for (const auto& sigSharetmp : batchedSigShares.sigShares) { CSigShare sigShare = RebuildSigShare(sessionInfo, sigSharetmp); @@ -437,14 +437,14 @@ bool CSigSharesManager::ProcessMessageBatchedSigShares(const CNode* pfrom, const } LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- signHash=%s, shares=%d, new=%d, inv={%s}, node=%d\n", __func__, - sessionInfo.signHash.ToString(), batchedSigShares.sigShares.size(), sigSharesToProcess.size(), batchedSigShares.ToInvString(), pfrom->GetId()); + sessionInfo.signHash.ToString(), batchedSigShares.sigShares.size(), sigSharesToProcess.size(), batchedSigShares.ToInvString(), pfrom.GetId()); if (sigSharesToProcess.empty()) { return true; } LOCK(cs); - auto& nodeState = nodeStates[pfrom->GetId()]; + auto& nodeState = nodeStates[pfrom.GetId()]; for (const auto& s : sigSharesToProcess) { nodeState.pendingIncomingSigShares.Add(s.GetKey(), s); } diff --git a/src/llmq/signing_shares.h b/src/llmq/signing_shares.h index aaf9238e7f..b4c1ce0417 100644 --- a/src/llmq/signing_shares.h +++ b/src/llmq/signing_shares.h @@ -416,7 +416,7 @@ public: void UnregisterAsRecoveredSigsListener(); void InterruptWorkerThread(); - void ProcessMessage(const CNode* pnode, const std::string& msg_type, CDataStream& vRecv, const CSporkManager& sporkManager); + void ProcessMessage(const CNode& pnode, const std::string& msg_type, CDataStream& vRecv, const CSporkManager& sporkManager); void AsyncSign(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash); std::optional CreateSigShare(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash) const; @@ -428,10 +428,10 @@ public: private: // all of these return false when the currently processed message should be aborted (as each message actually contains multiple messages) - bool ProcessMessageSigSesAnn(const CNode* pfrom, const CSigSesAnn& ann); - bool ProcessMessageSigSharesInv(const CNode* pfrom, const CSigSharesInv& inv); - bool ProcessMessageGetSigShares(const CNode* pfrom, const CSigSharesInv& inv); - bool ProcessMessageBatchedSigShares(const CNode* pfrom, const CBatchedSigShares& batchedSigShares); + bool ProcessMessageSigSesAnn(const CNode& pfrom, const CSigSesAnn& ann); + bool ProcessMessageSigSharesInv(const CNode& pfrom, const CSigSharesInv& inv); + bool ProcessMessageGetSigShares(const CNode& pfrom, const CSigSharesInv& inv); + bool ProcessMessageBatchedSigShares(const CNode& pfrom, const CBatchedSigShares& batchedSigShares); void ProcessMessageSigShare(NodeId fromId, const CSigShare& sigShare); static bool VerifySigSharesInv(Consensus::LLMQType llmqType, const CSigSharesInv& inv); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index fd6597e294..b91a966d7b 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4122,12 +4122,12 @@ void PeerLogicValidation::ProcessMessage( governance->ProcessMessage(pfrom, msg_type, vRecv, m_connman); CMNAuth::ProcessMessage(pfrom, msg_type, vRecv, m_connman); m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv); - m_llmq_ctx->qdkgsman->ProcessMessage(&pfrom, *m_llmq_ctx->qman, msg_type, vRecv); - m_llmq_ctx->qman->ProcessMessage(&pfrom, msg_type, vRecv); - m_llmq_ctx->shareman->ProcessMessage(&pfrom, msg_type, vRecv, *sporkManager); - m_llmq_ctx->sigman->ProcessMessage(&pfrom, msg_type, vRecv); - m_llmq_ctx->clhandler->ProcessMessage(&pfrom, msg_type, vRecv); - m_llmq_ctx->isman->ProcessMessage(&pfrom, msg_type, vRecv); + m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, *m_llmq_ctx->qman, msg_type, vRecv); + m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv); + m_llmq_ctx->shareman->ProcessMessage(pfrom, msg_type, vRecv, *sporkManager); + m_llmq_ctx->sigman->ProcessMessage(pfrom, msg_type, vRecv); + m_llmq_ctx->clhandler->ProcessMessage(pfrom, msg_type, vRecv); + m_llmq_ctx->isman->ProcessMessage(pfrom, msg_type, vRecv); return; }