Skip to content

Commit a0ae3fc

Browse files
committed
[prep/test] replace magic number 1000 with respective feerate vars
Github-Pull: #33106 Rebased-From: 3eab8b7
1 parent 1c1970f commit a0ae3fc

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/test/mempool_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
482482
BOOST_CHECK(!pool.exists(GenTxid::Txid(tx3.GetHash())));
483483

484484
CFeeRate maxFeeRateRemoved(25000, GetVirtualTransactionSize(CTransaction(tx3)) + GetVirtualTransactionSize(CTransaction(tx2)));
485-
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
485+
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE);
486486

487487
CMutableTransaction tx4 = CMutableTransaction();
488488
tx4.vin.resize(2);
@@ -559,28 +559,28 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
559559
std::vector<CTransactionRef> vtx;
560560
SetMockTime(42);
561561
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
562-
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
562+
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE);
563563
// ... we should keep the same min fee until we get a block
564564
pool.removeForBlock(vtx, 1);
565565
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE);
566-
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/2.0));
566+
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/2.0));
567567
// ... then feerate should drop 1/2 each halflife
568568

569569
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2);
570-
BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 5 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/4.0));
570+
BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 5 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/4.0));
571571
// ... with a 1/2 halflife when mempool is < 1/2 its target size
572572

573573
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
574-
BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + 1000)/8.0));
574+
BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), llround((maxFeeRateRemoved.GetFeePerK() + DEFAULT_INCREMENTAL_RELAY_FEE)/8.0));
575575
// ... with a 1/4 halflife when mempool is < 1/4 its target size
576576

577577
SetMockTime(42 + 7*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
578-
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 1000);
579-
// ... but feerate should never drop below 1000
578+
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), DEFAULT_INCREMENTAL_RELAY_FEE);
579+
// ... but feerate should never drop below DEFAULT_INCREMENTAL_RELAY_FEE
580580

581581
SetMockTime(42 + 8*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
582582
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 0);
583-
// ... unless it has gone all the way to 0 (after getting past 1000/2)
583+
// ... unless it has gone all the way to 0 (after getting past DEFAULT_INCREMENTAL_RELAY_FEE/2)
584584
}
585585

586586
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>())

test/functional/mempool_limit.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ def test_mid_package_eviction_success(self):
9494
assert_equal(node.getrawmempool(), [])
9595

9696
# Restarting the node resets mempool minimum feerate
97-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
98-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
97+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
9998

10099
fill_mempool(self, node)
101100
current_info = node.getmempoolinfo()
@@ -278,8 +277,7 @@ def test_mid_package_replacement(self):
278277
self.restart_node(0, extra_args=self.extra_args[0])
279278

280279
# Restarting the node resets mempool minimum feerate
281-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
282-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
280+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
283281

284282
fill_mempool(self, node)
285283
current_info = node.getmempoolinfo()
@@ -352,8 +350,7 @@ def run_test(self):
352350

353351
relayfee = node.getnetworkinfo()['relayfee']
354352
self.log.info('Check that mempoolminfee is minrelaytxfee')
355-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
356-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
353+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
357354

358355
fill_mempool(self, node)
359356

test/functional/test_framework/mempool_util.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Helpful routines for mempool testing."""
6-
from decimal import Decimal
76

87
from .blocktools import (
98
COINBASE_MATURITY,
@@ -52,9 +51,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
5251
"""
5352
test_framework.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
5453
txouts = gen_return_txouts()
55-
relayfee = node.getnetworkinfo()['relayfee']
56-
57-
assert_equal(relayfee, Decimal('0.00001000'))
54+
minrelayfee = node.getnetworkinfo()['relayfee']
5855

5956
tx_batch_size = 1
6057
num_of_batches = 75
@@ -74,7 +71,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
7471

7572
test_framework.log.debug("Create a mempool tx that will be evicted")
7673
tx_to_be_evicted_id = ephemeral_miniwallet.send_self_transfer(
77-
from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=relayfee)["txid"]
74+
from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=minrelayfee)["txid"]
7875

7976
def send_batch(fee):
8077
utxos = confirmed_utxos[:tx_batch_size]
@@ -84,14 +81,14 @@ def send_batch(fee):
8481
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
8582
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
8683
# by 130 should result in a fee that corresponds to 2x of that fee rate
87-
base_fee = relayfee * 130
84+
base_fee = minrelayfee * 130
8885
batch_fees = [(i + 1) * base_fee for i in range(num_of_batches)]
8986

9087
test_framework.log.debug("Fill up the mempool with txs with higher fee rate")
9188
for fee in batch_fees[:-3]:
9289
send_batch(fee)
9390
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync before any eviction
94-
assert_equal(node.getmempoolinfo()["mempoolminfee"], Decimal("0.00001000"))
91+
assert_equal(node.getmempoolinfo()["mempoolminfee"], minrelayfee)
9592
for fee in batch_fees[-3:]:
9693
send_batch(fee)
9794
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync after all evictions
@@ -103,8 +100,8 @@ def send_batch(fee):
103100
assert tx_to_be_evicted_id not in node.getrawmempool()
104101

105102
test_framework.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
106-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
107-
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
103+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], minrelayfee)
104+
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], minrelayfee)
108105

109106
def tx_in_orphanage(node, tx: CTransaction) -> bool:
110107
"""Returns true if the transaction is in the orphanage."""

0 commit comments

Comments
 (0)