Skip to content

Commit

Permalink
refactor: init, simplify index shutdown code
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Nov 28, 2023
1 parent fe6a520 commit 63ef83d
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,8 @@ void Interrupt(NodeContext& node)
InterruptMapPort();
if (node.connman)
node.connman->Interrupt();
if (g_txindex) {
g_txindex->Interrupt();
}
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
if (g_coin_stats_index) {
g_coin_stats_index->Interrupt();
for (auto* index : node.indexes) {
index->Interrupt();
}
}

Expand Down Expand Up @@ -303,16 +299,11 @@ void Shutdown(NodeContext& node)
GetMainSignals().FlushBackgroundCallbacks();

// Stop and delete all indexes only after flushing background callbacks.
if (g_txindex) {
g_txindex->Stop();
g_txindex.reset();
}
if (g_coin_stats_index) {
g_coin_stats_index->Stop();
g_coin_stats_index.reset();
}
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
for (auto* index : node.indexes) index->Stop();
if (g_txindex) g_txindex.reset();
if (g_coin_stats_index) g_coin_stats_index.reset();
DestroyAllBlockFilterIndexes();
node.indexes.clear(); // all instances are nullptr now

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

0 comments on commit 63ef83d

Please sign in to comment.