mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
9047337d36
Make LoadChainstate return an explicit error when snapshot validation succeeds, but there is an error trying to replace the background chainstate with the snapshot chainstate. Previously in this case LoadChainstate would trigger a shutdown and return INTERRUPTED, now it will return an actual error code. There's no real change to behavior other than error message being formatted a little differently. Motivation for this change is to replace error handling via callbacks with error handling via return value ahead of https://github.com/bitcoin/bitcoin/pull/27861
73 lines
2.6 KiB
C++
73 lines
2.6 KiB
C++
// Copyright (c) 2021-2022 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
|
|
|
|
#include <util/translation.h>
|
|
#include <validation.h>
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <tuple>
|
|
|
|
class CTxMemPool;
|
|
|
|
namespace node {
|
|
|
|
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};
|
|
//! 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.
|
|
bool require_full_verification{true};
|
|
int64_t check_blocks{DEFAULT_CHECKBLOCKS};
|
|
int64_t check_level{DEFAULT_CHECKLEVEL};
|
|
std::function<bool()> check_interrupt;
|
|
std::function<void()> coins_error_cb;
|
|
};
|
|
|
|
//! 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.
|
|
enum class ChainstateLoadStatus {
|
|
SUCCESS,
|
|
FAILURE, //!< Generic failure which reindexing may fix
|
|
FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
|
|
FAILURE_INCOMPATIBLE_DB,
|
|
FAILURE_INSUFFICIENT_DBCACHE,
|
|
INTERRUPTED,
|
|
};
|
|
|
|
//! Chainstate load status code and optional error string.
|
|
using ChainstateLoadResult = std::tuple<ChainstateLoadStatus, bilingual_str>;
|
|
|
|
/** 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
|
|
*
|
|
* LoadChainstate returns a (status code, error string) tuple.
|
|
*/
|
|
ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSizes& cache_sizes,
|
|
const ChainstateLoadOptions& options);
|
|
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options);
|
|
} // namespace node
|
|
|
|
#endif // BITCOIN_NODE_CHAINSTATE_H
|