29#include <unordered_map>
34std::vector<CBlockIndex *> BlockManager::GetAllBlockIndices() {
36 std::vector<CBlockIndex *> rv;
37 rv.reserve(m_block_index.size());
38 for (
auto &[
_, block_index] : m_block_index) {
39 rv.push_back(&block_index);
46 BlockMap::iterator it = m_block_index.find(hash);
47 return it == m_block_index.end() ? nullptr : &it->second;
52 BlockMap::const_iterator it = m_block_index.find(hash);
53 return it == m_block_index.end() ? nullptr : &it->second;
60 const auto [mi, inserted] =
61 m_block_index.try_emplace(block.
GetHash(), block);
73 BlockMap::iterator miPrev = m_block_index.find(block.
hashPrevBlock);
74 if (miPrev != m_block_index.end()) {
75 pindexNew->
pprev = &(*miPrev).second;
88 if (best_header ==
nullptr ||
90 best_header = pindexNew;
101 for (
auto &entry : m_block_index) {
103 if (pindex->nFile == fileNumber) {
104 pindex->nStatus = pindex->nStatus.withData(
false).withUndo(
false);
106 pindex->nDataPos = 0;
107 pindex->nUndoPos = 0;
115 while (range.first != range.second) {
116 std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it =
119 if (_it->second == pindex) {
131 int nManualPruneHeight,
143 const auto [min_block_to_prune, last_block_can_prune] =
144 chainman.GetPruneRange(chain, nManualPruneHeight);
149 if (fileinfo.nSize == 0 ||
150 fileinfo.nHeightLast > (
unsigned)last_block_can_prune ||
151 fileinfo.nHeightFirst < (unsigned)min_block_to_prune) {
156 setFilesToPrune.insert(fileNumber);
159 LogPrintf(
"[%s] Prune (Manual): prune_height=%d removed %d blk/rev pairs\n",
160 chain.GetRole(), last_block_can_prune,
count);
179 const auto [min_block_to_prune, last_block_can_prune] =
180 chainman.GetPruneRange(chain, last_prune);
187 uint64_t nBytesToPrune;
190 if (nCurrentUsage + nBuffer >= target) {
198 nBuffer += target / 10;
204 nBytesToPrune = fileinfo.nSize + fileinfo.nUndoSize;
206 if (fileinfo.nSize == 0) {
210 if (nCurrentUsage + nBuffer < target) {
216 if (fileinfo.nHeightLast > (
unsigned)last_block_can_prune ||
217 fileinfo.nHeightFirst < (unsigned)min_block_to_prune) {
223 setFilesToPrune.insert(fileNumber);
224 nCurrentUsage -= nBytesToPrune;
230 "[%s] target=%dMiB actual=%dMiB diff=%dMiB min_height=%d "
231 "max_prune_height=%d removed %d blk/rev pairs\n",
232 chain.GetRole(), target / 1024 / 1024, nCurrentUsage / 1024 / 1024,
233 (int64_t(target) - int64_t(nCurrentUsage)) / 1024 / 1024,
234 min_block_to_prune, last_block_can_prune,
count);
237void BlockManager::UpdatePruneLock(
const std::string &
name,
240 m_prune_locks[
name] = lock_info;
250 const auto [mi, inserted] = m_block_index.try_emplace(hash);
259 const std::optional<BlockHash> &snapshot_blockhash) {
261 if (!m_block_tree_db->LoadBlockIndexGuts(
270 if (snapshot_blockhash) {
281 snapshot_blockhash->ToString());
293 std::vector<CBlockIndex *> vSortedByHeight{GetAllBlockIndices()};
294 std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
302 if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
303 LogError(
"%s: block index is non-contiguous, index of height %d "
305 __func__, previous_index->nHeight + 1);
308 previous_index = pindex;
310 pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) +
313 (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime)
320 if (pindex->nTx > 0) {
321 const unsigned int prevNChainTx =
322 pindex->pprev ? pindex->pprev->nChainTx : 0;
324 pindex->GetBlockHash() == *snapshot_blockhash) {
326 Assert(pindex->nChainTx > 0);
327 }
else if (prevNChainTx == 0 && pindex->pprev) {
328 pindex->nChainTx = 0;
331 pindex->nChainTx = prevNChainTx + pindex->nTx;
335 if (!pindex->nStatus.hasFailed() && pindex->pprev &&
336 pindex->pprev->nStatus.hasFailed()) {
337 pindex->nStatus = pindex->nStatus.withFailedParent();
349bool BlockManager::WriteBlockIndexDB() {
350 std::vector<std::pair<int, const CBlockFileInfo *>> vFiles;
358 std::vector<const CBlockIndex *> vBlocks;
361 vBlocks.push_back(cbi);
368 if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) {
374bool BlockManager::LoadBlockIndexDB(
375 const std::optional<BlockHash> &snapshot_blockhash) {
379 int max_blockfile_num{0};
382 m_block_tree_db->ReadLastBlockFile(max_blockfile_num);
384 LogPrintf(
"%s: last block file = %i\n", __func__, max_blockfile_num);
385 for (
int nFile = 0; nFile <= max_blockfile_num; nFile++) {
388 LogPrintf(
"%s: last block file info: %s\n", __func__,
390 for (
int nFile = max_blockfile_num + 1;
true; nFile++) {
392 if (m_block_tree_db->ReadBlockFileInfo(nFile, info)) {
400 LogPrintf(
"Checking all blk files are present...\n");
401 std::set<int> setBlkDataFiles;
402 for (
const auto &[
_, block_index] : m_block_index) {
403 if (block_index.nStatus.hasData()) {
404 setBlkDataFiles.insert(block_index.nFile);
408 for (
const int i : setBlkDataFiles) {
422 static_cast<int>(i), 0};
427 m_block_tree_db->ReadFlag(
"prunedblockfiles",
m_have_pruned);
430 "LoadBlockIndexDB(): Block files have previously been pruned\n");
434 if (m_block_tree_db->IsReindexing()) {
441void BlockManager::ScanAndUnlinkAlreadyPrunedFiles() {
449 std::set<int> block_files_to_prune;
450 for (
int file_number = 0; file_number < max_blockfile; file_number++) {
452 block_files_to_prune.insert(file_number);
463 for (
const MapCheckpoints::value_type &i :
reverse_iterate(checkpoints)) {
474bool BlockManager::IsBlockPruned(
const CBlockIndex &block)
const {
480BlockManager::GetFirstBlock(
const CBlockIndex &upper_block,
486 assert(status_test(last_block->nStatus));
487 while (last_block->
pprev && status_test(last_block->
pprev->nStatus)) {
490 if (last_block == lower_block) {
497 last_block = last_block->
pprev;
499 assert(last_block !=
nullptr);
503bool BlockManager::CheckBlockDataAvailability(
const CBlockIndex &upper_block,
505 if (!(upper_block.nStatus.hasData())) {
508 return GetFirstBlock(
511 &lower_block) == &lower_block;
522 std::map<std::string, fs::path> mapBlockFiles;
527 LogPrintf(
"Removing unusable blk?????.dat and rev?????.dat files for "
528 "-reindex with -prune\n");
531 if (fs::is_regular_file(file) && path.length() == 12 &&
532 path.substr(8, 4) ==
".dat") {
533 if (path.substr(0, 3) ==
"blk") {
534 mapBlockFiles[path.substr(3, 5)] = file.path();
535 }
else if (path.substr(0, 3) ==
"rev") {
545 int contiguousCounter = 0;
546 for (
const auto &item : mapBlockFiles) {
547 if (LocaleIndependentAtoi<int>(item.first) == contiguousCounter) {
567 LogError(
"%s: OpenUndoFile failed\n", __func__);
573 fileout << messageStart << nSize;
576 long fileOutPos = ftell(fileout.
Get());
577 if (fileOutPos < 0) {
578 LogError(
"%s: ftell failed\n", __func__);
581 pos.
nPos = (
unsigned int)fileOutPos;
582 fileout << blockundo;
588 fileout << hasher.GetHash();
598 LogError(
"%s: no undo data available\n", __func__);
605 LogError(
"%s: OpenUndoFile failed\n", __func__);
615 verifier >> blockundo;
616 filein >> hashChecksum;
617 }
catch (
const std::exception &e) {
618 LogError(
"%s: Deserialize or I/O error - %s\n", __func__, e.what());
623 if (hashChecksum != verifier.
GetHash()) {
624 LogError(
"%s: Checksum mismatch\n", __func__);
634 if (!
UndoFileSeq().Flush(undo_pos_old, finalize)) {
636 "Flushing undo file to disk failed. This is likely the "
637 "result of an I/O error.");
644 bool finalize_undo) {
662 "Flushing block file to disk failed. This is likely the "
663 "result of an I/O error.");
669 if (!fFinalize || finalize_undo) {
679 return BlockfileType::NORMAL;
682 : BlockfileType::NORMAL;
704 retval += file.nSize + file.nUndoSize;
711 const std::set<int> &setFilesToPrune)
const {
712 std::error_code error_code;
713 for (
const int i : setFilesToPrune) {
715 const bool removed_blockfile{
717 const bool removed_undofile{
718 fs::remove(
UndoFileSeq().FileName(pos), error_code)};
719 if (removed_blockfile || removed_undofile) {
737 bool fReadOnly)
const {
757 if (!m_blockfile_cursors[chain_type]) {
762 m_blockfile_cursors[chain_type] = new_cursor;
764 "[%s] initializing blockfile cursor to %s\n", chain_type,
767 const int last_blockfile = m_blockfile_cursors[chain_type]->file_num;
769 int nFile = last_blockfile;
774 bool finalize_undo =
false;
779 max_blockfile_size = 0x10000;
780 if (nAddSize >= max_blockfile_size) {
783 max_blockfile_size = nAddSize + 1;
789 assert(nAddSize < max_blockfile_size);
798 Assert(m_blockfile_cursors[chain_type])->undo_height);
813 if (nFile != last_blockfile) {
815 "Leaving block file %i: %s (onto %i) (height %i)\n",
830 "Failed to flush previous block file %05i (finalize=1, "
831 "finalize_undo=%i) before opening new block file %05i\n",
832 last_blockfile, finalize_undo, nFile);
842 size_t bytes_allocated =
846 _(
"Disk space is too low!"));
863 auto &cursor{m_blockfile_cursors[chain_type]};
864 if (!cursor || cursor->file_num < pos.
nFile) {
870 const int nFile = pos.
nFile;
891 size_t bytes_allocated =
895 _(
"Disk space is too low!"));
910 LogError(
"WriteBlockToDisk: OpenBlockFile failed\n");
916 fileout << messageStart << nSize;
919 long fileOutPos = ftell(fileout.
Get());
920 if (fileOutPos < 0) {
921 LogError(
"WriteBlockToDisk: ftell failed\n");
925 pos.
nPos = (
unsigned int)fileOutPos;
931bool BlockManager::WriteUndoDataForBlock(
const CBlockUndo &blockundo,
944 LogError(
"ConnectBlock(): FindUndoPos failed\n");
950 "Failed to write undo data");
959 if (_pos.
nFile < cursor.file_num &&
960 static_cast<uint32_t
>(block.
nHeight) ==
969 "Failed to flush undo file %05i\n", _pos.
nFile);
971 }
else if (_pos.
nFile == cursor.file_num &&
972 block.
nHeight > cursor.undo_height) {
973 cursor.undo_height = block.
nHeight;
976 block.nUndoPos = _pos.
nPos;
977 block.nStatus = block.nStatus.withUndo();
991 LogError(
"ReadBlockFromDisk: OpenBlockFile failed for %s\n",
999 }
catch (
const std::exception &e) {
1000 LogError(
"%s: Deserialize or I/O error - %s at %s\n", __func__,
1007 LogError(
"ReadBlockFromDisk: Errors in block header at %s\n",
1024 LogError(
"ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() "
1025 "doesn't match index for %s at %s\n",
1026 index.
ToString(), block_pos.ToString());
1038 if (hpos.
nPos < 8) {
1044 if (filein.IsNull()) {
1051 unsigned int blk_size;
1053 filein >> blk_start >> blk_size;
1055 if (blk_start !=
GetParams().DiskMagic()) {
1056 LogError(
"%s: Block magic mismatch for %s: %s versus expected %s\n",
1063 LogError(
"%s: Block data is larger than maximum deserialization "
1064 "size for %s: %s versus %s\n",
1070 block.resize(blk_size);
1072 }
catch (
const std::exception &e) {
1073 LogError(
"%s: Read from block file failed: %s for %s\n", __func__,
1086 LogError(
"ReadTxFromDisk: OpenBlockFile failed for %s\n",
1094 }
catch (
const std::exception &e) {
1095 LogError(
"%s: Deserialize or I/O error - %s at %s\n", __func__,
1108 LogError(
"ReadTxUndoFromDisk: OpenUndoFile failed for %s\n",
1116 }
catch (
const std::exception &e) {
1117 LogError(
"%s: Deserialize or I/O error - %s at %s\n", __func__,
1132 if (blockPos.IsNull()) {
1133 LogError(
"%s: FindNextBlockPos failed\n", __func__);
1159 std::vector<fs::path> vImportFiles) {
1171 std::multimap<BlockHash, FlatFilePos> blocks_with_unknown_parent;
1183 LogPrintf(
"Reindexing block file blk%05u.dat...\n",
1184 (
unsigned int)nFile);
1186 file, &pos, &blocks_with_unknown_parent,
avalanche);
1188 LogPrintf(
"Interrupt requested. Exit %s\n", __func__);
1195 chainman.
m_blockman.m_block_tree_db->WriteReindexing(
false));
1204 for (
const fs::path &path : vImportFiles) {
1207 LogPrintf(
"Importing blocks file %s...\n",
1213 LogPrintf(
"Interrupt requested. Exit %s\n", __func__);
1217 LogPrintf(
"Warning: Could not open blocks file %s\n",
1227 for (
const MapCheckpoints::value_type &i : checkpoints) {
1233 if (pblockindex && !pblockindex->nStatus.isValid()) {
1234 LogPrintf(
"Reconsidering checkpointed block %s ...\n",
1239 if (pblockindex && pblockindex->nStatus.isOnParkedChain()) {
1240 LogPrintf(
"Unparking checkpointed block %s ...\n",
1256 if (!chainstate->ActivateBestChain(state,
nullptr,
avalanche)) {
1258 "Failed to connect best block (%s)", state.
ToString()));
1264 LogPrintf(
"Stopping after block import\n");
1273 case BlockfileType::NORMAL:
1280 os.setstate(std::ios_base::failbit);
1286 os <<
strprintf(
"BlockfileCursor(file_num=%d, undo_height=%d)",
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
@ TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
arith_uint256 GetBlockProof(const CBlockIndex &block)
#define Assert(val)
Identity function.
Non-refcounted RAII wrapper for FILE*.
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
std::FILE * Get() const
Get wrapped FILE* without transfer of ownership.
The block chain is a tree shaped structure starting with the genesis block at the root,...
std::string ToString() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
const BlockHash * phashBlock
pointer to the hash of the block, if any.
unsigned int nTimeMax
(memory only) Maximum nTime in the chain up to and including this block.
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(
unsigned int nTx
Number of transactions in this block.
bool RaiseValidity(enum BlockValidity nUpTo) EXCLUSIVE_LOCKS_REQUIRED(
Raise the validity level of this block index entry.
int64_t nTimeReceived
(memory only) block header metadata
BlockHash GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
Undo information for a CBlock.
int Height() const
Return the maximal height in the chain.
uint64_t PruneAfterHeight() const
const CCheckpointData & Checkpoints() const
Reads data from an underlying stream, while hashing the read data.
A mutable version of CTransaction.
Restore the UTXO in a Coin at a given COutPoint.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
CChain m_chain
The current chain of blockheaders we consult and build on.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(Chainstate ActiveChainstate)() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
kernel::Notifications & GetNotifications() const
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
void LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp=nullptr, std::multimap< BlockHash, FlatFilePos > *blocks_with_unknown_parent=nullptr, avalanche::Processor *const avalanche=nullptr)
Import blocks from an external file.
const util::SignalInterrupt & m_interrupt
const CChainParams & GetParams() const
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
FlatFileSeq represents a sequence of numbered files storing raw data.
fs::path FileName(const FlatFilePos &pos) const
Get the name of the file at the given position.
size_t Allocate(const FlatFilePos &pos, size_t add_size, bool &out_of_space)
Allocate additional space in a file after the given starting position.
FILE * Open(const FlatFilePos &pos, bool read_only=false)
Open a handle to the file at the given position.
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetHash()
Compute the double-SHA256 hash of all data written to this object.
std::string ToString() const
std::string GetHex() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
virtual void flushError(const std::string &debug_message)
The flush error notification is sent to notify the user that an error occurred while flushing block d...
virtual void fatalError(const std::string &debug_message, const bilingual_str &user_message={})
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
const kernel::BlockManagerOpts m_opts
std::set< int > m_dirty_fileinfo
Dirty block file entries.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
bool WriteBlockToDisk(const CBlock &block, FlatFilePos &pos, const CMessageHeader::MessageMagic &messageStart) const
Write a block to disk.
FlatFileSeq UndoFileSeq() const
RecursiveMutex cs_LastBlockFile
const CChainParams & GetParams() const
bool CheckBlockDataAvailability(const CBlockIndex &upper_block LIFETIMEBOUND, const CBlockIndex &lower_block LIFETIMEBOUND) EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetFirstBlock(const CBlockIndex &upper_block LIFETIMEBOUND, std::function< bool(BlockStatus)> status_test, const CBlockIndex *lower_block=nullptr) const EXCLUSIVE_LOCKS_REQUIRED(boo m_have_pruned)
Check if all blocks in the [upper_block, lower_block] range have data available.
bool FlushChainstateBlockFile(int tip_height)
void FindFilesToPrune(std::set< int > &setFilesToPrune, int last_prune, const Chainstate &chain, ChainstateManager &chainman)
Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a us...
void UpdateBlockInfo(const CBlock &block, unsigned int nHeight, const FlatFilePos &pos)
Update blockfile info while processing a block during reindex.
FlatFileSeq BlockFileSeq() const
FILE * OpenUndoFile(const FlatFilePos &pos, bool fReadOnly=false) const
Open an undo file (rev?????.dat)
bool StopAfterBlockImport() const
bool LoadBlockIndex(const std::optional< BlockHash > &snapshot_blockhash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the blocktree off disk and into memory.
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
BlockfileType BlockfileTypeForHeight(int height)
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool IsBlockPruned(const CBlockIndex &block) const EXCLUSIVE_LOCKS_REQUIRED(void UpdatePruneLock(const std::string &name, const PruneLockInfo &lock_info) EXCLUSIVE_LOCKS_REQUIRED(FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false) const
Check whether the block associated with this index entry is pruned or not.
bool ReadTxFromDisk(CMutableTransaction &tx, const FlatFilePos &pos) const
Functions for disk access for txs.
const Consensus::Params & GetConsensus() const
bool ReadRawBlockFromDisk(std::vector< uint8_t > &block, const FlatFilePos &pos) const
CBlockIndex * InsertBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
bool ReadTxUndoFromDisk(CTxUndo &tx, const FlatFilePos &pos) const
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex &index) const
fs::path GetBlockPosFilename(const FlatFilePos &pos) const
Translation to a filesystem path.
bool FlushBlockFile(int blockfile_num, bool fFinalize, bool finalize_undo)
Return false if block file or undo file flushing fails.
uint64_t GetPruneTarget() const
Attempt to stay below this number of bytes of block files.
int MaxBlockfileNum() const EXCLUSIVE_LOCKS_REQUIRED(cs_LastBlockFile)
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune) const
Actually unlink the specified files.
bool WriteUndoDataForBlock(const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex &block) EXCLUSIVE_LOCKS_REQUIRED(FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight)
Store block on disk and update block file statistics.
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(bool LoadBlockIndexDB(const std::optional< BlockHash > &snapshot_blockhash) EXCLUSIVE_LOCKS_REQUIRED(void ScanAndUnlinkAlreadyPrunedFiles() EXCLUSIVE_LOCKS_REQUIRED(CBlockIndex * AddToBlockIndex(const CBlockHeader &block, CBlockIndex *&best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove any pruned block & undo files that are still on disk.
FlatFilePos FindNextBlockPos(unsigned int nAddSize, unsigned int nHeight, uint64_t nTime)
Helper function performing various preparations before a block can be saved to disk: Returns the corr...
bool FlushUndoFile(int block_file, bool finalize=false)
Return false if undo file flushing fails.
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
const util::SignalInterrupt & m_interrupt
bool UndoWriteToDisk(const CBlockUndo &blockundo, FlatFilePos &pos, const BlockHash &hashBlock, const CMessageHeader::MessageMagic &messageStart) const
const CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
std::set< CBlockIndex * > m_dirty_blockindex
Dirty block index entries.
bool m_check_for_pruning
Global flag to indicate we should check to see if there are block/undo files that should be deleted.
bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize)
bool IsPruneMode() const
Whether running in -prune mode.
void CleanupBlockRevFiles() const
void FindFilesToPruneManual(std::set< int > &setFilesToPrune, int nManualPruneHeight, const Chainstate &chain, ChainstateManager &chainman)
Calculate the block/rev files to delete based on height specified by user with RPC command pruneblock...
std::atomic< bool > m_importing
std::vector< CBlockFileInfo > m_blockfile_info
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
std::optional< int > m_snapshot_height
The height of the base block of an assumeutxo snapshot, if one is in use.
std::vector< CBlockIndex * > GetAllBlockIndices() EXCLUSIVE_LOCKS_REQUIRED(std::multimap< CBlockIndex *, CBlockIndex * > m_blocks_unlinked
All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
ImportingNow(std::atomic< bool > &importing)
std::atomic< bool > & m_importing
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
std::map< int, BlockHash > MapCheckpoints
#define LogPrintLevel(category, level,...)
#define LogPrint(category,...)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
FILE * fopen(const fs::path &p, const char *mode)
static const unsigned int UNDOFILE_CHUNK_SIZE
The pre-allocation chunk size for rev?????.dat files (since 0.8)
std::ostream & operator<<(std::ostream &os, const BlockfileType &type)
static constexpr unsigned int BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE
Size of header written by WriteBlockToDisk before a serialized CBlock.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
std::atomic_bool fReindex
void ImportBlocks(ChainstateManager &chainman, avalanche::Processor *const avalanche, std::vector< fs::path > vImportFiles)
bool CheckProofOfWork(const BlockHash &hash, uint32_t nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
reverse_range< T > reverse_iterate(T &x)
static constexpr uint64_t MAX_SIZE
The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size...
size_t GetSerializeSize(const T &t, int nVersion=0)
void StartShutdown()
Request shutdown of the application.
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Holds configuration for use during UTXO snapshot load and validation.
unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
A BlockHash is a unqiue identifier for a block.
MapCheckpoints mapCheckpoints
std::string ToString() const
Notifications & notifications
const fs::path blocks_dir
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
bilingual_str _(const char *psz)
Translation function.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool FatalError(Notifications ¬ifications, BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage)
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev?...