Skip to content

Commit 7995490

Browse files
committed
Merge bitcoin/bitcoin#27620: test: miner: add coverage for -blockmintxfee setting
bbbb89d test: miner: add coverage for `-blockmintxfee` setting (Sebastian Falbesoner) Pull request description: This PR adds missing test coverage for the `-blockmintxfee` option, which can be used by miners to specify the lowest fee-rate for transactions to be included in blocks. The setting was introduced in PR #9380 (commit daec955), with the rationale to decouple different minimum fees from `-minrelaytxfee`. According to the PR description it _"should be set by miners to reflect their marginal cost of transmitting extra bytes."_. On each iteration, the test creates and submits two txs using MiniWallet: one with the the minimum fee-rate as specified for `-blockmintxfee` and a second one with a fee-rate a little below that (-0.01 sats/vbyte). Then it checks that only the first one is picked for the block template and accordingly also only exists in the block that is mined after. This is repeatedly done for a fixed (but obviously somewhat arbitrary) list of different `-blockmintxfee` settings on a single node, including the default and zero (i.e. no minimum fee a.k.a. "include even zero-fee txs") settings. ACKs for top commit: ryanofsky: Code review ACK bbbb89d, nice test brunoerg: reACK bbbb89d glozow: ACK bbbb89d, sorry for the late re-review! Tree-SHA512: 7b72612971e6a1667b4b3913ec27109953fd17a1020a4bde6941a93666b2e10a23fb6fe7df23471a5671ffe31e42cd992d2efb8b31903915b3dfc1d6478df757
2 parents ac7c177 + bbbb89d commit 7995490

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

test/functional/mining_basic.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@
1818
TIME_GENESIS_BLOCK,
1919
)
2020
from test_framework.messages import (
21+
BLOCK_HEADER_SIZE,
2122
CBlock,
2223
CBlockHeader,
23-
BLOCK_HEADER_SIZE,
24+
COIN,
2425
ser_uint256,
2526
)
2627
from test_framework.p2p import P2PDataStore
2728
from test_framework.test_framework import BitcoinTestFramework
2829
from test_framework.util import (
2930
assert_equal,
3031
assert_raises_rpc_error,
32+
get_fee,
3133
)
3234
from test_framework.wallet import MiniWallet
3335

3436

3537
VERSIONBITS_TOP_BITS = 0x20000000
3638
VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28
39+
DEFAULT_BLOCK_MIN_TX_FEE = 1000 # default `-blockmintxfee` setting [sat/kvB]
3740

3841

3942
def assert_template(node, block, expect, rehash=True):
@@ -73,6 +76,45 @@ def mine_chain(self):
7376
self.restart_node(0)
7477
self.connect_nodes(0, 1)
7578

79+
def test_blockmintxfee_parameter(self):
80+
self.log.info("Test -blockmintxfee setting")
81+
self.restart_node(0, extra_args=['-minrelaytxfee=0', '-persistmempool=0'])
82+
node = self.nodes[0]
83+
84+
# test default (no parameter), zero and a bunch of arbitrary blockmintxfee rates [sat/kvB]
85+
for blockmintxfee_sat_kvb in (DEFAULT_BLOCK_MIN_TX_FEE, 0, 50, 100, 500, 2500, 5000, 21000, 333333, 2500000):
86+
blockmintxfee_btc_kvb = blockmintxfee_sat_kvb / Decimal(COIN)
87+
if blockmintxfee_sat_kvb == DEFAULT_BLOCK_MIN_TX_FEE:
88+
self.log.info(f"-> Default -blockmintxfee setting ({blockmintxfee_sat_kvb} sat/kvB)...")
89+
else:
90+
blockmintxfee_parameter = f"-blockmintxfee={blockmintxfee_btc_kvb:.8f}"
91+
self.log.info(f"-> Test {blockmintxfee_parameter} ({blockmintxfee_sat_kvb} sat/kvB)...")
92+
self.restart_node(0, extra_args=[blockmintxfee_parameter, '-minrelaytxfee=0', '-persistmempool=0'])
93+
self.wallet.rescan_utxos() # to avoid spending outputs of txs that are not in mempool anymore after restart
94+
95+
# submit one tx with exactly the blockmintxfee rate, and one slightly below
96+
tx_with_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb)
97+
assert_equal(tx_with_min_feerate["fee"], get_fee(tx_with_min_feerate["tx"].get_vsize(), blockmintxfee_btc_kvb))
98+
if blockmintxfee_btc_kvb > 0:
99+
lowerfee_btc_kvb = blockmintxfee_btc_kvb - Decimal(10)/COIN # 0.01 sat/vbyte lower
100+
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=lowerfee_btc_kvb)
101+
assert_equal(tx_below_min_feerate["fee"], get_fee(tx_below_min_feerate["tx"].get_vsize(), lowerfee_btc_kvb))
102+
else: # go below zero fee by using modified fees
103+
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb)
104+
node.prioritisetransaction(tx_below_min_feerate["txid"], 0, -1)
105+
106+
# check that tx below specified fee-rate is neither in template nor in the actual block
107+
block_template = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
108+
block_template_txids = [tx['txid'] for tx in block_template['transactions']]
109+
self.generate(self.wallet, 1, sync_fun=self.no_op)
110+
block = node.getblock(node.getbestblockhash(), verbosity=2)
111+
block_txids = [tx['txid'] for tx in block['tx']]
112+
113+
assert tx_with_min_feerate['txid'] in block_template_txids
114+
assert tx_with_min_feerate['txid'] in block_txids
115+
assert tx_below_min_feerate['txid'] not in block_template_txids
116+
assert tx_below_min_feerate['txid'] not in block_txids
117+
76118
def run_test(self):
77119
node = self.nodes[0]
78120
self.wallet = MiniWallet(node)
@@ -279,6 +321,8 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
279321
node.submitheader(hexdata=CBlockHeader(bad_block_root).serialize().hex())
280322
assert_equal(node.submitblock(hexdata=block.serialize().hex()), 'duplicate') # valid
281323

324+
self.test_blockmintxfee_parameter()
325+
282326

283327
if __name__ == '__main__':
284328
MiningTest().main()

0 commit comments

Comments
 (0)