Skip to content

Commit a51aa28

Browse files
committed
Merge #17897: init: Stop indexes on shutdown after ChainStateFlushed callback.
9dd58ca init: Stop indexes on shutdown after ChainStateFlushed callback. (Jim Posen) Pull request description: Replaces bitcoin/bitcoin#17852. Currently, the latest index state may not be committed to disk on shutdown. The state is committed on `ChainStateFlushed` callbacks and the current init order unregisters the indexes as validation interfaces before the final `ChainStateFlushed` callback is called on them. Issue identified by paulyc. For review: an alternative or supplemental solution would be to call `Commit` at the end of `BaseIndex::Stop`. I don't see any harm in doing so and it makes the less prone to user error. However, the destructor would have to be modified to not call `Stop` because `Commit` calls a virtual method, so I figured it wasn't worth it. But I'm curious how others feel. ACKs for top commit: fjahr: tested ACK 9dd58ca paulyc: > Code review ACK [9dd58ca](bitcoin/bitcoin@9dd58ca), but failed to test because I can't reproduce the original problem. kallewoof: Tested ACK 9dd58ca promag: Code review ACK 9dd58ca, but failed to test because I can't reproduce the original problem. Tree-SHA512: 2918380b699833cb7eab07456d1667dbf8ebbe2d2b5988300a3cf5b6a6cfc818b6d9086e1936ffe7881f67e409306c4b91d61a08a169cfd0a301383479d4f3cb
2 parents e45463a + 9dd58ca commit a51aa28

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)