-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#31384: mining: bugfix: Fix duplicate coinbase t…
…x weight reservation 386eecf doc: add release notes (ismaelsadeeq) 3eaa0a3 miner: init: add `-blockreservedweight` startup option (ismaelsadeeq) 777434a doc: rpc: improve `getmininginfo` help text (ismaelsadeeq) c8acd40 init: fail to start when `-blockmaxweight` exceeds `MAX_BLOCK_WEIGHT` (ismaelsadeeq) 5bb3163 test: add `-blockmaxweight` startup option functional test (ismaelsadeeq) 2c7d90a miner: 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` https://github.com/bitcoin/bitcoin/blob/7590e93bc73b3bbac641f05d490fd5c984156b33/src/policy/policy.h#L23 And also reserve additional `4000` weight units in the default `BlockCreationOptions` struct. https://github.com/bitcoin/bitcoin/blob/7590e93bc73b3bbac641f05d490fd5c984156b33/src/node/types.h#L36-L40 **Motivation** - This issue was first noticed during a review here bitcoin/bitcoin#11100 (comment)) - 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: ACK 386eecf fjahr: Code review ACK 386eecf glozow: utACK 386eecf, nonblocking nits. I do think the release notes should be clarified more pinheadmz: ACK 386eecf Tree-SHA512: f27efa1da57947b7f4d42b9322b83d13afe73dd749dd9cac49360002824dd41c99a876a610554ac2d67bad7485020b9dcc423a8e6748fc79d6a10de6d4357d4c
- Loading branch information
Showing
11 changed files
with
202 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
- Node and Mining | ||
|
||
--- | ||
|
||
- **PR #31384** fixed an issue where block reserved weight for fixed-size block header, transactions count, | ||
and coinbase transaction was done in two separate places. | ||
Before this pull request, the policy default for the maximum block weight was `3,996,000` WU, calculated by | ||
subtracting `4,000 WU` from the `4,000,000 WU` consensus limit to account for the fixed-size block header, | ||
transactions count, and coinbase transaction. During block assembly, Bitcoin Core clamped custom `-blockmaxweight` | ||
value to not be more than the policy default. | ||
|
||
Additionally, the mining code added another `4,000 WU` to the initial reservation, reducing the effective block template | ||
size to `3,992,000 WU`. | ||
|
||
Due to this issue, the total reserved weight was always `8,000 WU`, meaning that even when specifying a `-blockmaxweight` | ||
higher than the policy default, the actual block size never exceeded `3,992,000 WU`. | ||
|
||
The fix consolidates the reservation into a single place and introduces a new startup option, | ||
`-blockreservedweight` (default: `8,000 WU`). This startup option specifies the reserved weight for | ||
the fixed-size block header, transactions count, and coinbase transaction. | ||
The default value of `-blockreservedweight` was chosen to preserve the previous behavior. | ||
|
||
**Upgrade Note:** The default `-blockreservedweight` ensures backward compatibility for users who relied on the previous behavior. | ||
|
||
Users who manually set `-blockmaxweight` to its maximum value of `4,000,000 WU` should be aware that this | ||
value previously had no effect since it was clamped to `3,996,000 WU`. | ||
|
||
Users lowering `-blockreservedweight` should ensure that the total weight (for the block header, transaction count, and coinbase transaction) | ||
does not exceed the reduced value. | ||
|
||
As a safety check, Bitcoin core will **fail to start** when `-blockreservedweight` init parameter value is lower than `2000` weight units. | ||
|
||
Bitcoin Core will also **fail to start** if the `-blockmaxweight` or `-blockreservedweight` init parameter exceeds | ||
consensus limit of `4,000,000` weight units. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.