2016-03-19 20:58:06 +01:00
|
|
|
#!/usr/bin/env python3
|
2022-12-25 00:49:50 +01:00
|
|
|
# Copyright (c) 2014-2022 The Bitcoin Core developers
|
2015-11-30 15:42:27 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2017-01-18 00:34:40 +01:00
|
|
|
"""Test mempool limiting together/eviction with the wallet."""
|
2015-11-30 15:42:27 +01:00
|
|
|
|
2018-07-07 00:10:35 +02:00
|
|
|
from decimal import Decimal
|
|
|
|
|
2021-09-10 13:37:58 +02:00
|
|
|
from test_framework.blocktools import COINBASE_MATURITY
|
2023-01-17 16:37:25 +01:00
|
|
|
from test_framework.p2p import P2PTxInvStore
|
2015-11-30 15:42:27 +01:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
test: fix misleading fee unit in mempool_limit.py
The helper `send_large_txs` in its current interface has a fee_rate
parameter, implying that it would create a transaction with exactly that
rate. Unfortunately, this fee rate is only passed to MiniWallet's
`create_self_transfer` method, which can't know that we append several
tx outputs after, increasing the tx's vsize and decreasing it's fee rate
accordingly.
In our case, the fee rate is off by several orders of magnitude, as the
tx's vsize changes changes from 96 to 67552 vbytes (>700x), i.e. the
value passed to this function is neither really a fee rate nor an
absolute fee, but something in-between, which is very confusing.
Clarify the interface by passing an absolute fee that is deducted in the end
(and verified, via testmempoolaccept) and also describe how we come up with the
value passed.
2021-09-14 15:39:03 +02:00
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
2023-01-17 16:37:25 +01:00
|
|
|
assert_fee_amount,
|
test: fix misleading fee unit in mempool_limit.py
The helper `send_large_txs` in its current interface has a fee_rate
parameter, implying that it would create a transaction with exactly that
rate. Unfortunately, this fee rate is only passed to MiniWallet's
`create_self_transfer` method, which can't know that we append several
tx outputs after, increasing the tx's vsize and decreasing it's fee rate
accordingly.
In our case, the fee rate is off by several orders of magnitude, as the
tx's vsize changes changes from 96 to 67552 vbytes (>700x), i.e. the
value passed to this function is neither really a fee rate nor an
absolute fee, but something in-between, which is very confusing.
Clarify the interface by passing an absolute fee that is deducted in the end
(and verified, via testmempoolaccept) and also describe how we come up with the
value passed.
2021-09-14 15:39:03 +02:00
|
|
|
assert_greater_than,
|
|
|
|
assert_raises_rpc_error,
|
2022-04-16 21:10:24 +02:00
|
|
|
create_lots_of_big_transactions,
|
test: fix misleading fee unit in mempool_limit.py
The helper `send_large_txs` in its current interface has a fee_rate
parameter, implying that it would create a transaction with exactly that
rate. Unfortunately, this fee rate is only passed to MiniWallet's
`create_self_transfer` method, which can't know that we append several
tx outputs after, increasing the tx's vsize and decreasing it's fee rate
accordingly.
In our case, the fee rate is off by several orders of magnitude, as the
tx's vsize changes changes from 96 to 67552 vbytes (>700x), i.e. the
value passed to this function is neither really a fee rate nor an
absolute fee, but something in-between, which is very confusing.
Clarify the interface by passing an absolute fee that is deducted in the end
(and verified, via testmempoolaccept) and also describe how we come up with the
value passed.
2021-09-14 15:39:03 +02:00
|
|
|
gen_return_txouts,
|
|
|
|
)
|
2023-01-17 16:37:25 +01:00
|
|
|
from test_framework.wallet import (
|
|
|
|
COIN,
|
|
|
|
DEFAULT_FEE,
|
|
|
|
MiniWallet,
|
|
|
|
)
|
2021-09-10 13:37:58 +02:00
|
|
|
|
2015-11-30 15:42:27 +01:00
|
|
|
|
|
|
|
class MempoolLimitTest(BitcoinTestFramework):
|
2017-06-10 00:21:21 +02:00
|
|
|
def set_test_params(self):
|
2016-05-14 13:01:31 +02:00
|
|
|
self.setup_clean_chain = True
|
2016-05-15 12:20:15 +02:00
|
|
|
self.num_nodes = 1
|
2019-04-24 23:55:58 +02:00
|
|
|
self.extra_args = [[
|
2022-06-29 17:51:39 +02:00
|
|
|
"-datacarriersize=100000",
|
2019-04-24 23:55:58 +02:00
|
|
|
"-maxmempool=5",
|
|
|
|
]]
|
2019-12-06 15:37:49 +01:00
|
|
|
self.supports_cli = False
|
2015-11-30 15:42:27 +01:00
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
def fill_mempool(self):
|
|
|
|
"""Fill mempool until eviction."""
|
|
|
|
self.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
|
2017-04-03 15:34:04 +02:00
|
|
|
txouts = gen_return_txouts()
|
test: fix misleading fee unit in mempool_limit.py
The helper `send_large_txs` in its current interface has a fee_rate
parameter, implying that it would create a transaction with exactly that
rate. Unfortunately, this fee rate is only passed to MiniWallet's
`create_self_transfer` method, which can't know that we append several
tx outputs after, increasing the tx's vsize and decreasing it's fee rate
accordingly.
In our case, the fee rate is off by several orders of magnitude, as the
tx's vsize changes changes from 96 to 67552 vbytes (>700x), i.e. the
value passed to this function is neither really a fee rate nor an
absolute fee, but something in-between, which is very confusing.
Clarify the interface by passing an absolute fee that is deducted in the end
(and verified, via testmempoolaccept) and also describe how we come up with the
value passed.
2021-09-14 15:39:03 +02:00
|
|
|
node = self.nodes[0]
|
2023-08-14 11:30:57 +02:00
|
|
|
miniwallet = self.wallet
|
2021-09-13 21:25:45 +02:00
|
|
|
relayfee = node.getnetworkinfo()['relayfee']
|
2017-04-03 15:34:04 +02:00
|
|
|
|
2023-04-17 13:25:04 +02:00
|
|
|
tx_batch_size = 1
|
|
|
|
num_of_batches = 75
|
2021-09-10 13:37:58 +02:00
|
|
|
# Generate UTXOs to flood the mempool
|
|
|
|
# 1 to create a tx initially that will be evicted from the mempool later
|
2023-08-14 11:30:57 +02:00
|
|
|
# 75 transactions each with a fee rate higher than the previous one
|
2021-09-10 13:37:58 +02:00
|
|
|
# And 1 more to verify that this tx does not get added to the mempool with a fee rate less than the mempoolminfee
|
2023-01-17 16:37:25 +01:00
|
|
|
# And 2 more for the package cpfp test
|
2023-08-14 11:30:57 +02:00
|
|
|
self.generate(miniwallet, 1 + (num_of_batches * tx_batch_size))
|
2021-09-10 13:37:58 +02:00
|
|
|
|
|
|
|
# Mine 99 blocks so that the UTXOs are allowed to be spent
|
2021-09-13 21:25:45 +02:00
|
|
|
self.generate(node, COINBASE_MATURITY - 1)
|
2015-11-30 15:42:27 +01:00
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
self.log.debug("Create a mempool tx that will be evicted")
|
2021-09-13 21:25:45 +02:00
|
|
|
tx_to_be_evicted_id = miniwallet.send_self_transfer(from_node=node, fee_rate=relayfee)["txid"]
|
2015-11-30 15:42:27 +01:00
|
|
|
|
test: fix misleading fee unit in mempool_limit.py
The helper `send_large_txs` in its current interface has a fee_rate
parameter, implying that it would create a transaction with exactly that
rate. Unfortunately, this fee rate is only passed to MiniWallet's
`create_self_transfer` method, which can't know that we append several
tx outputs after, increasing the tx's vsize and decreasing it's fee rate
accordingly.
In our case, the fee rate is off by several orders of magnitude, as the
tx's vsize changes changes from 96 to 67552 vbytes (>700x), i.e. the
value passed to this function is neither really a fee rate nor an
absolute fee, but something in-between, which is very confusing.
Clarify the interface by passing an absolute fee that is deducted in the end
(and verified, via testmempoolaccept) and also describe how we come up with the
value passed.
2021-09-14 15:39:03 +02:00
|
|
|
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
|
|
|
|
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
|
|
|
|
# by 130 should result in a fee that corresponds to 2x of that fee rate
|
|
|
|
base_fee = relayfee * 130
|
2021-09-10 13:37:58 +02:00
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
self.log.debug("Fill up the mempool with txs with higher fee rate")
|
|
|
|
with node.assert_debug_log(["rolling minimum fee bumped"]):
|
|
|
|
for batch_of_txid in range(num_of_batches):
|
|
|
|
fee = (batch_of_txid + 1) * base_fee
|
|
|
|
create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts)
|
2015-11-30 15:42:27 +01:00
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
self.log.debug("The tx should be evicted by now")
|
2021-09-10 13:37:58 +02:00
|
|
|
# The number of transactions created should be greater than the ones present in the mempool
|
2021-09-13 21:25:45 +02:00
|
|
|
assert_greater_than(tx_batch_size * num_of_batches, len(node.getrawmempool()))
|
2021-09-10 13:37:58 +02:00
|
|
|
# Initial tx created should not be present in the mempool anymore as it had a lower fee rate
|
2021-09-13 21:25:45 +02:00
|
|
|
assert tx_to_be_evicted_id not in node.getrawmempool()
|
2015-11-30 15:42:27 +01:00
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
self.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
|
2021-09-13 21:25:45 +02:00
|
|
|
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
|
|
|
|
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
|
2017-12-24 01:42:34 +01:00
|
|
|
|
2023-09-14 19:13:57 +02:00
|
|
|
def test_rbf_carveout_disallowed(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
|
|
|
|
self.log.info("Check that individually-evaluated transactions in a package don't increase package limits for other subpackage parts")
|
|
|
|
|
|
|
|
# We set chain limits to 2 ancestors, 1 descendant, then try to get a parents-and-child chain of 2 in mempool
|
|
|
|
#
|
|
|
|
# A: Solo transaction to be RBF'd (to bump descendant limit for package later)
|
|
|
|
# B: First transaction in package, RBFs A by itself under individual evaluation, which would give it +1 descendant limit
|
|
|
|
# C: Second transaction in package, spends B. If the +1 descendant limit persisted, would make it into mempool
|
|
|
|
|
|
|
|
self.restart_node(0, extra_args=self.extra_args[0] + ["-limitancestorcount=2", "-limitdescendantcount=1"])
|
|
|
|
|
|
|
|
# Generate a confirmed utxo we will double-spend
|
|
|
|
rbf_utxo = self.wallet.send_self_transfer(
|
|
|
|
from_node=node,
|
|
|
|
confirmed_only=True
|
|
|
|
)["new_utxo"]
|
|
|
|
self.generate(node, 1)
|
|
|
|
|
|
|
|
# tx_A needs to be RBF'd, set minfee at set size
|
|
|
|
A_weight = 1000
|
|
|
|
mempoolmin_feerate = node.getmempoolinfo()["mempoolminfee"]
|
|
|
|
tx_A = self.wallet.send_self_transfer(
|
|
|
|
from_node=node,
|
|
|
|
fee=(mempoolmin_feerate / 1000) * (A_weight // 4) + Decimal('0.000001'),
|
|
|
|
target_weight=A_weight,
|
|
|
|
utxo_to_spend=rbf_utxo,
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
|
|
|
|
# RBF's tx_A, is not yet submitted
|
|
|
|
tx_B = self.wallet.create_self_transfer(
|
|
|
|
fee=tx_A["fee"] * 4,
|
|
|
|
target_weight=A_weight,
|
|
|
|
utxo_to_spend=rbf_utxo,
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
|
|
|
|
# Spends tx_B's output, too big for cpfp carveout (because that would also increase the descendant limit by 1)
|
|
|
|
non_cpfp_carveout_weight = 40001 # EXTRA_DESCENDANT_TX_SIZE_LIMIT + 1
|
|
|
|
tx_C = self.wallet.create_self_transfer(
|
|
|
|
target_weight=non_cpfp_carveout_weight,
|
|
|
|
fee = (mempoolmin_feerate / 1000) * (non_cpfp_carveout_weight // 4) + Decimal('0.000001'),
|
|
|
|
utxo_to_spend=tx_B["new_utxo"],
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_raises_rpc_error(-26, "too-long-mempool-chain", node.submitpackage, [tx_B["hex"], tx_C["hex"]])
|
|
|
|
|
2023-08-14 11:53:39 +02:00
|
|
|
def test_mid_package_eviction(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
self.log.info("Check a package where each parent passes the current mempoolminfee but would cause eviction before package submission terminates")
|
|
|
|
|
|
|
|
self.restart_node(0, extra_args=self.extra_args[0])
|
|
|
|
|
|
|
|
# Restarting the node resets mempool minimum feerate
|
|
|
|
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
|
|
|
|
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
|
|
|
|
|
|
|
|
self.fill_mempool()
|
|
|
|
current_info = node.getmempoolinfo()
|
|
|
|
mempoolmin_feerate = current_info["mempoolminfee"]
|
|
|
|
|
|
|
|
package_hex = []
|
|
|
|
# UTXOs to be spent by the ultimate child transaction
|
|
|
|
parent_utxos = []
|
|
|
|
|
|
|
|
evicted_weight = 8000
|
|
|
|
# Mempool transaction which is evicted due to being at the "bottom" of the mempool when the
|
|
|
|
# mempool overflows and evicts by descendant score. It's important that the eviction doesn't
|
|
|
|
# happen in the middle of package evaluation, as it can invalidate the coins cache.
|
|
|
|
mempool_evicted_tx = self.wallet.send_self_transfer(
|
|
|
|
from_node=node,
|
|
|
|
fee=(mempoolmin_feerate / 1000) * (evicted_weight // 4) + Decimal('0.000001'),
|
|
|
|
target_weight=evicted_weight,
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
# Already in mempool when package is submitted.
|
|
|
|
assert mempool_evicted_tx["txid"] in node.getrawmempool()
|
|
|
|
|
|
|
|
# This parent spends the above mempool transaction that exists when its inputs are first
|
|
|
|
# looked up, but disappears later. It is rejected for being too low fee (but eligible for
|
|
|
|
# reconsideration), and its inputs are cached. When the mempool transaction is evicted, its
|
|
|
|
# coin is no longer available, but the cache could still contains the tx.
|
|
|
|
cpfp_parent = self.wallet.create_self_transfer(
|
|
|
|
utxo_to_spend=mempool_evicted_tx["new_utxo"],
|
|
|
|
fee_rate=mempoolmin_feerate - Decimal('0.00001'),
|
|
|
|
confirmed_only=True)
|
|
|
|
package_hex.append(cpfp_parent["hex"])
|
|
|
|
parent_utxos.append(cpfp_parent["new_utxo"])
|
|
|
|
assert_equal(node.testmempoolaccept([cpfp_parent["hex"]])[0]["reject-reason"], "mempool min fee not met")
|
|
|
|
|
|
|
|
self.wallet.rescan_utxos()
|
|
|
|
|
|
|
|
# Series of parents that don't need CPFP and are submitted individually. Each one is large and
|
|
|
|
# high feerate, which means they should trigger eviction but not be evicted.
|
|
|
|
parent_weight = 100000
|
|
|
|
num_big_parents = 3
|
|
|
|
assert_greater_than(parent_weight * num_big_parents, current_info["maxmempool"] - current_info["bytes"])
|
|
|
|
parent_fee = (100 * mempoolmin_feerate / 1000) * (parent_weight // 4)
|
|
|
|
|
|
|
|
big_parent_txids = []
|
|
|
|
for i in range(num_big_parents):
|
|
|
|
parent = self.wallet.create_self_transfer(fee=parent_fee, target_weight=parent_weight, confirmed_only=True)
|
|
|
|
parent_utxos.append(parent["new_utxo"])
|
|
|
|
package_hex.append(parent["hex"])
|
|
|
|
big_parent_txids.append(parent["txid"])
|
|
|
|
# There is room for each of these transactions independently
|
|
|
|
assert node.testmempoolaccept([parent["hex"]])[0]["allowed"]
|
|
|
|
|
|
|
|
# Create a child spending everything, bumping cpfp_parent just above mempool minimum
|
|
|
|
# feerate. It's important not to bump too much as otherwise mempool_evicted_tx would not be
|
|
|
|
# evicted, making this test much less meaningful.
|
|
|
|
approx_child_vsize = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos)["tx"].get_vsize()
|
|
|
|
cpfp_fee = (mempoolmin_feerate / 1000) * (cpfp_parent["tx"].get_vsize() + approx_child_vsize) - cpfp_parent["fee"]
|
|
|
|
# Specific number of satoshis to fit within a small window. The parent_cpfp + child package needs to be
|
|
|
|
# - When there is mid-package eviction, high enough feerate to meet the new mempoolminfee
|
|
|
|
# - When there is no mid-package eviction, low enough feerate to be evicted immediately after submission.
|
|
|
|
magic_satoshis = 1200
|
|
|
|
cpfp_satoshis = int(cpfp_fee * COIN) + magic_satoshis
|
|
|
|
|
|
|
|
child = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos, fee_per_output=cpfp_satoshis)
|
|
|
|
package_hex.append(child["hex"])
|
|
|
|
|
|
|
|
# Package should be submitted, temporarily exceeding maxmempool, and then evicted.
|
|
|
|
with node.assert_debug_log(expected_msgs=["rolling minimum fee bumped"]):
|
|
|
|
assert_raises_rpc_error(-26, "mempool full", node.submitpackage, package_hex)
|
|
|
|
|
|
|
|
# Maximum size must never be exceeded.
|
|
|
|
assert_greater_than(node.getmempoolinfo()["maxmempool"], node.getmempoolinfo()["bytes"])
|
|
|
|
|
|
|
|
# Evicted transaction and its descendants must not be in mempool.
|
|
|
|
resulting_mempool_txids = node.getrawmempool()
|
|
|
|
assert mempool_evicted_tx["txid"] not in resulting_mempool_txids
|
|
|
|
assert cpfp_parent["txid"] not in resulting_mempool_txids
|
|
|
|
assert child["txid"] not in resulting_mempool_txids
|
|
|
|
for txid in big_parent_txids:
|
|
|
|
assert txid in resulting_mempool_txids
|
|
|
|
|
|
|
|
def test_mid_package_replacement(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
self.log.info("Check a package where an early tx depends on a later-replaced mempool tx")
|
|
|
|
|
|
|
|
self.restart_node(0, extra_args=self.extra_args[0])
|
|
|
|
|
|
|
|
# Restarting the node resets mempool minimum feerate
|
|
|
|
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
|
|
|
|
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
|
|
|
|
|
|
|
|
self.fill_mempool()
|
|
|
|
current_info = node.getmempoolinfo()
|
|
|
|
mempoolmin_feerate = current_info["mempoolminfee"]
|
|
|
|
|
|
|
|
# Mempool transaction which is evicted due to being at the "bottom" of the mempool when the
|
|
|
|
# mempool overflows and evicts by descendant score. It's important that the eviction doesn't
|
|
|
|
# happen in the middle of package evaluation, as it can invalidate the coins cache.
|
|
|
|
double_spent_utxo = self.wallet.get_utxo(confirmed_only=True)
|
|
|
|
replaced_tx = self.wallet.send_self_transfer(
|
|
|
|
from_node=node,
|
|
|
|
utxo_to_spend=double_spent_utxo,
|
|
|
|
fee_rate=mempoolmin_feerate,
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
# Already in mempool when package is submitted.
|
|
|
|
assert replaced_tx["txid"] in node.getrawmempool()
|
|
|
|
|
|
|
|
# This parent spends the above mempool transaction that exists when its inputs are first
|
|
|
|
# looked up, but disappears later. It is rejected for being too low fee (but eligible for
|
|
|
|
# reconsideration), and its inputs are cached. When the mempool transaction is evicted, its
|
|
|
|
# coin is no longer available, but the cache could still contain the tx.
|
|
|
|
cpfp_parent = self.wallet.create_self_transfer(
|
|
|
|
utxo_to_spend=replaced_tx["new_utxo"],
|
|
|
|
fee_rate=mempoolmin_feerate - Decimal('0.00001'),
|
|
|
|
confirmed_only=True)
|
|
|
|
|
|
|
|
self.wallet.rescan_utxos()
|
|
|
|
|
|
|
|
# Parent that replaces the parent of cpfp_parent.
|
|
|
|
replacement_tx = self.wallet.create_self_transfer(
|
|
|
|
utxo_to_spend=double_spent_utxo,
|
|
|
|
fee_rate=10*mempoolmin_feerate,
|
|
|
|
confirmed_only=True
|
|
|
|
)
|
|
|
|
parent_utxos = [cpfp_parent["new_utxo"], replacement_tx["new_utxo"]]
|
|
|
|
|
|
|
|
# Create a child spending everything, CPFPing the low-feerate parent.
|
|
|
|
approx_child_vsize = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos)["tx"].get_vsize()
|
|
|
|
cpfp_fee = (2 * mempoolmin_feerate / 1000) * (cpfp_parent["tx"].get_vsize() + approx_child_vsize) - cpfp_parent["fee"]
|
|
|
|
child = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_utxos, fee_per_output=int(cpfp_fee * COIN))
|
|
|
|
# It's very important that the cpfp_parent is before replacement_tx so that its input (from
|
|
|
|
# replaced_tx) is first looked up *before* replacement_tx is submitted.
|
|
|
|
package_hex = [cpfp_parent["hex"], replacement_tx["hex"], child["hex"]]
|
|
|
|
|
|
|
|
# Package should be submitted, temporarily exceeding maxmempool, and then evicted.
|
|
|
|
assert_raises_rpc_error(-26, "bad-txns-inputs-missingorspent", node.submitpackage, package_hex)
|
|
|
|
|
|
|
|
# Maximum size must never be exceeded.
|
|
|
|
assert_greater_than(node.getmempoolinfo()["maxmempool"], node.getmempoolinfo()["bytes"])
|
|
|
|
|
|
|
|
resulting_mempool_txids = node.getrawmempool()
|
|
|
|
# The replacement should be successful.
|
|
|
|
assert replacement_tx["txid"] in resulting_mempool_txids
|
|
|
|
# The replaced tx and all of its descendants must not be in mempool.
|
|
|
|
assert replaced_tx["txid"] not in resulting_mempool_txids
|
|
|
|
assert cpfp_parent["txid"] not in resulting_mempool_txids
|
|
|
|
assert child["txid"] not in resulting_mempool_txids
|
|
|
|
|
|
|
|
|
2023-08-14 11:30:57 +02:00
|
|
|
def run_test(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
self.wallet = MiniWallet(node)
|
|
|
|
miniwallet = self.wallet
|
|
|
|
|
|
|
|
# Generate coins needed to create transactions in the subtests (excluding coins used in fill_mempool).
|
2023-08-14 11:53:39 +02:00
|
|
|
self.generate(miniwallet, 20)
|
2023-08-14 11:30:57 +02:00
|
|
|
|
|
|
|
relayfee = node.getnetworkinfo()['relayfee']
|
|
|
|
self.log.info('Check that mempoolminfee is minrelaytxfee')
|
|
|
|
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
|
|
|
|
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
|
|
|
|
|
|
|
|
self.fill_mempool()
|
|
|
|
|
2021-09-10 13:37:58 +02:00
|
|
|
# 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
|
2018-02-06 03:00:57 +01:00
|
|
|
self.log.info('Create a mempool tx that will not pass mempoolminfee')
|
2022-06-13 14:08:12 +02:00
|
|
|
assert_raises_rpc_error(-26, "mempool min fee not met", miniwallet.send_self_transfer, from_node=node, fee_rate=relayfee)
|
2021-09-10 13:37:58 +02:00
|
|
|
|
2023-01-17 16:37:25 +01:00
|
|
|
self.log.info("Check that submitpackage allows cpfp of a parent below mempool min feerate")
|
|
|
|
node = self.nodes[0]
|
|
|
|
peer = node.add_p2p_connection(P2PTxInvStore())
|
|
|
|
|
|
|
|
# Package with 2 parents and 1 child. One parent has a high feerate due to modified fees,
|
|
|
|
# another is below the mempool minimum feerate but bumped by the child.
|
|
|
|
tx_poor = miniwallet.create_self_transfer(fee_rate=relayfee)
|
|
|
|
tx_rich = miniwallet.create_self_transfer(fee=0, fee_rate=0)
|
|
|
|
node.prioritisetransaction(tx_rich["txid"], 0, int(DEFAULT_FEE * COIN))
|
|
|
|
package_txns = [tx_rich, tx_poor]
|
|
|
|
coins = [tx["new_utxo"] for tx in package_txns]
|
|
|
|
tx_child = miniwallet.create_self_transfer_multi(utxos_to_spend=coins, fee_per_output=10000) #DEFAULT_FEE
|
|
|
|
package_txns.append(tx_child)
|
|
|
|
|
|
|
|
submitpackage_result = node.submitpackage([tx["hex"] for tx in package_txns])
|
|
|
|
|
|
|
|
rich_parent_result = submitpackage_result["tx-results"][tx_rich["wtxid"]]
|
|
|
|
poor_parent_result = submitpackage_result["tx-results"][tx_poor["wtxid"]]
|
|
|
|
child_result = submitpackage_result["tx-results"][tx_child["tx"].getwtxid()]
|
|
|
|
assert_fee_amount(poor_parent_result["fees"]["base"], tx_poor["tx"].get_vsize(), relayfee)
|
|
|
|
assert_equal(rich_parent_result["fees"]["base"], 0)
|
|
|
|
assert_equal(child_result["fees"]["base"], DEFAULT_FEE)
|
|
|
|
# The "rich" parent does not require CPFP so its effective feerate is just its individual feerate.
|
|
|
|
assert_fee_amount(DEFAULT_FEE, tx_rich["tx"].get_vsize(), rich_parent_result["fees"]["effective-feerate"])
|
|
|
|
assert_equal(rich_parent_result["fees"]["effective-includes"], [tx_rich["wtxid"]])
|
|
|
|
# The "poor" parent and child's effective feerates are the same, composed of their total
|
|
|
|
# fees divided by their combined vsize.
|
|
|
|
package_fees = poor_parent_result["fees"]["base"] + child_result["fees"]["base"]
|
|
|
|
package_vsize = tx_poor["tx"].get_vsize() + tx_child["tx"].get_vsize()
|
|
|
|
assert_fee_amount(package_fees, package_vsize, poor_parent_result["fees"]["effective-feerate"])
|
|
|
|
assert_fee_amount(package_fees, package_vsize, child_result["fees"]["effective-feerate"])
|
|
|
|
assert_equal([tx_poor["wtxid"], tx_child["tx"].getwtxid()], poor_parent_result["fees"]["effective-includes"])
|
|
|
|
assert_equal([tx_poor["wtxid"], tx_child["tx"].getwtxid()], child_result["fees"]["effective-includes"])
|
|
|
|
|
|
|
|
# The node will broadcast each transaction, still abiding by its peer's fee filter
|
|
|
|
peer.wait_for_broadcast([tx["tx"].getwtxid() for tx in package_txns])
|
2023-04-17 13:25:04 +02:00
|
|
|
|
|
|
|
self.log.info("Check a package that passes mempoolminfee but is evicted immediately after submission")
|
|
|
|
mempoolmin_feerate = node.getmempoolinfo()["mempoolminfee"]
|
|
|
|
current_mempool = node.getrawmempool(verbose=False)
|
|
|
|
worst_feerate_btcvb = Decimal("21000000")
|
|
|
|
for txid in current_mempool:
|
|
|
|
entry = node.getmempoolentry(txid)
|
|
|
|
worst_feerate_btcvb = min(worst_feerate_btcvb, entry["fees"]["descendant"] / entry["descendantsize"])
|
|
|
|
# Needs to be large enough to trigger eviction
|
|
|
|
target_weight_each = 200000
|
|
|
|
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
|
|
|
|
parent_fee = (mempoolmin_feerate / 1000) * (target_weight_each // 4) - Decimal("0.00001")
|
|
|
|
# Parent + child is above mempool minimum feerate
|
|
|
|
child_fee = (worst_feerate_btcvb) * (target_weight_each // 4) - Decimal("0.00001")
|
|
|
|
# However, when eviction is triggered, these transactions should be at the bottom.
|
|
|
|
# This assertion assumes parent and child are the same size.
|
|
|
|
miniwallet.rescan_utxos()
|
|
|
|
tx_parent_just_below = miniwallet.create_self_transfer(fee=parent_fee, 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)
|
|
|
|
# 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()))
|
|
|
|
assert_greater_than(mempoolmin_feerate, (parent_fee) / (tx_parent_just_below["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_raises_rpc_error(-26, "mempool full", node.submitpackage, [tx_parent_just_below["hex"], tx_child_just_above["hex"]])
|
2023-01-17 16:37:25 +01:00
|
|
|
|
2022-06-13 14:58:22 +02:00
|
|
|
self.log.info('Test passing a value below the minimum (5 MB) to -maxmempool throws an error')
|
|
|
|
self.stop_node(0)
|
|
|
|
self.nodes[0].assert_start_raises_init_error(["-maxmempool=4"], "Error: -maxmempool must be at least 5 MB")
|
|
|
|
|
2023-08-14 11:53:39 +02:00
|
|
|
self.test_mid_package_replacement()
|
|
|
|
self.test_mid_package_eviction()
|
2023-09-14 19:13:57 +02:00
|
|
|
self.test_rbf_carveout_disallowed()
|
2023-08-14 11:53:39 +02:00
|
|
|
|
2018-02-06 03:00:57 +01:00
|
|
|
|
2015-11-30 15:42:27 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
MempoolLimitTest().main()
|