block header commits to height

This commit is contained in:
instagibbs 2016-05-27 11:10:44 -04:00 committed by Gregory Sanders
parent 88802e76f1
commit 372e20d8b1
6 changed files with 22 additions and 1 deletions

View file

@ -2037,6 +2037,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
if (!fJustCheck) {
assert(block.vtx.size() == 1);
assert(block.nHeight == 0);
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
std::multimap<uint256, std::pair<COutPoint, CAmount> > mLocksCreated;
@ -3347,6 +3348,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())
return state.Invalid(false, REJECT_INVALID, "time-too-old", "block's timestamp is too early");
// Check height in header against prev
if ((uint32_t)pindexPrev->nHeight + 1 != block.nHeight)
return state.Invalid(error("%s: block height in header is incorrect", __func__),
REJECT_INVALID, "bad-header-height");
// Check timestamp
if (block.GetBlockTime() > nAdjustedTime + 2 * 60 * 60)
return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future");