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:
Sjors Provoost
2026-05-18 15:59:57 +02:00
parent 8daac1d6eb
commit 4637cd157d
10 changed files with 71 additions and 37 deletions

View File

@@ -969,16 +969,6 @@ public:
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options, bool cooldown) override
{
// Reject too-small values instead of clamping so callers don't silently
// end up mining with different options than requested. This matches the
// behavior of the `-blockreservedweight` startup option, which rejects
// values below MINIMUM_BLOCK_RESERVED_WEIGHT.
if (options.block_reserved_weight && options.block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) {
throw std::runtime_error(strprintf("block_reserved_weight (%zu) must be at least %u weight units",
*options.block_reserved_weight,
MINIMUM_BLOCK_RESERVED_WEIGHT));
}
// Ensure m_tip_block is set so consumers of BlockTemplate can rely on that.
std::optional<BlockRef> maybe_tip{waitTipChanged(uint256::ZERO, MillisecondsDouble::max())};