19 #include <validation.h> 38 LogPrintf(
"Validating signatures for all blocks.\n");
44 if (
nPruneTarget == std::numeric_limits<uint64_t>::max()) {
45 LogPrintf(
"Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
47 LogPrintf(
"Prune configured to target %u MiB on disk for block and undo files.\n",
nPruneTarget / 1024 / 1024);
51 chainman.InitializeChainstate(options.
mempool);
55 auto& pblocktree{chainman.
m_blockman.m_block_tree_db};
62 pblocktree->WriteReindexing(
true);
90 return {
ChainstateLoadStatus::FAILURE,
_(
"You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain")};
105 chainstate->InitCoinsDB(
111 chainstate->CoinsErrorCatcher().AddReadErrCallback(options.
coins_error_cb);
116 if (chainstate->CoinsDB().NeedsUpgrade()) {
118 "Please restart with -reindex-chainstate. This will " 119 "rebuild the chainstate database.")};
123 if (!chainstate->ReplayBlocks()) {
128 chainstate->InitCoinsCache(cache_sizes.
coins);
129 assert(chainstate->CanFlushToDisk());
131 if (!is_coinsview_empty(chainstate)) {
133 if (!chainstate->LoadChainTip()) {
136 assert(chainstate->m_chain.Tip() !=
nullptr);
141 auto chainstates{chainman.
GetAll()};
142 if (std::any_of(chainstates.begin(), chainstates.end(),
161 if (!is_coinsview_empty(chainstate)) {
162 const CBlockIndex* tip = chainstate->m_chain.Tip();
165 "This may be due to your computer's date and time being set incorrectly. " 166 "Only rebuild the block database if you are sure that your computer's date and time are correct")};
170 *chainstate, chainman.
GetConsensus(), chainstate->CoinsDB(),
void CleanupBlockRevFiles()
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
std::atomic_bool fReindex
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
bool block_tree_db_in_memory
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
std::function< bool()> check_interrupt
arith_uint256 UintToArith256(const uint256 &a)
uint64_t nPruneTarget
Number of bytes of block files that we're trying to stay below.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
Access to the block database (blocks/index/)
bilingual_str _(const char *psz)
Translation function.
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex...
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
const Consensus::Params & GetConsensus() const
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Chainstate &InitializeChainstate(CTxMemPool *mempool, const std::optional< uint256 > &snapshot_blockhash=std::nullopt) LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate and assign it based upon whether it is from a snapshot.
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
int64_t m_total_coinstip_cache
The total number of bytes available for us to use across all in-memory coins caches.
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
std::function< void()> coins_error_cb
uint256 nMinimumChainWork
The best chain should have at least this much work.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
const CBlockIndex *GetFirstStoredBlock(const CBlockIndex &start_block LIFETIMEBOUND) EXCLUSIVE_LOCKS_REQUIRED(bool m_have_pruned
Find the first block that is not pruned.
The block chain is a tree shaped structure starting with the genesis block at the root...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
std::string GetHex() const
int SegwitHeight
Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.
std::string GetHex() const
std::tuple< ChainstateLoadStatus, bilingual_str > ChainstateLoadResult
Chainstate load status code and optional error string.
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 ...
ChainstateLoadResult LoadChainstate(ChainstateManager &chainman, const CacheSizes &cache_sizes, const ChainstateLoadOptions &options)
This sequence can have 4 types of outcomes:
Chainstate & ActiveChainstate() const
The most-work chain.
int64_t m_total_coinsdb_cache
The total number of bytes available for us to use across all leveldb coins databases.
int64_t GetTime()
DEPRECATED, see GetTime.