Skip to content

Commit cd6e193

Browse files
author
MarcoFalke
committed
Merge #20126: test: p2p_leak_tx.py improvements (use MiniWallet, add p2p_lock acquires)
5b77f80 test: add p2p_lock acquires in p2p_leak_tx.py (Sebastian Falbesoner) cc8c682 test: use MiniWallet for p2p_leak_tx.py (Sebastian Falbesoner) Pull request description: This PR enables one more of the non-wallet functional tests (p2p_leak_tx.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078. It also adds missing p2p_lock acquires that need to be held while modifying internal p2p Interface state (in this case the `last_message` dictionary) to avoid data races. ACKs for top commit: laanwj: Code review ACK 5b77f80 Tree-SHA512: 6661bc6e3491a9af4bf040f379e5955c525136397e99d3eadde92e247580d0d87efff750e6d3b1f6d9a4e578144a433a982f574ef056b44dd6bca33873a1bae6
2 parents ad90dd9 + 5b77f80 commit cd6e193

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

test/functional/p2p_leak_tx.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"""Test that we don't leak txs to inbound peers that we haven't yet announced to"""
66

77
from test_framework.messages import msg_getdata, CInv, MSG_TX
8-
from test_framework.p2p import P2PDataStore
8+
from test_framework.p2p import p2p_lock, P2PDataStore
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_equal,
1212
)
13+
from test_framework.wallet import MiniWallet
1314

1415

1516
class P2PNode(P2PDataStore):
@@ -21,31 +22,33 @@ class P2PLeakTxTest(BitcoinTestFramework):
2122
def set_test_params(self):
2223
self.num_nodes = 1
2324

24-
def skip_test_if_missing_module(self):
25-
self.skip_if_no_wallet()
26-
2725
def run_test(self):
2826
gen_node = self.nodes[0] # The block and tx generating node
29-
gen_node.generate(1)
27+
miniwallet = MiniWallet(gen_node)
28+
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins
29+
miniwallet.generate(1)
30+
gen_node.generate(100)
3031

3132
inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) # An "attacking" inbound peer
3233

3334
MAX_REPEATS = 100
3435
self.log.info("Running test up to {} times.".format(MAX_REPEATS))
3536
for i in range(MAX_REPEATS):
3637
self.log.info('Run repeat {}'.format(i + 1))
37-
txid = gen_node.sendtoaddress(gen_node.getnewaddress(), 0.01)
38+
txid = miniwallet.send_self_transfer(from_node=gen_node)['wtxid']
3839

3940
want_tx = msg_getdata()
4041
want_tx.inv.append(CInv(t=MSG_TX, h=int(txid, 16)))
41-
inbound_peer.last_message.pop('notfound', None)
42+
with p2p_lock:
43+
inbound_peer.last_message.pop('notfound', None)
4244
inbound_peer.send_and_ping(want_tx)
4345

4446
if inbound_peer.last_message.get('notfound'):
4547
self.log.debug('tx {} was not yet announced to us.'.format(txid))
4648
self.log.debug("node has responded with a notfound message. End test.")
4749
assert_equal(inbound_peer.last_message['notfound'].vec[0].hash, int(txid, 16))
48-
inbound_peer.last_message.pop('notfound')
50+
with p2p_lock:
51+
inbound_peer.last_message.pop('notfound')
4952
break
5053
else:
5154
self.log.debug('tx {} was already announced to us. Try test again.'.format(txid))

0 commit comments

Comments
 (0)