Skip to content

Commit

Permalink
Merge #541: Blockindex compatibility fix, startup speedup
Browse files Browse the repository at this point in the history
0baa135 Only check 1 in 1000 block header sigs on load (Gregory Sanders)
87c06d4 Save some space, maintain compatibility with elements-0.14 header index (Gregory Sanders)

Pull request description:

  We diverged from the 0.14 codebase, fix included here as well as performance speedup on initial load.

  In 0.14 we did no signature checking at all, but the signature checks were what alerted me to the incompatibility, so I opted to preserve some of that as sanity check.

Tree-SHA512: 565c9d771e8f7a1057f7dcd1107c9d3f23159d3cf9f9968fdc53f7732abdfbf8a65e3c0a42807fbb80c712cb65d6fa2a7c83c3bf3de5ac0a6b72b49e55f00e83
  • Loading branch information
stevenroose committed Mar 28, 2019
2 parents dd1623a + 0baa135 commit 09e20ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ class CBlockIndex
int32_t nVersion;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t block_height;
uint32_t nBits;
uint32_t nNonce;
CProof proof;
Expand Down Expand Up @@ -240,7 +239,6 @@ class CBlockIndex
nVersion = 0;
hashMerkleRoot = uint256();
nTime = 0;
block_height = 0;
nBits = 0;
nNonce = 0;
proof.SetNull();
Expand All @@ -258,7 +256,6 @@ class CBlockIndex
nVersion = block.nVersion;
hashMerkleRoot = block.hashMerkleRoot;
nTime = block.nTime;
block_height = block.block_height;
nBits = block.nBits;
nNonce = block.nNonce;
proof = block.proof;
Expand Down Expand Up @@ -290,7 +287,9 @@ class CBlockIndex
block.hashPrevBlock = pprev->GetBlockHash();
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.block_height = block_height;
if (g_con_blockheightinheader) {
block.block_height = nHeight;
}
block.nBits = nBits;
block.nNonce = nNonce;
block.proof = proof;
Expand Down Expand Up @@ -411,7 +410,6 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(block_height);
// For compatibility with elements 0.14 based chains
if (g_signed_blocks) {
READWRITE(proof);
Expand All @@ -428,7 +426,9 @@ class CDiskBlockIndex : public CBlockIndex
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.block_height = block_height;
if (g_con_blockheightinheader) {
block.block_height = nHeight;
}
block.nBits = nBits;
block.nNonce = nNonce;
block.proof = proof;
Expand Down
5 changes: 3 additions & 2 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
pindexNew->nHeight = diskindex.nHeight;
pindexNew->block_height = diskindex.block_height;
pindexNew->nFile = diskindex.nFile;
pindexNew->nDataPos = diskindex.nDataPos;
pindexNew->nUndoPos = diskindex.nUndoPos;
Expand All @@ -321,7 +320,9 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
pindexNew->nTx = diskindex.nTx;

const uint256 block_hash = pindexNew->GetBlockHash();
if (!CheckProof(pindexNew->GetBlockHeader(), consensusParams) &&
// Only validate one of every 1000 block header for sanity check
if (pindexNew->nHeight % 1000 == 0 &&
!CheckProof(pindexNew->GetBlockHeader(), consensusParams) &&
block_hash != consensusParams.hashGenesisBlock) {
return error("%s: CheckProof: %s, %s", __func__, block_hash.ToString(), pindexNew->ToString());
}
Expand Down

0 comments on commit 09e20ab

Please sign in to comment.