@@ -154,6 +154,10 @@ class CChainState {
154
154
155
155
bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock);
156
156
157
+ /* *
158
+ * If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
159
+ * that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
160
+ */
157
161
bool AcceptBlockHeader (const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex);
158
162
bool AcceptBlock (const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested , const CDiskBlockPos* dbp, bool * fNewBlock );
159
163
@@ -185,6 +189,11 @@ class CChainState {
185
189
CBlockIndex* AddToBlockIndex (const CBlockHeader& block);
186
190
/* * Create a new block index entry for a given block hash */
187
191
CBlockIndex * InsertBlockIndex (const uint256& hash);
192
+ /* *
193
+ * Make various assertions about the state of the block index.
194
+ *
195
+ * By default this only executes fully when using the Regtest chain; see: fCheckBlockIndex.
196
+ */
188
197
void CheckBlockIndex (const Consensus::Params& consensusParams);
189
198
190
199
void InvalidBlockFound (CBlockIndex *pindex, const CValidationState &state);
@@ -2625,6 +2634,10 @@ static void NotifyHeaderTip() {
2625
2634
* Make the best chain active, in multiple steps. The result is either failure
2626
2635
* or an activated best chain. pblock is either nullptr or a pointer to a block
2627
2636
* that is already loaded (to avoid loading it again from disk).
2637
+ *
2638
+ * ActivateBestChain is split into steps (see ActivateBestChainStep) so that
2639
+ * we avoid holding cs_main for an extended period of time; the length of this
2640
+ * call may be quite long during reindexing or a substantial reorg.
2628
2641
*/
2629
2642
bool CChainState::ActivateBestChain (CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
2630
2643
// Note that while we're often called here from ProcessNewBlock, this is
@@ -3323,6 +3336,9 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
3323
3336
if (!ContextualCheckBlockHeader (block, state, chainparams, pindexPrev, GetAdjustedTime ()))
3324
3337
return error (" %s: Consensus::ContextualCheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
3325
3338
3339
+ // If the previous block index isn't valid, determine if it descends from any block which
3340
+ // has been found invalid (g_failed_blocks), then mark pindexPrev and any blocks
3341
+ // between them as failed.
3326
3342
if (!pindexPrev->IsValid (BLOCK_VALID_SCRIPTS)) {
3327
3343
for (const CBlockIndex* failedit : g_failed_blocks) {
3328
3344
if (pindexPrev->GetAncestor (failedit->nHeight ) == failedit) {
0 commit comments