Skip to content

Commit 9dd58ca

Browse files
committed
init: Stop indexes on shutdown after ChainStateFlushed callback.
Currently, the latest index state may not be committed to disk on shutdown.
1 parent 6196e93 commit 9dd58ca

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/init.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ void Shutdown(NodeContext& node)
197197
// using the other before destroying them.
198198
if (node.peer_logic) UnregisterValidationInterface(node.peer_logic.get());
199199
if (node.connman) node.connman->Stop();
200-
if (g_txindex) g_txindex->Stop();
201-
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
202200

203201
StopTorControl();
204202

@@ -212,8 +210,6 @@ void Shutdown(NodeContext& node)
212210
node.peer_logic.reset();
213211
node.connman.reset();
214212
node.banman.reset();
215-
g_txindex.reset();
216-
DestroyAllBlockFilterIndexes();
217213

218214
if (::mempool.IsLoaded() && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
219215
DumpMempool(::mempool);
@@ -246,6 +242,14 @@ void Shutdown(NodeContext& node)
246242
// CValidationInterface callbacks, flush them...
247243
GetMainSignals().FlushBackgroundCallbacks();
248244

245+
// Stop and delete all indexes only after flushing background callbacks.
246+
if (g_txindex) {
247+
g_txindex->Stop();
248+
g_txindex.reset();
249+
}
250+
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
251+
DestroyAllBlockFilterIndexes();
252+
249253
// Any future callbacks will be dropped. This should absolutely be safe - if
250254
// missing a callback results in an unrecoverable situation, unclean shutdown
251255
// would too. The only reason to do the above flushes is to let the wallet catch

0 commit comments

Comments
 (0)