21 #include <validation.h>
41 LogPrintf(
"Validating signatures for all blocks.\n");
48 LogPrintf(
"Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
58 chainman.InitializeChainstate(options.
mempool);
61 chainman.DetectSnapshotChainstate(options.
mempool);
63 auto& pblocktree{chainman.
m_blockman.m_block_tree_db};
70 pblocktree->WriteReindexing(
true);
98 return {
ChainstateLoadStatus::FAILURE,
_(
"You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain")};
113 double init_cache_fraction = 0.2;
119 LogPrintf(
"Initializing chainstate %s\n", chainstate->ToString());
121 chainstate->InitCoinsDB(
127 chainstate->CoinsErrorCatcher().AddReadErrCallback(options.
coins_error_cb);
132 if (chainstate->CoinsDB().NeedsUpgrade()) {
134 "Please restart with -reindex-chainstate. This will "
135 "rebuild the chainstate database.")};
139 if (!chainstate->ReplayBlocks()) {
145 assert(chainstate->CanFlushToDisk());
147 if (!is_coinsview_empty(chainstate)) {
149 if (!chainstate->LoadChainTip()) {
152 assert(chainstate->m_chain.Tip() !=
nullptr);
157 auto chainstates{chainman.
GetAll()};
158 if (std::any_of(chainstates.begin(), chainstates.end(),
168 chainman.MaybeRebalanceCaches();
182 if (!is_coinsview_empty(chainstate)) {
183 const CBlockIndex* tip = chainstate->m_chain.Tip();
186 "This may be due to your computer's date and time being set incorrectly. "
187 "Only rebuild the block database if you are sure that your computer's date and time are correct")};
191 *chainstate, chainman.
GetConsensus(), chainstate->CoinsDB(),
arith_uint256 UintToArith256(const uint256 &a)
static constexpr int64_t MAX_FUTURE_BLOCK_TIME
Maximum amount of time that a block timestamp is allowed to exceed the current network-adjusted time ...
The block chain is a tree shaped structure starting with the genesis block at the root,...
Access to the block database (blocks/index/)
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
int64_t m_total_coinstip_cache
The total number of bytes available for us to use across all in-memory coins caches.
const arith_uint256 & MinimumChainWork() const
int64_t m_total_coinsdb_cache
The total number of bytes available for us to use across all leveldb coins databases.
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Chainstate & ActiveChainstate() const
The most-work chain.
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
const uint256 & AssumedValidBlock() const
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
const Consensus::Params & GetConsensus() const
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
std::string GetHex() const
std::string GetHex() const
const CBlockIndex *GetFirstStoredBlock(const CBlockIndex &start_block LIFETIMEBOUND) EXCLUSIVE_LOCKS_REQUIRED(bool m_have_pruned
Find the first block that is not pruned.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
uint64_t GetPruneTarget() const
Attempt to stay below this number of bytes of block files.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
@ FAILURE_INCOMPATIBLE_DB
std::tuple< ChainstateLoadStatus, bilingual_str > ChainstateLoadResult
Chainstate load status code and optional error string.
void CleanupBlockRevFiles()
ChainstateLoadResult LoadChainstate(ChainstateManager &chainman, const CacheSizes &cache_sizes, const ChainstateLoadOptions &options)
This sequence can have 4 types of outcomes:
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
std::atomic_bool fReindex
int SegwitHeight
Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.
uint256 nMinimumChainWork
The best chain should have at least this much work.
bool block_tree_db_in_memory
std::function< void()> coins_error_cb
std::function< bool()> check_interrupt
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bilingual_str _(const char *psz)
Translation function.