diff options
author | Jorge Timón <jtimon@jtimon.cc> | 2015-06-17 21:23:53 +0200 |
---|---|---|
committer | Jorge Timón <jtimon@jtimon.cc> | 2015-06-21 01:24:51 +0200 |
commit | 36c97b4e5dbf233734bd1882f8b6822a3bdcee97 (patch) | |
tree | 97c9e332b871694f93e62645fa5b1279bc0944cd | |
parent | 247b91449ad7d041c6af5d2abf5660ab00be0fb4 (diff) |
Bugfix: Don't check the genesis block header before accepting it
This fixes an error triggered when running with -reindex after #5975
-rw-r--r-- | src/main.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0be54ebd41..a4cbe43d3b 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 (hash != chainparams.GetConsensus().hashGenesisBlock) { - if (!CheckBlockHeader(block, state)) - return false; + 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; + } - // Get prev block index - CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus().hashGenesisBlock) { + 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); |