You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
index: prevent race by calling 'CustomInit' prior setting 'synced' flag
The 'm_synced' flag enables 'BlockConnected' events to be processed by
the index. If we set the flag before calling 'CustomInit', we could be
dispatching a block connected event to an uninitialized index child
class.
e.g. BlockFilterIndex, initializes the next filter position
inside 'CustomInit'. So, if `CustomInit` is not called prior receiving
the block event, the index will use 'next_filter_position=0' which
overwrites the first filter in disk.
// if the bestblock is not part of the mainchain, find the fork
125
122
// and make sure we have all data down to the fork
@@ -143,6 +140,16 @@ bool BaseIndex::Init()
143
140
returnInitError(strprintf(Untranslated("%s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"), GetName()));
144
141
}
145
142
}
143
+
144
+
// Child init
145
+
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockKey{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
146
+
returnfalse;
147
+
}
148
+
149
+
// Note: this will latch to true immediately if the user starts up with an empty
150
+
// datadir and an index enabled. If this is the case, indexation will happen solely
151
+
// via `BlockConnected` signals until, possibly, the next restart.
152
+
m_synced = synced;
146
153
returntrue;
147
154
}
148
155
@@ -408,11 +415,6 @@ bool BaseIndex::Start()
408
415
RegisterValidationInterface(this);
409
416
if (!Init()) returnfalse;
410
417
411
-
const CBlockIndex* index = m_best_block_index.load();
412
-
if (!CustomInit(index ? std::make_optional(interfaces::BlockKey{index->GetBlockHash(), index->nHeight}) : std::nullopt)) {
0 commit comments