diff options
author | Carl Dong <contact@carldong.me> | 2021-09-22 15:36:24 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-12-07 14:48:49 -0500 |
commit | 4da9c076d1cf12728730bb1f7e8906d4e9bfaba5 (patch) | |
tree | 507a2cce76d7e59f936ef54c8d822765170247a8 /src/node | |
parent | 05441c2dc5f60e2025476d8ec94c9025032d118c (diff) |
node/chainstate: Decouple from ShutdownRequested
...instead allow optionally passing in a std::function<bool()>
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/chainstate.cpp | 6 | ||||
-rw-r--r-- | src/node/chainstate.h | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 242b202d2f..c112bc949a 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -6,7 +6,6 @@ #include <chainparams.h> // for CChainParams #include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex -#include <shutdown.h> // for ShutdownRequested #include <validation.h> // for a lot of things std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, @@ -18,6 +17,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, int64_t nCoinCacheUsage, + std::function<bool()> shutdown_requested, std::function<void()> coins_error_cb) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { @@ -45,14 +45,14 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, CleanupBlockRevFiles(); } - if (ShutdownRequested()) return ChainstateLoadingError::SHUTDOWN_PROBED; + if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED; // LoadBlockIndex will load fHavePruned if we've ever removed a // block file from disk. // Note that it also sets fReindex based on the disk flag! // From here on out fReindex and fReset mean something different! if (!chainman.LoadBlockIndex()) { - if (ShutdownRequested()) return ChainstateLoadingError::SHUTDOWN_PROBED; + if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED; return ChainstateLoadingError::ERROR_LOADING_BLOCK_DB; } diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 3c950409d3..735906a540 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -45,10 +45,10 @@ enum class ChainstateLoadingError { * differentiable by the specific enumerator. * * Note that a return value of SHUTDOWN_PROBED means ONLY that "during - * this sequence, when we explicitly checked ShutdownRequested() at + * this sequence, when we explicitly checked shutdown_requested() at * arbitrary points, one of those calls returned true". Therefore, a * return value other than SHUTDOWN_PROBED does not guarantee that - * ShutdownRequested() hasn't been called indirectly. + * shutdown_requested() hasn't been called indirectly. * - else * - Success! */ @@ -61,6 +61,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, int64_t nCoinCacheUsage, + std::function<bool()> shutdown_requested = nullptr, std::function<void()> coins_error_cb = nullptr); enum class ChainstateLoadVerifyError { |