Skip to content

Commit 3587f6a

Browse files
committed
Fix relay mechanism for whitelisted peers under blocks only mode.
Previously in blocks only mode all inv messages where type!=MSG_BLOCK would be rejected without regard for whitelisting or whitelistalwaysrelay. As such whitelisted peers would never send the transaction (which would be processed).
1 parent 776848a commit 3587f6a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,6 +4210,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42104210
return error("message inv size() = %u", vInv.size());
42114211
}
42124212

4213+
bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
4214+
4215+
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistalwaysrelay is true
4216+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY))
4217+
fBlocksOnly = false;
4218+
42134219
LOCK(cs_main);
42144220

42154221
std::vector<CInv> vToFetch;
@@ -4224,9 +4230,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42244230
bool fAlreadyHave = AlreadyHave(inv);
42254231
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
42264232

4227-
if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY))
4228-
pfrom->AskFor(inv);
4229-
42304233
if (inv.type == MSG_BLOCK) {
42314234
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
42324235
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
@@ -4250,6 +4253,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42504253
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id);
42514254
}
42524255
}
4256+
else
4257+
{
4258+
if (fBlocksOnly)
4259+
LogPrint("net", "peer sent inv %s in violation of protocol peer=%d\n", inv.ToString(), pfrom->id);
4260+
else if (!fAlreadyHave && !fImporting && !fReindex)
4261+
pfrom->AskFor(inv);
4262+
}
42534263

42544264
// Track requests for our stuff
42554265
GetMainSignals().Inventory(inv.hash);

0 commit comments

Comments
 (0)