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 [ + - ]: 2218 : struct ChainstateLoadOptions {
24 : : CTxMemPool* mempool{nullptr};
25 : : bool block_tree_db_in_memory{false};
26 : : bool coins_db_in_memory{false};
27 : : // Whether to wipe the block tree database when loading it. If set, this
28 : : // will also set a reindexing flag so any existing block data files will be
29 : : // scanned and added to the database.
30 : : bool wipe_block_tree_db{false};
31 : : // Whether to wipe the chainstate database when loading it. If set, this
32 : : // will cause the chainstate database to be rebuilt starting from genesis.
33 : : bool wipe_chainstate_db{false};
34 : : bool prune{false};
35 : : //! Setting require_full_verification to true will require all checks at
36 : : //! check_level (below) to succeed for loading to succeed. Setting it to
37 : : //! false will skip checks if cache is not big enough to run them, so may be
38 : : //! helpful for running with a small cache.
39 : : bool require_full_verification{true};
40 : : int64_t check_blocks{DEFAULT_CHECKBLOCKS};
41 : : int64_t check_level{DEFAULT_CHECKLEVEL};
42 : : std::function<void()> coins_error_cb;
43 : : };
44 : :
45 : : //! Chainstate load status. Simple applications can just check for the success
46 : : //! case, and treat other cases as errors. More complex applications may want to
47 : : //! try reindexing in the generic failure case, and pass an interrupt callback
48 : : //! and exit cleanly in the interrupted case.
49 : : enum class ChainstateLoadStatus {
50 : : SUCCESS,
51 : : FAILURE, //!< Generic failure which reindexing may fix
52 : : FAILURE_FATAL, //!< Fatal error which should not prompt to reindex
53 : : FAILURE_INCOMPATIBLE_DB,
54 : : FAILURE_INSUFFICIENT_DBCACHE,
55 : : INTERRUPTED,
56 : : };
57 : :
58 : : //! Chainstate load status code and optional error string.
59 : : using ChainstateLoadResult = std::tuple<ChainstateLoadStatus, bilingual_str>;
60 : :
61 : : /** This sequence can have 4 types of outcomes:
62 : : *
63 : : * 1. Success
64 : : * 2. Shutdown requested
65 : : * - nothing failed but a shutdown was triggered in the middle of the
66 : : * sequence
67 : : * 3. Soft failure
68 : : * - a failure that might be recovered from with a reindex
69 : : * 4. Hard failure
70 : : * - a failure that definitively cannot be recovered from with a reindex
71 : : *
72 : : * LoadChainstate returns a (status code, error string) tuple.
73 : : */
74 : : ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const kernel::CacheSizes& cache_sizes,
75 : : const ChainstateLoadOptions& options);
76 : : ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options);
77 : : } // namespace node
78 : :
79 : : #endif // BITCOIN_NODE_CHAINSTATE_H
|