[prep/test] replace magic number 1000 with respective feerate vars
What changed, and why it matters
This commit only changes test code. It replaces hard-coded fee rate numbers like 1000 with named constants and removes duplicated hard-coded values in test assertions. There is no change to the actual Bitcoin Core node behavior, so it cannot introduce a security vulnerability or fix one in production code.
No security action needed. This is a test-only refactor and can be reviewed as normal code quality/maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff touches three test files: src/test/mempool_tests.cpp, test/functional/mempool_limit.py, and test/functional/test_framework/mempool_util.py. It substitutes the literal 1000 with DEFAULT_INCREMENTAL_RELAY_FEE in C++ unit tests and replaces hard-coded Decimal(‘0.00001000’) comparisons with comparisons against the node’s reported minrelayfee/mempoolminfee in Python functional tests. No production mempool, consensus, networking, or wallet logic is modified.
Changed components
src/test/mempool_tests.cpptest/functional/mempool_limit.pytest/functional/test_framework/mempool_util.pyInspect captured patch +17 / −23
diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp
index 5992d2a4..b75a1cc7 100644
--- a/src/test/mempool_tests.cpp
+++ b/src/test/mempool_tests.cpp
@@ -482,7 +482,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
BOOST_CHECK(!pool.exists(tx3.GetHash()));
CFeeRate maxFeeRateRemoved(25000, GetVirtualTransactionSize(CTransaction(tx3)) + GetVirtualTransactionSize(CTransaction(tx2)));
- BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
+ BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE);
CMutableTransaction tx4 = CMutableTransaction();
tx4.vin.resize(2);
@@ -559,28 +559,28 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
std::vector<CTransactionRef> vtx;
SetMockTime(42);
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
- BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
+ BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE);
// ... we should keep the same min fee until we get a block
pool.removeForBlock(vtx, 1);
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE);
- BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/2.0));
+ BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/2.0));
// ... then feerate should drop 1/2 each halflife
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2);
- BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 5 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/4.0));
+ BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 5 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/4.0));
// ... with a 1/2 halflife when mempool is < 1/2 its target size
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
- BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/8.0));
+ BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/8.0));
// ... with a 1/4 halflife when mempool is < 1/4 its target size
SetMockTime(42 + 7*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
- BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 1000);
- // ... but feerate should never drop below 1000
+ BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), DEFAULT_INCREMENTAL_RELAY_FEE);
+ // ... but feerate should never drop below DEFAULT_INCREMENTAL_RELAY_FEE
SetMockTime(42 + 8*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 0);
- // ... unless it has gone all the way to 0 (after getting past 1000/2)
+ // ... unless it has gone all the way to 0 (after getting past DEFAULT_INCREMENTAL_RELAY_FEE/2)
}
inline CTransactionRef make_tx(std::vector<CAmount>&& output_values, std::vector<CTransactionRef>&& inputs=std::vector<CTransactionRef>(), std::vector<uint32_t>&& input_indices=std::vector<uint32_t>())
diff --git a/test/functional/mempool_limit.py b/test/functional/mempool_limit.py
index c9a200cf..2a127007 100755
--- a/test/functional/mempool_limit.py
+++ b/test/functional/mempool_limit.py
@@ -92,8 +92,7 @@ class MempoolLimitTest(BitcoinTestFramework):
assert_equal(node.getrawmempool(), [])
# Restarting the node resets mempool minimum feerate
- assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
- assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
+ assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
fill_mempool(self, node)
current_info = node.getmempoolinfo()
@@ -184,8 +183,7 @@ class MempoolLimitTest(BitcoinTestFramework):
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'))
+ assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
fill_mempool(self, node)
current_info = node.getmempoolinfo()
@@ -256,8 +254,7 @@ class MempoolLimitTest(BitcoinTestFramework):
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'))
+ assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
fill_mempool(self, node)
diff --git a/test/functional/test_framework/mempool_util.py b/test/functional/test_framework/mempool_util.py
index a0b6f5d0..78e5f060 100644
--- a/test/functional/test_framework/mempool_util.py
+++ b/test/functional/test_framework/mempool_util.py
@@ -3,7 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Helpful routines for mempool testing."""
-from decimal import Decimal
import random
from .blocktools import (
@@ -62,9 +61,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
"""
test_framework.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
txouts = gen_return_txouts()
- relayfee = node.getnetworkinfo()['relayfee']
-
- assert_equal(relayfee, Decimal('0.00001000'))
+ minrelayfee = node.getnetworkinfo()['relayfee']
tx_batch_size = 1
num_of_batches = 75
@@ -84,7 +81,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
test_framework.log.debug("Create a mempool tx that will be evicted")
tx_to_be_evicted_id = ephemeral_miniwallet.send_self_transfer(
- from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=relayfee)["txid"]
+ from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=minrelayfee)["txid"]
def send_batch(fee):
utxos = confirmed_utxos[:tx_batch_size]
@@ -94,14 +91,14 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
# 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
+ base_fee = minrelayfee * 130
batch_fees = [(i + 1) * base_fee for i in range(num_of_batches)]
test_framework.log.debug("Fill up the mempool with txs with higher fee rate")
for fee in batch_fees[:-3]:
send_batch(fee)
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync before any eviction
- assert_equal(node.getmempoolinfo()["mempoolminfee"], Decimal("0.00001000"))
+ assert_equal(node.getmempoolinfo()["mempoolminfee"], minrelayfee)
for fee in batch_fees[-3:]:
send_batch(fee)
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync after all evictions
@@ -113,8 +110,8 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
assert tx_to_be_evicted_id not in node.getrawmempool()
test_framework.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
- assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
- assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
+ assert_equal(node.getmempoolinfo()['minrelaytxfee'], minrelayfee)
+ assert_greater_than(node.getmempoolinfo()['mempoolminfee'], minrelayfee)
def tx_in_orphanage(node, tx: CTransaction) -> bool:
"""Returns true if the transaction is in the orphanage."""
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.