Merge bitcoin/bitcoin#23042: net: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer

fa2662c293 net: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer (MarcoFalke)

Pull request description:

  There is no need to log `AlreadyHaveTx` for an inv when a peer is marked for disconnection due to sending that inv. In fact, I find it confusing that a `block-relay-only` connection calls `AlreadyHaveTx` at all. Also there is no need to call `AddKnownTx` when the peer is marked for disconnection.

ACKs for top commit:
  naumenkogs:
    ACK fa2662c293
  jnewbery:
    Code review ACK fa2662c293
  dunxen:
    Concept and code review ACK fa2662c293

Tree-SHA512: 9996b807a824021f992b5281d82ff0cbbe6a442c2fedf7dfd6adda64ccc5e0ef4fb0ff91ab75086f975837bbbb7a5934ac7e671a80dcababa7203c92fc0c7f84
This commit is contained in:
fanquake 2021-10-22 19:07:28 +08:00
commit 788909f3c7
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -2960,16 +2960,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
best_block = &inv.hash; best_block = &inv.hash;
} }
} else if (inv.IsGenTxMsg()) { } else if (inv.IsGenTxMsg()) {
if (reject_tx_invs) {
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom.GetId());
pfrom.fDisconnect = true;
return;
}
const GenTxid gtxid = ToGenTxid(inv); const GenTxid gtxid = ToGenTxid(inv);
const bool fAlreadyHave = AlreadyHaveTx(gtxid); const bool fAlreadyHave = AlreadyHaveTx(gtxid);
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());
pfrom.AddKnownTx(inv.hash); pfrom.AddKnownTx(inv.hash);
if (reject_tx_invs) { if (!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom.GetId());
pfrom.fDisconnect = true;
return;
} else if (!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
AddTxAnnouncement(pfrom, gtxid, current_time); AddTxAnnouncement(pfrom, gtxid, current_time);
} }
} else { } else {