Skip to content

Commit 3182514

Browse files
committed
Don't relay anything to fMasternode connections
This reduces traffic on these connections to PS and DKG/LLMQ traffic only.
1 parent f4f57fb commit 3182514

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/llmq/quorums_signing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re
713713

714714
CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash());
715715
g_connman->ForEachNode([&](CNode* pnode) {
716-
if (pnode->nVersion >= LLMQS_PROTO_VERSION && pnode->fSendRecSigs) {
716+
if (pnode->nVersion >= LLMQS_PROTO_VERSION && pnode->fSendRecSigs && !pnode->fMasternode) {
717717
pnode->PushInventory(inv);
718718
}
719719
});

src/net.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,22 +2944,26 @@ void CConnman::RelayTransaction(const CTransaction& tx)
29442944
LOCK(cs_vNodes);
29452945
for (CNode* pnode : vNodes)
29462946
{
2947+
if (pnode->fMasternode)
2948+
continue;
29472949
pnode->PushInventory(inv);
29482950
}
29492951
}
29502952

2951-
void CConnman::RelayInv(CInv &inv, const int minProtoVersion) {
2953+
void CConnman::RelayInv(CInv &inv, const int minProtoVersion, bool fAllowMasternodeConnections) {
29522954
LOCK(cs_vNodes);
2953-
for (const auto& pnode : vNodes)
2954-
if(pnode->nVersion >= minProtoVersion)
2955-
pnode->PushInventory(inv);
2955+
for (const auto& pnode : vNodes) {
2956+
if (pnode->nVersion < minProtoVersion || (pnode->fMasternode && !fAllowMasternodeConnections))
2957+
continue;
2958+
pnode->PushInventory(inv);
2959+
}
29562960
}
29572961

2958-
void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
2962+
void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion, bool fAllowMasternodeConnections)
29592963
{
29602964
LOCK(cs_vNodes);
29612965
for (const auto& pnode : vNodes) {
2962-
if(pnode->nVersion < minProtoVersion)
2966+
if (pnode->nVersion < minProtoVersion || (pnode->fMasternode && !fAllowMasternodeConnections))
29632967
continue;
29642968
{
29652969
LOCK(pnode->cs_filter);
@@ -2970,11 +2974,12 @@ void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const
29702974
}
29712975
}
29722976

2973-
void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion)
2977+
void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion, bool fAllowMasternodeConnections)
29742978
{
29752979
LOCK(cs_vNodes);
29762980
for (const auto& pnode : vNodes) {
2977-
if(pnode->nVersion < minProtoVersion) continue;
2981+
if (pnode->nVersion < minProtoVersion || (pnode->fMasternode && !fAllowMasternodeConnections))
2982+
continue;
29782983
{
29792984
LOCK(pnode->cs_filter);
29802985
if(pnode->pfilter && !pnode->pfilter->contains(relatedTxHash)) continue;

src/net.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ class CConnman
353353
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);
354354

355355
void RelayTransaction(const CTransaction& tx);
356-
void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
357-
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
356+
void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
357+
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
358358
// This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters
359-
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
359+
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
360360
void RemoveAskFor(const uint256& hash);
361361

362362
// Addrman functions

src/net_processing.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
955955
}
956956
// Relay inventory, but don't relay old inventory during initial block download.
957957
connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
958+
if (pnode->fMasternode) return;
958959
if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
959960
for (const uint256& hash : reverse_iterate(vHashes)) {
960961
pnode->PushBlockHash(hash);
@@ -1875,6 +1876,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
18751876
vRecv >> fOtherMasternode;
18761877
if (pfrom->fInbound) {
18771878
pfrom->fMasternode = fOtherMasternode;
1879+
if (fOtherMasternode) {
1880+
LogPrint(BCLog::NET, "peer=%d is an inbound masternode connection, not relaying anything to it\n", pfrom->GetId());
1881+
if (!fMasternodeMode) {
1882+
LogPrint(BCLog::NET, "but we're not a masternode, disconnecting\n");
1883+
pfrom->fDisconnect = true;
1884+
return true;
1885+
}
1886+
}
18781887
}
18791888
}
18801889
// Disconnect if we connected to ourself
@@ -2316,7 +2325,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
23162325
LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
23172326
break;
23182327
}
2319-
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
2328+
if (!pfrom->fMasternode) {
2329+
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
2330+
}
23202331
if (--nLimit <= 0)
23212332
{
23222333
// When this block is requested, we'll send an inv that'll
@@ -3613,7 +3624,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
36133624
if (pindexBestHeader == nullptr)
36143625
pindexBestHeader = chainActive.Tip();
36153626
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.
3616-
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
3627+
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && !pto->fMasternode) {
36173628
// Only actively request headers from a single peer, unless we're close to end of initial download.
36183629
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) {
36193630
state.fSyncStarted = true;

0 commit comments

Comments
 (0)