Skip to content

Commit d15b3af

Browse files
committed
[net processing] Always supply debug message to Misbehaving()
Misbehaving() could optionally take a debug string for printing to the log file. Make this mandatory and always provide the string. A couple of additional minor changes: - remove the unnecessary forward declaration of Misbehaving() - don't include the nodeid or newline in the passed debug message. Misbehaving() adds these itself.
1 parent 634144a commit d15b3af

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ std::map<uint256, std::map<uint256, COrphanTx>::iterator> g_orphans_by_wtxid GUA
157157

158158
void EraseOrphansFor(NodeId peer);
159159

160-
/** Increase a node's misbehavior score. */
161-
void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="") EXCLUSIVE_LOCKS_REQUIRED(cs_main);
162-
163160
// Internal stuff
164161
namespace {
165162
/** Number of nodes with fSyncStarted. */
@@ -1799,7 +1796,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac
17991796
for (size_t i = 0; i < req.indexes.size(); i++) {
18001797
if (req.indexes[i] >= block.vtx.size()) {
18011798
LOCK(cs_main);
1802-
Misbehaving(pfrom.GetId(), 100, strprintf("Peer %d sent us a getblocktxn with out-of-bounds tx indices", pfrom.GetId()));
1799+
Misbehaving(pfrom.GetId(), 100, "getblocktxn with out-of-bounds tx indices");
18031800
return;
18041801
}
18051802
resp.txn[i] = block.vtx[req.indexes[i]];
@@ -1848,7 +1845,7 @@ static void ProcessHeadersMessage(CNode& pfrom, CConnman& connman, ChainstateMan
18481845
UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash());
18491846

18501847
if (nodestate->nUnconnectingHeaders % MAX_UNCONNECTING_HEADERS == 0) {
1851-
Misbehaving(pfrom.GetId(), 20);
1848+
Misbehaving(pfrom.GetId(), 20, strprintf("%d non-connecting headers", nodestate->nUnconnectingHeaders));
18521849
}
18531850
return;
18541851
}
@@ -2307,7 +2304,7 @@ void ProcessMessage(
23072304
if (pfrom.nVersion != 0)
23082305
{
23092306
LOCK(cs_main);
2310-
Misbehaving(pfrom.GetId(), 1);
2307+
Misbehaving(pfrom.GetId(), 1, "redundant version message");
23112308
return;
23122309
}
23132310

@@ -2468,7 +2465,7 @@ void ProcessMessage(
24682465
if (pfrom.nVersion == 0) {
24692466
// Must have a version message before anything else
24702467
LOCK(cs_main);
2471-
Misbehaving(pfrom.GetId(), 1);
2468+
Misbehaving(pfrom.GetId(), 1, "non-version message before version handshake");
24722469
return;
24732470
}
24742471

@@ -2535,7 +2532,7 @@ void ProcessMessage(
25352532
if (!pfrom.fSuccessfullyConnected) {
25362533
// Must have a verack message before anything else
25372534
LOCK(cs_main);
2538-
Misbehaving(pfrom.GetId(), 1);
2535+
Misbehaving(pfrom.GetId(), 1, "non-verack message before version handshake");
25392536
return;
25402537
}
25412538

@@ -3203,7 +3200,7 @@ void ProcessMessage(
32033200
ReadStatus status = partialBlock.InitData(cmpctblock, vExtraTxnForCompact);
32043201
if (status == READ_STATUS_INVALID) {
32053202
MarkBlockAsReceived(pindex->GetBlockHash()); // Reset in-flight state in case Misbehaving does not result in a disconnect
3206-
Misbehaving(pfrom.GetId(), 100, strprintf("Peer %d sent us invalid compact block\n", pfrom.GetId()));
3203+
Misbehaving(pfrom.GetId(), 100, "invalid compact block");
32073204
return;
32083205
} else if (status == READ_STATUS_FAILED) {
32093206
// Duplicate txindexes, the block is now in-flight, so just request it
@@ -3336,7 +3333,7 @@ void ProcessMessage(
33363333
ReadStatus status = partialBlock.FillBlock(*pblock, resp.txn);
33373334
if (status == READ_STATUS_INVALID) {
33383335
MarkBlockAsReceived(resp.blockhash); // Reset in-flight state in case Misbehaving does not result in a disconnect
3339-
Misbehaving(pfrom.GetId(), 100, strprintf("Peer %d sent us invalid compact block/non-matching block transactions\n", pfrom.GetId()));
3336+
Misbehaving(pfrom.GetId(), 100, "invalid compact block/non-matching block transactions");
33403337
return;
33413338
} else if (status == READ_STATUS_FAILED) {
33423339
// Might have collided, fall back to getdata now :(
@@ -3605,7 +3602,7 @@ void ProcessMessage(
36053602
{
36063603
// There is no excuse for sending a too-large filter
36073604
LOCK(cs_main);
3608-
Misbehaving(pfrom.GetId(), 100);
3605+
Misbehaving(pfrom.GetId(), 100, "too-large bloom filter");
36093606
}
36103607
else if (pfrom.m_tx_relay != nullptr)
36113608
{
@@ -3639,7 +3636,7 @@ void ProcessMessage(
36393636
}
36403637
if (bad) {
36413638
LOCK(cs_main);
3642-
Misbehaving(pfrom.GetId(), 100);
3639+
Misbehaving(pfrom.GetId(), 100, "bad filteradd message");
36433640
}
36443641
return;
36453642
}

0 commit comments

Comments
 (0)