Branch data Line data Source code
1 : : // Copyright (c) 2021-2022 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #ifndef BITCOIN_NODE_CHAINSTATE_H
6 : : #define BITCOIN_NODE_CHAINSTATE_H
7 : :
8 : : #include <util/translation.h>
9 : : #include <validation.h>
10 : :
11 : : #include <cstdint>
12 : : #include <functional>
13 : : #include <tuple>
14 : :
15 : : class CTxMemPool;
16 : :
17 : : namespace kernel {
18 : : struct CacheSizes;
19 : : } // namespace kernel
20 : :
21 : : namespace node {
22 : :
23 [ + - ]: 2252 : struct ChainstateLoadOptions {
24 : : CTxMemPool* mempool{nullptr};
25 : : bool coins_db_in_memory{false};
26 : : // Whether to wipe the chainstate database when loading it. If set, this
27 : : // will cause the chainstate database to be rebuilt starting from genesis.
28 : : bool wipe_chainstate_db{false};
29 : : bool prune{false};
30 : : //! Setting require_full_verification to true will require all checks at
31 : : //! check_level (below) to succeed for loading to succeed. Setting it to
32 : : //! false will skip checks if cache is not big enough to run them, so may be
33 : : //! helpful for running with a small cache.
34 : : bool require_full_verification{true};
35 : : int64_t check_blocks{DEFAULT_CHECKBLOCKS};
36 : : int64_t check_level{DEFAULT_CHECKLEVEL};
37 : : std::function<void()> coins_error_cb;
38 : : };
39 : :
40 : : //! Chainstate load status. Simple applications can just check for the success
41 : : //! case, and treat other cases as errors. More complex applications may want to
42 : : //! try reindexing in the generic failure case, and pass an interrupt callback
43 : : //! and exit cleanly in the interrupted case.
44 : : enum class ChainstateLoadStatus {
45 : : SUCCESS,
46 : : FAILURE, //!< Generic failure which reindexing may fix
47 : : FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
48 : : FAILURE_INCOMPATIBLE_DB,
49 : : FAILURE_INSUFFICIENT_DBCACHE,
50 : : INTERRUPTED,
51 : : };
52 : :
53 : : //! Chainstate load status code and optional error string.
54 : : using ChainstateLoadResult = std::tuple<ChainstateLoadStatus, bilingual_str>;
55 : :
56 : : /** This sequence can have 4 types of outcomes:
57 : : *
58 : : * 1. Success
59 : : * 2. Shutdown requested
60 : : * - nothing failed but a shutdown was triggered in the middle of the
61 : : * sequence
62 : : * 3. Soft failure
63 : : * - a failure that might be recovered from with a reindex
64 : : * 4. Hard failure
65 : : * - a failure that definitively cannot be recovered from with a reindex
66 : : *
67 : : * LoadChainstate returns a (status code, error string) tuple.
68 : : */
69 : : ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const kernel::CacheSizes& cache_sizes,
70 : : const ChainstateLoadOptions& options);
71 : : ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options);
72 : : } // namespace node
73 : :
74 : : #endif // BITCOIN_NODE_CHAINSTATE_H
|