@@ -4211,6 +4211,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4211
4211
return error (" message inv size() = %u" , vInv.size ());
4212
4212
}
4213
4213
4214
+ bool fBlocksOnly = GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY);
4215
+
4216
+ // Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistalwaysrelay is true
4217
+ if (pfrom->fWhitelisted && GetBoolArg (" -whitelistalwaysrelay" , DEFAULT_WHITELISTALWAYSRELAY))
4218
+ fBlocksOnly = false ;
4219
+
4214
4220
LOCK (cs_main);
4215
4221
4216
4222
std::vector<CInv> vToFetch;
@@ -4225,9 +4231,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4225
4231
bool fAlreadyHave = AlreadyHave (inv);
4226
4232
LogPrint (" net" , " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom->id );
4227
4233
4228
- if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY))
4229
- pfrom->AskFor (inv);
4230
-
4231
4234
if (inv.type == MSG_BLOCK) {
4232
4235
UpdateBlockAvailability (pfrom->GetId (), inv.hash );
4233
4236
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count (inv.hash )) {
@@ -4251,6 +4254,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4251
4254
LogPrint (" net" , " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->nHeight , inv.hash .ToString (), pfrom->id );
4252
4255
}
4253
4256
}
4257
+ else
4258
+ {
4259
+ if (fBlocksOnly )
4260
+ LogPrint (" net" , " transaction (%s) inv sent in violation of protocol peer=%d\n " , inv.hash .ToString (), pfrom->id );
4261
+ else if (!fAlreadyHave && !fImporting && !fReindex )
4262
+ pfrom->AskFor (inv);
4263
+ }
4254
4264
4255
4265
// Track requests for our stuff
4256
4266
GetMainSignals ().Inventory (inv.hash );
@@ -4375,6 +4385,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4375
4385
4376
4386
else if (strCommand == " tx" )
4377
4387
{
4388
+ // Stop processing the transaction early if
4389
+ // We are in blocks only mode and peer is either not whitelisted or whitelistalwaysrelay is off
4390
+ if (GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg (" -whitelistalwaysrelay" , DEFAULT_WHITELISTALWAYSRELAY)))
4391
+ {
4392
+ LogPrint (" net" , " transaction sent in violation of protocol peer=%d\n " , pfrom->id );
4393
+ return true ;
4394
+ }
4395
+
4378
4396
vector<uint256> vWorkQueue;
4379
4397
vector<uint256> vEraseQueue;
4380
4398
CTransaction tx;
0 commit comments