@@ -750,7 +750,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
750
750
}
751
751
752
752
// Requires cs_main.
753
- void Misbehaving (NodeId pnode, int howmuch)
753
+ void Misbehaving (NodeId pnode, int howmuch, const std::string& message )
754
754
{
755
755
if (howmuch == 0 )
756
756
return ;
@@ -761,12 +761,13 @@ void Misbehaving(NodeId pnode, int howmuch)
761
761
762
762
state->nMisbehavior += howmuch;
763
763
int banscore = gArgs .GetArg (" -banscore" , DEFAULT_BANSCORE_THRESHOLD);
764
+ std::string message_prefixed = message.empty () ? " " : (" : " + message);
764
765
if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore)
765
766
{
766
- LogPrintf ( " %s: %s peer=%d (%d -> %d) BAN THRESHOLD EXCEEDED\n " , __func__, state->name , pnode, state->nMisbehavior -howmuch, state->nMisbehavior );
767
+ LogPrint (BCLog::NET, " %s: %s peer=%d (%d -> %d) BAN THRESHOLD EXCEEDED%s \n " , __func__, state->name , pnode, state->nMisbehavior -howmuch, state->nMisbehavior , message_prefixed );
767
768
state->fShouldBan = true ;
768
769
} else
769
- LogPrintf ( " %s: %s peer=%d (%d -> %d)\n " , __func__, state->name , pnode, state->nMisbehavior -howmuch, state->nMisbehavior );
770
+ LogPrint (BCLog::NET, " %s: %s peer=%d (%d -> %d)%s \n " , __func__, state->name , pnode, state->nMisbehavior -howmuch, state->nMisbehavior , message_prefixed );
770
771
}
771
772
772
773
@@ -1260,8 +1261,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac
1260
1261
for (size_t i = 0 ; i < req.indexes .size (); i++) {
1261
1262
if (req.indexes [i] >= block.vtx .size ()) {
1262
1263
LOCK (cs_main);
1263
- Misbehaving (pfrom->GetId (), 100 );
1264
- LogPrintf (" Peer %d sent us a getblocktxn with out-of-bounds tx indices" , pfrom->GetId ());
1264
+ Misbehaving (pfrom->GetId (), 100 , strprintf (" Peer %d sent us a getblocktxn with out-of-bounds tx indices" , pfrom->GetId ()));
1265
1265
return ;
1266
1266
}
1267
1267
resp.txn [i] = block.vtx [req.indexes [i]];
@@ -1318,8 +1318,8 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1318
1318
uint256 hashLastBlock;
1319
1319
for (const CBlockHeader& header : headers) {
1320
1320
if (!hashLastBlock.IsNull () && header.hashPrevBlock != hashLastBlock) {
1321
- Misbehaving (pfrom->GetId (), 20 );
1322
- return error ( " non-continuous headers sequence " ) ;
1321
+ Misbehaving (pfrom->GetId (), 20 , " non-continuous headers sequence " );
1322
+ return false ;
1323
1323
}
1324
1324
hashLastBlock = header.GetHash ();
1325
1325
}
@@ -1338,7 +1338,9 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1338
1338
if (state.IsInvalid (nDoS)) {
1339
1339
LOCK (cs_main);
1340
1340
if (nDoS > 0 ) {
1341
- Misbehaving (pfrom->GetId (), nDoS);
1341
+ Misbehaving (pfrom->GetId (), nDoS, " invalid header received" );
1342
+ } else {
1343
+ LogPrint (BCLog::NET, " peer=%d: invalid header received\n " , pfrom->GetId ());
1342
1344
}
1343
1345
if (punish_duplicate_invalid && mapBlockIndex.find (first_invalid_header.GetHash ()) != mapBlockIndex.end ()) {
1344
1346
// Goal: don't allow outbound peers to use up our outbound
@@ -1374,7 +1376,7 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1374
1376
// etc), and not just the duplicate-invalid case.
1375
1377
pfrom->fDisconnect = true ;
1376
1378
}
1377
- return error ( " invalid header received " ) ;
1379
+ return false ;
1378
1380
}
1379
1381
}
1380
1382
@@ -1783,8 +1785,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1783
1785
if (vAddr.size () > 1000 )
1784
1786
{
1785
1787
LOCK (cs_main);
1786
- Misbehaving (pfrom->GetId (), 20 );
1787
- return error ( " message addr size() = %u " , vAddr. size ()) ;
1788
+ Misbehaving (pfrom->GetId (), 20 , strprintf ( " message addr size() = %u " , vAddr. size ()) );
1789
+ return false ;
1788
1790
}
1789
1791
1790
1792
// Store the new addresses
@@ -1859,8 +1861,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1859
1861
if (vInv.size () > MAX_INV_SZ)
1860
1862
{
1861
1863
LOCK (cs_main);
1862
- Misbehaving (pfrom->GetId (), 20 );
1863
- return error ( " message inv size() = %u " , vInv. size ()) ;
1864
+ Misbehaving (pfrom->GetId (), 20 , strprintf ( " message inv size() = %u " , vInv. size ()) );
1865
+ return false ;
1864
1866
}
1865
1867
1866
1868
bool fBlocksOnly = !fRelayTxes ;
@@ -1920,8 +1922,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1920
1922
if (vInv.size () > MAX_INV_SZ)
1921
1923
{
1922
1924
LOCK (cs_main);
1923
- Misbehaving (pfrom->GetId (), 20 );
1924
- return error ( " message getdata size() = %u " , vInv. size ()) ;
1925
+ Misbehaving (pfrom->GetId (), 20 , strprintf ( " message getdata size() = %u " , vInv. size ()) );
1926
+ return false ;
1925
1927
}
1926
1928
1927
1929
LogPrint (BCLog::NET, " received getdata (%u invsz) peer=%d\n " , vInv.size (), pfrom->GetId ());
@@ -2323,9 +2325,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2323
2325
int nDoS;
2324
2326
if (state.IsInvalid (nDoS)) {
2325
2327
if (nDoS > 0 ) {
2326
- LogPrintf (" Peer %d sent us invalid header via cmpctblock\n " , pfrom->GetId ());
2327
2328
LOCK (cs_main);
2328
- Misbehaving (pfrom->GetId (), nDoS);
2329
+ Misbehaving (pfrom->GetId (), nDoS, strprintf ( " Peer %d sent us invalid header via cmpctblock \n " , pfrom-> GetId ()) );
2329
2330
} else {
2330
2331
LogPrint (BCLog::NET, " Peer %d sent us invalid header via cmpctblock\n " , pfrom->GetId ());
2331
2332
}
@@ -2411,8 +2412,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2411
2412
ReadStatus status = partialBlock.InitData (cmpctblock, vExtraTxnForCompact);
2412
2413
if (status == READ_STATUS_INVALID) {
2413
2414
MarkBlockAsReceived (pindex->GetBlockHash ()); // Reset in-flight state in case of whitelist
2414
- Misbehaving (pfrom->GetId (), 100 );
2415
- LogPrintf (" Peer %d sent us invalid compact block\n " , pfrom->GetId ());
2415
+ Misbehaving (pfrom->GetId (), 100 , strprintf (" Peer %d sent us invalid compact block\n " , pfrom->GetId ()));
2416
2416
return true ;
2417
2417
} else if (status == READ_STATUS_FAILED) {
2418
2418
// Duplicate txindexes, the block is now in-flight, so just request it
@@ -2539,8 +2539,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2539
2539
ReadStatus status = partialBlock.FillBlock (*pblock, resp.txn );
2540
2540
if (status == READ_STATUS_INVALID) {
2541
2541
MarkBlockAsReceived (resp.blockhash ); // Reset in-flight state in case of whitelist
2542
- Misbehaving (pfrom->GetId (), 100 );
2543
- LogPrintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->GetId ());
2542
+ Misbehaving (pfrom->GetId (), 100 , strprintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->GetId ()));
2544
2543
return true ;
2545
2544
} else if (status == READ_STATUS_FAILED) {
2546
2545
// Might have collided, fall back to getdata now :(
@@ -2602,8 +2601,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2602
2601
unsigned int nCount = ReadCompactSize (vRecv);
2603
2602
if (nCount > MAX_HEADERS_RESULTS) {
2604
2603
LOCK (cs_main);
2605
- Misbehaving (pfrom->GetId (), 20 );
2606
- return error ( " headers message size = %u " , nCount) ;
2604
+ Misbehaving (pfrom->GetId (), 20 , strprintf ( " headers message size = %u " , nCount) );
2605
+ return false ;
2607
2606
}
2608
2607
headers.resize (nCount);
2609
2608
for (unsigned int n = 0 ; n < nCount; n++) {
0 commit comments