Skip to content

Commit 40a720a

Browse files
author
MarcoFalke
committed
Merge bitcoin#15697: qa: Make swap_magic_bytes in p2p_invalid_messages atomic
faca95e qa: Make swap_magic_bytes in p2p_invalid_messages atomic (MarcoFalke) Pull request description: Otherwise, this will lead to errors logged in the network thread: https://travis-ci.org/MarcoFalke/bitcoin/jobs/513076282#L2765 ACKs for commit faca95: Tree-SHA512: 8bc8280f9c0e8d40bc68c0ff1cab1c3386cbfef0728dbab5f29c2606dd65a9ac3c695b0c286be707a9f2bd62a6f87ac2032d7749fc2cf8b9fa1eba3c4cf70933
2 parents 4bd7187 + faca95e commit 40a720a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/functional/p2p_invalid_messages.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test node responses to invalid network messages."""
6+
import asyncio
67
import os
78
import struct
89

910
from test_framework import messages
10-
from test_framework.mininode import P2PDataStore
11+
from test_framework.mininode import P2PDataStore, NetworkThread
1112
from test_framework.test_framework import BitcoinTestFramework
1213

1314

@@ -143,8 +144,15 @@ def run_test(self):
143144

144145
def test_magic_bytes(self):
145146
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
146-
conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes
147-
conn.magic_bytes = b'\x00\x11\x22\x32'
147+
148+
def swap_magic_bytes():
149+
conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes
150+
conn.magic_bytes = b'\x00\x11\x22\x32'
151+
152+
# Call .result() to block until the atomic swap is complete, otherwise
153+
# we might run into races later on
154+
asyncio.run_coroutine_threadsafe(asyncio.coroutine(swap_magic_bytes)(), NetworkThread.network_event_loop).result()
155+
148156
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']):
149157
conn.send_message(messages.msg_ping(nonce=0xff))
150158
conn.wait_for_disconnect(timeout=1)

0 commit comments

Comments
 (0)