Skip to content

Commit a1a07cf

Browse files
committed
[validation] Fix peer punishment for bad blocks
Because the call to MaybePunishNode() in PeerLogicValidation::BlockChecked() only previously happened if the REJECT code was > 0 and < REJECT_INTERNAL, then there are cases were MaybePunishNode() can get called where it wasn't previously: - when AcceptBlockHeader() fails with CACHED_INVALID. - when AcceptBlockHeader() fails with BLOCK_MISSING_PREV. Note that BlockChecked() cannot fail with an 'internal' reject code. The only internal reject code was REJECT_HIGHFEE, which was only set in ATMP. This change restores the behaviour pre-commit 5d08c9c which did punish nodes that sent us CACHED_INVALID and BLOCK_MISSING_PREV blocks.
1 parent ceecefe commit a1a07cf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,12 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationSta
12341234
const uint256 hash(block.GetHash());
12351235
std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash);
12361236

1237-
if (state.IsInvalid()) {
1238-
// Don't send reject message with code 0 or an internal reject code.
1239-
if (it != mapBlockSource.end() && State(it->second.first) && state.GetRejectCode() > 0 && state.GetRejectCode() < REJECT_INTERNAL) {
1237+
// If the block failed validation, we know where it came from and we're still connected
1238+
// to that peer, maybe punish.
1239+
if (state.IsInvalid() &&
1240+
it != mapBlockSource.end() &&
1241+
State(it->second.first)) {
12401242
MaybePunishNode(/*nodeid=*/ it->second.first, state, /*via_compact_block=*/ !it->second.second);
1241-
}
12421243
}
12431244
// Check that:
12441245
// 1. The block is valid

0 commit comments

Comments
 (0)