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.

Co-authored-by: Brad Miller <brad@z.cash>
This commit is contained in:
Jack Grigg 2018-02-26 20:51:10 +00:00
parent be262f065f
commit 704b76358d
No known key found for this signature in database
GPG Key ID: 665DBCD284F7DAFF
1 changed files with 4 additions and 2 deletions

View File

@ -314,9 +314,11 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nTx = diskindex.nTx; pindexNew->nTx = diskindex.nTx;
pindexNew->nSproutValue = diskindex.nSproutValue; pindexNew->nSproutValue = diskindex.nSproutValue;
// Consistency checks
auto header = pindexNew->GetBlockHeader(); auto header = pindexNew->GetBlockHeader();
if (!CheckEquihashSolution(&header, Params())) if (header.GetHash() != pindexNew->GetBlockHash())
return error("LoadBlockIndex(): CheckEquihashSolution failed: %s", pindexNew->ToString()); return error("LoadBlockIndex(): block header inconsistency detected: on-disk = %s, in-memory = %s",
diskindex.ToString(), pindexNew->ToString());
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus())) if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus()))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());