| 4562 | } |
| 4563 | |
| 4564 | bool 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 | |
| 4596 | bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex* const pindexPrev) |
| 4597 | { |
no test coverage detected