Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_leak_tx.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017-2018 The Bitcoin Core developers | # Copyright (c) 2017-2018 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test that we don't leak txs to inbound peers that we haven't yet announced to""" | """Test that we don't leak txs to inbound peers that we haven't yet announced to""" | ||||
from test_framework.messages import msg_getdata, CInv | from test_framework.messages import msg_getdata, CInv | ||||
from test_framework.mininode import P2PDataStore, network_thread_start | from test_framework.mininode import P2PDataStore | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
) | ) | ||||
class P2PNode(P2PDataStore): | class P2PNode(P2PDataStore): | ||||
def on_inv(self, msg): | def on_inv(self, msg): | ||||
Show All 12 Lines | def run_test(self): | ||||
gen_node = self.nodes[0] | gen_node = self.nodes[0] | ||||
gen_node.generate(1) | gen_node.generate(1) | ||||
# An "attacking" inbound peer | # An "attacking" inbound peer | ||||
inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) | inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) | ||||
# Backport note: the following two lines were backported out of order, | # Backport note: the following two lines were backported out of order, | ||||
# and should be removed in the appropriate future backports that do a | # and should be removed in the appropriate future backports that do a | ||||
# blanket removal of each of these calls across many tests. | # blanket removal of each of these calls across many tests. | ||||
network_thread_start() | |||||
self.nodes[0].p2p.wait_for_verack() | self.nodes[0].p2p.wait_for_verack() | ||||
MAX_REPEATS = 100 | MAX_REPEATS = 100 | ||||
self.log.info("Running test up to {} times.".format(MAX_REPEATS)) | self.log.info("Running test up to {} times.".format(MAX_REPEATS)) | ||||
for i in range(MAX_REPEATS): | for i in range(MAX_REPEATS): | ||||
self.log.info('Run repeat {}'.format(i + 1)) | self.log.info('Run repeat {}'.format(i + 1)) | ||||
txid = gen_node.sendtoaddress(gen_node.getnewaddress(), 0.01) | txid = gen_node.sendtoaddress(gen_node.getnewaddress(), 0.01) | ||||
Show All 24 Lines |