Skip to content

Commit 3eab8b7

Browse files
committed
[prep/test] replace magic number 1000 with respective feerate vars
1 parent 5f2df0e commit 3eab8b7

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(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
@@ -92,8 +92,7 @@ def test_mid_package_eviction_success(self):
9292
assert_equal(node.getrawmempool(), [])
9393

9494
# Restarting the node resets mempool minimum feerate
95-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
96-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
95+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
9796

9897
fill_mempool(self, node)
9998
current_info = node.getmempoolinfo()
@@ -184,8 +183,7 @@ def test_mid_package_replacement(self):
184183
self.restart_node(0, extra_args=self.extra_args[0])
185184

186185
# Restarting the node resets mempool minimum feerate
187-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
188-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
186+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
189187

190188
fill_mempool(self, node)
191189
current_info = node.getmempoolinfo()
@@ -256,8 +254,7 @@ def run_test(self):
256254

257255
relayfee = node.getnetworkinfo()['relayfee']
258256
self.log.info('Check that mempoolminfee is minrelaytxfee')
259-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
260-
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
257+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], node.getmempoolinfo()["mempoolminfee"])
261258

262259
fill_mempool(self, node)
263260

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
import random
87

98
from .blocktools import (
@@ -62,9 +61,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
6261
"""
6362
test_framework.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
6463
txouts = gen_return_txouts()
65-
relayfee = node.getnetworkinfo()['relayfee']
66-
67-
assert_equal(relayfee, Decimal('0.00001000'))
64+
minrelayfee = node.getnetworkinfo()['relayfee']
6865

6966
tx_batch_size = 1
7067
num_of_batches = 75
@@ -84,7 +81,7 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
8481

8582
test_framework.log.debug("Create a mempool tx that will be evicted")
8683
tx_to_be_evicted_id = ephemeral_miniwallet.send_self_transfer(
87-
from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=relayfee)["txid"]
84+
from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=minrelayfee)["txid"]
8885

8986
def send_batch(fee):
9087
utxos = confirmed_utxos[:tx_batch_size]
@@ -94,14 +91,14 @@ def send_batch(fee):
9491
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
9592
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
9693
# by 130 should result in a fee that corresponds to 2x of that fee rate
97-
base_fee = relayfee * 130
94+
base_fee = minrelayfee * 130
9895
batch_fees = [(i + 1) * base_fee for i in range(num_of_batches)]
9996

10097
test_framework.log.debug("Fill up the mempool with txs with higher fee rate")
10198
for fee in batch_fees[:-3]:
10299
send_batch(fee)
103100
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync before any eviction
104-
assert_equal(node.getmempoolinfo()["mempoolminfee"], Decimal("0.00001000"))
101+
assert_equal(node.getmempoolinfo()["mempoolminfee"], minrelayfee)
105102
for fee in batch_fees[-3:]:
106103
send_batch(fee)
107104
tx_sync_fun() if tx_sync_fun else test_framework.sync_mempools() # sync after all evictions
@@ -113,8 +110,8 @@ def send_batch(fee):
113110
assert tx_to_be_evicted_id not in node.getrawmempool()
114111

115112
test_framework.log.debug("Check that mempoolminfee is larger than minrelaytxfee")
116-
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
117-
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
113+
assert_equal(node.getmempoolinfo()['minrelaytxfee'], minrelayfee)
114+
assert_greater_than(node.getmempoolinfo()['mempoolminfee'], minrelayfee)
118115

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

0 commit comments

Comments
 (0)