Skip to content

Commit 4da9c07

Browse files
committed
node/chainstate: Decouple from ShutdownRequested
...instead allow optionally passing in a std::function<bool()>
1 parent 05441c2 commit 4da9c07

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14301430
nBlockTreeDBCache,
14311431
nCoinDBCache,
14321432
nCoinCacheUsage,
1433+
ShutdownRequested,
14331434
[]() {
14341435
uiInterface.ThreadSafeMessageBox(
14351436
_("Error reading from database, shutting down."),

src/node/chainstate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <chainparams.h> // for CChainParams
88
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
9-
#include <shutdown.h> // for ShutdownRequested
109
#include <validation.h> // for a lot of things
1110

1211
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
@@ -18,6 +17,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
1817
int64_t nBlockTreeDBCache,
1918
int64_t nCoinDBCache,
2019
int64_t nCoinCacheUsage,
20+
std::function<bool()> shutdown_requested,
2121
std::function<void()> coins_error_cb)
2222
{
2323
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
@@ -45,14 +45,14 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
4545
CleanupBlockRevFiles();
4646
}
4747

48-
if (ShutdownRequested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
48+
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
4949

5050
// LoadBlockIndex will load fHavePruned if we've ever removed a
5151
// block file from disk.
5252
// Note that it also sets fReindex based on the disk flag!
5353
// From here on out fReindex and fReset mean something different!
5454
if (!chainman.LoadBlockIndex()) {
55-
if (ShutdownRequested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
55+
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
5656
return ChainstateLoadingError::ERROR_LOADING_BLOCK_DB;
5757
}
5858

src/node/chainstate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ enum class ChainstateLoadingError {
4545
* differentiable by the specific enumerator.
4646
*
4747
* Note that a return value of SHUTDOWN_PROBED means ONLY that "during
48-
* this sequence, when we explicitly checked ShutdownRequested() at
48+
* this sequence, when we explicitly checked shutdown_requested() at
4949
* arbitrary points, one of those calls returned true". Therefore, a
5050
* return value other than SHUTDOWN_PROBED does not guarantee that
51-
* ShutdownRequested() hasn't been called indirectly.
51+
* shutdown_requested() hasn't been called indirectly.
5252
* - else
5353
* - Success!
5454
*/
@@ -61,6 +61,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
6161
int64_t nBlockTreeDBCache,
6262
int64_t nCoinDBCache,
6363
int64_t nCoinCacheUsage,
64+
std::function<bool()> shutdown_requested = nullptr,
6465
std::function<void()> coins_error_cb = nullptr);
6566

6667
enum class ChainstateLoadVerifyError {

0 commit comments

Comments
 (0)