| 3355 | } |
| 3356 | |
| 3357 | bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev) |
| 3358 | { |
| 3359 | const CChainParams& chainParams = Params(); |
| 3360 | const Consensus::Params& consensusParams = chainParams.GetConsensus(); |
| 3361 | uint256 hash = block.GetHash(); |
| 3362 | if (hash == consensusParams.hashGenesisBlock) |
| 3363 | return true; |
| 3364 | |
| 3365 | assert(pindexPrev); |
| 3366 | |
| 3367 | int nHeight = pindexPrev->nHeight+1; |
| 3368 | |
| 3369 | // Check proof of work |
| 3370 | if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) |
| 3371 | return state.DoS(100, error("%s: incorrect proof of work", __func__), |
| 3372 | REJECT_INVALID, "bad-diffbits"); |
| 3373 | |
| 3374 | // Check timestamp against prev |
| 3375 | if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) |
| 3376 | return state.Invalid(error("%s: block's timestamp is too early", __func__), |
| 3377 | REJECT_INVALID, "time-too-old"); |
| 3378 | |
| 3379 | if(fCheckpointsEnabled) |
| 3380 | { |
| 3381 | // Check that the block chain matches the known block chain up to a checkpoint |
| 3382 | if (!Checkpoints::CheckBlock(chainParams.Checkpoints(), nHeight, hash)) |
| 3383 | return state.DoS(100, error("%s: rejected by checkpoint lock-in at %d", __func__, nHeight), |
| 3384 | REJECT_CHECKPOINT, "checkpoint mismatch"); |
| 3385 | |
| 3386 | // Don't accept any forks from the main chain prior to last checkpoint |
| 3387 | CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); |
| 3388 | if (pcheckpoint && nHeight < pcheckpoint->nHeight) |
| 3389 | return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight)); |
| 3390 | } |
| 3391 | |
| 3392 | // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: |
| 3393 | if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
| 3394 | return state.Invalid(error("%s: rejected nVersion=1 block", __func__), |
| 3395 | REJECT_OBSOLETE, "bad-version"); |
| 3396 | |
| 3397 | // Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded: |
| 3398 | if (block.nVersion < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
| 3399 | return state.Invalid(error("%s : rejected nVersion=2 block", __func__), |
| 3400 | REJECT_OBSOLETE, "bad-version"); |
| 3401 | |
| 3402 | // Reject block.nVersion=3 blocks when 95% (75% on testnet) of the network has upgraded: |
| 3403 | if (block.nVersion < 4 && IsSuperMajority(4, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
| 3404 | return state.Invalid(error("%s : rejected nVersion=3 block", __func__), |
| 3405 | REJECT_OBSOLETE, "bad-version"); |
| 3406 | |
| 3407 | return true; |
| 3408 | } |
| 3409 | |
| 3410 | bool ContextualCheckTransaction(const CTransaction &tx, CValidationState &state, int nHeight, |
| 3411 | int64_t nLockTimeCutoff, int64_t nMedianTimePastPrev) { |