5
5
"""
6
6
Test transaction download behavior
7
7
"""
8
+ from decimal import Decimal
8
9
import time
9
10
10
11
from test_framework .messages import (
14
15
MSG_WTX ,
15
16
msg_inv ,
16
17
msg_notfound ,
18
+ msg_tx ,
17
19
)
18
20
from test_framework .p2p import (
19
21
P2PInterface ,
22
24
from test_framework .test_framework import BitcoinTestFramework
23
25
from test_framework .util import (
24
26
assert_equal ,
27
+ fill_mempool ,
25
28
)
26
29
from test_framework .wallet import MiniWallet
27
30
@@ -54,6 +57,7 @@ def on_getdata(self, message):
54
57
class TxDownloadTest (BitcoinTestFramework ):
55
58
def set_test_params (self ):
56
59
self .num_nodes = 2
60
+ self .extra_args = [['-datacarriersize=100000' , '-maxmempool=5' , '-persistmempool=0' ]] * self .num_nodes
57
61
58
62
def test_tx_requests (self ):
59
63
self .log .info ("Test that we request transactions from all our peers, eventually" )
@@ -241,6 +245,29 @@ def test_spurious_notfound(self):
241
245
self .log .info ('Check that spurious notfound is ignored' )
242
246
self .nodes [0 ].p2ps [0 ].send_message (msg_notfound (vec = [CInv (MSG_TX , 1 )]))
243
247
248
+ def test_rejects_filter_reset (self ):
249
+ self .log .info ('Check that rejected tx is not requested again' )
250
+ node = self .nodes [0 ]
251
+ fill_mempool (self , node , self .wallet )
252
+ self .wallet .rescan_utxos ()
253
+ mempoolminfee = node .getmempoolinfo ()['mempoolminfee' ]
254
+ peer = node .add_p2p_connection (TestP2PConn ())
255
+ low_fee_tx = self .wallet .create_self_transfer (fee_rate = Decimal ("0.9" )* mempoolminfee )
256
+ assert_equal (node .testmempoolaccept ([low_fee_tx ['hex' ]])[0 ]["reject-reason" ], "mempool min fee not met" )
257
+ peer .send_and_ping (msg_tx (low_fee_tx ['tx' ]))
258
+ peer .send_and_ping (msg_inv ([CInv (t = MSG_WTX , h = int (low_fee_tx ['wtxid' ], 16 ))]))
259
+ node .setmocktime (int (time .time ()))
260
+ node .bumpmocktime (MAX_GETDATA_INBOUND_WAIT )
261
+ peer .sync_with_ping ()
262
+ assert_equal (peer .tx_getdata_count , 0 )
263
+
264
+ self .log .info ('Check that rejection filter is cleared after new block comes in' )
265
+ self .generate (self .wallet , 1 , sync_fun = self .no_op )
266
+ peer .sync_with_ping ()
267
+ peer .send_and_ping (msg_inv ([CInv (t = MSG_WTX , h = int (low_fee_tx ['wtxid' ], 16 ))]))
268
+ node .bumpmocktime (MAX_GETDATA_INBOUND_WAIT )
269
+ peer .wait_for_getdata ([int (low_fee_tx ['wtxid' ], 16 )])
270
+
244
271
def run_test (self ):
245
272
self .wallet = MiniWallet (self .nodes [0 ])
246
273
@@ -257,7 +284,8 @@ def run_test(self):
257
284
258
285
# Run each test against new bitcoind instances, as setting mocktimes has long-term effects on when
259
286
# the next trickle relay event happens.
260
- for test in [self .test_in_flight_max , self .test_inv_block , self .test_tx_requests ]:
287
+ for test in [self .test_in_flight_max , self .test_inv_block , self .test_tx_requests ,
288
+ self .test_rejects_filter_reset ]:
261
289
self .stop_nodes ()
262
290
self .start_nodes ()
263
291
self .connect_nodes (1 , 0 )
0 commit comments