merge bitcoin#23042: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer

This commit is contained in:
Kittywhiskers Van Gogh 2024-09-30 11:22:33 +00:00
parent 05395ff37b
commit 7229eb0ae2
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD

View File

@ -3831,6 +3831,12 @@ void PeerManagerImpl::ProcessMessage(
best_block = &inv.hash; best_block = &inv.hash;
} }
} else { } else {
if (fBlocksOnly && NetMessageViolatesBlocksOnly(inv.GetCommand())) {
LogPrint(BCLog::NET, "%s (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.GetCommand(), inv.hash.ToString(), pfrom.GetId());
pfrom.fDisconnect = true;
return;
}
const bool fAlreadyHave = AlreadyHave(inv); const bool fAlreadyHave = AlreadyHave(inv);
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
::g_stats_client->inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f); ::g_stats_client->inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f);
@ -3840,11 +3846,7 @@ void PeerManagerImpl::ProcessMessage(
}; };
AddKnownInv(*peer, inv.hash); AddKnownInv(*peer, inv.hash);
if (fBlocksOnly && NetMessageViolatesBlocksOnly(inv.GetCommand())) { if (!fAlreadyHave) {
LogPrint(BCLog::NET, "%s (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.GetCommand(), inv.hash.ToString(), pfrom.GetId());
pfrom.fDisconnect = true;
return;
} else if (!fAlreadyHave) {
if (fBlocksOnly && inv.type == MSG_ISDLOCK) { if (fBlocksOnly && inv.type == MSG_ISDLOCK) {
if (pfrom.GetCommonVersion() <= ADDRV2_PROTO_VERSION) { if (pfrom.GetCommonVersion() <= ADDRV2_PROTO_VERSION) {
// It's ok to receive these invs, we just ignore them // It's ok to receive these invs, we just ignore them