File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 6767#include < any>
6868#include < memory>
6969#include < optional>
70+ #include < stdexcept>
7071#include < utility>
7172
7273#include < boost/signals2/signal.hpp>
@@ -963,6 +964,16 @@ class MinerImpl : public Mining
963964
964965 std::unique_ptr<BlockTemplate> createNewBlock (const BlockCreateOptions& options) override
965966 {
967+ // Reject too-small values instead of clamping so callers don't silently
968+ // end up mining with different options than requested. This matches the
969+ // behavior of the `-blockreservedweight` startup option, which rejects
970+ // values below MINIMUM_BLOCK_RESERVED_WEIGHT.
971+ if (options.block_reserved_weight && options.block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) {
972+ throw std::runtime_error (strprintf (" block_reserved_weight (%zu) must be at least %u weight units" ,
973+ *options.block_reserved_weight ,
974+ MINIMUM_BLOCK_RESERVED_WEIGHT));
975+ }
976+
966977 // Ensure m_tip_block is set so consumers of BlockTemplate can rely on that.
967978 if (!waitTipChanged (uint256::ZERO, MillisecondsDouble::max ())) return {};
968979
Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ struct BlockCreateOptions {
4141 bool use_mempool{true };
4242 /* *
4343 * The default reserved weight for the fixed-size block header,
44- * transaction count and coinbase transaction.
44+ * transaction count and coinbase transaction. Minimum: 2000 weight units
45+ * (MINIMUM_BLOCK_RESERVED_WEIGHT).
4546 *
4647 * Cap'n Proto IPC clients do not currently have a way of leaving this field
4748 * unset and will always provide a value.
Original file line number Diff line number Diff line change @@ -272,6 +272,16 @@ async def wait_for_block():
272272 assert empty_template is not None
273273 block = await self .parse_and_deserialize_block (empty_template , ctx )
274274 assert_equal (len (block .vtx ), 1 )
275+
276+ self .log .debug ("Enforce minimum reserved weight for IPC clients too" )
277+ opts .blockReservedWeight = 0
278+ try :
279+ await mining .createNewBlock (opts )
280+ raise AssertionError ("createNewBlock unexpectedly succeeded" )
281+ except capnp .lib .capnp .KjException as e :
282+ assert_equal (e .description , "remote exception: std::exception: block_reserved_weight (0) must be at least 2000 weight units" )
283+ assert_equal (e .type , "FAILED" )
284+
275285 # Restore opts
276286 opts .blockReservedWeight = 4000
277287
You can’t perform that action at this time.
0 commit comments