2021-09-20 16:12:18 -04:00
|
|
|
// Copyright (c) 2021 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NODE_CHAINSTATE_H
|
|
|
|
#define BITCOIN_NODE_CHAINSTATE_H
|
|
|
|
|
2021-11-11 14:40:50 -05:00
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2021-09-20 16:12:18 -04:00
|
|
|
|
|
|
|
class ChainstateManager;
|
2021-09-20 16:44:21 -04:00
|
|
|
class CTxMemPool;
|
2021-09-20 16:12:18 -04:00
|
|
|
|
2021-11-12 10:06:00 -05:00
|
|
|
namespace node {
|
2021-08-17 18:07:14 -04:00
|
|
|
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,
|
|
|
|
SHUTDOWN_PROBED,
|
|
|
|
};
|
|
|
|
|
2021-09-20 16:12:18 -04:00
|
|
|
/** This sequence can have 4 types of outcomes:
|
|
|
|
*
|
|
|
|
* 1. Success
|
|
|
|
* 2. Shutdown requested
|
|
|
|
* - nothing failed but a shutdown was triggered in the middle of the
|
|
|
|
* sequence
|
|
|
|
* 3. Soft failure
|
|
|
|
* - a failure that might be recovered from with a reindex
|
|
|
|
* 4. Hard failure
|
|
|
|
* - a failure that definitively cannot be recovered from with a reindex
|
|
|
|
*
|
2021-08-17 18:07:14 -04:00
|
|
|
* 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
|
2021-09-22 15:36:24 -04:00
|
|
|
* this sequence, when we explicitly checked shutdown_requested() at
|
2021-08-17 18:07:14 -04:00
|
|
|
* arbitrary points, one of those calls returned true". Therefore, a
|
|
|
|
* return value other than SHUTDOWN_PROBED does not guarantee that
|
2021-12-23 16:41:53 -05:00
|
|
|
* shutdown hasn't been called indirectly.
|
2021-08-17 18:07:14 -04:00
|
|
|
* - else
|
|
|
|
* - Success!
|
2021-09-20 16:12:18 -04:00
|
|
|
*/
|
2021-08-17 18:07:14 -04:00
|
|
|
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|
|
|
ChainstateManager& chainman,
|
2021-09-20 16:44:21 -04:00
|
|
|
CTxMemPool* mempool,
|
2021-08-17 18:07:14 -04:00
|
|
|
bool fPruneMode,
|
|
|
|
bool fReindexChainState,
|
|
|
|
int64_t nBlockTreeDBCache,
|
|
|
|
int64_t nCoinDBCache,
|
2021-08-18 13:39:34 -04:00
|
|
|
int64_t nCoinCacheUsage,
|
2021-09-21 12:10:51 -04:00
|
|
|
bool block_tree_db_in_memory,
|
|
|
|
bool coins_db_in_memory,
|
2021-09-22 15:36:24 -04:00
|
|
|
std::function<bool()> shutdown_requested = nullptr,
|
2021-08-18 13:39:34 -04:00
|
|
|
std::function<void()> coins_error_cb = nullptr);
|
2021-11-10 15:57:14 -05:00
|
|
|
|
|
|
|
enum class ChainstateLoadVerifyError {
|
|
|
|
ERROR_BLOCK_FROM_FUTURE,
|
|
|
|
ERROR_CORRUPTED_BLOCK_DB,
|
|
|
|
ERROR_GENERIC_FAILURE,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
|
|
|
|
bool fReset,
|
|
|
|
bool fReindexChainState,
|
2022-02-21 10:41:08 +01:00
|
|
|
int check_blocks,
|
2022-05-18 18:31:19 +02:00
|
|
|
int check_level);
|
2021-11-12 10:06:00 -05:00
|
|
|
} // namespace node
|
2021-09-20 16:12:18 -04:00
|
|
|
|
|
|
|
#endif // BITCOIN_NODE_CHAINSTATE_H
|