Merge bitcoin/bitcoin#36611: test: consolidate mempool constants
What changed, and why it matters
This commit is a test-only cleanup. It moves several hard-coded numbers used in Bitcoin Core's functional tests into a shared helper file so they are defined in one place. No production code, consensus rules, or network behavior were changed.
No security action needed. This is a routine refactoring of test constants.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit consolidates mempool-related constants (DEFAULT_CLUSTER_LIMIT, DEFAULT_ANCESTOR_LIMIT, MAX_REPLACEMENT_CANDIDATES, TRUC_MAX_VSIZE, TRUC_CHILD_MAX_VSIZE) and MAX_FUTURE_BLOCK_TIME into shared test-framework modules (test_framework/mempool_util.py and test_framework/blocktools). The changes are purely import/definition refactorings across functional test files; no node logic, policy enforcement, or protocol handling is modified.
Changed components
test/functional/feature_rbf.pytest/functional/feature_taproot.pytest/functional/mempool_package_rbf.pytest/functional/mempool_packages.pytest/functional/mempool_truc.pytest/functional/mining_basic.pytest/functional/p2p_orphan_handling.pytest/functional/test_framework/mempool_util.pytest/functional/test_framework/messages.pytest/functional/wallet_basic.pyInspect captured patch +38 / −35
### test/functional/feature_rbf.py
@@ -20,9 +20,10 @@
)
from test_framework.wallet import MiniWallet
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
-from test_framework.mempool_util import DEFAULT_CLUSTER_LIMIT
-
-MAX_REPLACEMENT_LIMIT = 100
+from test_framework.mempool_util import (
+ DEFAULT_CLUSTER_LIMIT,
+ MAX_REPLACEMENT_CANDIDATES,
+)
class ReplaceByFeeTest(BitcoinTestFramework):
def set_test_params(self):
@@ -349,20 +350,20 @@ def test_new_unconfirmed_input_with_low_feerate(self):
def test_too_many_replacements(self):
"""Replacements that conflict with too many clusters are rejected"""
- # Try directly replacing transactions in more than MAX_REPLACEMENT_LIMIT
+ # Try directly replacing transactions in more than MAX_REPLACEMENT_CANDIDATES
# distinct clusters
# Start by creating a single transaction with many outputs
initial_nValue = 10 * COIN
utxo = self.make_utxo(self.nodes[0], initial_nValue)
fee = int(0.0001 * COIN)
- split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1))
+ split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_CANDIDATES + 1))
splitting_tx_utxos = self.wallet.send_self_transfer_multi(
from_node=self.nodes[0],
utxos_to_spend=[utxo],
sequence=0,
- num_outputs=MAX_REPLACEMENT_LIMIT + 1,
+ num_outputs=MAX_REPLACEMENT_CANDIDATES + 1,
amount_per_output=split_value,
)["new_utxos"]
@@ -380,7 +381,7 @@ def test_too_many_replacements(self):
# Now create doublespend of the whole lot; should fail.
# Need a big enough fee to cover all spending transactions and have
# a higher fee rate
- double_spend_value = (split_value - 100 * fee) * (MAX_REPLACEMENT_LIMIT + 1)
+ double_spend_value = (split_value - 100 * fee) * (MAX_REPLACEMENT_CANDIDATES + 1)
double_tx = self.wallet.create_self_transfer_multi(
utxos_to_spend=splitting_tx_utxos,
sequence=0,
@@ -390,7 +391,7 @@ def test_too_many_replacements(self):
# This will raise an exception
reject_reason = "too many potential replacements"
- reject_details = f"{reject_reason}, rejecting replacement {double_tx.txid_hex}; too many conflicting clusters ({MAX_REPLACEMENT_LIMIT + 1} > {MAX_REPLACEMENT_LIMIT})"
+ reject_details = f"{reject_reason}, rejecting replacement {double_tx.txid_hex}; too many conflicting clusters ({MAX_REPLACEMENT_CANDIDATES + 1} > {MAX_REPLACEMENT_CANDIDATES})"
res = self.nodes[0].testmempoolaccept(rawtxs=[double_tx_hex])[0]
assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details)
### test/functional/feature_taproot.py
@@ -11,6 +11,9 @@
add_witness_commitment,
MAX_BLOCK_SIGOPS_WEIGHT,
)
+from test_framework.mempool_util import (
+ TRUC_MAX_VSIZE,
+)
from test_framework.messages import (
COutPoint,
CTransaction,
@@ -670,7 +673,6 @@ def byte_popper(expr):
MIN_FEE = 50000
TX_STANDARD_VERSIONS = [1, 2, TX_MAX_STANDARD_VERSION]
-TRUC_MAX_VSIZE = 10000 # test doesn't cover in-mempool spends, so only this limit is hit
# === Actual test cases ===
@@ -1636,6 +1638,7 @@ def test_spenders(self, node, spenders, input_counts):
fail_input is None # Must be valid to be standard
and (all(utxo.spender.is_standard for utxo in input_utxos)) # All inputs must be standard
and tx.version in TX_STANDARD_VERSIONS # The tx version must be standard
+ # test doesn't cover in-mempool spends, so only TRUC_MAX_VSIZE limit is hit
and not (tx.version == 3 and tx.get_vsize() > TRUC_MAX_VSIZE) # Topological standardness rules must be followed
)
msg = ','.join(utxo.spender.comment + ("*" if n == fail_input else "") for n, utxo in enumerate(input_utxos))
### test/functional/mempool_package_rbf.py
@@ -10,7 +10,10 @@
MAX_BIP125_RBF_SEQUENCE,
)
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.mempool_util import fill_mempool
+from test_framework.mempool_util import (
+ fill_mempool,
+ MAX_REPLACEMENT_CANDIDATES,
+)
from test_framework.util import (
assert_greater_than_or_equal,
assert_equal,
@@ -21,8 +24,6 @@
)
from test_framework import mempool_util
-MAX_REPLACEMENT_CANDIDATES = 100
-
# Value high enough to cause evictions in each subtest
# for typical cases
DEFAULT_CHILD_FEE = DEFAULT_FEE * 4
@@ -191,12 +192,12 @@ def test_package_rbf_additional_fees(self):
def test_package_rbf_max_conflicts(self):
node = self.nodes[0]
- self.log.info("Check Package RBF cannot conflict with more than MAX_REPLACEMENT_CANDIDATES clusters")
- num_coins = 101
+ self.log.info("Check Package RBF cannot conflict with more than MAX_REPLACEMENT_CANDIDATES clusters")
+ num_coins = MAX_REPLACEMENT_CANDIDATES + 1
parent_coins = self.coins[:num_coins]
del self.coins[:num_coins]
- # Original transactions: 101 transactions with 2 descendants each -> 303 total transactions, 101 clusters
+ # Original transactions: num_coins transactions with 2 descendants each -> num_coins * 3 total transactions, num_coins clusters
size_three_clusters = []
for coin in parent_coins:
size_three_clusters.append(self.wallet.send_self_transfer_chain(from_node=node, chain_length=3, utxo_to_spend=coin))
@@ -211,13 +212,13 @@ def test_package_rbf_max_conflicts(self):
parent_fee_per_conflict = 10000
child_feerate = 10000 * DEFAULT_FEE
- # Conflict against all transactions by double-spending each parent, causing 101 cluster conflicts
+ # Conflict against all transactions by double-spending each parent, causing num_coins cluster conflicts
package_parent = self.wallet.create_self_transfer_multi(utxos_to_spend=parent_coins, fee_per_output=parent_fee_per_conflict)
package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0])
pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0)
assert_equal("transaction failed", pkg_results["package_msg"])
- assert_equal(f"too many potential replacements, rejecting replacement {package_parent['txid']}; too many conflicting clusters (101 > 100)", pkg_results["tx-results"][package_parent["wtxid"]]["error"])
+ assert_equal(f"too many potential replacements, rejecting replacement {package_parent['txid']}; too many conflicting clusters ({num_coins} > {MAX_REPLACEMENT_CANDIDATES})", pkg_results["tx-results"][package_parent["wtxid"]]["error"])
self.assert_mempool_contents(expected=expected_txns)
# Make singleton tx to conflict with in next batch
@@ -233,7 +234,7 @@ def test_package_rbf_max_conflicts(self):
package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0])
pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0)
assert_equal("transaction failed", pkg_results["package_msg"])
- assert_equal(f"too many potential replacements, rejecting replacement {package_parent['txid']}; too many conflicting clusters (101 > 100)", pkg_results["tx-results"][package_parent["wtxid"]]["error"])
+ assert_equal(f"too many potential replacements, rejecting replacement {package_parent['txid']}; too many conflicting clusters ({num_coins} > {MAX_REPLACEMENT_CANDIDATES})", pkg_results["tx-results"][package_parent["wtxid"]]["error"])
self.assert_mempool_contents(expected=expected_txns)
# Finally, conflict with MAX_REPLACEMENT_CANDIDATES clusters
### test/functional/mempool_packages.py
@@ -6,7 +6,7 @@
from decimal import Decimal
-from test_framework.messages import (
+from test_framework.mempool_util import (
DEFAULT_CLUSTER_LIMIT,
)
from test_framework.p2p import P2PTxInvStore
### test/functional/mempool_truc.py
@@ -21,10 +21,11 @@
from test_framework.blocktools import (
create_empty_fork,
)
-
-MAX_REPLACEMENT_CANDIDATES = 100
-TRUC_MAX_VSIZE = 10000
-TRUC_CHILD_MAX_VSIZE = 1000
+from test_framework.mempool_util import (
+ MAX_REPLACEMENT_CANDIDATES,
+ TRUC_MAX_VSIZE,
+ TRUC_CHILD_MAX_VSIZE,
+)
def cleanup(extra_args=None):
def decorator(func):
### test/functional/mining_basic.py
@@ -17,6 +17,7 @@
create_block,
create_coinbase,
get_witness_script,
+ MAX_FUTURE_BLOCK_TIME,
NORMAL_GBT_REQUEST_PARAMS,
TIME_GENESIS_BLOCK,
REGTEST_N_BITS,
@@ -52,7 +53,6 @@
DIFFICULTY_ADJUSTMENT_INTERVAL = 144
-MAX_FUTURE_BLOCK_TIME = 2 * 3600
MAX_TIMEWARP = 600
VERSIONBITS_TOP_BITS = 0x20000000
VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28
### test/functional/p2p_orphan_handling.py
@@ -8,11 +8,11 @@
from test_framework.blocktools import MAX_STANDARD_TX_WEIGHT
from test_framework.mempool_util import (
create_large_orphan,
+ DEFAULT_ANCESTOR_LIMIT,
tx_in_orphanage,
)
from test_framework.messages import (
CInv,
- DEFAULT_ANCESTOR_LIMIT,
MSG_TX,
MSG_WITNESS_TX,
MSG_WTX,
### test/functional/test_framework/mempool_util.py
@@ -33,9 +33,13 @@
DEFAULT_MIN_RELAY_TX_FEE = 100
# Default for -incrementalrelayfee in sat/kvB
DEFAULT_INCREMENTAL_RELAY_FEE = 100
-DEFAULT_CLUSTER_LIMIT = 64
+DEFAULT_CLUSTER_LIMIT = 64 # default max number of transactions in a cluster
DEFAULT_CLUSTER_SIZE_LIMIT_KVB = 101
+DEFAULT_ANCESTOR_LIMIT = 25 # default max number of in-mempool ancestors
+
+MAX_REPLACEMENT_CANDIDATES = 100
+
TRUC_MAX_VSIZE = 10000
TRUC_CHILD_MAX_VSIZE = 1000
### test/functional/test_framework/messages.py
@@ -74,11 +74,6 @@
WITNESS_SCALE_FACTOR = 4
-DEFAULT_ANCESTOR_LIMIT = 25 # default max number of in-mempool ancestors
-DEFAULT_DESCENDANT_LIMIT = 25 # default max number of in-mempool descendants
-DEFAULT_CLUSTER_LIMIT = 64 # default max number of transactions in a cluster
-
-
# Default setting for -datacarriersize.
MAX_OP_RETURN_RELAY = 100_000
### test/functional/wallet_basic.py
@@ -8,10 +8,8 @@
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.descriptors import descsum_create
-from test_framework.messages import (
- COIN,
- DEFAULT_ANCESTOR_LIMIT,
-)
+from test_framework.mempool_util import DEFAULT_ANCESTOR_LIMIT
+from test_framework.messages import COIN
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_array_result,Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.