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 759 Lines • ▼ Show 20 Lines | try { | ||||
} | } | ||||
if (dbp == nullptr) { | if (dbp == nullptr) { | ||||
if (!WriteBlockToDisk(block, blockPos, chainparams.DiskMagic())) { | if (!WriteBlockToDisk(block, blockPos, chainparams.DiskMagic())) { | ||||
AbortNode(state, "Failed to write block"); | AbortNode(state, "Failed to write block"); | ||||
} | } | ||||
} | } | ||||
if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) { | if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) { | ||||
deadalnix: This method is there to do all the bookeeping happening once a block is found. It belongs in… | |||||
schancelAuthorUnsubmitted Done Inline Actions@deadalnix Okay, thank you. Will fix. schancel: @deadalnix Okay, thank you. Will fix. | |||||
return error("AcceptBlock(): ReceivedBlockTransactions failed"); | return error("AcceptBlock(): ReceivedBlockTransactions failed"); | ||||
} | } | ||||
} catch (const std::runtime_error &e) { | } catch (const std::runtime_error &e) { | ||||
return AbortNode(state, std::string("System error: ") + e.what()); | return AbortNode(state, std::string("System error: ") + e.what()); | ||||
} | } | ||||
if (fCheckForPruning) { | if (fCheckForPruning) { | ||||
// we just allocated more disk space for block files. | // we just allocated more disk space for block files. | ||||
FlushStateToDisk(config.GetChainParams(), state, FLUSH_STATE_NONE); | FlushStateToDisk(config.GetChainParams(), state, FLUSH_STATE_NONE); | ||||
} | } | ||||
// 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(); | |||||
return true; | return true; | ||||
} | } | ||||
bool ProcessNewBlock(const Config &config, | bool ProcessNewBlock(const Config &config, | ||||
const std::shared_ptr<const CBlock> pblock, | const std::shared_ptr<const CBlock> pblock, | ||||
bool fForceProcessing, bool *fNewBlock) { | bool fForceProcessing, bool *fNewBlock) { | ||||
{ | { | ||||
if (fNewBlock) { | if (fNewBlock) { | ||||
▲ Show 20 Lines • Show All 1,588 Lines • Show Last 20 Lines |
This method is there to do all the bookeeping happening once a block is found. It belongs in there.