diff options
author | fanquake <fanquake@gmail.com> | 2020-01-22 17:30:00 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2020-01-22 17:42:27 +0800 |
commit | a51aa2880d123fc0bcbc0ccd930dbf98e4d29863 (patch) | |
tree | 6125ea9e2685ec369a1f352600461b9a31a6f17e /src/init.cpp | |
parent | e45463a06abef44e9fff0f9bb19435283fd568df (diff) | |
parent | 9dd58ca611f6f2b59c25d727a4e955333525d345 (diff) |
Merge #17897: init: Stop indexes on shutdown after ChainStateFlushed callback.
9dd58ca611f6f2b59c25d727a4e955333525d345 init: Stop indexes on shutdown after ChainStateFlushed callback. (Jim Posen)
Pull request description:
Replaces https://github.com/bitcoin/bitcoin/pull/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 9dd58ca611f6f2b59c25d727a4e955333525d345
paulyc:
> Code review ACK [9dd58ca](https://github.com/bitcoin/bitcoin/commit/9dd58ca611f6f2b59c25d727a4e955333525d345), but failed to test because I can't reproduce the original problem.
kallewoof:
Tested ACK 9dd58ca611f6f2b59c25d727a4e955333525d345
promag:
Code review ACK 9dd58ca611f6f2b59c25d727a4e955333525d345, but failed to test because I can't reproduce the original problem.
Tree-SHA512: 2918380b699833cb7eab07456d1667dbf8ebbe2d2b5988300a3cf5b6a6cfc818b6d9086e1936ffe7881f67e409306c4b91d61a08a169cfd0a301383479d4f3cb
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/init.cpp b/src/init.cpp index 21b7a26cb9..539546117b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -197,8 +197,6 @@ void Shutdown(NodeContext& node) // using the other before destroying them. if (node.peer_logic) UnregisterValidationInterface(node.peer_logic.get()); if (node.connman) node.connman->Stop(); - if (g_txindex) g_txindex->Stop(); - ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); }); StopTorControl(); @@ -212,8 +210,6 @@ void Shutdown(NodeContext& node) node.peer_logic.reset(); node.connman.reset(); node.banman.reset(); - g_txindex.reset(); - DestroyAllBlockFilterIndexes(); if (::mempool.IsLoaded() && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { DumpMempool(::mempool); @@ -246,6 +242,14 @@ void Shutdown(NodeContext& node) // CValidationInterface callbacks, flush them... GetMainSignals().FlushBackgroundCallbacks(); + // Stop and delete all indexes only after flushing background callbacks. + if (g_txindex) { + g_txindex->Stop(); + g_txindex.reset(); + } + ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); }); + DestroyAllBlockFilterIndexes(); + // Any future callbacks will be dropped. This should absolutely be safe - if // missing a callback results in an unrecoverable situation, unclean shutdown // would too. The only reason to do the above flushes is to let the wallet catch |