diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index b6dd7076b2e4..d8cc535ef83c 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -1018,11 +1018,10 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector& } bool fAsked = false; for (const auto& pnode : vNodesCopy) { - // Only use regular peers, don't try to ask from outbound "masternode" connections - - // they stay connected for a short period of time and it's possible that we won't get everything we should. - // Only use outbound connections - inbound connection could be a "masternode" connection + // Don't try to sync any data from outbound non-relay "masternode" connections. + // Inbound connection this early is most likely a "masternode" connection // initiated from another node, so skip it too. - if (pnode->m_masternode_connection || (fMasternodeMode && pnode->fInbound)) continue; + if (!pnode->CanRelay() || (fMasternodeMode && pnode->fInbound)) continue; // only use up to date peers if (pnode->nVersion < MIN_GOVERNANCE_PEER_PROTO_VERSION) continue; // stop early to prevent setAskFor overflow @@ -1222,7 +1221,7 @@ void CGovernanceManager::RequestOrphanObjects(CConnman& connman) LogPrint(BCLog::GOBJECT, "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashesFiltered.size()); for (const uint256& nHash : vecHashesFiltered) { for (CNode* pnode : vNodesCopy) { - if (pnode->m_masternode_connection) { + if (!pnode->CanRelay()) { continue; } RequestGovernanceObject(pnode, nHash, connman); diff --git a/src/masternode/masternode-sync.cpp b/src/masternode/masternode-sync.cpp index ea26400c413f..07e1713d6ac6 100644 --- a/src/masternode/masternode-sync.cpp +++ b/src/masternode/masternode-sync.cpp @@ -142,11 +142,10 @@ void CMasternodeSync::ProcessTick(CConnman& connman) { CNetMsgMaker msgMaker(pnode->GetSendVersion()); - // Don't try to sync any data from outbound "masternode" connections - - // they are temporary and should be considered unreliable for a sync process. + // Don't try to sync any data from outbound non-relay "masternode" connections. // Inbound connection this early is most likely a "masternode" connection // initiated from another node, so skip it too. - if(pnode->m_masternode_connection || (fMasternodeMode && pnode->fInbound)) continue; + if (!pnode->CanRelay() || (fMasternodeMode && pnode->fInbound)) continue; // QUICK MODE (REGTEST ONLY!) if(Params().NetworkIDString() == CBaseChainParams::REGTEST) diff --git a/src/net.cpp b/src/net.cpp index c880b2eb52e9..9a8138636e9c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3688,29 +3688,23 @@ void CConnman::RelayTransaction(const CTransaction& tx) nInv = MSG_DSTX; } CInv inv(nInv, hash); - LOCK(cs_vNodes); - for (CNode* pnode : vNodes) - { - if (pnode->m_masternode_connection) - continue; - pnode->PushInventory(inv); - } + RelayInv(inv); } -void CConnman::RelayInv(CInv &inv, const int minProtoVersion, bool fAllowMasternodeConnections) { +void CConnman::RelayInv(CInv &inv, const int minProtoVersion) { LOCK(cs_vNodes); for (const auto& pnode : vNodes) { - if (pnode->nVersion < minProtoVersion || (pnode->m_masternode_connection && !fAllowMasternodeConnections)) + if (pnode->nVersion < minProtoVersion || !pnode->CanRelay()) continue; pnode->PushInventory(inv); } } -void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion, bool fAllowMasternodeConnections) +void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion) { LOCK(cs_vNodes); for (const auto& pnode : vNodes) { - if (pnode->nVersion < minProtoVersion || (pnode->m_masternode_connection && !fAllowMasternodeConnections)) + if (pnode->nVersion < minProtoVersion || !pnode->CanRelay()) continue; { LOCK(pnode->cs_filter); @@ -3721,11 +3715,11 @@ void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const } } -void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion, bool fAllowMasternodeConnections) +void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion) { LOCK(cs_vNodes); for (const auto& pnode : vNodes) { - if (pnode->nVersion < minProtoVersion || (pnode->m_masternode_connection && !fAllowMasternodeConnections)) + if (pnode->nVersion < minProtoVersion || !pnode->CanRelay()) continue; { LOCK(pnode->cs_filter); diff --git a/src/net.h b/src/net.h index e725ded94c62..36290537cc3e 100644 --- a/src/net.h +++ b/src/net.h @@ -362,10 +362,10 @@ friend class CNode; void ReleaseNodeVector(const std::vector& vecNodes); void RelayTransaction(const CTransaction& tx); - void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false); - void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false); + void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION); + void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION); // This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters - void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false); + void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION); // Addrman functions size_t GetAddressCount() const; @@ -1128,6 +1128,8 @@ class CNode void MaybeSetAddrName(const std::string& addrNameIn); std::string GetLogString() const; + + bool CanRelay() const { return !m_masternode_connection || m_masternode_iqr_connection; } }; class CExplicitNetCleanup diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 90f71d848b1c..5a4b46596554 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1249,7 +1249,9 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB } // Relay inventory, but don't relay old inventory during initial block download. connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) { - if (pnode->m_masternode_connection) return; + if (!pnode->CanRelay()) { + return; + } if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) { for (const uint256& hash : reverse_iterate(vHashes)) { pnode->PushBlockHash(hash); @@ -2358,7 +2360,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr // nodes) connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDHEADERS)); - if (!pfrom->m_masternode_connection) { + if (pfrom->CanRelay()) { // Tell our peer we are willing to provide version-1 cmpctblocks // However, we do not request new block announcements using // cmpctblock messages. @@ -2652,7 +2654,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); break; } - if (!pfrom->m_masternode_connection) { + if (pfrom->CanRelay()) { pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); } if (--nLimit <= 0) @@ -3984,7 +3986,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto) if (pindexBestHeader == nullptr) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && !pto->m_masternode_connection) { + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->CanRelay()) { // Only actively request headers from a single peer, unless we're close to end of initial download. if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) { state.fSyncStarted = true; @@ -4023,7 +4025,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto) // // Try sending block announcements via headers // - if (!pto->m_masternode_connection) { + if (pto->CanRelay()) { // If we have less than MAX_BLOCKS_TO_ANNOUNCE in our // list of block hashes we're relaying, and our peer wants // headers announcements, then find the first header @@ -4381,7 +4383,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto) // Message: getdata (blocks) // std::vector vGetData; - if (!pto->fClient && !pto->m_masternode_connection && ((fFetch && !pto->m_limited_node) || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { + if (!pto->fClient && pto->CanRelay() && ((fFetch && !pto->m_limited_node) || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { std::vector vToDownload; NodeId staller = -1; FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams);