mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
test: MiniWallet: respect fee_rate for target_weight, use in mempool_limit.py
This commit is contained in:
parent
b2f0a9f8b0
commit
39d135e79f
2 changed files with 21 additions and 12 deletions
|
@ -59,7 +59,7 @@ class MempoolLimitTest(BitcoinTestFramework):
|
||||||
mempoolmin_feerate = node.getmempoolinfo()["mempoolminfee"]
|
mempoolmin_feerate = node.getmempoolinfo()["mempoolminfee"]
|
||||||
tx_A = self.wallet.send_self_transfer(
|
tx_A = self.wallet.send_self_transfer(
|
||||||
from_node=node,
|
from_node=node,
|
||||||
fee=(mempoolmin_feerate / 1000) * (A_weight // 4) + Decimal('0.000001'),
|
fee_rate=mempoolmin_feerate,
|
||||||
target_weight=A_weight,
|
target_weight=A_weight,
|
||||||
utxo_to_spend=rbf_utxo,
|
utxo_to_spend=rbf_utxo,
|
||||||
confirmed_only=True
|
confirmed_only=True
|
||||||
|
@ -77,7 +77,7 @@ class MempoolLimitTest(BitcoinTestFramework):
|
||||||
non_cpfp_carveout_weight = 40001 # EXTRA_DESCENDANT_TX_SIZE_LIMIT + 1
|
non_cpfp_carveout_weight = 40001 # EXTRA_DESCENDANT_TX_SIZE_LIMIT + 1
|
||||||
tx_C = self.wallet.create_self_transfer(
|
tx_C = self.wallet.create_self_transfer(
|
||||||
target_weight=non_cpfp_carveout_weight,
|
target_weight=non_cpfp_carveout_weight,
|
||||||
fee = (mempoolmin_feerate / 1000) * (non_cpfp_carveout_weight // 4) + Decimal('0.000001'),
|
fee_rate=mempoolmin_feerate,
|
||||||
utxo_to_spend=tx_B["new_utxo"],
|
utxo_to_spend=tx_B["new_utxo"],
|
||||||
confirmed_only=True
|
confirmed_only=True
|
||||||
)
|
)
|
||||||
|
@ -109,7 +109,7 @@ class MempoolLimitTest(BitcoinTestFramework):
|
||||||
# happen in the middle of package evaluation, as it can invalidate the coins cache.
|
# happen in the middle of package evaluation, as it can invalidate the coins cache.
|
||||||
mempool_evicted_tx = self.wallet.send_self_transfer(
|
mempool_evicted_tx = self.wallet.send_self_transfer(
|
||||||
from_node=node,
|
from_node=node,
|
||||||
fee=(mempoolmin_feerate / 1000) * (evicted_weight // 4) + Decimal('0.000001'),
|
fee_rate=mempoolmin_feerate,
|
||||||
target_weight=evicted_weight,
|
target_weight=evicted_weight,
|
||||||
confirmed_only=True
|
confirmed_only=True
|
||||||
)
|
)
|
||||||
|
@ -135,11 +135,11 @@ class MempoolLimitTest(BitcoinTestFramework):
|
||||||
parent_weight = 100000
|
parent_weight = 100000
|
||||||
num_big_parents = 3
|
num_big_parents = 3
|
||||||
assert_greater_than(parent_weight * num_big_parents, current_info["maxmempool"] - current_info["bytes"])
|
assert_greater_than(parent_weight * num_big_parents, current_info["maxmempool"] - current_info["bytes"])
|
||||||
parent_fee = (100 * mempoolmin_feerate / 1000) * (parent_weight // 4)
|
parent_feerate = 100 * mempoolmin_feerate
|
||||||
|
|
||||||
big_parent_txids = []
|
big_parent_txids = []
|
||||||
for i in range(num_big_parents):
|
for i in range(num_big_parents):
|
||||||
parent = self.wallet.create_self_transfer(fee=parent_fee, target_weight=parent_weight, confirmed_only=True)
|
parent = self.wallet.create_self_transfer(fee_rate=parent_feerate, target_weight=parent_weight, confirmed_only=True)
|
||||||
parent_utxos.append(parent["new_utxo"])
|
parent_utxos.append(parent["new_utxo"])
|
||||||
package_hex.append(parent["hex"])
|
package_hex.append(parent["hex"])
|
||||||
big_parent_txids.append(parent["txid"])
|
big_parent_txids.append(parent["txid"])
|
||||||
|
@ -314,18 +314,20 @@ class MempoolLimitTest(BitcoinTestFramework):
|
||||||
target_weight_each = 200000
|
target_weight_each = 200000
|
||||||
assert_greater_than(target_weight_each * 2, node.getmempoolinfo()["maxmempool"] - node.getmempoolinfo()["bytes"])
|
assert_greater_than(target_weight_each * 2, node.getmempoolinfo()["maxmempool"] - node.getmempoolinfo()["bytes"])
|
||||||
# Should be a true CPFP: parent's feerate is just below mempool min feerate
|
# Should be a true CPFP: parent's feerate is just below mempool min feerate
|
||||||
parent_fee = (mempoolmin_feerate / 1000) * (target_weight_each // 4) - Decimal("0.00001")
|
parent_feerate = mempoolmin_feerate - Decimal("0.000001") # 0.1 sats/vbyte below min feerate
|
||||||
# Parent + child is above mempool minimum feerate
|
# Parent + child is above mempool minimum feerate
|
||||||
child_fee = (worst_feerate_btcvb) * (target_weight_each // 4) - Decimal("0.00001")
|
child_feerate = (worst_feerate_btcvb * 1000) - Decimal("0.000001") # 0.1 sats/vbyte below worst feerate
|
||||||
# However, when eviction is triggered, these transactions should be at the bottom.
|
# However, when eviction is triggered, these transactions should be at the bottom.
|
||||||
# This assertion assumes parent and child are the same size.
|
# This assertion assumes parent and child are the same size.
|
||||||
miniwallet.rescan_utxos()
|
miniwallet.rescan_utxos()
|
||||||
tx_parent_just_below = miniwallet.create_self_transfer(fee=parent_fee, target_weight=target_weight_each)
|
tx_parent_just_below = miniwallet.create_self_transfer(fee_rate=parent_feerate, target_weight=target_weight_each)
|
||||||
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)
|
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)
|
||||||
# This package ranks below the lowest descendant package in the mempool
|
# This package ranks below the lowest descendant package in the mempool
|
||||||
assert_greater_than(worst_feerate_btcvb, (parent_fee + child_fee) / (tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()))
|
package_fee = tx_parent_just_below["fee"] + tx_child_just_above["fee"]
|
||||||
assert_greater_than(mempoolmin_feerate, (parent_fee) / (tx_parent_just_below["tx"].get_vsize()))
|
package_vsize = tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()
|
||||||
assert_greater_than((parent_fee + child_fee) / (tx_parent_just_below["tx"].get_vsize() + tx_child_just_above["tx"].get_vsize()), mempoolmin_feerate / 1000)
|
assert_greater_than(worst_feerate_btcvb, package_fee / package_vsize)
|
||||||
|
assert_greater_than(mempoolmin_feerate, tx_parent_just_below["fee"] / (tx_parent_just_below["tx"].get_vsize()))
|
||||||
|
assert_greater_than(package_fee / package_vsize, mempoolmin_feerate / 1000)
|
||||||
res = node.submitpackage([tx_parent_just_below["hex"], tx_child_just_above["hex"]])
|
res = node.submitpackage([tx_parent_just_below["hex"], tx_child_just_above["hex"]])
|
||||||
for wtxid in [tx_parent_just_below["wtxid"], tx_child_just_above["wtxid"]]:
|
for wtxid in [tx_parent_just_below["wtxid"], tx_child_just_above["wtxid"]]:
|
||||||
assert_equal(res["tx-results"][wtxid]["error"], "mempool full")
|
assert_equal(res["tx-results"][wtxid]["error"], "mempool full")
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import math
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Optional,
|
Optional,
|
||||||
|
@ -34,6 +35,7 @@ from test_framework.messages import (
|
||||||
CTxOut,
|
CTxOut,
|
||||||
hash256,
|
hash256,
|
||||||
ser_compact_size,
|
ser_compact_size,
|
||||||
|
WITNESS_SCALE_FACTOR,
|
||||||
)
|
)
|
||||||
from test_framework.script import (
|
from test_framework.script import (
|
||||||
CScript,
|
CScript,
|
||||||
|
@ -54,6 +56,7 @@ from test_framework.script_util import (
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_greater_than_or_equal,
|
assert_greater_than_or_equal,
|
||||||
|
get_fee,
|
||||||
)
|
)
|
||||||
from test_framework.wallet_util import generate_keypair
|
from test_framework.wallet_util import generate_keypair
|
||||||
|
|
||||||
|
@ -372,6 +375,10 @@ class MiniWallet:
|
||||||
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
|
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
if target_weight and not fee: # respect fee_rate if target weight is passed
|
||||||
|
# the actual weight might be off by 3 WUs, so calculate based on that (see self._bulk_tx)
|
||||||
|
max_actual_weight = target_weight + 3
|
||||||
|
fee = get_fee(math.ceil(max_actual_weight / WITNESS_SCALE_FACTOR), fee_rate)
|
||||||
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
|
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
|
||||||
|
|
||||||
# create tx
|
# create tx
|
||||||
|
|
Loading…
Add table
Reference in a new issue