Skip to content

Commit

Permalink
Merge #15697: qa: Make swap_magic_bytes in p2p_invalid_messages atomic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Apr 23, 2019
2 parents 4bd7187 + faca95e commit 40a720a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/functional/p2p_invalid_messages.py
Expand Up @@ -3,11 +3,12 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test node responses to invalid network messages."""
import asyncio
import os
import struct

from test_framework import messages
from test_framework.mininode import P2PDataStore
from test_framework.mininode import P2PDataStore, NetworkThread
from test_framework.test_framework import BitcoinTestFramework


Expand Down Expand Up @@ -143,8 +144,15 @@ def run_test(self):

def test_magic_bytes(self):
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes
conn.magic_bytes = b'\x00\x11\x22\x32'

def swap_magic_bytes():
conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes
conn.magic_bytes = b'\x00\x11\x22\x32'

# Call .result() to block until the atomic swap is complete, otherwise
# we might run into races later on
asyncio.run_coroutine_threadsafe(asyncio.coroutine(swap_magic_bytes)(), NetworkThread.network_event_loop).result()

with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']):
conn.send_message(messages.msg_ping(nonce=0xff))
conn.wait_for_disconnect(timeout=1)
Expand Down

0 comments on commit 40a720a

Please sign in to comment.