-
Notifications
You must be signed in to change notification settings - Fork 37.7k
miner: don't needlessly append dummy OP_0 to bip34 #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 react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
src/node/miner.cpp
Outdated
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; | ||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight; | ||
// IsTestChain() can be dropped if hardcoded block hashes in tests are regenerated | ||
if (nHeight <= 16 || chainparams.IsTestChain()) { |
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.
nit: Would be good to limit this to regtest, assuming this is the only test network that "needs" it. Otherwise this can't be tested outside of mainnet?
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.
I'll try to narrow it down to regtest.
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.
Match the comment to the updated code too?
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.
Fixed
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
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. |
Our miner code adds OP_0 to the coinbase scriptSig in order to avoid triggering the bad-cb-length consensus error on test networks. This commit, like blocktools.py, limits that workaround to blocks 1 through 16 where it's actually needed (OP1 through OP_16). 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.
Some tests implement their own miner code. Where possible, update those similar to the previous commit.
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 |
Our miner code adds
OP_0
to the coinbasescriptSig
in order to avoid triggering thebad-cb-length
consensus error on test networks.This commit, like blocktools.py, limits that workaround to blocks 1 through 16 where it's actually needed (
OP1
throughOP_16
).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 #30200 we do expose this dummy coinbase transaction. In Stratum v2 several parts of it are communicated downstream, including the
scriptSig
.To avoid churning various hardcoded hashes in test files, this PR continues to add
OP_0
for regtest. This can be changed if we ever need to change them anyway, such as in #32155.There's a few places where the tests generate their own coinbase transactions. Those are modified to either match the new behavior, or a code comment is added.