Skip to content

Commit e779d59

Browse files
committed
[test] check miner doesn't select 0fee transactions
Github-Pull: bitcoin#33106 Rebased-From: e5f896b
1 parent a0b5730 commit e779d59

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/functional/mining_basic.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from test_framework.test_framework import BitcoinTestFramework
2929
from test_framework.util import (
3030
assert_equal,
31+
assert_greater_than,
3132
assert_greater_than_or_equal,
3233
assert_raises_rpc_error,
3334
get_fee,
@@ -86,7 +87,7 @@ def test_blockmintxfee_parameter(self):
8687
node = self.nodes[0]
8788

8889
# test default (no parameter), zero and a bunch of arbitrary blockmintxfee rates [sat/kvB]
89-
for blockmintxfee_sat_kvb in (DEFAULT_BLOCK_MIN_TX_FEE, 0, 50, 100, 500, 2500, 5000, 21000, 333333, 2500000):
90+
for blockmintxfee_sat_kvb in (DEFAULT_BLOCK_MIN_TX_FEE, 0, 1, 5, 10, 50, 100, 500, 2500, 5000, 21000, 333333, 2500000):
9091
blockmintxfee_btc_kvb = blockmintxfee_sat_kvb / Decimal(COIN)
9192
if blockmintxfee_sat_kvb == DEFAULT_BLOCK_MIN_TX_FEE:
9293
self.log.info(f"-> Default -blockmintxfee setting ({blockmintxfee_sat_kvb} sat/kvB)...")
@@ -97,19 +98,27 @@ def test_blockmintxfee_parameter(self):
9798
self.wallet.rescan_utxos() # to avoid spending outputs of txs that are not in mempool anymore after restart
9899

99100
# submit one tx with exactly the blockmintxfee rate, and one slightly below
100-
tx_with_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb)
101+
tx_with_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb, confirmed_only=True)
101102
assert_equal(tx_with_min_feerate["fee"], get_fee(tx_with_min_feerate["tx"].get_vsize(), blockmintxfee_btc_kvb))
102-
if blockmintxfee_btc_kvb > 0:
103+
if blockmintxfee_sat_kvb > 5:
103104
lowerfee_btc_kvb = blockmintxfee_btc_kvb - Decimal(10)/COIN # 0.01 sat/vbyte lower
104-
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=lowerfee_btc_kvb)
105+
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=lowerfee_btc_kvb, confirmed_only=True)
105106
assert_equal(tx_below_min_feerate["fee"], get_fee(tx_below_min_feerate["tx"].get_vsize(), lowerfee_btc_kvb))
106107
else: # go below zero fee by using modified fees
107-
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb)
108+
tx_below_min_feerate = self.wallet.send_self_transfer(from_node=node, fee_rate=blockmintxfee_btc_kvb, confirmed_only=True)
108109
node.prioritisetransaction(tx_below_min_feerate["txid"], 0, -1)
109110

110111
# check that tx below specified fee-rate is neither in template nor in the actual block
111112
block_template = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
112113
block_template_txids = [tx['txid'] for tx in block_template['transactions']]
114+
115+
# Unless blockmintxfee is 0, the template shouldn't contain free transactions.
116+
# Note that the real block assembler uses package feerates, but we didn't create dependent transactions so it's ok to use base feerate.
117+
if blockmintxfee_btc_kvb > 0:
118+
for txid in block_template_txids:
119+
tx = node.getmempoolentry(txid)
120+
assert_greater_than(tx['fees']['base'], 0)
121+
113122
self.generate(self.wallet, 1, sync_fun=self.no_op)
114123
block = node.getblock(node.getbestblockhash(), verbosity=2)
115124
block_txids = [tx['txid'] for tx in block['tx']]

0 commit comments

Comments
 (0)