Skip to content

Commit 4013c3d

Browse files
fanquakevijaydasmp
authored andcommitted
Merge bitcoin#27695: test: Add test to check tx in the last block can be downloaded
fa4c16b test: Add test to check tx in the last block can be downloaded (MarcoFalke) fadc849 test: Split up test_notfound_on_unannounced_tx test case (MarcoFalke) Pull request description: If a peer received an `inv` about a transaction, which was included in a block before receiving the corresponding `getdata`, it can be beneficial to send this transaction to the peer to aid compact block relay. Add a test for this to avoid breaking it in the future. ACKs for top commit: sdaftuar: ACK fa4c16b instagibbs: ACK fa4c16b Tree-SHA512: 1ec16dcc216dd29c849928e753158d45c409612e9ac528db16e5af465bb5b69cd42241ac6f67e5a4583b8e558eeba49fa0a0889a4247b3fb0053b2758eec9490
1 parent aeb1844 commit 4013c3d

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

test/functional/p2p_leak_tx.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) 2017-2020 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test that we don't leak txs to inbound peers that we haven't yet announced to"""
5+
"""Test transaction upload"""
66

77
from test_framework.messages import msg_getdata, CInv, MSG_TX
88
from test_framework.p2p import p2p_lock, P2PDataStore
@@ -23,19 +23,40 @@ def set_test_params(self):
2323
self.num_nodes = 1
2424

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

32-
inbound_peer = self.nodes[0].add_p2p_connection(P2PNode()) # An "attacking" inbound peer
32+
self.test_tx_in_block()
33+
self.test_notfound_on_unannounced_tx()
34+
35+
def test_tx_in_block(self):
36+
self.log.info("Check that a transaction in the last block is uploaded (beneficial for compact block relay)")
37+
inbound_peer = self.gen_node.add_p2p_connection(P2PNode())
38+
39+
self.log.debug("Generate transaction and block")
40+
inbound_peer.last_message.pop("inv", None)
41+
wtxid = self.miniwallet.send_self_transfer(from_node=self.gen_node)["wtxid"]
42+
inbound_peer.wait_until(lambda: "inv" in inbound_peer.last_message and inbound_peer.last_message.get("inv").inv[0].hash == int(wtxid, 16))
43+
want_tx = msg_getdata(inv=inbound_peer.last_message.get("inv").inv)
44+
self.generate(self.gen_node, 1)
45+
46+
self.log.debug("Request transaction")
47+
inbound_peer.last_message.pop("tx", None)
48+
inbound_peer.send_and_ping(want_tx)
49+
assert_equal(inbound_peer.last_message.get("tx").tx.getwtxid(), wtxid)
50+
51+
def test_notfound_on_unannounced_tx(self):
52+
self.log.info("Check that we don't leak txs to inbound peers that we haven't yet announced to")
53+
inbound_peer = self.gen_node.add_p2p_connection(P2PNode()) # An "attacking" inbound peer
3354

3455
MAX_REPEATS = 100
3556
self.log.info("Running test up to {} times.".format(MAX_REPEATS))
3657
for i in range(MAX_REPEATS):
3758
self.log.info('Run repeat {}'.format(i + 1))
38-
txid = miniwallet.send_self_transfer(from_node=gen_node)['txid']
59+
txid = self.miniwallet.send_self_transfer(from_node=self.gen_node)['txid']
3960

4061
want_tx = msg_getdata()
4162
want_tx.inv.append(CInv(t=MSG_TX, h=int(txid, 16)))

0 commit comments

Comments
 (0)