Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,519 Lines • ▼ Show 20 Lines | if (!AcceptBlockHeader(config, block, state, &pindex)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Try to process all requested blocks that we don't have, but only | // Try to process all requested blocks that we don't have, but only | ||||
// process an unrequested block if it's new and has enough work to | // process an unrequested block if it's new and has enough work to | ||||
// advance our tip, and isn't too many blocks ahead. | // advance our tip, and isn't too many blocks ahead. | ||||
bool fAlreadyHave = pindex->nStatus.hasData(); | bool fAlreadyHave = pindex->nStatus.hasData(); | ||||
// TODO: deal better with return value and error conditions for duplicate | |||||
// and unrequested blocks. | |||||
if (fAlreadyHave) { | |||||
return true; | |||||
} | |||||
// 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; | ||||
Show All 22 Lines | bool fTooFarAhead = | ||||
(pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | ||||
// TODO: Decouple this function from the block download logic by removing | // TODO: Decouple this function from the block download logic by removing | ||||
// fRequested | // fRequested | ||||
// This requires some new chain datastructure to efficiently look up if a | // This requires some new chain datastructure to efficiently look up if a | ||||
// block is in a chain leading to a candidate for best tip, despite not | // block is in a chain leading to a candidate for best tip, despite not | ||||
// being such a candidate itself. | // being such a candidate itself. | ||||
// TODO: deal better with return value and error conditions for duplicate | |||||
// and unrequested blocks. | |||||
if (fAlreadyHave) { | |||||
return true; | |||||
} | |||||
// If we didn't ask for it: | // If we didn't ask for it: | ||||
if (!fRequested) { | if (!fRequested) { | ||||
// This is a previously-processed block that was pruned. | // This is a previously-processed block that was pruned. | ||||
if (pindex->nTx != 0) { | if (pindex->nTx != 0) { | ||||
return true; | return true; | ||||
} | } | ||||
// Don't process less-work chains. | // Don't process less-work chains. | ||||
▲ Show 20 Lines • Show All 1,672 Lines • Show Last 20 Lines |