MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / ContextualCheckBlockHeader

Function ContextualCheckBlockHeader

src/main.cpp:3357–3408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3355}
3356
3357bool 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
3410bool ContextualCheckTransaction(const CTransaction &tx, CValidationState &state, int nHeight,
3411 int64_t nLockTimeCutoff, int64_t nMedianTimePastPrev) {

Callers 2

AcceptBlockHeaderFunction · 0.85
TestBlockValidityFunction · 0.85

Calls 11

GetNextWorkRequiredFunction · 0.85
errorFunction · 0.85
GetLastCheckpointFunction · 0.85
IsSuperMajorityFunction · 0.85
DoSMethod · 0.80
GetMedianTimePastMethod · 0.80
InvalidMethod · 0.80
ParamsClass · 0.70
CheckBlockFunction · 0.70
GetHashMethod · 0.45
GetBlockTimeMethod · 0.45

Tested by 1

TestBlockValidityFunction · 0.68