Sending wtxidrelay twice before verack must not increment m_wtxid_relay_peers twice, otherwise the consistency check in FinalizeNode fails. This PR adds a test case for it as well as it kills the following mutant (https://mutanthub.space/mutants/3756):
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index beec44f..a050f08 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -4200,5 +4200,5 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
if (pfrom.GetCommonVersion() >= WTXID_RELAY_VERSION) {
+ m_wtxid_relay_peers++;
if (!peer.m_wtxid_relay) {
peer.m_wtxid_relay = true;
- m_wtxid_relay_peers++;
} else {
This test case basically connects an inbound peer and sends its version message, but not verack yet. Sends wtxidrelay twice. The second one should be ignored as a duplicate, and the test checks the peer isn't disconnected. And then, calls FinalizeNode. When the last peer is removed, PeerManagerImpl checks that m_wtxid_relay_peers == 0.