22# Copyright (c) 2017-2021 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
77from test_framework .messages import msg_getdata , CInv , MSG_TX
88from test_framework .p2p import p2p_lock , P2PDataStore
@@ -26,10 +26,28 @@ def run_test(self):
2626 self .gen_node = self .nodes [0 ] # The block and tx generating node
2727 self .miniwallet = MiniWallet (self .gen_node )
2828
29+ self .test_tx_in_block ()
2930 self .test_notfound_on_unannounced_tx ()
3031
32+ def test_tx_in_block (self ):
33+ self .log .info ("Check that a transaction in the last block is uploaded (beneficial for compact block relay)" )
34+ inbound_peer = self .gen_node .add_p2p_connection (P2PNode ())
35+
36+ self .log .debug ("Generate transaction and block" )
37+ inbound_peer .last_message .pop ("inv" , None )
38+ wtxid = self .miniwallet .send_self_transfer (from_node = self .gen_node )["wtxid" ]
39+ inbound_peer .wait_until (lambda : "inv" in inbound_peer .last_message and inbound_peer .last_message .get ("inv" ).inv [0 ].hash == int (wtxid , 16 ))
40+ want_tx = msg_getdata (inv = inbound_peer .last_message .get ("inv" ).inv )
41+ self .generate (self .gen_node , 1 )
42+
43+ self .log .debug ("Request transaction" )
44+ inbound_peer .last_message .pop ("tx" , None )
45+ inbound_peer .send_and_ping (want_tx )
46+ assert_equal (inbound_peer .last_message .get ("tx" ).tx .getwtxid (), wtxid )
47+
3148 def test_notfound_on_unannounced_tx (self ):
32- inbound_peer = self .nodes [0 ].add_p2p_connection (P2PNode ()) # An "attacking" inbound peer
49+ self .log .info ("Check that we don't leak txs to inbound peers that we haven't yet announced to" )
50+ inbound_peer = self .gen_node .add_p2p_connection (P2PNode ()) # An "attacking" inbound peer
3351
3452 MAX_REPEATS = 100
3553 self .log .info ("Running test up to {} times." .format (MAX_REPEATS ))
0 commit comments