Skip to content

Commit e9dc511

Browse files
glozowtheStack
andcommitted
fixup: get all utxos up front in fill_mempool, discourage wallet mixing
Co-authored-by: Sebastian Falbesoner <[email protected]>
1 parent bdb33ec commit e9dc511

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

test/functional/rpc_packages.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,14 @@ def test_maxfeerate_submitpackage(self):
386386
"-maxmempool=5",
387387
"-persistmempool=0",
388388
])
389+
self.wallet.rescan_utxos()
389390

390391
fill_mempool(self, node, self.wallet)
391392

392393
minrelay = node.getmempoolinfo()["minrelaytxfee"]
393394
parent = self.wallet.create_self_transfer(
394395
fee_rate=minrelay,
396+
confirmed_only=True,
395397
)
396398

397399
child = self.wallet.create_self_transfer(
@@ -411,6 +413,7 @@ def test_maxfeerate_submitpackage(self):
411413

412414
# Reset maxmempool, datacarriersize, reset dynamic mempool minimum feerate, and empty mempool.
413415
self.restart_node(0)
416+
self.wallet.rescan_utxos()
414417

415418
assert_equal(node.getrawmempool(), [])
416419

@@ -420,7 +423,10 @@ def test_maxburn_submitpackage(self):
420423
assert_equal(node.getrawmempool(), [])
421424

422425
self.log.info("Submitpackage maxburnamount arg testing")
423-
chained_txns_burn = self.wallet.create_self_transfer_chain(chain_length=2)
426+
chained_txns_burn = self.wallet.create_self_transfer_chain(
427+
chain_length=2,
428+
utxo_to_spend=self.wallet.get_utxo(confirmed_only=True),
429+
)
424430
chained_burn_hex = [t["hex"] for t in chained_txns_burn]
425431

426432
tx = tx_from_hex(chained_burn_hex[1])

test/functional/test_framework/util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)