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

Function CheckWork

src/main.cpp:4564–4594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4562}
4563
4564bool CheckWork(const CBlock &block, CBlockIndex* const pindexPrev)
4565{
4566 const CChainParams& chainParams = Params();
4567 const Consensus::Params& consensusParams = chainParams.GetConsensus();
4568 if (pindexPrev == NULL)
4569 return error("%s: null pindexPrev for block %s", __func__, block.GetHash().GetHex());
4570
4571 unsigned int nBitsRequired = GetNextWorkRequired(pindexPrev, &block, consensusParams, block.IsProofOfStake());
4572
4573 if (block.IsProofOfWork() && pindexPrev->nHeight + 1 > chainParams.LAST_POW_BLOCK())
4574 return error("%s: reject proof-of-work at height %d", __func__, pindexPrev->nHeight + 1);
4575
4576 if (block.nBits != nBitsRequired)
4577 return error("%s: incorrect proof of work at %d", __func__, pindexPrev->nHeight + 1);
4578
4579 if (block.IsProofOfStake()) {
4580 uint256 hashProofOfStake, proof;
4581 uint256 hash = block.GetHash(pindexPrev->nHeight + 1);
4582 if (!stake->CheckProof(pindexPrev, block, hashProofOfStake)) {
4583 return error("%s: invalid proof-of-stake (block %s)", __func__, hash.GetHex());
4584 }
4585 if (stake->GetProof(hash, proof)) {
4586 if (proof != hashProofOfStake)
4587 return error("%s: diverged stake %s, %s (block %s)", __func__,
4588 hashProofOfStake.GetHex(), proof.GetHex(), hash.GetHex());
4589 } else {
4590 stake->SetProof(hash, hashProofOfStake);
4591 }
4592 }
4593 return true;
4594}
4595
4596bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex* const pindexPrev)
4597{

Callers 1

AcceptBlockFunction · 0.85

Calls 11

errorFunction · 0.85
GetNextWorkRequiredFunction · 0.85
LAST_POW_BLOCKMethod · 0.80
CheckProofMethod · 0.80
GetProofMethod · 0.80
SetProofMethod · 0.80
ParamsClass · 0.70
GetHexMethod · 0.45
GetHashMethod · 0.45
IsProofOfStakeMethod · 0.45
IsProofOfWorkMethod · 0.45

Tested by

no test coverage detected