Merge pull request #4887

4bb30a1 Correct logging AcceptBlock()->AcceptBlockHeader() (R E Broadley)
This commit is contained in:
Pieter Wuille 2014-10-03 04:27:27 +02:00
commit 5ccd735d30
No known key found for this signature in database
GPG Key ID: 57896D2FF8F0B657

View File

@ -2274,7 +2274,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
if (miSelf != mapBlockIndex.end()) { if (miSelf != mapBlockIndex.end()) {
pindex = miSelf->second; pindex = miSelf->second;
if (pindex->nStatus & BLOCK_FAILED_MASK) if (pindex->nStatus & BLOCK_FAILED_MASK)
return state.Invalid(error("AcceptBlock() : block is marked invalid"), 0, "duplicate"); return state.Invalid(error("%s : block is marked invalid", __func__), 0, "duplicate");
} }
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(); CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint();
@ -2284,12 +2284,12 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
int64_t deltaTime = block.GetBlockTime() - pcheckpoint->GetBlockTime(); int64_t deltaTime = block.GetBlockTime() - pcheckpoint->GetBlockTime();
if (deltaTime < 0) if (deltaTime < 0)
{ {
return state.DoS(100, error("CheckBlockHeader() : block with timestamp before last checkpoint"), return state.DoS(100, error("%s : block with timestamp before last checkpoint", __func__),
REJECT_CHECKPOINT, "time-too-old"); REJECT_CHECKPOINT, "time-too-old");
} }
if (!CheckMinWork(block.nBits, pcheckpoint->nBits, deltaTime)) if (!CheckMinWork(block.nBits, pcheckpoint->nBits, deltaTime))
{ {
return state.DoS(100, error("CheckBlockHeader() : block with too little proof-of-work"), return state.DoS(100, error("%s : block with too little proof-of-work", __func__),
REJECT_INVALID, "bad-diffbits"); REJECT_INVALID, "bad-diffbits");
} }
} }
@ -2300,36 +2300,36 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
if (hash != Params().HashGenesisBlock()) { if (hash != Params().HashGenesisBlock()) {
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi == mapBlockIndex.end()) if (mi == mapBlockIndex.end())
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk"); return state.DoS(10, error("%s : prev block not found", __func__), 0, "bad-prevblk");
pindexPrev = (*mi).second; pindexPrev = (*mi).second;
nHeight = pindexPrev->nHeight+1; nHeight = pindexPrev->nHeight+1;
// Check proof of work // Check proof of work
if ((!Params().SkipProofOfWorkCheck()) && if ((!Params().SkipProofOfWorkCheck()) &&
(block.nBits != GetNextWorkRequired(pindexPrev, &block))) (block.nBits != GetNextWorkRequired(pindexPrev, &block)))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"), return state.DoS(100, error("%s : incorrect proof of work", __func__),
REJECT_INVALID, "bad-diffbits"); REJECT_INVALID, "bad-diffbits");
// Check timestamp against prev // Check timestamp against prev
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())
return state.Invalid(error("AcceptBlock() : block's timestamp is too early"), return state.Invalid(error("%s : block's timestamp is too early", __func__),
REJECT_INVALID, "time-too-old"); REJECT_INVALID, "time-too-old");
// Check that the block chain matches the known block chain up to a checkpoint // Check that the block chain matches the known block chain up to a checkpoint
if (!Checkpoints::CheckBlock(nHeight, hash)) if (!Checkpoints::CheckBlock(nHeight, hash))
return state.DoS(100, error("AcceptBlock() : rejected by checkpoint lock-in at %d", nHeight), return state.DoS(100, error("%s : rejected by checkpoint lock-in at %d", __func__, nHeight),
REJECT_CHECKPOINT, "checkpoint mismatch"); REJECT_CHECKPOINT, "checkpoint mismatch");
// Don't accept any forks from the main chain prior to last checkpoint // Don't accept any forks from the main chain prior to last checkpoint
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(); CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint();
if (pcheckpoint && nHeight < pcheckpoint->nHeight) if (pcheckpoint && nHeight < pcheckpoint->nHeight)
return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight)); return state.DoS(100, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight));
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
if (block.nVersion < 2 && if (block.nVersion < 2 &&
CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
{ {
return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"), return state.Invalid(error("%s : rejected nVersion=1 block", __func__),
REJECT_OBSOLETE, "bad-version"); REJECT_OBSOLETE, "bad-version");
} }
} }