-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Chainparams: Don't check the genesis block #6597
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
Conversation
How is this an optimization? You are now comparing the blocks hash against the genesis block every time |
By saving some checks for the genesis block.
The check in ConnectBlock was already there, now |
In any case, benchmarking welcomed. |
13c5755
to
b95a2f9
Compare
Rebased and simplified. Looking at it again, @dcousens was right that many of the changes would have affected performance negatively. Besides they were (or at least they currently seem to be) unnecessary for #6382 (or for facilitating the creating of testchains in general by not requiring tester to "mine" the genesis block of their testchains: the genesis block is correct by definition). |
utACK |
@@ -203,7 +204,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts() | |||
pindexNew->nStatus = diskindex.nStatus; | |||
pindexNew->nTx = diskindex.nTx; | |||
|
|||
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus())) | |||
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams) && | |||
pindexNew->GetBlockHash() != consensusParams.hashGenesisBlock) |
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.
Is the genesis block expected to fail PoW?
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.
Not usually, but this is useful for creating new testchains (whether those testchains are merged in master or not) without having to spend costly PoW to "mine" a genesis block to hardcode.
For example, #6382 introduces std::numeric_limits<uint64_t>::max() new testchains whose genesis blocks are created dynamically (but not mined dynamically in chainparams.cpp) and will therefore fail PoW.
For any production chain, mining the genesis block is a meaningless cost, but for a testnet (specially regtest-like testchains) it is utterly absurd. Even for mainchain, Satoshi didn't need to mine the genesis block because it is correct by definition (or more accurately, it is part of the definition of how valid chains must be). Just in the same way, he could have decided to make the genesis subsidy spendable but he didn't (but changing that now would be a hardfork). The creator of the system worked in mysterious ways...
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.
Fair enough.
ACK |
Care to pass in the params from above like #6986? |
@gmaxwell you mean passing it explicitly to CBlockTreeDB::LoadBlockIndexGuts()? |
@jtimon Right. Do you agree it would be the correct and consistent thing to do? |
Sure, using the local variable is in preparation for that at some point later (see #5970), but I'm happy to do it here directly. |
b95a2f9
to
e4037dd
Compare
Updated with @gmaxwell 's nit solved. |
Still ACK |
still ping, I've been thinking about closing this and reopen it whith a test that makes sure a new non-mined chain wold work (that means another chain in master), |
re-ACK e4037dd, @jtimon test sounds good too 👍 |
From experience elsewhere: if you introduce a new chain with an "invalid" genesis block and this change, it will fail to reindex, as the check is still done in that case. Suggested fix: see sipa@f7a1a47 |
Mhmm, why #6382 seems to be working just fine with reindex then? Have you actually reproduced the error you claim would appear? This shouldn't be necessary, certainly not in CheckBlockHeader(). In AcceptBlockHeader, it won't be called for the genesis block, see https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L3071 Probably a good test for this would be to create a new regtest-like chain with a genesis block that doesn't satisfy the proof of work and run it for a few blocks both with and without reindex from the python tests. But without #6907 and something like jtimon@98923c3 it seems like the testing would be much more than the change itself. |
@jtimon Because Bitcoin's genesis block does actually pass PoW checks.
What I mean is that this patch is effectively removing the invariant that
genesis blocks have to be valid. However, if you actually try with an
invalid genesis block, reindex fails.
Technically not a concern for Bitcoin at this point, so this is not a
blocker for merge. Just some advice that if we'd actually want to start
creating invalid genesis blocks (which makes creating test chains much
easier), this patch isn't enough.
|
Genesis blocks are valid by definition and should never be checked (whether they pass pow or not). Does that make sense? Addionally, I don't plan to create a new chain without #6907 (and generic selection with -chain, also part of #6382 ),and that's why I'm closing this for now. |
I'm not against merging this! I was simply giving a suggestion for further work towards its stated goal. |
And I'm saying I believe this is enough for fulfilling its stated goal, but the fact that we disagree means we should introduce tests here to make sure the goal is achieved (and later merges don't ruin it). |
…id (HF for bitcoin) - Like in bitcoin#6597 (bitcoin), the genesis block shouldn't be checked because it is a consensus rule in itself - On the other hand, some elements like deterministic peg (because the 21M reserve of pegged-coins needs to be created at some point) and multi-assets (because one cannot define new assets without existing utxos to be used as input for the asset definition transactions)
…s asvalid (HF for bitcoin) - Like in bitcoin#6597 (bitcoin), the genesis block shouldn't be checked because it is a consensus rule in itself - On the other hand, some elements like deterministic peg (because the 21M reserve of pegged-coins needs to be created at some point) and multi-assets (because one cannot define new assets without existing utxos to be used as input for the asset definition transactions)
Rebased by Pieter Wuille. Cleanup by Matt Corallo.
The genesis block is the truth: don't check it.
Apart from being a minimal optimization, this removes the necessity of "mining the genesis block" when new testchains are created. This is a necessary step for #6382 (which creates
std::numeric_limits<uint64_t>::max()
new testchains).