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(
269 if (snapshot_blockhash) {
280 snapshot_blockhash->ToString());
292 std::vector<CBlockIndex *> vSortedByHeight{GetAllBlockIndices()};
293 std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
300 pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) +
303 (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime)
310 if (pindex->nTx > 0) {
312 pindex->GetBlockHash() == *snapshot_blockhash) {
315 Assert(pindex->nChainTx > 0);
316 }
else if (!pindex->UpdateChainStats() && pindex->pprev) {
318 pindex->ResetChainStats();
322 if (!pindex->nStatus.hasFailed() && pindex->pprev &&
323 pindex->pprev->nStatus.hasFailed()) {
324 pindex->nStatus = pindex->nStatus.withFailedParent();
336bool BlockManager::WriteBlockIndexDB() {
337 std::vector<std::pair<int, const CBlockFileInfo *>> vFiles;
345 std::vector<const CBlockIndex *> vBlocks;
348 vBlocks.push_back(cbi);
355 if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) {
361bool BlockManager::LoadBlockIndexDB(
362 const std::optional<BlockHash> &snapshot_blockhash) {
366 int max_blockfile_num{0};
369 m_block_tree_db->ReadLastBlockFile(max_blockfile_num);
371 LogPrintf(
"%s: last block file = %i\n", __func__, max_blockfile_num);
372 for (
int nFile = 0; nFile <= max_blockfile_num; nFile++) {
375 LogPrintf(
"%s: last block file info: %s\n", __func__,
377 for (
int nFile = max_blockfile_num + 1;
true; nFile++) {
379 if (m_block_tree_db->ReadBlockFileInfo(nFile, info)) {
387 LogPrintf(
"Checking all blk files are present...\n");
388 std::set<int> setBlkDataFiles;
389 for (
const auto &[
_, block_index] : m_block_index) {
390 if (block_index.nStatus.hasData()) {
391 setBlkDataFiles.insert(block_index.nFile);
395 for (
const int i : setBlkDataFiles) {
409 static_cast<int>(i), 0};
414 m_block_tree_db->ReadFlag(
"prunedblockfiles",
m_have_pruned);
417 "LoadBlockIndexDB(): Block files have previously been pruned\n");
421 if (m_block_tree_db->IsReindexing()) {
428void BlockManager::ScanAndUnlinkAlreadyPrunedFiles() {
436 std::set<int> block_files_to_prune;
437 for (
int file_number = 0; file_number < max_blockfile; file_number++) {
439 block_files_to_prune.insert(file_number);
450 for (
const MapCheckpoints::value_type &i :
reverse_iterate(checkpoints)) {
461bool BlockManager::IsBlockPruned(
const CBlockIndex *pblockindex) {
464 pblockindex->
nTx > 0);
468BlockManager::GetFirstStoredBlock(
const CBlockIndex &upper_block,
473 assert(last_block->nStatus.hasData());
474 while (last_block->
pprev && (last_block->
pprev->nStatus.hasData())) {
477 if (last_block == lower_block) {
484 last_block = last_block->
pprev;
486 assert(last_block !=
nullptr);
490bool BlockManager::CheckBlockDataAvailability(
const CBlockIndex &upper_block,
492 if (!(upper_block.nStatus.hasData())) {
495 return GetFirstStoredBlock(upper_block, &lower_block) == &lower_block;
506 std::map<std::string, fs::path> mapBlockFiles;
511 LogPrintf(
"Removing unusable blk?????.dat and rev?????.dat files for "
512 "-reindex with -prune\n");
515 if (fs::is_regular_file(file) && path.length() == 12 &&
516 path.substr(8, 4) ==
".dat") {
517 if (path.substr(0, 3) ==
"blk") {
518 mapBlockFiles[path.substr(3, 5)] = file.path();
519 }
else if (path.substr(0, 3) ==
"rev") {
529 int contiguousCounter = 0;
530 for (
const auto &item : mapBlockFiles) {
531 if (
atoi(item.first) == contiguousCounter) {
551 return error(
"%s: OpenUndoFile failed", __func__);
556 fileout << messageStart << nSize;
559 long fileOutPos = ftell(fileout.
Get());
560 if (fileOutPos < 0) {
561 return error(
"%s: ftell failed", __func__);
563 pos.
nPos = (
unsigned int)fileOutPos;
564 fileout << blockundo;
570 fileout << hasher.GetHash();
580 return error(
"%s: no undo data available", __func__);
586 return error(
"%s: OpenUndoFile failed", __func__);
595 verifier >> blockundo;
596 filein >> hashChecksum;
597 }
catch (
const std::exception &e) {
598 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
602 if (hashChecksum != verifier.
GetHash()) {
603 return error(
"%s: Checksum mismatch", __func__);
612 if (!
UndoFileSeq().Flush(undo_pos_old, finalize)) {
614 "Flushing undo file to disk failed. This is likely the "
615 "result of an I/O error.");
621 bool finalize_undo) {
638 AbortNode(
"Flushing block file to disk failed. This is likely the "
639 "result of an I/O error.");
645 if (!fFinalize || finalize_undo) {
655 return BlockfileType::NORMAL;
658 : BlockfileType::NORMAL;
680 retval += file.nSize + file.nUndoSize;
687 const std::set<int> &setFilesToPrune)
const {
688 std::error_code error_code;
689 for (
const int i : setFilesToPrune) {
691 const bool removed_blockfile{
693 const bool removed_undofile{
694 fs::remove(
UndoFileSeq().FileName(pos), error_code)};
695 if (removed_blockfile || removed_undofile) {
713 bool fReadOnly)
const {
727 unsigned int nHeight, uint64_t nTime,
733 if (!m_blockfile_cursors[chain_type]) {
738 m_blockfile_cursors[chain_type] = new_cursor;
740 "[%s] initializing blockfile cursor to %s\n", chain_type,
743 const int last_blockfile = m_blockfile_cursors[chain_type]->file_num;
745 int nFile = fKnown ? pos.
nFile : last_blockfile;
750 bool finalize_undo =
false;
756 max_blockfile_size = 0x10000;
757 if (nAddSize >= max_blockfile_size) {
760 max_blockfile_size = nAddSize + 1;
766 assert(nAddSize < max_blockfile_size);
775 Assert(m_blockfile_cursors[chain_type])->undo_height);
790 if (nFile != last_blockfile) {
793 "Leaving block file %i: %s (onto %i) (height %i)\n",
809 "Failed to flush previous block file %05i (finalize=%i, "
810 "finalize_undo=%i) before opening new block file %05i\n",
811 last_blockfile, !fKnown, finalize_undo, nFile);
827 size_t bytes_allocated =
830 return AbortNode(
"Disk space is too low!",
831 _(
"Disk space is too low!"));
853 size_t bytes_allocated =
856 return AbortNode(state,
"Disk space is too low!",
857 _(
"Disk space is too low!"));
872 return error(
"WriteBlockToDisk: OpenBlockFile failed");
877 fileout << messageStart << nSize;
880 long fileOutPos = ftell(fileout.
Get());
881 if (fileOutPos < 0) {
882 return error(
"WriteBlockToDisk: ftell failed");
885 pos.
nPos = (
unsigned int)fileOutPos;
891bool BlockManager::WriteUndoDataForBlock(
const CBlockUndo &blockundo,
904 return error(
"ConnectBlock(): FindUndoPos failed");
908 return AbortNode(state,
"Failed to write undo data");
917 if (_pos.
nFile < cursor.file_num &&
918 static_cast<uint32_t
>(block.
nHeight) ==
927 "Failed to flush undo file %05i\n", _pos.
nFile);
929 }
else if (_pos.
nFile == cursor.file_num &&
930 block.
nHeight > cursor.undo_height) {
931 cursor.undo_height = block.
nHeight;
934 block.nUndoPos = _pos.
nPos;
935 block.nStatus = block.nStatus.withUndo();
949 return error(
"ReadBlockFromDisk: OpenBlockFile failed for %s",
956 }
catch (
const std::exception &e) {
957 return error(
"%s: Deserialize or I/O error - %s at %s", __func__,
963 return error(
"ReadBlockFromDisk: Errors in block header at %s",
979 return error(
"ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() "
980 "doesn't match index for %s at %s",
981 index.
ToString(), block_pos.ToString());
992 return error(
"ReadTxFromDisk: OpenBlockFile failed for %s",
999 }
catch (
const std::exception &e) {
1000 return error(
"%s: Deserialize or I/O error - %s at %s", __func__,
1012 return error(
"ReadTxUndoFromDisk: OpenUndoFile failed for %s",
1019 }
catch (
const std::exception &e) {
1020 return error(
"%s: Deserialize or I/O error - %s at %s", __func__,
1031 const auto position_known{dbp !=
nullptr};
1032 if (position_known) {
1046 error(
"%s: FindBlockPos failed", __func__);
1049 if (!position_known) {
1074 std::vector<fs::path> vImportFiles) {
1086 std::multimap<BlockHash, FlatFilePos> blocks_with_unknown_parent;
1098 LogPrintf(
"Reindexing block file blk%05u.dat...\n",
1099 (
unsigned int)nFile);
1101 file, &pos, &blocks_with_unknown_parent,
avalanche);
1103 LogPrintf(
"Shutdown requested. Exit %s\n", __func__);
1110 chainman.
m_blockman.m_block_tree_db->WriteReindexing(
false));
1119 for (
const fs::path &path : vImportFiles) {
1122 LogPrintf(
"Importing blocks file %s...\n",
1128 LogPrintf(
"Shutdown requested. Exit %s\n", __func__);
1132 LogPrintf(
"Warning: Could not open blocks file %s\n",
1142 for (
const MapCheckpoints::value_type &i : checkpoints) {
1148 if (pblockindex && !pblockindex->nStatus.isValid()) {
1149 LogPrintf(
"Reconsidering checkpointed block %s ...\n",
1154 if (pblockindex && pblockindex->nStatus.isOnParkedChain()) {
1155 LogPrintf(
"Unparking checkpointed block %s ...\n",
1171 if (!chainstate->ActivateBestChain(state,
nullptr,
avalanche)) {
1172 LogPrintf(
"Failed to connect best block (%s)\n",
1180 LogPrintf(
"Stopping after block import\n");
1189 case BlockfileType::NORMAL:
1196 os.setstate(std::ios_base::failbit);
1202 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.
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
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(std::function< void(bilingual_str)> shutdown_fnc=[](bilingual_str msg) { AbortNode(msg.original, msg);}) 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...
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 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:...
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
FlatFileSeq UndoFileSeq() const
RecursiveMutex cs_LastBlockFile
bool CheckBlockDataAvailability(const CBlockIndex &upper_block LIFETIMEBOUND, const CBlockIndex &lower_block LIFETIMEBOUND) EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetFirstStoredBlock(const CBlockIndex &start_block LIFETIMEBOUND, const CBlockIndex *lower_block=nullptr) EXCLUSIVE_LOCKS_REQUIRED(boo m_have_pruned)
Check if all blocks in the [upper_block, lower_block] range have data available.
const CChainParams & GetParams() const
bool WriteUndoDataForBlock(const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex &block) EXCLUSIVE_LOCKS_REQUIRED(FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight, const FlatFilePos *dbp)
Store block on disk.
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...
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 ReadTxFromDisk(CMutableTransaction &tx, const FlatFilePos &pos) const
Functions for disk access for txs.
const Consensus::Params & GetConsensus() 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 FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown)
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 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.
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.
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.
bool IsBlockPruned(const CBlockIndex *pblockindex) 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.
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
bool error(const char *fmt, const Args &...args)
#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)
size_t GetSerializeSize(const T &t, int nVersion=0)
bool AbortNode(const std::string &strMessage, bilingual_str user_message)
Abort with a message.
bool ShutdownRequested()
Returns true if a shutdown is requested, false otherwise.
void StartShutdown()
Request shutdown of the application.
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
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.
int atoi(const std::string &str)
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?...