@@ -505,6 +505,8 @@ def fill_mempool(test_framework, node, miniwallet):
505505 It will not ensure mempools become synced as it
506506 is based on a single node and assumes -minrelaytxfee
507507 is 1 sat/vbyte.
508+ To avoid unintentional tx dependencies, it is recommended to use separate miniwallets for
509+ mempool filling vs transactions in tests.
508510 """
509511 test_framework .log .info ("Fill the mempool until eviction is triggered and the mempoolminfee rises" )
510512 txouts = gen_return_txouts ()
@@ -522,8 +524,14 @@ def fill_mempool(test_framework, node, miniwallet):
522524 # Mine COINBASE_MATURITY - 1 blocks so that the UTXOs are allowed to be spent
523525 test_framework .generate (node , 100 - 1 )
524526
527+ # Get all UTXOs up front to ensure none of the transactions spend from each other, as that may
528+ # change their effective feerate and thus the order in which they are selected for eviction.
529+ confirmed_utxos = [miniwallet .get_utxo (confirmed_only = True ) for _ in range (num_of_batches * tx_batch_size + 1 )]
530+ assert_equal (len (confirmed_utxos ), num_of_batches * tx_batch_size + 1 )
531+
525532 test_framework .log .debug ("Create a mempool tx that will be evicted" )
526- tx_to_be_evicted_id = miniwallet .send_self_transfer (from_node = node , fee_rate = relayfee )["txid" ]
533+ tx_to_be_evicted_id = miniwallet .send_self_transfer (from_node = node , utxo_to_spend = confirmed_utxos [0 ], fee_rate = relayfee )["txid" ]
534+ del confirmed_utxos [0 ]
527535
528536 # Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
529537 # The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
@@ -534,7 +542,9 @@ def fill_mempool(test_framework, node, miniwallet):
534542 with node .assert_debug_log (["rolling minimum fee bumped" ]):
535543 for batch_of_txid in range (num_of_batches ):
536544 fee = (batch_of_txid + 1 ) * base_fee
537- create_lots_of_big_transactions (miniwallet , node , fee , tx_batch_size , txouts )
545+ utxos = confirmed_utxos [:tx_batch_size ]
546+ create_lots_of_big_transactions (miniwallet , node , fee , tx_batch_size , txouts , utxos )
547+ del confirmed_utxos [:tx_batch_size ]
538548
539549 test_framework .log .debug ("The tx should be evicted by now" )
540550 # The number of transactions created should be greater than the ones present in the mempool
0 commit comments