55"""
66Test transaction download behavior
77"""
8+ from decimal import Decimal
89import time
910
1011from test_framework .messages import (
1415 MSG_WTX ,
1516 msg_inv ,
1617 msg_notfound ,
18+ msg_tx ,
1719)
1820from test_framework .p2p import (
1921 P2PInterface ,
2224from test_framework .test_framework import BitcoinTestFramework
2325from test_framework .util import (
2426 assert_equal ,
27+ fill_mempool ,
2528)
2629from test_framework .wallet import MiniWallet
2730
@@ -54,6 +57,7 @@ def on_getdata(self, message):
5457class TxDownloadTest (BitcoinTestFramework ):
5558 def set_test_params (self ):
5659 self .num_nodes = 2
60+ self .extra_args = [['-datacarriersize=100000' , '-maxmempool=5' , '-persistmempool=0' ]] * self .num_nodes
5761
5862 def test_tx_requests (self ):
5963 self .log .info ("Test that we request transactions from all our peers, eventually" )
@@ -241,6 +245,29 @@ def test_spurious_notfound(self):
241245 self .log .info ('Check that spurious notfound is ignored' )
242246 self .nodes [0 ].p2ps [0 ].send_message (msg_notfound (vec = [CInv (MSG_TX , 1 )]))
243247
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+
244271 def run_test (self ):
245272 self .wallet = MiniWallet (self .nodes [0 ])
246273
@@ -257,7 +284,8 @@ def run_test(self):
257284
258285 # Run each test against new bitcoind instances, as setting mocktimes has long-term effects on when
259286 # 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 ]:
261289 self .stop_nodes ()
262290 self .start_nodes ()
263291 self .connect_nodes (1 , 0 )
0 commit comments