Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,060 Lines • ▼ Show 20 Lines | BlockMap::iterator mi = | ||||
mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; | ||||
pindexNew->phashBlock = &((*mi).first); | pindexNew->phashBlock = &((*mi).first); | ||||
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); | BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); | ||||
if (miPrev != mapBlockIndex.end()) { | if (miPrev != mapBlockIndex.end()) { | ||||
pindexNew->pprev = (*miPrev).second; | pindexNew->pprev = (*miPrev).second; | ||||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1; | pindexNew->nHeight = pindexNew->pprev->nHeight + 1; | ||||
pindexNew->BuildSkip(); | pindexNew->BuildSkip(); | ||||
} | } | ||||
pindexNew->nTimeReceived = GetTime(); | pindexNew->nTimeHeaderReceived = GetTime(); | ||||
pindexNew->nTimeMax = | pindexNew->nTimeMax = | ||||
(pindexNew->pprev | (pindexNew->pprev | ||||
? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) | ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) | ||||
: pindexNew->nTime); | : pindexNew->nTime); | ||||
pindexNew->nChainWork = | pindexNew->nChainWork = | ||||
(pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + | (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + | ||||
GetBlockProof(*pindexNew); | GetBlockProof(*pindexNew); | ||||
pindexNew->RaiseValidity(BlockValidity::TREE); | pindexNew->RaiseValidity(BlockValidity::TREE); | ||||
▲ Show 20 Lines • Show All 638 Lines • ▼ Show 20 Lines | static bool AcceptBlock(const Config &config, | ||||
bool fAlreadyHave = pindex->nStatus.hasData(); | bool fAlreadyHave = pindex->nStatus.hasData(); | ||||
// TODO: deal better with return value and error conditions for duplicate | // TODO: deal better with return value and error conditions for duplicate | ||||
// and unrequested blocks. | // and unrequested blocks. | ||||
if (fAlreadyHave) { | if (fAlreadyHave) { | ||||
return true; | return true; | ||||
} | } | ||||
// This function is ran once all block data is found. If we don't already | |||||
// have the block, record when we first saw all the data. | |||||
pindex->nTimeBlockReceived = GetTime(); | |||||
// 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 20 Lines • Show All 1,723 Lines • Show Last 20 Lines |