From 36c97b4e5dbf233734bd1882f8b6822a3bdcee97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Wed, 17 Jun 2015 21:23:53 +0200 Subject: [PATCH 1/2] Bugfix: Don't check the genesis block header before accepting it This fixes an error triggered when running with -reindex after #5975 --- src/main.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0be54ebd4..a4cbe43d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2809,36 +2809,37 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc uint256 hash = block.GetHash(); BlockMap::iterator miSelf = mapBlockIndex.find(hash); CBlockIndex *pindex = NULL; - if (miSelf != mapBlockIndex.end()) { - // Block header is already known. - pindex = miSelf->second; - if (ppindex) - *ppindex = pindex; - if (pindex->nStatus & BLOCK_FAILED_MASK) - return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - return true; - } - - if (!CheckBlockHeader(block, state)) - return false; - - // Get prev block index - CBlockIndex* pindexPrev = NULL; if (hash != chainparams.GetConsensus().hashGenesisBlock) { + + if (miSelf != mapBlockIndex.end()) { + // Block header is already known. + pindex = miSelf->second; + if (ppindex) + *ppindex = pindex; + if (pindex->nStatus & BLOCK_FAILED_MASK) + return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + return true; + } + + if (!CheckBlockHeader(block, state)) + return false; + + // Get prev block index + CBlockIndex* pindexPrev = NULL; BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); pindexPrev = (*mi).second; if (pindexPrev->nStatus & BLOCK_FAILED_MASK) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); + + assert(pindexPrev); + if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, hash)) + return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str()); + + if (!ContextualCheckBlockHeader(block, state, pindexPrev)) + return false; } - assert(pindexPrev); - if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, hash)) - return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str()); - - if (!ContextualCheckBlockHeader(block, state, pindexPrev)) - return false; - if (pindex == NULL) pindex = AddToBlockIndex(block); From 4f40716dcb61f492f93a781751bfa25f712cba8b Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 17 Jun 2015 18:06:39 +0200 Subject: [PATCH 2/2] test: Move reindex test to standard tests This test finishes very quickly, so it should be part of the default set of tests in rpc-tests. --- qa/pull-tester/rpc-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 426d81fa9..0f394094c 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -33,6 +33,7 @@ testScripts=( 'signrawtransactions.py' 'walletbackup.py' 'nodehandling.py' + 'reindex.py' ); testScriptsExt=( 'bipdersig-p2p.py' @@ -44,7 +45,6 @@ testScriptsExt=( 'invalidateblock.py' 'keypool.py' 'receivedby.py' - 'reindex.py' 'rpcbind_test.py' # 'script_test.py' 'smartfees.py'