Implement basic private chain mode

This commit is contained in:
jtimon 2016-01-11 07:14:30 -08:00 committed by Gregory Sanders
parent 0e97c5e468
commit db42a26b72
20 changed files with 257 additions and 268 deletions

View file

@ -1147,7 +1147,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
}
// Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams) &&
if (!CheckProof(block, consensusParams) &&
block.GetHash() != consensusParams.hashGenesisBlock)
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
@ -2830,8 +2830,14 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW)
{
// Check proof of work matches claimed amount
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");
if (fCheckPOW && !CheckProof(block, Params().GetConsensus()))
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),
REJECT_INVALID, "high-hash");
// Check timestamp
if (block.GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60)
return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),
REJECT_INVALID, "time-too-new");
return true;
}
@ -2979,7 +2985,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
{
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
// Check proof of work
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
if (!CheckChallenge(block, *pindexPrev, consensusParams))
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");
// Check timestamp against prev