Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,870 Lines • ▼ Show 20 Lines | static bool AcceptBlock(const Config &config, | ||||
// Compare block header timestamps and received times of the block and the | // Compare block header timestamps and received times of the block and the | ||||
// chaintip. If they have the same chain height, use these diffs as a | // chaintip. If they have the same chain height, use these diffs as a | ||||
// tie-breaker, attempting to pick the more honestly-mined block. | // tie-breaker, attempting to pick the more honestly-mined block. | ||||
int64_t newBlockTimeDiff = std::llabs(pindex->GetReceivedTimeDiff()); | int64_t newBlockTimeDiff = std::llabs(pindex->GetReceivedTimeDiff()); | ||||
int64_t chainTipTimeDiff = | int64_t chainTipTimeDiff = | ||||
chainActive.Tip() ? std::llabs(chainActive.Tip()->GetReceivedTimeDiff()) | chainActive.Tip() ? std::llabs(chainActive.Tip()->GetReceivedTimeDiff()) | ||||
: 0; | : 0; | ||||
bool isSameHeightAndMoreHonestlyMined = | bool isSameHeight = chainActive.Tip() && | ||||
chainActive.Tip() && | (pindex->nChainWork == chainActive.Tip()->nChainWork); | ||||
(pindex->nChainWork == chainActive.Tip()->nChainWork) && | if (isSameHeight) { | ||||
(newBlockTimeDiff < chainTipTimeDiff); | |||||
if (isSameHeightAndMoreHonestlyMined) { | |||||
LogPrintf("Chain tip timestamp-to-received-time difference: hash=%s, " | LogPrintf("Chain tip timestamp-to-received-time difference: hash=%s, " | ||||
"diff=%d\n", | "diff=%d\n", | ||||
chainActive.Tip()->GetBlockHash().ToString(), | chainActive.Tip()->GetBlockHash().ToString(), | ||||
chainTipTimeDiff); | chainTipTimeDiff); | ||||
LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | ||||
"diff=%d\n", | "diff=%d\n", | ||||
pindex->GetBlockHash().ToString(), newBlockTimeDiff); | pindex->GetBlockHash().ToString(), newBlockTimeDiff); | ||||
} | } | ||||
bool isSameHeightAndMoreHonestlyMined = | |||||
isSameHeight && (newBlockTimeDiff < chainTipTimeDiff); | |||||
bool fHasMoreWork = | bool fHasMoreWork = | ||||
(chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork | (chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork | ||||
: true); | : true); | ||||
// Blocks that are too out-of-order needlessly limit the effectiveness of | // Blocks that are too out-of-order needlessly limit the effectiveness of | ||||
// pruning, because pruning will not delete block files that contain any | // pruning, because pruning will not delete block files that contain any | ||||
// blocks which are too close in height to the tip. Apply this test | // blocks which are too close in height to the tip. Apply this test | ||||
// regardless of whether pruning is enabled; it should generally be safe to | // regardless of whether pruning is enabled; it should generally be safe to | ||||
▲ Show 20 Lines • Show All 1,649 Lines • Show Last 20 Lines |