2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2021-2022 The Bitcoin Core developers
|
2021-09-20 16:12:18 -04:00
|
|
|
// 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
|
|
|
|
|
2022-07-21 20:16:03 +02:00
|
|
|
#include <util/translation.h>
|
2021-12-01 18:16:29 -05:00
|
|
|
#include <validation.h>
|
|
|
|
|
2021-11-11 14:40:50 -05:00
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
2022-07-21 20:16:03 +02:00
|
|
|
#include <tuple>
|
2021-09-20 16:12:18 -04:00
|
|
|
|
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-12-01 18:16:29 -05:00
|
|
|
|
|
|
|
struct CacheSizes;
|
|
|
|
|
|
|
|
struct ChainstateLoadOptions {
|
|
|
|
CTxMemPool* mempool{nullptr};
|
|
|
|
bool block_tree_db_in_memory{false};
|
|
|
|
bool coins_db_in_memory{false};
|
|
|
|
bool reindex{false};
|
|
|
|
bool reindex_chainstate{false};
|
|
|
|
bool prune{false};
|
2023-02-24 14:02:47 -05:00
|
|
|
//! Setting require_full_verification to true will require all checks at
|
|
|
|
//! check_level (below) to succeed for loading to succeed. Setting it to
|
|
|
|
//! false will skip checks if cache is not big enough to run them, so may be
|
|
|
|
//! helpful for running with a small cache.
|
2022-10-06 17:11:02 -04:00
|
|
|
bool require_full_verification{true};
|
2021-12-01 18:16:29 -05:00
|
|
|
int64_t check_blocks{DEFAULT_CHECKBLOCKS};
|
|
|
|
int64_t check_level{DEFAULT_CHECKLEVEL};
|
|
|
|
std::function<bool()> check_interrupt;
|
|
|
|
std::function<void()> coins_error_cb;
|
|
|
|
};
|
|
|
|
|
2021-12-01 18:16:29 -05:00
|
|
|
//! Chainstate load status. Simple applications can just check for the success
|
|
|
|
//! case, and treat other cases as errors. More complex applications may want to
|
|
|
|
//! try reindexing in the generic failure case, and pass an interrupt callback
|
|
|
|
//! and exit cleanly in the interrupted case.
|
2022-10-06 17:11:02 -04:00
|
|
|
enum class ChainstateLoadStatus {
|
|
|
|
SUCCESS,
|
2023-06-12 11:48:27 -04:00
|
|
|
FAILURE, //!< Generic failure which reindexing may fix
|
|
|
|
FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
|
2022-10-06 17:11:02 -04:00
|
|
|
FAILURE_INCOMPATIBLE_DB,
|
|
|
|
FAILURE_INSUFFICIENT_DBCACHE,
|
|
|
|
INTERRUPTED,
|
|
|
|
};
|
2021-12-01 18:16:29 -05:00
|
|
|
|
|
|
|
//! Chainstate load status code and optional error string.
|
|
|
|
using ChainstateLoadResult = std::tuple<ChainstateLoadStatus, bilingual_str>;
|
2021-08-17 18:07:14 -04:00
|
|
|
|
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-12-01 18:16:29 -05:00
|
|
|
* LoadChainstate returns a (status code, error string) tuple.
|
2021-09-20 16:12:18 -04:00
|
|
|
*/
|
2021-12-01 18:16:29 -05:00
|
|
|
ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSizes& cache_sizes,
|
|
|
|
const ChainstateLoadOptions& options);
|
|
|
|
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options);
|
2021-11-12 10:06:00 -05:00
|
|
|
} // namespace node
|
2021-09-20 16:12:18 -04:00
|
|
|
|
|
|
|
#endif // BITCOIN_NODE_CHAINSTATE_H
|