diff options
author | Carl Dong <contact@carldong.me> | 2021-08-17 18:07:14 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-12-06 15:56:50 -0500 |
commit | ae9121f958a4124ea6238cad0c3f2acb8b9eb4bb (patch) | |
tree | aa63441abf035cb5c00ce9e48955f8d445b85803 /src/node/chainstate.h | |
parent | cbac28b72f5b831f6f84b7628f73e85627af3d94 (diff) | |
download | bitcoin-ae9121f958a4124ea6238cad0c3f2acb8b9eb4bb.tar.xz |
node/chainstate: Decouple from stringy errors
This allows us to separate the initialization code from translations and
error reporting.
This change changes the caller semantics of LoadChainstate quite
drastically.
To see that this change doesn't change behaviour, observe that:
1. Prior to this change, LoadChainstate returned false only in the "bad
genesis block" failure case (by returning InitError()), indicating
that the caller should immediately bail. After this change, the
corresponding ERROR_BAD_GENESIS_BLOCK handler in src/init.cpp
maintains behavioue by also bailing immediately.
2. The failed_* temporary booleans were only used to break out of the
outer do/while(false) loop. They can therefore be safely removed.
Diffstat (limited to 'src/node/chainstate.h')
-rw-r--r-- | src/node/chainstate.h | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 6181e671ba..921b8d89e5 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -6,13 +6,28 @@ #define BITCOIN_NODE_CHAINSTATE_H #include <cstdint> // for int64_t +#include <optional> // for std::optional class ArgsManager; -struct bilingual_str; class CChainParams; class ChainstateManager; struct NodeContext; +enum class ChainstateLoadingError { + ERROR_LOADING_BLOCK_DB, + ERROR_BAD_GENESIS_BLOCK, + ERROR_PRUNED_NEEDS_REINDEX, + ERROR_LOAD_GENESIS_BLOCK_FAILED, + ERROR_CHAINSTATE_UPGRADE_FAILED, + ERROR_REPLAYBLOCKS_FAILED, + ERROR_LOADCHAINTIP_FAILED, + ERROR_GENERIC_BLOCKDB_OPEN_FAILED, + ERROR_BLOCKS_WITNESS_INSUFFICIENTLY_VALIDATED, + ERROR_BLOCK_FROM_FUTURE, + ERROR_CORRUPTED_BLOCK_DB, + SHUTDOWN_PROBED, +}; + /** This sequence can have 4 types of outcomes: * * 1. Success @@ -24,25 +39,30 @@ struct NodeContext; * 4. Hard failure * - a failure that definitively cannot be recovered from with a reindex * - * Currently, LoadChainstate returns a bool which: - * - if false - * - Definitely a "Hard failure" - * - if true - * - if fLoaded -> "Success" - * - if ShutdownRequested() -> "Shutdown requested" - * - else -> "Soft failure" + * Currently, LoadChainstate returns a std::optional<ChainstateLoadingError> + * which: + * + * - if has_value() + * - Either "Soft failure", "Hard failure", or "Shutdown requested", + * 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 + * 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. + * - else + * - Success! */ -bool LoadChainstate(bool& fLoaded, - bilingual_str& strLoadError, - bool fReset, - ChainstateManager& chainman, - NodeContext& node, - bool fPruneMode, - const CChainParams& chainparams, - const ArgsManager& args, - bool fReindexChainState, - int64_t nBlockTreeDBCache, - int64_t nCoinDBCache, - int64_t nCoinCacheUsage); +std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, + ChainstateManager& chainman, + NodeContext& node, + bool fPruneMode, + const CChainParams& chainparams, + const ArgsManager& args, + bool fReindexChainState, + int64_t nBlockTreeDBCache, + int64_t nCoinDBCache, + int64_t nCoinCacheUsage); #endif // BITCOIN_NODE_CHAINSTATE_H |