MCPcopy Create free account
hub / github.com/LUX-Core/lux / ContextualCheckBlockHeader

Function ContextualCheckBlockHeader

src/main.cpp:4596–4651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4594}
4595
4596bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex* const pindexPrev)
4597{
4598 const CChainParams& chainParams = Params();
4599 uint256 hash;
4600 if (pindexPrev) {
4601 hash = block.GetHash(pindexPrev->nHeight + 1);
4602 } else {
4603 hash = block.GetHash();
4604 }
4605
4606 if (hash == Params().HashGenesisBlock())
4607 return true;
4608
4609 assert(pindexPrev);
4610
4611 int nHeight = pindexPrev->nHeight + 1;
4612
4613 if (chainActive.Height() - nHeight >= Params().FirstSCBlock() && !(block.nVersion & (1 << 30)))
4614 return state.DoS(1, error("%s: smart contracts hardfork is not active yet. (height %d)", __func__, nHeight));
4615
4616 //If this is a reorg, check that it is not too depp
4617 if (chainActive.Height() - nHeight >= Params().MaxReorganizationDepth())
4618 return state.DoS(1, error("%s: forked chain older than max reorganization depth (height %d)", __func__, nHeight));
4619
4620// // Check timestamp against prev
4621// if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) {
4622// LogPrintf("Block time = %d , GetMedianTimePast = %d \n", block.GetBlockTime(), pindexPrev->GetMedianTimePast());
4623// return state.Invalid(error("%s : block's timestamp is too early", __func__),
4624// REJECT_INVALID, "time-too-old");
4625// }
4626
4627 // Check that the block chain matches the known block chain up to a checkpoint
4628 if (!Checkpoints::CheckBlock(chainParams.Checkpoints(), nHeight, hash))
4629 return state.DoS(100, error("%s : rejected by checkpoint lock-in at %d", __func__, nHeight),
4630 REJECT_CHECKPOINT, "checkpoint mismatch");
4631
4632 // Don't accept any forks from the main chain prior to last checkpoint
4633 CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints());
4634 if (pcheckpoint && nHeight < pcheckpoint->nHeight)
4635 return state.DoS(0, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight));
4636
4637// // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
4638// if (block.nVersion < 2 &&
4639// CBlockIndex::IsSuperMajority(2, pindexPrev, )) {
4640// return state.Invalid(error("%s : rejected nVersion=1 block", __func__),
4641// REJECT_OBSOLETE, "bad-version");
4642// }
4643//
4644// // Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded:
4645// if (block.nVersion < 3 && CBlockIndex::IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) {
4646// return state.Invalid(error("%s : rejected nVersion=2 block", __func__),
4647// REJECT_OBSOLETE, "bad-version");
4648// }
4649
4650 return true;
4651}
4652
4653bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex* const pindexPrev)

Callers 2

AcceptBlockHeaderFunction · 0.85
TestBlockValidityFunction · 0.85

Calls 9

errorFunction · 0.85
GetLastCheckpointFunction · 0.85
HeightMethod · 0.80
FirstSCBlockMethod · 0.80
DoSMethod · 0.80
ParamsClass · 0.70
CheckBlockFunction · 0.70
GetHashMethod · 0.45

Tested by 1

TestBlockValidityFunction · 0.68