Skip to content

Commit

Permalink
Auto merge of zcash#2993 - str4d:2977-performance-regression, r=str4d
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zkbot committed Feb 27, 2018
2 parents be262f0 + 704b763 commit f9dbd1e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nTx = diskindex.nTx;
pindexNew->nSproutValue = diskindex.nSproutValue;

// Consistency checks
auto header = pindexNew->GetBlockHeader();
if (!CheckEquihashSolution(&header, Params()))
return error("LoadBlockIndex(): CheckEquihashSolution failed: %s", pindexNew->ToString());
if (header.GetHash() != pindexNew->GetBlockHash())
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()))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());

Expand Down

0 comments on commit f9dbd1e

Please sign in to comment.