test: fix race condition in p2p_v2_misbehaving.py peerid assertion
What changed, and why it matters
This commit fixes a flaky test, not a security bug. The test checked for specific peer ID numbers in log messages, but because of unpredictable scheduling in the test framework, those IDs could differ between runs. The fix removes the specific ID numbers from the expected log messages so the test passes reliably. No production code or network behavior was changed.
No security action needed. This is a test-only reliability fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is in test/functional/p2p_v2_misbehaving.py, a functional test for BIP324 v2 P2P transport misbehavior handling. It relaxes two expected debug log strings by removing the ‘peer=N’ suffix: ‘V2 transport error: missing garbage terminator, peer=1’ becomes ‘V2 transport error: missing garbage terminator’, and ‘V2 handshake timeout, disconnecting peer=3’ becomes ‘V2 handshake timeout, disconnecting peer’. The commit message explains this is because asyncio task scheduling can cause peer2 to connect before peer1, swapping the assigned peer IDs. The test still verifies the correct peer remains connected and the correct disconnection reasons are logged; only the numeric peer ID assertion is removed.
Changed components
test/functional/p2p_v2_misbehaving.pyInspect captured patch +2 / −2
diff --git a/test/functional/p2p_v2_misbehaving.py b/test/functional/p2p_v2_misbehaving.py
index ee589010..32fe2833 100755
--- a/test/functional/p2p_v2_misbehaving.py
+++ b/test/functional/p2p_v2_misbehaving.py
@@ -161,8 +161,8 @@ class EncryptedP2PMisbehaving(BitcoinTestFramework):
node0 = self.nodes[0]
expected_debug_message = [
[], # EARLY_KEY_RESPONSE
- ["V2 transport error: missing garbage terminator, peer=1"], # EXCESS_GARBAGE
- ["V2 handshake timeout, disconnecting peer=3"], # WRONG_GARBAGE_TERMINATOR
+ ["V2 transport error: missing garbage terminator"], # EXCESS_GARBAGE
+ ["V2 handshake timeout, disconnecting peer"], # WRONG_GARBAGE_TERMINATOR
["V2 transport error: packet decryption failure"], # WRONG_GARBAGE
["V2 transport error: packet decryption failure"], # SEND_NO_AAD
[], # SEND_NON_EMPTY_VERSION_PACKET
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.