-
Notifications
You must be signed in to change notification settings - Fork 38.6k
miner: drop dummy extraNonce in coinbase scriptSig for templates requested via IPC #32420
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
base: master
Are you sure you want to change the base?
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/32420. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste 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. |
|
I limited the exception to regtest. I also found two tests that for some reason implement their own coinbase construction code. I adjusted those for consistently with the first commit.
|
31fd071 to
ca8a52f
Compare
shahsb
left a comment
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.
Concept ACK
Correct me if I'm wrong, please! I think what's actually going on here is:
So I think it's more fair to say that our miner code adds In the current code, having a dummy extraNonce actually seems sensible to me -- in real PoW contexts, we'd need a real extraNonce anyway, so this makes the test environment a little more similar to reality... So I feel a bit -0 on this as a consequence. I wonder if there isn't a way to have this work for stratumv2 without changing the way the existing code works? Would it work for the stratumv2 interface (the part of it inside bitcoin core?) to just recognise we supply a dummy extra nonce, and drop it? Even for the first 16 blocks, sv2 miners that supply a non-empty extraNonce of their own, or that include a pool-signature in the coinbase will pass the cb-length check. And after the first 16 blocks, it's not an issue at all. |
|
Rebased after #32155.
Possibly, but It doesn't belong in a block template imo.
The Template Distribution protocol defines a message
In the Job Declaration Protocol (which the node doesn't play a role in)
Yes but this would be a foot gun if a future soft fork requires an additional commitment. It's also up to every consumer of our Mining interface to implement that (correctly), not just the one I wrote. We could implement it somewhere between the mining code and interface, so at least interface users don't have to deal with this. But currently |
Right, but we currently don't include it in a block template either, so that's (currently) fine.
I think it's more likely that any additional commitments required by future soft forks will be in the coinbase tx's outputs because the coinbase scriptSig's limited to 100 bytes. The segwit commitment output is designed to allow for this, so additional outputs aren't needed; signet makes use of this ability for the block signature.
Yeah, this was what I was thinking. Maybe adding something like: struct CBlockTemplate
{
CBlock block;
std::span<unsigned char> CoinbaseScriptSigPrefix()
{
if (block.vtx.size() == 0 || block.vtx[0].vin.size() == 0 || block.vtx[0].vin[0].scriptSig.size() == 0) return {};
// our scriptSig includes a dummy extraNonce. Drop it here.
std::span<unsigned char> r{block.vtx[0].vin[0].scriptSig};
return r.first(r.size()-1);
}
...
};and whatever |
|
I also don't think Although |
|
Are you still working on this? |
I think a block should (almost) always have an extraNonce -- whether for mainnet to provide sufficient work, or for early blocks on regtest/signet to avoid bad-cb-length, or for test net blocks to more closely simulate mainnet behaviour. Whether the template should also include an extraNonce depends on the user of the template -- if they want a template they can just apply work to via nNonce, without further fussing about (like we do in our unit tests), then the template should also include an extraNonce, but otherwise it doesn't need to. The current commit descriptions in this PR claim "Our miner code adds OP_0 to the coinbase scriptSig in order to avoid So rather than special casing early blocks and regtest, how about just making it an explicit option, whether defaulting to true (ie, current behaviour) or false? eg: https://github.com/ajtowns/bitcoin/commits/202510-miner-extranonce/ |
|
Indeed the Lines 454 to 457 in e071a3f
There was also no documented reason for adding Lines 2236 to 2244 in e071a3f
But as you point out in your historical overview, nBits was swapped for nTime, and then later for the height which became a consensus requirement. So I agree it makes sense to call it |
|
I switched to the approach of adding an |
5188ab5 to
b03feed
Compare
|
Looks like |
ryanofsky
left a comment
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 ACK b03feedadb411e15967659be83940d73ce977848. Assuming #33819 goes ahead, there should be less need for this change from the mining interface perspective. But not adding OP_0 seems like more sensible default behavior and all the changes here seem nice to make the test code and BlockAssembler code more explicit and clear about what they are doing.
src/node/types.h
Outdated
| @@ -64,6 +63,10 @@ struct BlockCreateOptions { | |||
| * coinbase_max_additional_weight and coinbase_output_max_additional_sigops. | |||
| */ | |||
| CScript coinbase_output_script{CScript() << OP_TRUE}; | |||
| /** | |||
| * Whether to include and OP_0 as a dummy extraNonce in the template's coinbase | |||
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.
/**\n+ * Whether to include and OP_0 as a dummy extraNonce in the template's coinbase\n+ */\n -> "and" -> "an" [Correct article: "an OP_0" (singular noun) makes the sentence grammatical and clear.]
|
Rebased after #33745 due to import conflict in the test. Also fixed comment typo. |
ryanofsky
left a comment
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 ACK 9832a9a. Just rebased since last review and tweaked comment
Previously the coinbase transaction generated by our miner code was not used downstream, because the getblocktemplate RPC excludes it. Since the Mining IPC interface was introduced in bitcoin#30200 we do expose this dummy coinbase transaction. In Stratum v2 several parts of it are communicated downstream, including the scriptSig. This commit removes the dummy extraNonce from the coinbase scriptSig in block templates requested via IPC. This limits the scriptSig to what is essential for consensus (BIP34) and removes the need for external mining software to remove the dummy, or even ignore the scriptSig we provide and generate it some other way. This could cause problems if a future soft fork requires additional data to be committed here. A test is added to verify the new IPC behavior. It achieves this by introducing an include_dummy_extranonce option which defaults to false with all test code updated to set it to true. Because this option is not exposed via IPC, callers will no longer see it. The caller needs to ensure that for blocks 1 through 16 they pad the scriptSig in order to avoid bad-cb-length. Co-authored-by: Anthony Towns <[email protected]>
|
Trivial rebase after #34003. |
ryanofsky
left a comment
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 ACK a3e8877, just fixing conflict in test since last review
|
🐙 This pull request conflicts with the target branch and needs rebase. |
Our miner code adds
OP_0as a dummyextraNonceto the coinbasescriptSig. This has been in place since v0.1.0 and removing it entirely would trigger thebad-cb-lengthconsensus error on test networks for blocks 1 through 16 (OP1throughOP_16).Previously the coinbase transaction generated by our miner code was not used downstream, because the
getblocktemplateRPC excludes it. Since the Mining IPC interface was introduced in #30200 we do expose this dummy coinbase transaction. In Stratum v2 several parts of it are communicated downstream, including thescriptSig.This PR adds a
include_dummy_extranonceoption which isfalseby default, but for the time being all test code opts in to it. This avoids churning hardcoded block and transaction hashes.The effect of having the default
falsefor IPC callers is that we remove the dummyextraNoncefrom the coinbasescriptSigin block templates requested that way. This limits thescriptSigto what is essential for consensus (BIP34) and removes the need for external mining software to remove the dummy, or even ignore thescriptSigwe provide and generate it some other way. This could cause problems if a future soft fork requires additional data to be committed here.test/functional/interface_ipc.pyis expanded to verify the new IPC behavior.