Skip to content

Commit 09e20ab

Browse files
committed
Merge #541: Blockindex compatibility fix, startup speedup
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
2 parents dd1623a + 0baa135 commit 09e20ab

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/chain.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ class CBlockIndex
210210
int32_t nVersion;
211211
uint256 hashMerkleRoot;
212212
uint32_t nTime;
213-
uint32_t block_height;
214213
uint32_t nBits;
215214
uint32_t nNonce;
216215
CProof proof;
@@ -240,7 +239,6 @@ class CBlockIndex
240239
nVersion = 0;
241240
hashMerkleRoot = uint256();
242241
nTime = 0;
243-
block_height = 0;
244242
nBits = 0;
245243
nNonce = 0;
246244
proof.SetNull();
@@ -258,7 +256,6 @@ class CBlockIndex
258256
nVersion = block.nVersion;
259257
hashMerkleRoot = block.hashMerkleRoot;
260258
nTime = block.nTime;
261-
block_height = block.block_height;
262259
nBits = block.nBits;
263260
nNonce = block.nNonce;
264261
proof = block.proof;
@@ -290,7 +287,9 @@ class CBlockIndex
290287
block.hashPrevBlock = pprev->GetBlockHash();
291288
block.hashMerkleRoot = hashMerkleRoot;
292289
block.nTime = nTime;
293-
block.block_height = block_height;
290+
if (g_con_blockheightinheader) {
291+
block.block_height = nHeight;
292+
}
294293
block.nBits = nBits;
295294
block.nNonce = nNonce;
296295
block.proof = proof;
@@ -411,7 +410,6 @@ class CDiskBlockIndex : public CBlockIndex
411410
READWRITE(hashPrev);
412411
READWRITE(hashMerkleRoot);
413412
READWRITE(nTime);
414-
READWRITE(block_height);
415413
// For compatibility with elements 0.14 based chains
416414
if (g_signed_blocks) {
417415
READWRITE(proof);
@@ -428,7 +426,9 @@ class CDiskBlockIndex : public CBlockIndex
428426
block.hashPrevBlock = hashPrev;
429427
block.hashMerkleRoot = hashMerkleRoot;
430428
block.nTime = nTime;
431-
block.block_height = block_height;
429+
if (g_con_blockheightinheader) {
430+
block.block_height = nHeight;
431+
}
432432
block.nBits = nBits;
433433
block.nNonce = nNonce;
434434
block.proof = proof;

src/txdb.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
307307
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
308308
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
309309
pindexNew->nHeight = diskindex.nHeight;
310-
pindexNew->block_height = diskindex.block_height;
311310
pindexNew->nFile = diskindex.nFile;
312311
pindexNew->nDataPos = diskindex.nDataPos;
313312
pindexNew->nUndoPos = diskindex.nUndoPos;
@@ -321,7 +320,9 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
321320
pindexNew->nTx = diskindex.nTx;
322321

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

0 commit comments

Comments
 (0)