Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2021-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_NODE_CHAINSTATE_H6#define BITCOIN_NODE_CHAINSTATE_H8#include <util/translation.h>9#include <validation.h>11#include <cstdint>12#include <functional>13#include <tuple>15class CTxMemPool;17namespace kernel {18struct CacheSizes;19} // namespace kernel21namespace node {23struct ChainstateLoadOptions {24CTxMemPool* mempool{nullptr};25bool coins_db_in_memory{false};26// Whether to wipe the chainstate database when loading it. If set, this27// will cause the chainstate database to be rebuilt starting from genesis.28bool wipe_chainstate_db{false};29bool prune{false};30//! Setting require_full_verification to true will require all checks at31//! check_level (below) to succeed for loading to succeed. Setting it to32//! false will skip checks if cache is not big enough to run them, so may be33//! helpful for running with a small cache.34bool require_full_verification{true};35int64_t check_blocks{DEFAULT_CHECKBLOCKS};36int64_t check_level{DEFAULT_CHECKLEVEL};37std::function<void()> coins_error_cb;38};40//! Chainstate load status. Simple applications can just check for the success41//! case, and treat other cases as errors. More complex applications may want to42//! try reindexing in the generic failure case, and pass an interrupt callback43//! and exit cleanly in the interrupted case.44enum class ChainstateLoadStatus {45SUCCESS,46FAILURE, //!< Generic failure which reindexing may fix47FAILURE_FATAL, //!< Fatal error which should not prompt to reindex48FAILURE_INCOMPATIBLE_DB,49FAILURE_INSUFFICIENT_DBCACHE,50INTERRUPTED,51};53//! Chainstate load status code and optional error string.54using ChainstateLoadResult = std::tuple<ChainstateLoadStatus, bilingual_str>;56/** This sequence can have 4 types of outcomes:57*58* 1. Success59* 2. Shutdown requested60* - nothing failed but a shutdown was triggered in the middle of the61* sequence62* 3. Soft failure63* - a failure that might be recovered from with a reindex64* 4. Hard failure65* - a failure that definitively cannot be recovered from with a reindex66*67* LoadChainstate returns a (status code, error string) tuple.68*/69ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const kernel::CacheSizes& cache_sizes,70const ChainstateLoadOptions& options);71ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options);72} // namespace node74#endif // BITCOIN_NODE_CHAINSTATE_H