Although this PR is primarily a refactor, there are behavior changes documented in the release note:
- the IPC mining interface now rejects out-of-range block template options instead of silently clamping them;
- startup now rejects
-blockmaxweightvalues lower than-blockreservedweight, instead of allowing them to be clamped later.
The interaction between node startup options like -blockreservedweight and runtime options, especially those passed via IPC, is confusing.
They're combined in BlockAssembler::Options, which this PR gets rid of in favour of BlockCreateOptions.
BlockCreateOptions is used by interface clients. As before, IPC clients have access to a safe / sane subset, whereas RPC and test code can use all fields. The same type is also used to store mining defaults parsed once during node startup in NodeContext.
The maximum block weight setting (block_max_weight) is optional. When read from startup options it matches -blockmaxweight; when provided by callers it is a runtime override. Merge() fills unset fields from startup defaults while preserving caller-provided values.
This all happens in commits mining: add block create option helpers and mining: store block create options in NodeContext, and requires some preparation to keep things easy to review.
We get rid of BlockAssembler::Options but this is used in many tests. Since large churn is inevitable, we might as well switch all tests, bench and fuzzers over to the Mining interface. The mining: use interface for tests, bench and fuzzers commit does that, dramatically reducing direct use of BlockAssembler. Two exceptions are documented in the commit message. Because test_block_validity wasn't available via the interface and the block_assemble benchmark needs it, it's moved from BlockAssembler::Options to BlockCreateOptions (still not exposed via IPC).
We need access to mining related structs from both the miner and node initialization code. To avoid having to pull in all of BlockAssembler for the latter, the move-only: add node/mining_types.h commit introduces node/mining_types.h and moves BlockCreateOptions, BlockWaitOptions and BlockCheckOptions there from src/node/types.h.
I considered also moving DEFAULT_BLOCK_MAX_WEIGHT, DEFAULT_BLOCK_RESERVED_WEIGHT, MINIMUM_BLOCK_RESERVED_WEIGHT and DEFAULT_BLOCK_MIN_TX_FEE there from policy.h, since they are distinct from relay policy and not needed by the kernel. But this seems more appropriate for a follow-up and requires additional discussion.
I kept variable renaming and other formatting changes to a minimum to ease review with --color-moved=dimmed-zebra.
Commit summary
Tests and test cleanup:
test: misc interface_ipc_mining.py improvementstest: add assert_create_fails helpertest: regression test for waitNext mining policytest: cover IPC blockmaxweight policy
Refactoring test/bench/fuzz callers:
interfaces: make Mining use const NodeContextmining: use interface for tests, bench and fuzzers
Moving mining interface types:
move-only: add node/mining_types.h
Separating startup defaults from runtime options:
mining: parse block creation args in mining_args: addsnode/mining_args.{h,cpp}and moves mining option parsing out ofinit.cpp, without storing the parsed values yet.miner: add block_max_weight to BlockCreateOptions: moves the runtime maximum block weight setting intoBlockCreateOptionsas an optional value, so it can later be defaulted from startup args when unset.mining: add block create option helpers: centralizes block template option defaulting and merging, removesBlockAssembler::Options, and preserves behavior except for dropping theSpecifiedprefix from startup option error messages.mining: reject invalid block create options: checks typedBlockCreateOptionsbefore block template creation, so invalid runtime options are rejected instead of silently clamped. Startup validation also rejects-blockmaxweightvalues lower than-blockreservedweight.mining: store block create options in NodeContext: stores the startup mining options inNodeContextasBlockCreateOptions, so startup defaults and runtime overrides can be merged with the same option type.
Include hygiene, CI and release note:
refactor: have mining files include what they useci: enforce iwyu for touched filesdoc: add release note for mining option validation