Skip to content

Commit 39d135e

Browse files
committed
test: MiniWallet: respect fee_rate for target_weight, use in mempool_limit.py
1 parent b2f0a9f commit 39d135e

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

test/functional/mempool_limit.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_rbf_carveout_disallowed(self):
5959
mempoolmin_feerate = node.getmempoolinfo()["mempoolminfee"]
6060
tx_A = self.wallet.send_self_transfer(
6161
from_node=node,
62-
fee=(mempoolmin_feerate / 1000) * (A_weight // 4) + Decimal('0.000001'),
62+
fee_rate=mempoolmin_feerate,
6363
target_weight=A_weight,
6464
utxo_to_spend=rbf_utxo,
6565
confirmed_only=True
@@ -77,7 +77,7 @@ def test_rbf_carveout_disallowed(self):
7777
non_cpfp_carveout_weight = 40001 # EXTRA_DESCENDANT_TX_SIZE_LIMIT + 1
7878
tx_C = self.wallet.create_self_transfer(
7979
target_weight=non_cpfp_carveout_weight,
80-
fee = (mempoolmin_feerate / 1000) * (non_cpfp_carveout_weight // 4) + Decimal('0.000001'),
80+
fee_rate=mempoolmin_feerate,
8181
utxo_to_spend=tx_B["new_utxo"],
8282
confirmed_only=True
8383
)
@@ -109,7 +109,7 @@ def test_mid_package_eviction(self):
109109
# happen in the middle of package evaluation, as it can invalidate the coins cache.
110110
mempool_evicted_tx = self.wallet.send_self_transfer(
111111
from_node=node,
112-
fee=(mempoolmin_feerate / 1000) * (evicted_weight // 4) + Decimal('0.000001'),
112+
fee_rate=mempoolmin_feerate,
113113
target_weight=evicted_weight,
114114
confirmed_only=True
115115
)
@@ -135,11 +135,11 @@ def test_mid_package_eviction(self):
135135
parent_weight = 100000
136136
num_big_parents = 3
137137
assert_greater_than(parent_weight * num_big_parents, current_info["maxmempool"] - current_info["bytes"])
138-
parent_fee = (100 * mempoolmin_feerate / 1000) * (parent_weight // 4)
138+
parent_feerate = 100 * mempoolmin_feerate
139139

140140
big_parent_txids = []
141141
for i in range(num_big_parents):
142-
parent = self.wallet.create_self_transfer(fee=parent_fee, target_weight=parent_weight, confirmed_only=True)
142+
parent = self.wallet.create_self_transfer(fee_rate=parent_feerate, target_weight=parent_weight, confirmed_only=True)
143143
parent_utxos.append(parent["new_utxo"])
144144
package_hex.append(parent["hex"])
145145
big_parent_txids.append(parent["txid"])
@@ -314,18 +314,20 @@ def run_test(self):
314314
target_weight_each = 200000
315315
assert_greater_than(target_weight_each * 2, node.getmempoolinfo()["maxmempool"] - node.getmempoolinfo()["bytes"])
316316
# Should be a true CPFP: parent's feerate is just below mempool min feerate
317-
parent_fee = (mempoolmin_feerate / 1000) * (target_weight_each // 4) - Decimal("0.00001")
317+
parent_feerate = mempoolmin_feerate - Decimal("0.000001") # 0.1 sats/vbyte below min feerate
318318
# Parent + child is above mempool minimum feerate
319-
child_fee = (worst_feerate_btcvb) * (target_weight_each // 4) - Decimal("0.00001")
319+
child_feerate = (worst_feerate_btcvb * 1000) - Decimal("0.000001") # 0.1 sats/vbyte below worst feerate
320320
# However, when eviction is triggered, these transactions should be at the bottom.
321321
# This assertion assumes parent and child are the same size.
322322
miniwallet.rescan_utxos()
323-
tx_parent_just_below = miniwallet.create_self_transfer(fee=parent_fee, target_weight=target_weight_each)
324-
tx_child_just_above = miniwallet.create_self_transfer(utxo_to_spend=tx_parent_just_below["new_utxo"], fee=child_fee, target_weight=target_weight_each)
323+
tx_parent_just_below = miniwallet.create_self_transfer(fee_rate=parent_feerate, target_weight=target_weight_each)
324+
tx_child_just_above = miniwallet.create_self_transfer(utxo_to_spend=tx_parent_just_below["new_utxo"], fee_rate=child_feerate, target_weight=target_weight_each)
325325
# This package ranks below the lowest descendant package in the mempool
326-
assert_greater_than(worst_feerate_btcvb, (parent_fee + child_fee) / (tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()))
327-
assert_greater_than(mempoolmin_feerate, (parent_fee) / (tx_parent_just_below["tx"].get_vsize()))
328-
assert_greater_than((parent_fee + child_fee) / (tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()), mempoolmin_feerate / 1000)
326+
package_fee = tx_parent_just_below["fee"] + tx_child_just_above["fee"]
327+
package_vsize = tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()
328+
assert_greater_than(worst_feerate_btcvb, package_fee / package_vsize)
329+
assert_greater_than(mempoolmin_feerate, tx_parent_just_below["fee"] / (tx_parent_just_below["tx"].get_vsize()))
330+
assert_greater_than(package_fee / package_vsize, mempoolmin_feerate / 1000)
329331
res = node.submitpackage([tx_parent_just_below["hex"], tx_child_just_above["hex"]])
330332
for wtxid in [tx_parent_just_below["wtxid"], tx_child_just_above["wtxid"]]:
331333
assert_equal(res["tx-results"][wtxid]["error"], "mempool full")

test/functional/test_framework/wallet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from copy import deepcopy
88
from decimal import Decimal
99
from enum import Enum
10+
import math
1011
from typing import (
1112
Any,
1213
Optional,
@@ -34,6 +35,7 @@
3435
CTxOut,
3536
hash256,
3637
ser_compact_size,
38+
WITNESS_SCALE_FACTOR,
3739
)
3840
from test_framework.script import (
3941
CScript,
@@ -54,6 +56,7 @@
5456
from test_framework.util import (
5557
assert_equal,
5658
assert_greater_than_or_equal,
59+
get_fee,
5760
)
5861
from test_framework.wallet_util import generate_keypair
5962

@@ -372,6 +375,10 @@ def create_self_transfer(
372375
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
373376
else:
374377
assert False
378+
if target_weight and not fee: # respect fee_rate if target weight is passed
379+
# the actual weight might be off by 3 WUs, so calculate based on that (see self._bulk_tx)
380+
max_actual_weight = target_weight + 3
381+
fee = get_fee(math.ceil(max_actual_weight / WITNESS_SCALE_FACTOR), fee_rate)
375382
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
376383

377384
# create tx

0 commit comments

Comments
 (0)