-
Notifications
You must be signed in to change notification settings - Fork 36.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mining: bugfix: Fix duplicate coinbase tx weight reservation #31384
base: master
Are you sure you want to change the base?
mining: bugfix: Fix duplicate coinbase tx weight reservation #31384
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31384. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
c8842c2
to
889145a
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
889145a
to
74a5d7b
Compare
I'm in favor of fixing this bug, but differently, see #21950 (comment) |
Something like this should do: diff --git a/src/init.cpp b/src/init.cpp
index f79ebe881d..881a254efc 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -54,6 +54,7 @@
#include <node/mempool_persist_args.h>
#include <node/miner.h>
#include <node/peerman_args.h>
+#include <node/types.h> // for BlockCreateOptions
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/fees_args.h>
@@ -645,7 +646,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-whitelistrelay", strprintf("Add 'relay' permission to whitelisted peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
- argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
+ argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d). Note that getblocktemplate reserves %d weight units for the pool to customize the coinbase.", DEFAULT_BLOCK_MAX_WEIGHT, node::BlockCreateOptions{}.coinbase_max_additional_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);
diff --git a/src/policy/policy.h b/src/policy/policy.h
index 4412f2db87..f0c9e822ec 100644
--- a/src/policy/policy.h
+++ b/src/policy/policy.h
@@ -20,7 +20,7 @@ class CFeeRate;
class CScript;
/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
-static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT - 4000};
+static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT};
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
/** The maximum weight for transactions we're willing to relay/mine */ While you're touching this, maybe |
e8ead38
to
4784131
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Thanks for your review, @Sjors. I addressed all of your comments.
Done. Instead of creating
We already clamp the block size in the block assembler, so it will never exceed I've added a functional test and release notes. |
True, but I think it's always better to clearly inform the user when they're trying to do something impossible. That said, not everyone might agree with that. If other reviewers don't like it you can always drop the check. Will review shortly. |
3a2dd90
to
f7a2f12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you talk to why it is not a concern for existing deployed pool software which relies on the 8k value? It seems that reducing the default to 4k could at best cause issues to upgrading to a new Bitcoin Core version if noticed or at worst lead to creating an invalid block.
From a quick skim through a block explorer there is a bunch of blocks with a >4k coinbase transaction right now:
- https://blockstream.info/tx/121436b7346a49e12495a9286638636bf4baed0a218ce47867cad510c78030b1
- https://blockstream.info/tx/9017f8200301770d2bac3fc224302ab207ccec2ef42e00eae78a30928fdb40a7
- https://blockstream.info/tx/134a47f4853382ec2b066c580a2b98867e90fe264889b71e562c94fb83991350
- https://blockstream.info/tx/747a8b230bd07e738ad4d5392190121e91da3a8125d1a33ccac4ec21f37cddc0
- https://blockstream.info/tx/9d2203b1c72eddc072b566c4a16ed8757fcba95a3be6f270e17a128e41554b33
- https://blockstream.info/tx/0987ebb31c4d8abd8158d5c7d63af8aea76df8581289ba0d676d7d38923ecd4f
It seems those were all created by a single pool, so it might make sense to look into their software if it's open source, or reach out to them. Also probably a good idea to scan the past year of blocks to see if any other miner was creating coinbase between 4k and 8k.
To be clear i think it makes absolute sense to not double count or at least to clarify the actual max block weight Bitcoin Core will use by default. Just want to make sure that lowering the default doesn't lead our users to make an expensive mistake.
2fb833e
to
7ab1344
Compare
Thanks for reviewing @pinheadmz @luke-jr @Sjors I've recently foreced pushed from 2fb833e to 7ab1344 diff Changes were:
I believe this is addressed now.
I am not touching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 7ab1344
Just some feedback on the release notes.
7ab1344
to
dba211a
Compare
re-ACK dba211a |
Concept ACK |
@0xB10C pointed out the header always uses 80 bytes and there's few other unavoidable bytes in the block. So it sounds like there should be a minimum value for Additionally perhaps it should be renamed to just Alternatively we could make Still a third option is to reduce |
From #21950 (comment)
Given that this weight is reserved for the coinbase and the header, I don't think we should call it "coinbase reserved weight" or introduce something called edit: @Sjors was faster |
This change will alter the behavior, resulting in a transactions weight of I think I prefer the first idea, which is similar to what @0xB10C suggested: renaming coinbasereservedweight to The minimum value would be:
In the help text, we can clearly indicate this information. |
If we're going to set a minimum value for
And maybe add warning, in the help or at startup, that any value under (alternatively we could be pedantic and just not allow anything under 2000 - and then have a code comment above this constant to remind anyone about to recompile of the things they should consider) |
9475218
to
ad1bc03
Compare
Thanks for your review @Sjors and recent insight from @0xB10C Changes
|
The first commit a7d4364 changes
So I was initially a bit reluctant, but I think it's fine. The Template Provider (sidecar) in Sjors#48 will just have to convert I'll probably just have it add 2000 weight units, so it can never go below the minimum. It was already doing some math: Sjors@f481d65#diff-576b7d75ad2ccce85935852fbc155515ebc3afdfd8fe7b806f6b56c29053b786R124 Some background... The Stratum v2 spec gives the following explanation of
By "coinbase field" they refer to coinbase The "Job Declarator" is another piece of software that sits between the pool and the Template Provider. The way I interpret the spec is that it puts the onus of accounting for nitty gritty encoding stuff on the Template Provider. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ad1bc03, mostly happy.
Maybe @wangchun from F2Pool can confirm if this would work for F2Pool and how many weigh units they currently reserve. And if they do it with a custom patch or |
We (F2Pool) reserved 2000 WU for the coinbase transaction. This was achieved by patching the source code, ensuring that the check in |
@wincss thanks for the clarification. You should be able to use |
- This commit renamed coinbase_max_additional_weight to block_reserved_weight. - Also clarify that the reservation is for block header, transaction count and coinbase transaction.
- The reserved weight of the coinbase transaction is an estimate and may not reflect the exact value; it can be lower. - It should be clear that `currentblockweight` includes the reserved coinbase transaction weight. whereas `currentblocktx` does not account for the coinbase transaction count. - Also clarify `m_last_block_num_txs` and `m_last_block_weight`
- Prevent setting the value of `-blockreservedweight` below a safety value of 2000.
ad1bc03
to
fd31031
Compare
ACK fd31031 |
We reserve 4000 weight units for coinbase transaction in
DEFAULT_BLOCK_MAX_WEIGHT
bitcoin/src/policy/policy.h
Line 23 in 7590e93
And also reserve additional
4000
weight units in the defaultBlockCreationOptions
struct.bitcoin/src/node/types.h
Lines 36 to 40 in 7590e93
Motivation
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 is8000
that can be used to lower or increase the block reserved weight for block header, txs count, coinbase tx.