Skip to content

assumevalid is not always applied when reindexing #31494

@mzumsande

Description

@mzumsande

assumevalid (which disables script verification and therefore speeds up IBD) is not always applied in the context of a -reindex:

The assumevalid criteria are

bitcoin/src/validation.cpp

Lines 2497 to 2500 in d73f37d

if (it != m_blockman.m_block_index.end()) {
if (it->second.GetAncestor(pindex->nHeight) == pindex &&
m_chainman.m_best_header->GetAncestor(pindex->nHeight) == pindex &&
m_chainman.m_best_header->nChainWork >= m_chainman.MinimumChainWork()) {

meaning that our best known header needs to have at least as much work than the hard-coded minchainwork.
During normal IBD, we don't connect blocks before having minchainwork headers (headers sync phase), so this is not a problem.
However,-reindex deletes the block tree db and attempts to rebuild it based on local block files, without attempting to re-request headers for which we don't have the full block yet (because we didn't get to that point in the previous IBD).

Therefore, users that encounter an error somewhere midway through IBD and need to reindex, won't use -assumevalid and will rebuild the chainstate slowly.
This has also been encountered in the context of benchmarking.

Possible solutions:

  • always enable assumvalid while connecting blocks in the context of reindexing
  • attempt to sync remaining headers via the p2p nework after rebuilding the block tree db, but before calling ActivateBestChain() to start connecting blocks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions