2
2
# Copyright (c) 2017-2021 The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# 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 """
6
6
7
7
from test_framework .messages import msg_getdata , CInv , MSG_TX
8
8
from test_framework .p2p import p2p_lock , P2PDataStore
@@ -26,10 +26,28 @@ def run_test(self):
26
26
self .gen_node = self .nodes [0 ] # The block and tx generating node
27
27
self .miniwallet = MiniWallet (self .gen_node )
28
28
29
+ self .test_tx_in_block ()
29
30
self .test_notfound_on_unannounced_tx ()
30
31
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
+
31
48
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
33
51
34
52
MAX_REPEATS = 100
35
53
self .log .info ("Running test up to {} times." .format (MAX_REPEATS ))
0 commit comments