Skip to content

Commit 11780f2

Browse files
committed
doc: BaseIndex sync behavior with empty datadir
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()).
1 parent 8d4a058 commit 11780f2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/index/base.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ bool BaseIndex::Init()
6969
} else {
7070
SetBestBlockIndex(m_chainstate->FindForkInGlobalIndex(locator));
7171
}
72+
73+
// Note: this will latch to true immediately if the user starts up with an empty
74+
// datadir and an index enabled. If this is the case, indexation will happen solely
75+
// via `BlockConnected` signals until, possibly, the next restart.
7276
m_synced = m_best_block_index.load() == active_chain.Tip();
7377
if (!m_synced) {
7478
bool prune_violation = false;

src/index/base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class BaseIndex : public CValidationInterface
5151
/// Whether the index is in sync with the main chain. The flag is flipped
5252
/// from false to true once, after which point this starts processing
5353
/// ValidationInterface notifications to stay in sync.
54+
///
55+
/// Note that this will latch to true *immediately* upon startup if
56+
/// `m_chainstate->m_chain` is empty, which will be the case upon startup
57+
/// with an empty datadir if, e.g., `-txindex=1` is specified.
5458
std::atomic<bool> m_synced{false};
5559

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

0 commit comments

Comments
 (0)