mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-12 16:45:40 +01:00
Merge bitcoin/bitcoin#31384: mining: bugfix: Fix duplicate coinbase tx weight reservation
386eecff5fdoc: add release notes (ismaelsadeeq)3eaa0a3b66miner: init: add `-blockreservedweight` startup option (ismaelsadeeq)777434a2cddoc: rpc: improve `getmininginfo` help text (ismaelsadeeq)c8acd4032dinit: fail to start when `-blockmaxweight` exceeds `MAX_BLOCK_WEIGHT` (ismaelsadeeq)5bb31633cctest: add `-blockmaxweight` startup option functional test (ismaelsadeeq)2c7d90a6d6miner: bugfix: fix duplicate weight reservation in block assembler (ismaelsadeeq) Pull request description: * This PR attempts to fix the duplicate coinbase weight reservation issue we currently have. * Fixes #21950 We reserve 4000 weight units for coinbase transaction in `DEFAULT_BLOCK_MAX_WEIGHT`7590e93bc7/src/policy/policy.h (L23)And also reserve additional `4000` weight units in the default `BlockCreationOptions` struct.7590e93bc7/src/node/types.h (L36-L40)**Motivation** - This issue was first noticed during a review here https://github.com/bitcoin/bitcoin/pull/11100#discussion_r136157411) - It was later reported in issue #21950. - I also came across the bug while writing a test for building the block template. I could not create a block template above `3,992,000` in the block assembler, and this was not documented anywhere. It took me a while to realize that we were reserving space for the coinbase transaction weight twice. --- This PR fixes this by consolidating the reservation to be in a single location in the codebase. This PR then adds a new startup option `-blockreservedweight` whose default is `8000` that can be used to lower or increase the block reserved weight for block header, txs count, coinbase tx. ACKs for top commit: Sjors: ACK386eecff5ffjahr: Code review ACK386eecff5fglozow: utACK386eecff5f, nonblocking nits. I do think the release notes should be clarified more pinheadmz: ACK386eecff5fTree-SHA512: f27efa1da57947b7f4d42b9322b83d13afe73dd749dd9cac49360002824dd41c99a876a610554ac2d67bad7485020b9dcc423a8e6748fc79d6a10de6d4357d4c
This commit is contained in:
19
src/init.cpp
19
src/init.cpp
@@ -19,6 +19,7 @@
|
||||
#include <common/args.h>
|
||||
#include <common/system.h>
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <deploymentstatus.h>
|
||||
#include <hash.h>
|
||||
#include <httprpc.h>
|
||||
@@ -648,6 +649,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
|
||||
|
||||
|
||||
argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
|
||||
argsman.AddArg("-blockreservedweight=<n>", strprintf("Reserve space for the fixed-size block header plus the largest coinbase transaction the mining software may add to the block. (default: %d).", DEFAULT_BLOCK_RESERVED_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
|
||||
argsman.AddArg("-blockmintxfee=<amt>", strprintf("Set lowest fee rate (in %s/kvB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
|
||||
argsman.AddArg("-blockversion=<n>", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION);
|
||||
|
||||
@@ -1015,6 +1017,23 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||
}
|
||||
}
|
||||
|
||||
if (args.IsArgSet("-blockmaxweight")) {
|
||||
const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
|
||||
if (max_block_weight > MAX_BLOCK_WEIGHT) {
|
||||
return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT));
|
||||
}
|
||||
}
|
||||
|
||||
if (args.IsArgSet("-blockreservedweight")) {
|
||||
const auto block_reserved_weight = args.GetIntArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT);
|
||||
if (block_reserved_weight > MAX_BLOCK_WEIGHT) {
|
||||
return InitError(strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT));
|
||||
}
|
||||
if (block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) {
|
||||
return InitError(strprintf(_("Specified -blockreservedweight (%d) is lower than minimum safety value of (%d)"), block_reserved_weight, MINIMUM_BLOCK_RESERVED_WEIGHT));
|
||||
}
|
||||
}
|
||||
|
||||
nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp);
|
||||
|
||||
if (!g_wallet_init_interface.ParameterInteraction()) return false;
|
||||
|
||||
Reference in New Issue
Block a user