Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,864 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); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,658 Lines • Show Last 20 Lines |