Skip to content
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

[backport] Blockindex compatibility fix, startup speedup #552

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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