|
|
@ -2809,36 +2809,37 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
BlockMap::iterator miSelf = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator miSelf = mapBlockIndex.find(hash); |
|
|
|
CBlockIndex *pindex = NULL; |
|
|
|
CBlockIndex *pindex = NULL; |
|
|
|
if (miSelf != mapBlockIndex.end()) { |
|
|
|
if (hash != chainparams.GetConsensus().hashGenesisBlock) { |
|
|
|
// 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)) |
|
|
|
if (miSelf != mapBlockIndex.end()) { |
|
|
|
return false; |
|
|
|
// 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
|
|
|
|
if (!CheckBlockHeader(block, state)) |
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
return false; |
|
|
|
if (hash != chainparams.GetConsensus().hashGenesisBlock) { |
|
|
|
|
|
|
|
|
|
|
|
// Get prev block index
|
|
|
|
|
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); |
|
|
|
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); |
|
|
|
pindexPrev = (*mi).second; |
|
|
|
pindexPrev = (*mi).second; |
|
|
|
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) |
|
|
|
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) |
|
|
|
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); |
|
|
|
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)) |
|
|
|
assert(pindexPrev); |
|
|
|
return false; |
|
|
|
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) |
|
|
|
if (pindex == NULL) |
|
|
|
pindex = AddToBlockIndex(block); |
|
|
|
pindex = AddToBlockIndex(block); |
|
|
|
|
|
|
|
|
|
|
|