Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,680 Lines • ▼ Show 20 Lines | bool ProcessNewBlockHeaders(const Config &config, | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Store a block on disk. | * Store a block on disk. | ||||
* | * | ||||
* @param[in] config The global config. | * @param[in] config The global config. | ||||
* @param[in-out] pblock The block we want to accept. | * @param[in-out] pblock The block we want to accept. | ||||
* @param[out] ppindex The last new block index, only set if the block | |||||
* was accepted. | |||||
* @param[in] fRequested A boolean to indicate if this block was requested | * @param[in] fRequested A boolean to indicate if this block was requested | ||||
* from our peers. | * from our peers. | ||||
* @param[in] dbp If non-null, the disk position of the block. | * @param[in] dbp If non-null, the disk position of the block. | ||||
* @param[in-out] fNewBlock True if block was first received via this call. | * @param[in-out] fNewBlock True if block was first received via this call. | ||||
* @return True if the block is accepted as a valid block and written to disk. | * @return True if the block is accepted as a valid block and written to disk. | ||||
*/ | */ | ||||
static bool AcceptBlock(const Config &config, | static bool AcceptBlock(const Config &config, | ||||
const std::shared_ptr<const CBlock> &pblock, | const std::shared_ptr<const CBlock> &pblock, | ||||
CValidationState &state, CBlockIndex **ppindex, | CValidationState &state, bool fRequested, | ||||
bool fRequested, const CDiskBlockPos *dbp, | const CDiskBlockPos *dbp, bool *fNewBlock) { | ||||
bool *fNewBlock) { | |||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CBlock &block = *pblock; | const CBlock &block = *pblock; | ||||
if (fNewBlock) { | if (fNewBlock) { | ||||
*fNewBlock = false; | *fNewBlock = false; | ||||
} | } | ||||
CBlockIndex *pindexDummy = nullptr; | CBlockIndex *pindex = nullptr; | ||||
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy; | |||||
if (!AcceptBlockHeader(config, block, state, &pindex)) { | 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(); | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | static bool AcceptBlock(const Config &config, | ||||
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) { | ||||
{ | { | ||||
CBlockIndex *pindex = nullptr; | |||||
if (fNewBlock) { | if (fNewBlock) { | ||||
*fNewBlock = false; | *fNewBlock = false; | ||||
} | } | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
CValidationState state; | CValidationState state; | ||||
// Ensure that CheckBlock() passes before calling AcceptBlock, as | // Ensure that CheckBlock() passes before calling AcceptBlock, as | ||||
// belt-and-suspenders. | // belt-and-suspenders. | ||||
bool ret = CheckBlock(config, *pblock, state); | bool ret = CheckBlock(config, *pblock, state); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (ret) { | if (ret) { | ||||
// Store to disk | // Store to disk | ||||
ret = AcceptBlock(config, pblock, state, &pindex, fForceProcessing, | ret = AcceptBlock(config, pblock, state, fForceProcessing, nullptr, | ||||
nullptr, fNewBlock); | fNewBlock); | ||||
} | } | ||||
CheckBlockIndex(chainparams.GetConsensus()); | CheckBlockIndex(chainparams.GetConsensus()); | ||||
if (!ret) { | if (!ret) { | ||||
GetMainSignals().BlockChecked(*pblock, state); | GetMainSignals().BlockChecked(*pblock, state); | ||||
return error("%s: AcceptBlock FAILED", __func__); | return error("%s: AcceptBlock FAILED", __func__); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 987 Lines • ▼ Show 20 Lines | try { | ||||
continue; | continue; | ||||
} | } | ||||
// process in case the block isn't known yet | // process in case the block isn't known yet | ||||
if (mapBlockIndex.count(hash) == 0 || | if (mapBlockIndex.count(hash) == 0 || | ||||
!mapBlockIndex[hash]->nStatus.hasData()) { | !mapBlockIndex[hash]->nStatus.hasData()) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CValidationState state; | CValidationState state; | ||||
if (AcceptBlock(config, pblock, state, nullptr, true, dbp, | if (AcceptBlock(config, pblock, state, true, dbp, | ||||
nullptr)) { | nullptr)) { | ||||
nLoaded++; | nLoaded++; | ||||
} | } | ||||
if (state.IsError()) { | if (state.IsError()) { | ||||
break; | break; | ||||
} | } | ||||
} else if (hash != | } else if (hash != | ||||
Show All 36 Lines | try { | ||||
LogPrint( | LogPrint( | ||||
BCLog::REINDEX, | BCLog::REINDEX, | ||||
"%s: Processing out of order child %s of %s\n", | "%s: Processing out of order child %s of %s\n", | ||||
__func__, pblockrecursive->GetHash().ToString(), | __func__, pblockrecursive->GetHash().ToString(), | ||||
head.ToString()); | head.ToString()); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CValidationState dummy; | CValidationState dummy; | ||||
if (AcceptBlock(config, pblockrecursive, dummy, | if (AcceptBlock(config, pblockrecursive, dummy, | ||||
nullptr, true, &it->second, | true, &it->second, nullptr)) { | ||||
nullptr)) { | |||||
nLoaded++; | nLoaded++; | ||||
queue.push_back(pblockrecursive->GetHash()); | queue.push_back(pblockrecursive->GetHash()); | ||||
} | } | ||||
} | } | ||||
range.first++; | range.first++; | ||||
mapBlocksUnknownParent.erase(it); | mapBlocksUnknownParent.erase(it); | ||||
NotifyHeaderTip(); | NotifyHeaderTip(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 507 Lines • Show Last 20 Lines |