v30.3-roots.1 · Commit 10: [PATCH 10/68] fix: harden Roots priority and wallet policy boundaries
test/functional/mining_basic.py
Before: test/functional/mining_basic.py · After: test/functional/mining_basic.py
File metadata
index 7e71761ae65479752990d9d6c32e828d90d41c4d..0289893b07c28724ec73351135f83d4288c50894 100755
Download original patch · Release notes
Diff rows 1–68 of 68. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/mining_basic.py
CHANGED
|
@@ -55,13 +55,13 @@ MAX_FUTURE_BLOCK_TIME = 2 * 3600
|
|
| 55 |
MAX_TIMEWARP = 600
|
| 56 |
VERSIONBITS_TOP_BITS = 0x20000000
|
| 57 |
VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28
|
| 58 |
-
DEFAULT_BLOCK_MIN_TX_FEE = 1 # default `-blockmintxfee` setting [sat/kvB]
|
| 59 |
|
| 60 |
class MiningTest(BitcoinTestFramework):
|
| 61 |
def set_test_params(self):
|
| 62 |
self.num_nodes = 3
|
| 63 |
self.extra_args = [
|
| 64 |
-
[],
|
| 65 |
[],
|
| 66 |
["-fastprune", "-prune=1"]
|
| 67 |
]
|
|
@@ -140,18 +140,19 @@ class MiningTest(BitcoinTestFramework):
|
|
| 140 |
|
| 141 |
def test_blockmintxfee_parameter(self):
|
| 142 |
self.log.info("Test -blockmintxfee setting")
|
| 143 |
-
self.restart_node(0, extra_args=['-minrelaytxfee=0', '-persistmempool=0'])
|
| 144 |
node = self.nodes[0]
|
| 145 |
|
| 146 |
# test default (no parameter), zero and a bunch of arbitrary blockmintxfee rates [sat/kvB]
|
| 147 |
-
for blockmintxfee_sat_kvb in (DEFAULT_BLOCK_MIN_TX_FEE, 0, 5, 10, 50, 100, 500, 1000, 2500, 5000, 21000, 333333, 2500000):
|
| 148 |
blockmintxfee_btc_kvb = blockmintxfee_sat_kvb / Decimal(COIN)
|
| 149 |
if blockmintxfee_sat_kvb == DEFAULT_BLOCK_MIN_TX_FEE:
|
| 150 |
self.log.info(f"-> Default -blockmintxfee setting ({blockmintxfee_sat_kvb} sat/kvB)...")
|
| 151 |
else:
|
| 152 |
blockmintxfee_parameter = f"-blockmintxfee={blockmintxfee_btc_kvb:.8f}"
|
| 153 |
self.log.info(f"-> Test {blockmintxfee_parameter} ({blockmintxfee_sat_kvb} sat/kvB)...")
|
| 154 |
-
self.restart_node(0, extra_args=[blockmintxfee_parameter, '-minrelaytxfee=0', '-persistmempool=0'])
|
|
|
|
| 155 |
assert_equal(node.getmininginfo()['blockmintxfee'], blockmintxfee_btc_kvb)
|
| 156 |
|
| 157 |
# submit one tx with exactly the blockmintxfee rate, and one slightly below
|
|
@@ -291,6 +292,7 @@ class MiningTest(BitcoinTestFramework):
|
|
| 291 |
LARGE_TXS_COUNT = 10
|
| 292 |
LARGE_VSIZE = int(((MAX_BLOCK_WEIGHT - DEFAULT_BLOCK_RESERVED_WEIGHT) / WITNESS_SCALE_FACTOR) / LARGE_TXS_COUNT)
|
| 293 |
HIGH_FEERATE = Decimal("0.0003")
|
|
|
|
| 294 |
|
| 295 |
# Ensure the mempool is empty
|
| 296 |
assert_equal(len(self.nodes[0].getrawmempool()), 0)
|
|
@@ -318,7 +320,7 @@ class MiningTest(BitcoinTestFramework):
|
|
| 318 |
# Test block template creation with custom -blockmaxweight
|
| 319 |
custom_block_weight = MAX_BLOCK_WEIGHT - 2000
|
| 320 |
# Reducing the weight by 2000 units will prevent 1 large transaction from fitting into the block.
|
| 321 |
-
self.restart_node(0, extra_args=[f"-blockmaxweight={custom_block_weight}"])
|
| 322 |
|
| 323 |
self.log.info("Testing the block template with custom -blockmaxweight to include 9 large and 2 normal transactions.")
|
| 324 |
self.verify_block_template(
|
|
@@ -328,7 +330,7 @@ class MiningTest(BitcoinTestFramework):
|
|
| 328 |
|
| 329 |
# Ensure the block weight does not exceed the maximum
|
| 330 |
self.log.info(f"Testing that the block weight will never exceed {MAX_BLOCK_WEIGHT - DEFAULT_BLOCK_RESERVED_WEIGHT}.")
|
| 331 |
-
self.restart_node(0, extra_args=[f"-blockmaxweight={MAX_BLOCK_WEIGHT}"])
|
| 332 |
self.log.info("Sending 2 additional normal transactions to fill the mempool to the maximum block weight.")
|
| 333 |
self.send_transactions(utxos[LARGE_TXS_COUNT + 2:], NORMAL_FEERATE, NORMAL_VSIZE)
|
| 334 |
self.log.info(f"Testing that the mempool's weight matches the maximum block weight: {MAX_BLOCK_WEIGHT}.")
|
|
@@ -342,7 +344,7 @@ class MiningTest(BitcoinTestFramework):
|
|
| 342 |
|
| 343 |
self.log.info("Test -blockreservedweight startup option.")
|
| 344 |
# Lowering the -blockreservedweight by 4000 will allow for two more transactions.
|
| 345 |
-
self.restart_node(0, extra_args=["-blockreservedweight=4000"])
|
| 346 |
self.verify_block_template(
|
| 347 |
expected_tx_count=12,
|
| 348 |
expected_weight=MAX_BLOCK_WEIGHT - 4000,
|
|
|
|
| 55 |
MAX_TIMEWARP = 600
|
| 56 |
VERSIONBITS_TOP_BITS = 0x20000000
|
| 57 |
VERSIONBITS_DEPLOYMENT_TESTDUMMY_BIT = 28
|
| 58 |
+
DEFAULT_BLOCK_MIN_TX_FEE = 1000 # default `-blockmintxfee` setting [sat/kvB]
|
| 59 |
|
| 60 |
class MiningTest(BitcoinTestFramework):
|
| 61 |
def set_test_params(self):
|
| 62 |
self.num_nodes = 3
|
| 63 |
self.extra_args = [
|
| 64 |
+
["-permitbarepubkey=1"],
|
| 65 |
[],
|
| 66 |
["-fastprune", "-prune=1"]
|
| 67 |
]
|
|
|
|
| 140 |
|
| 141 |
def test_blockmintxfee_parameter(self):
|
| 142 |
self.log.info("Test -blockmintxfee setting")
|
| 143 |
+
self.restart_node(0, extra_args=['-blockprioritysize=0', '-minrelaytxfee=0', '-persistmempool=0'])
|
| 144 |
node = self.nodes[0]
|
| 145 |
|
| 146 |
# test default (no parameter), zero and a bunch of arbitrary blockmintxfee rates [sat/kvB]
|
| 147 |
+
for blockmintxfee_sat_kvb in (DEFAULT_BLOCK_MIN_TX_FEE, 0, 5, 10, 50, 100, 500, 2500, 5000, 21000, 333333, 2500000):
|
| 148 |
blockmintxfee_btc_kvb = blockmintxfee_sat_kvb / Decimal(COIN)
|
| 149 |
if blockmintxfee_sat_kvb == DEFAULT_BLOCK_MIN_TX_FEE:
|
| 150 |
self.log.info(f"-> Default -blockmintxfee setting ({blockmintxfee_sat_kvb} sat/kvB)...")
|
| 151 |
else:
|
| 152 |
blockmintxfee_parameter = f"-blockmintxfee={blockmintxfee_btc_kvb:.8f}"
|
| 153 |
self.log.info(f"-> Test {blockmintxfee_parameter} ({blockmintxfee_sat_kvb} sat/kvB)...")
|
| 154 |
+
self.restart_node(0, extra_args=[blockmintxfee_parameter, '-blockprioritysize=0', '-minrelaytxfee=0', '-persistmempool=0'])
|
| 155 |
+
self.wallet.rescan_utxos() # to avoid spending outputs of txs that are not in mempool anymore after restart
|
| 156 |
assert_equal(node.getmininginfo()['blockmintxfee'], blockmintxfee_btc_kvb)
|
| 157 |
|
| 158 |
# submit one tx with exactly the blockmintxfee rate, and one slightly below
|
|
|
|
| 292 |
LARGE_TXS_COUNT = 10
|
| 293 |
LARGE_VSIZE = int(((MAX_BLOCK_WEIGHT - DEFAULT_BLOCK_RESERVED_WEIGHT) / WITNESS_SCALE_FACTOR) / LARGE_TXS_COUNT)
|
| 294 |
HIGH_FEERATE = Decimal("0.0003")
|
| 295 |
+
self.restart_node(0, extra_args=["-blockprioritysize=0", f"-blockmaxweight={MAX_BLOCK_WEIGHT}", f"-datacarriersize={LARGE_VSIZE}", f"-maxscriptsize={LARGE_VSIZE}"])
|
| 296 |
|
| 297 |
# Ensure the mempool is empty
|
| 298 |
assert_equal(len(self.nodes[0].getrawmempool()), 0)
|
|
|
|
| 320 |
# Test block template creation with custom -blockmaxweight
|
| 321 |
custom_block_weight = MAX_BLOCK_WEIGHT - 2000
|
| 322 |
# Reducing the weight by 2000 units will prevent 1 large transaction from fitting into the block.
|
| 323 |
+
self.restart_node(0, extra_args=["-blockprioritysize=0", f"-datacarriersize={LARGE_VSIZE}", f"-maxscriptsize={LARGE_VSIZE}", f"-blockmaxweight={custom_block_weight}"])
|
| 324 |
|
| 325 |
self.log.info("Testing the block template with custom -blockmaxweight to include 9 large and 2 normal transactions.")
|
| 326 |
self.verify_block_template(
|
|
|
|
| 330 |
|
| 331 |
# Ensure the block weight does not exceed the maximum
|
| 332 |
self.log.info(f"Testing that the block weight will never exceed {MAX_BLOCK_WEIGHT - DEFAULT_BLOCK_RESERVED_WEIGHT}.")
|
| 333 |
+
self.restart_node(0, extra_args=["-blockprioritysize=0", f"-datacarriersize={LARGE_VSIZE}", f"-maxscriptsize={LARGE_VSIZE}", f"-blockmaxweight={MAX_BLOCK_WEIGHT}"])
|
| 334 |
self.log.info("Sending 2 additional normal transactions to fill the mempool to the maximum block weight.")
|
| 335 |
self.send_transactions(utxos[LARGE_TXS_COUNT + 2:], NORMAL_FEERATE, NORMAL_VSIZE)
|
| 336 |
self.log.info(f"Testing that the mempool's weight matches the maximum block weight: {MAX_BLOCK_WEIGHT}.")
|
|
|
|
| 344 |
|
| 345 |
self.log.info("Test -blockreservedweight startup option.")
|
| 346 |
# Lowering the -blockreservedweight by 4000 will allow for two more transactions.
|
| 347 |
+
self.restart_node(0, extra_args=["-blockprioritysize=0", f"-blockmaxweight={MAX_BLOCK_WEIGHT}", f"-datacarriersize={LARGE_VSIZE}", f"-maxscriptsize={LARGE_VSIZE}", "-blockreservedweight=4000"])
|
| 348 |
self.verify_block_template(
|
| 349 |
expected_tx_count=12,
|
| 350 |
expected_weight=MAX_BLOCK_WEIGHT - 4000,
|