From 87c06d4091b9ed42da5cef0f12d9334e48b1a959 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 27 Mar 2019 13:54:19 -0400 Subject: [PATCH 1/2] Save some space, maintain compatibility with elements-0.14 header index --- src/chain.h | 12 ++++++------ src/txdb.cpp | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/chain.h b/src/chain.h index d844af29f4..0e813557d9 100644 --- a/src/chain.h +++ b/src/chain.h @@ -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; @@ -240,7 +239,6 @@ class CBlockIndex nVersion = 0; hashMerkleRoot = uint256(); nTime = 0; - block_height = 0; nBits = 0; nNonce = 0; proof.SetNull(); @@ -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; @@ -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; @@ -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); @@ -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; diff --git a/src/txdb.cpp b/src/txdb.cpp index da4a63a905..7871f86b66 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -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; From 0baa13581e373133b7405eb700b42fce1b23c704 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 27 Mar 2019 14:42:27 -0400 Subject: [PATCH 2/2] Only check 1 in 1000 block header sigs on load --- src/txdb.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 7871f86b66..5aac7860fb 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -320,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()); }