Skip to content

Commit 99afb9d

Browse files
committed
refactor: init, simplify index shutdown code
1 parent 0faafb5 commit 99afb9d

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/init.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,8 @@ void Interrupt(NodeContext& node)
256256
InterruptMapPort();
257257
if (node.connman)
258258
node.connman->Interrupt();
259-
if (g_txindex) {
260-
g_txindex->Interrupt();
261-
}
262-
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
263-
if (g_coin_stats_index) {
264-
g_coin_stats_index->Interrupt();
259+
for (auto* index : node.indexes) {
260+
index->Interrupt();
265261
}
266262
}
267263

@@ -337,16 +333,11 @@ void Shutdown(NodeContext& node)
337333
if (node.validation_signals) node.validation_signals->FlushBackgroundCallbacks();
338334

339335
// Stop and delete all indexes only after flushing background callbacks.
340-
if (g_txindex) {
341-
g_txindex->Stop();
342-
g_txindex.reset();
343-
}
344-
if (g_coin_stats_index) {
345-
g_coin_stats_index->Stop();
346-
g_coin_stats_index.reset();
347-
}
348-
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
336+
for (auto* index : node.indexes) index->Stop();
337+
if (g_txindex) g_txindex.reset();
338+
if (g_coin_stats_index) g_coin_stats_index.reset();
349339
DestroyAllBlockFilterIndexes();
340+
node.indexes.clear(); // all instances are nullptr now
350341

351342
// Any future callbacks will be dropped. This should absolutely be safe - if
352343
// missing a callback results in an unrecoverable situation, unclean shutdown

0 commit comments

Comments
 (0)