Use block hash comparison for consistency check when loading block index#2993
Use block hash comparison for consistency check when loading block index#2993zkbot merged 1 commit intozcash:masterfrom
Conversation
|
Hmm, seems like the following code will always pass no matter what. because earlier in the code: where and That is, |
|
Not quite 😃 Another way to achieve this would be: CDiskBlockIndex reserialized(*pindexNew);
reserialized.GetBlockHash()But I think this PR is more intuitive. |
|
You mean Does this sound right?
So when Once the values from Am I missing something? |
"Once the values are copied" is the sticking point: this consistency check is intended to defend against bugs like #2931. |
|
Imagine there is disk corruption. When zcashd wrote a block to disk, its Checking the block hash can help catch developer error of forgetting to copy a field (which is used as part of computing the block hash), but is there a way we can catch this type of error at build time? This PR as it stands is fine for purpose of fixing the performance regression. Non-blocking: Perhaps the log message "CheckEquihashSolution failed" should be changed to something like "GetBlockHash inconsistency detected, expected {} but got {}" |
It is protecting against us making similar mistakes as #2931 when making future changes to the block header format.
Not with the current architecture inherited from Bitcoin Core (this function is unchanged upstream). We'd need to largely rewrite this function at a minimum, which is well outside the scope of this PR.
Oops, I change this message on one computer but forgot to do so on the one I actually made the commit on. Will fix. |
There was a problem hiding this comment.
Make the error message reflect what is checked.
The Equihash check caused block index loading to take around 38x longer. However, we don't need to check it directly, as the only paths to writing a block header to disk already go through a proof-of-work check (e.g. receiving a block over the network). By forcing the block header inside the CBlockIndex to be re-serialized, we retain the benefits of the consistency check without the overhead at startup. Co-authored-by: Brad Miller <brad@z.cash>
b067503 to
704b763
Compare
|
The modified check is useful, but not equivalent to checking the Equihash solution. That said, it seems a pragmatic choice given the performance regression. The error message definitely needs to be changed as well though. |
|
Force-pushed to update error message. |
|
@zkbot r+ |
|
📌 Commit 704b763 has been approved by |
Use block hash comparison for consistency check when loading block index The Equihash check caused block index loading to take around 38x longer. However, we don't need to check it directly, as the only paths to writing a block header to disk already go through a proof-of-work check (e.g. receiving a block over the network). By forcing the block header inside the CBlockIndex to be re-serialized, we retain the benefits of the consistency check without the overhead at startup.
The Equihash check caused block index loading to take around 38x longer.
However, we don't need to check it directly, as the only paths to writing a
block header to disk already go through a proof-of-work check (e.g. receiving a
block over the network). By forcing the block header inside the CBlockIndex to
be re-serialized, we retain the benefits of the consistency check without the
overhead at startup.