Skip to content

Commit a3da63e

Browse files
committed
Move fill_mempool to util function
1 parent 73b68bd commit a3da63e

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

test/functional/mempool_limit.py

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
from decimal import Decimal
88

9-
from test_framework.blocktools import COINBASE_MATURITY
109
from test_framework.p2p import P2PTxInvStore
1110
from test_framework.test_framework import BitcoinTestFramework
1211
from test_framework.util import (
1312
assert_equal,
1413
assert_fee_amount,
1514
assert_greater_than,
1615
assert_raises_rpc_error,
17-
create_lots_of_big_transactions,
18-
gen_return_txouts,
16+
fill_mempool,
1917
)
2018
from test_framework.wallet import (
2119
COIN,
@@ -34,48 +32,6 @@ def set_test_params(self):
3432
]]
3533
self.supports_cli = False
3634

37-
def fill_mempool(self):
38-
"""Fill mempool until eviction."""
39-
self.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
40-
txouts = gen_return_txouts()
41-
node = self.nodes[0]
42-
miniwallet = self.wallet
43-
relayfee = node.getnetworkinfo()['relayfee']
44-
45-
tx_batch_size = 1
46-
num_of_batches = 75
47-
# Generate UTXOs to flood the mempool
48-
# 1 to create a tx initially that will be evicted from the mempool later
49-
# 75 transactions each with a fee rate higher than the previous one
50-
self.generate(miniwallet, 1 + (num_of_batches * tx_batch_size))
51-
52-
# Mine 99 blocks so that the UTXOs are allowed to be spent
53-
self.generate(node, COINBASE_MATURITY - 1)
54-
55-
self.log.debug("Create a mempool tx that will be evicted")
56-
tx_to_be_evicted_id = miniwallet.send_self_transfer(from_node=node, fee_rate=relayfee)["txid"]
57-
58-
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
59-
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
60-
# by 130 should result in a fee that corresponds to 2x of that fee rate
61-
base_fee = relayfee * 130
62-
63-
self.log.debug("Fill up the mempool with txs with higher fee rate")
64-
with node.assert_debug_log(["rolling minimum fee bumped"]):
65-
for batch_of_txid in range(num_of_batches):
66-
fee = (batch_of_txid + 1) * base_fee
67-
create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts)
68-
69-
self.log.debug("The tx should be evicted by now")
70-
# The number of transactions created should be greater than the ones present in the mempool
71-
assert_greater_than(tx_batch_size * num_of_batches, len(node.getrawmempool()))
72-
# Initial tx created should not be present in the mempool anymore as it had a lower fee rate
73-
assert tx_to_be_evicted_id not in node.getrawmempool()
74-
75-
self.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
76-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
77-
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
78-
7935
def test_rbf_carveout_disallowed(self):
8036
node = self.nodes[0]
8137

@@ -137,7 +93,7 @@ def test_mid_package_eviction(self):
13793
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
13894
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
13995

140-
self.fill_mempool()
96+
fill_mempool(self, node, self.wallet)
14197
current_info = node.getmempoolinfo()
14298
mempoolmin_feerate = current_info["mempoolminfee"]
14399

@@ -227,7 +183,7 @@ def test_mid_package_replacement(self):
227183
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
228184
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
229185

230-
self.fill_mempool()
186+
fill_mempool(self, node, self.wallet)
231187
current_info = node.getmempoolinfo()
232188
mempoolmin_feerate = current_info["mempoolminfee"]
233189

@@ -301,7 +257,7 @@ def run_test(self):
301257
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
302258
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
303259

304-
self.fill_mempool()
260+
fill_mempool(self, node, self.wallet)
305261

306262
# Deliberately try to create a tx with a fee less than the minimum mempool fee to assert that it does not get added to the mempool
307263
self.log.info('Create a mempool tx that will not pass mempoolminfee')

test/functional/test_framework/util.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,45 @@ def check_node_connections(*, node, num_in, num_out):
496496
assert_equal(info["connections_in"], num_in)
497497
assert_equal(info["connections_out"], num_out)
498498

499+
def fill_mempool(test_framework, node, miniwallet):
500+
"""Fill mempool until eviction."""
501+
test_framework.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
502+
txouts = gen_return_txouts()
503+
relayfee = node.getnetworkinfo()['relayfee']
504+
505+
tx_batch_size = 1
506+
num_of_batches = 75
507+
# Generate UTXOs to flood the mempool
508+
# 1 to create a tx initially that will be evicted from the mempool later
509+
# 75 transactions each with a fee rate higher than the previous one
510+
test_framework.generate(miniwallet, 1 + (num_of_batches * tx_batch_size))
511+
512+
# Mine COINBASE_MATURITY - 1 blocks so that the UTXOs are allowed to be spent
513+
test_framework.generate(node, 100 - 1)
514+
515+
test_framework.log.debug("Create a mempool tx that will be evicted")
516+
tx_to_be_evicted_id = miniwallet.send_self_transfer(from_node=node, fee_rate=relayfee)["txid"]
517+
518+
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
519+
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
520+
# by 130 should result in a fee that corresponds to 2x of that fee rate
521+
base_fee = relayfee * 130
522+
523+
test_framework.log.debug("Fill up the mempool with txs with higher fee rate")
524+
with node.assert_debug_log(["rolling minimum fee bumped"]):
525+
for batch_of_txid in range(num_of_batches):
526+
fee = (batch_of_txid + 1) * base_fee
527+
create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts)
528+
529+
test_framework.log.debug("The tx should be evicted by now")
530+
# The number of transactions created should be greater than the ones present in the mempool
531+
assert_greater_than(tx_batch_size * num_of_batches, len(node.getrawmempool()))
532+
# Initial tx created should not be present in the mempool anymore as it had a lower fee rate
533+
assert tx_to_be_evicted_id not in node.getrawmempool()
534+
535+
test_framework.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
536+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
537+
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
499538

500539
# Transaction/Block functions
501540
#############################

0 commit comments

Comments
 (0)