Skip to content

Commit

Permalink
Merge #22485: doc: BaseIndex sync behavior with empty datadir
Browse files Browse the repository at this point in the history
11780f2 doc: BaseIndex sync behavior with empty datadir (James O'Beirne)

Pull request description:

  Make a note about a potentially confusing behavior with `BaseIndex::m_synced`;
  if the user starts bitcoind with an empty datadir and an index enabled,
  BaseIndex will consider itself synced (as a degenerate case). This affects
  how indices are built during IBD (relying solely on BlockConnected signals vs.
  using ThreadSync()).

ACKs for top commit:
  mzumsande:
    ACK 11780f2

Tree-SHA512: 0b530379e57c62e05d2ddca7bb8e2c936786fa00678f9eaa1bb3742d957c48f141d46f936734b03f6673d964abc7eb72c1769f1784b9d3563d218e96296b7afd
  • Loading branch information
MacroFake committed Jul 21, 2022
2 parents d1e4265 + 11780f2 commit b8067cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ bool BaseIndex::Init()
} else {
SetBestBlockIndex(m_chainstate->FindForkInGlobalIndex(locator));
}

// Note: this will latch to true immediately if the user starts up with an empty
// datadir and an index enabled. If this is the case, indexation will happen solely
// via `BlockConnected` signals until, possibly, the next restart.
m_synced = m_best_block_index.load() == active_chain.Tip();
if (!m_synced) {
bool prune_violation = false;
Expand Down
4 changes: 4 additions & 0 deletions src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class BaseIndex : public CValidationInterface
/// Whether the index is in sync with the main chain. The flag is flipped
/// from false to true once, after which point this starts processing
/// ValidationInterface notifications to stay in sync.
///
/// Note that this will latch to true *immediately* upon startup if
/// `m_chainstate->m_chain` is empty, which will be the case upon startup
/// with an empty datadir if, e.g., `-txindex=1` is specified.
std::atomic<bool> m_synced{false};

/// The last block in the chain that the index is in sync with.
Expand Down

0 comments on commit b8067cd

Please sign in to comment.