mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-13 16:20:20 +02:00
mining: reject invalid block create options
Check BlockCreateOptions before block template creation instead of clamping runtime values. This makes invalid runtime block creation options, including those passed by IPC mining clients, fail explicitly instead of silently mining with different values than the caller requested. Runtime option validation now uses the same error wording as startup option validation. Startup validation also rejects -blockmaxweight values lower than -blockreservedweight instead of allowing them to be clamped later. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
@@ -17,6 +17,7 @@ from test_framework.messages import (
|
||||
CTxInWitness,
|
||||
CTxOut,
|
||||
DEFAULT_BLOCK_RESERVED_WEIGHT,
|
||||
MAX_BLOCK_SIGOPS_COST,
|
||||
MAX_BLOCK_WEIGHT,
|
||||
from_hex,
|
||||
msg_headers,
|
||||
@@ -322,9 +323,27 @@ class IPCMiningTest(BitcoinTestFramework):
|
||||
self.log.debug("Enforce minimum reserved weight for IPC clients too")
|
||||
opts.blockReservedWeight = 0
|
||||
await assert_create_new_block_fails(ctx, mining, opts,
|
||||
"block_reserved_weight (0) must be at least 2000 weight units")
|
||||
"block_reserved_weight (0) is lower than minimum safety value of (2000)")
|
||||
|
||||
async def async_routine_check_max_reserved_weight():
|
||||
self.log.debug("Enforce maximum reserved weight for IPC clients too")
|
||||
ctx, mining = await make_mining_ctx(self)
|
||||
opts = self.capnp_modules['mining'].BlockCreateOptions()
|
||||
opts.blockReservedWeight = MAX_BLOCK_WEIGHT + 1
|
||||
await assert_create_new_block_fails(ctx, mining, opts,
|
||||
f"block_reserved_weight ({MAX_BLOCK_WEIGHT + 1}) exceeds consensus maximum block weight ({MAX_BLOCK_WEIGHT})")
|
||||
|
||||
async def async_routine_check_sigops_limit():
|
||||
self.log.debug("Enforce sigops limit for IPC clients too")
|
||||
ctx, mining = await make_mining_ctx(self)
|
||||
opts = self.capnp_modules['mining'].BlockCreateOptions()
|
||||
opts.coinbaseOutputMaxAdditionalSigops = MAX_BLOCK_SIGOPS_COST + 1
|
||||
await assert_create_new_block_fails(ctx, mining, opts,
|
||||
f"coinbase_output_max_additional_sigops ({MAX_BLOCK_SIGOPS_COST + 1}) exceeds consensus maximum block sigops cost ({MAX_BLOCK_SIGOPS_COST})")
|
||||
|
||||
asyncio.run(capnp.run(async_routine()))
|
||||
asyncio.run(capnp.run(async_routine_check_max_reserved_weight()))
|
||||
asyncio.run(capnp.run(async_routine_check_sigops_limit()))
|
||||
|
||||
def run_waitnext_mining_policy_test(self):
|
||||
"""Verify that waitNext() preserves the mining policy from -blockmintxfee
|
||||
|
||||
@@ -374,6 +374,13 @@ class MiningTest(BitcoinTestFramework):
|
||||
expected_msg=f"Error: -blockmaxweight ({MAX_BLOCK_WEIGHT + 1}) exceeds consensus maximum block weight ({MAX_BLOCK_WEIGHT})",
|
||||
)
|
||||
|
||||
self.log.info("Test that node will fail to start when -blockmaxweight is lower than -blockreservedweight")
|
||||
self.stop_node(0)
|
||||
self.nodes[0].assert_start_raises_init_error(
|
||||
extra_args=[f"-blockmaxweight={DEFAULT_BLOCK_RESERVED_WEIGHT - 1}"],
|
||||
expected_msg=f"Error: -blockreservedweight ({DEFAULT_BLOCK_RESERVED_WEIGHT}) exceeds -blockmaxweight ({DEFAULT_BLOCK_RESERVED_WEIGHT - 1})",
|
||||
)
|
||||
|
||||
def test_height_in_locktime(self):
|
||||
self.log.info("Sanity check generated blocks have their coinbase timelocked to their height.")
|
||||
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
|
||||
|
||||
@@ -36,6 +36,7 @@ from test_framework.util import (
|
||||
|
||||
MAX_LOCATOR_SZ = 101
|
||||
MAX_BLOCK_WEIGHT = 4000000
|
||||
MAX_BLOCK_SIGOPS_COST = 80000
|
||||
DEFAULT_BLOCK_RESERVED_WEIGHT = 8000
|
||||
MINIMUM_BLOCK_RESERVED_WEIGHT = 2000
|
||||
MAX_BLOOM_FILTER_SIZE = 36000
|
||||
|
||||
Reference in New Issue
Block a user