31 #include <unordered_map> 68 bool BlockTreeDB::WriteBatchSync(
const std::vector<std::pair<int, const CBlockFileInfo*>>& fileInfo,
int nLastFile,
const std::vector<const CBlockIndex*>& blockinfo)
71 for (
const auto& [file, info] : fileInfo) {
83 return Write(std::make_pair(
DB_FLAG,
name), fValue ? uint8_t{
'1'} : uint8_t{
'0'});
92 fValue = ch == uint8_t{
'1'};
99 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
103 while (pcursor->Valid()) {
104 if (interrupt)
return false;
105 std::pair<uint8_t, uint256> key;
108 if (pcursor->GetValue(diskindex)) {
113 pindexNew->nFile = diskindex.nFile;
114 pindexNew->nDataPos = diskindex.nDataPos;
115 pindexNew->nUndoPos = diskindex.nUndoPos;
121 pindexNew->nStatus = diskindex.nStatus;
122 pindexNew->
nTx = diskindex.
nTx;
125 return error(
"%s: CheckProofOfWork failed: %s", __func__, pindexNew->
ToString());
130 return error(
"%s: failed to read value", __func__);
156 if (pa < pb)
return false;
157 if (pa > pb)
return true;
168 std::vector<CBlockIndex*> BlockManager::GetAllBlockIndices()
171 std::vector<CBlockIndex*> rv;
172 rv.reserve(m_block_index.size());
173 for (
auto& [
_, block_index] : m_block_index) {
174 rv.push_back(&block_index);
182 BlockMap::iterator it = m_block_index.find(hash);
183 return it == m_block_index.end() ? nullptr : &it->second;
189 BlockMap::const_iterator it = m_block_index.find(hash);
190 return it == m_block_index.end() ? nullptr : &it->second;
197 auto [mi, inserted] = m_block_index.try_emplace(block.
GetHash(), block);
209 BlockMap::iterator miPrev = m_block_index.find(block.
hashPrevBlock);
210 if (miPrev != m_block_index.end()) {
211 pindexNew->
pprev = &(*miPrev).second;
219 best_header = pindexNew;
232 for (
auto& entry : m_block_index) {
234 if (pindex->nFile == fileNumber) {
238 pindex->nDataPos = 0;
239 pindex->nUndoPos = 0;
247 while (range.first != range.second) {
248 std::multimap<CBlockIndex*, CBlockIndex*>::iterator _it = range.first;
250 if (_it->second == pindex) {
262 std::set<int>& setFilesToPrune,
263 int nManualPruneHeight,
274 const auto [min_block_to_prune, last_block_can_prune] = chainman.GetPruneRange(chain, nManualPruneHeight);
277 for (
int fileNumber = 0; fileNumber < this->
MaxBlockfileNum(); fileNumber++) {
279 if (fileinfo.nSize == 0 || fileinfo.nHeightLast > (
unsigned)last_block_can_prune || fileinfo.nHeightFirst < (unsigned)min_block_to_prune) {
284 setFilesToPrune.insert(fileNumber);
287 LogPrintf(
"[%s] Prune (Manual): prune_height=%d removed %d blk/rev pairs\n",
288 chain.GetRole(), last_block_can_prune,
count);
292 std::set<int>& setFilesToPrune,
299 const auto target = std::max(
309 const auto [min_block_to_prune, last_block_can_prune] = chainman.GetPruneRange(chain, last_prune);
316 uint64_t nBytesToPrune;
319 if (nCurrentUsage + nBuffer >= target) {
326 nBuffer += target / 10;
329 for (
int fileNumber = 0; fileNumber < this->
MaxBlockfileNum(); fileNumber++) {
331 nBytesToPrune = fileinfo.nSize + fileinfo.nUndoSize;
333 if (fileinfo.nSize == 0) {
337 if (nCurrentUsage + nBuffer < target) {
343 if (fileinfo.nHeightLast > (
unsigned)last_block_can_prune || fileinfo.nHeightFirst < (unsigned)min_block_to_prune) {
349 setFilesToPrune.insert(fileNumber);
350 nCurrentUsage -= nBytesToPrune;
355 LogPrint(
BCLog::PRUNE,
"[%s] target=%dMiB actual=%dMiB diff=%dMiB min_height=%d max_prune_height=%d removed %d blk/rev pairs\n",
356 chain.GetRole(), target / 1024 / 1024, nCurrentUsage / 1024 / 1024,
357 (int64_t(target) - int64_t(nCurrentUsage)) / 1024 / 1024,
358 min_block_to_prune, last_block_can_prune,
count);
361 void BlockManager::UpdatePruneLock(
const std::string&
name,
const PruneLockInfo& lock_info) {
363 m_prune_locks[
name] = lock_info;
374 const auto [mi, inserted]{m_block_index.try_emplace(hash)};
384 if (!m_block_tree_db->LoadBlockIndexGuts(
389 if (snapshot_blockhash) {
391 if (!maybe_au_data) {
403 LogPrintf(
"[snapshot] set nChainTx=%d for %s\n", au_data.
nChainTx, snapshot_blockhash->ToString());
414 std::vector<CBlockIndex*> vSortedByHeight{GetAllBlockIndices()};
415 std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
421 if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
422 return error(
"%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1);
424 previous_index = pindex;
425 pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) +
GetBlockProof(*pindex);
426 pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);
432 if (pindex->nTx > 0) {
435 pindex->GetBlockHash() == *snapshot_blockhash) {
437 Assert(pindex->nChainTx > 0);
438 }
else if (pindex->pprev->nChainTx > 0) {
439 pindex->nChainTx = pindex->pprev->nChainTx + pindex->nTx;
441 pindex->nChainTx = 0;
445 pindex->nChainTx = pindex->nTx;
460 bool BlockManager::WriteBlockIndexDB()
463 std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
469 std::vector<const CBlockIndex*> vBlocks;
472 vBlocks.push_back(*it);
476 if (!m_block_tree_db->WriteBatchSync(vFiles, max_blockfile, vBlocks)) {
482 bool BlockManager::LoadBlockIndexDB(
const std::optional<uint256>& snapshot_blockhash)
487 int max_blockfile_num{0};
490 m_block_tree_db->ReadLastBlockFile(max_blockfile_num);
492 LogPrintf(
"%s: last block file = %i\n", __func__, max_blockfile_num);
493 for (
int nFile = 0; nFile <= max_blockfile_num; nFile++) {
497 for (
int nFile = max_blockfile_num + 1;
true; nFile++) {
499 if (m_block_tree_db->ReadBlockFileInfo(nFile, info)) {
507 LogPrintf(
"Checking all blk files are present...\n");
508 std::set<int> setBlkDataFiles;
509 for (
const auto& [
_, block_index] : m_block_index) {
511 setBlkDataFiles.insert(block_index.nFile);
514 for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++) {
531 m_block_tree_db->ReadFlag(
"prunedblockfiles",
m_have_pruned);
533 LogPrintf(
"LoadBlockIndexDB(): Block files have previously been pruned\n");
537 bool fReindexing =
false;
538 m_block_tree_db->ReadReindexing(fReindexing);
544 void BlockManager::ScanAndUnlinkAlreadyPrunedFiles()
552 std::set<int> block_files_to_prune;
553 for (
int file_number = 0; file_number < max_blockfile; file_number++) {
555 block_files_to_prune.insert(file_number);
566 for (
const MapCheckpoints::value_type& i :
reverse_iterate(checkpoints)) {
567 const uint256& hash = i.second;
576 bool BlockManager::IsBlockPruned(
const CBlockIndex* pblockindex)
590 if (last_block == lower_block)
return lower_block;
595 last_block = last_block->
pprev;
597 assert(last_block !=
nullptr);
601 bool BlockManager::CheckBlockDataAvailability(
const CBlockIndex& upper_block,
const CBlockIndex& lower_block)
604 return GetFirstStoredBlock(upper_block, &lower_block) == &lower_block;
615 std::map<std::string, fs::path> mapBlockFiles;
620 LogPrintf(
"Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
621 for (fs::directory_iterator it(
m_opts.
blocks_dir); it != fs::directory_iterator(); it++) {
623 if (fs::is_regular_file(*it) &&
624 path.length() == 12 &&
625 path.substr(8,4) ==
".dat")
627 if (path.substr(0, 3) ==
"blk") {
628 mapBlockFiles[path.substr(3, 5)] = it->path();
629 }
else if (path.substr(0, 3) ==
"rev") {
639 int nContigCounter = 0;
640 for (
const std::pair<const std::string, fs::path>& item : mapBlockFiles) {
641 if (LocaleIndependentAtoi<int>(item.first) == nContigCounter) {
660 if (fileout.IsNull()) {
661 return error(
"%s: OpenUndoFile failed", __func__);
669 long fileOutPos = ftell(fileout.Get());
670 if (fileOutPos < 0) {
671 return error(
"%s: ftell failed", __func__);
673 pos.
nPos = (
unsigned int)fileOutPos;
674 fileout << blockundo;
680 fileout << hasher.GetHash();
690 return error(
"%s: no undo data available", __func__);
695 if (filein.IsNull()) {
696 return error(
"%s: OpenUndoFile failed", __func__);
704 verifier >> blockundo;
705 filein >> hashChecksum;
706 }
catch (
const std::exception& e) {
707 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
711 if (hashChecksum != verifier.GetHash()) {
712 return error(
"%s: Checksum mismatch", __func__);
721 if (!
UndoFileSeq().Flush(undo_pos_old, finalize)) {
749 if (!fFinalize || finalize_undo) {
760 return BlockfileType::NORMAL;
785 retval += file.nSize + file.nUndoSize;
793 for (std::set<int>::iterator it = setFilesToPrune.begin(); it != setFilesToPrune.end(); ++it) {
795 const bool removed_blockfile{fs::remove(
BlockFileSeq().FileName(pos), ec)};
796 const bool removed_undofile{fs::remove(
UndoFileSeq().FileName(pos), ec)};
797 if (removed_blockfile || removed_undofile) {
835 if (!m_blockfile_cursors[chain_type]) {
839 m_blockfile_cursors[chain_type] = new_cursor;
842 const int last_blockfile = m_blockfile_cursors[chain_type]->file_num;
844 int nFile = fKnown ? pos.
nFile : last_blockfile;
849 bool finalize_undo =
false;
855 max_blockfile_size = 0x10000;
856 if (nAddSize >= max_blockfile_size) {
858 max_blockfile_size = nAddSize + 1;
861 assert(nAddSize < max_blockfile_size);
868 Assert(m_blockfile_cursors[chain_type])->undo_height);
883 if (nFile != last_blockfile) {
898 "Failed to flush previous block file %05i (finalize=%i, finalize_undo=%i) before opening new block file %05i\n",
899 last_blockfile, !fKnown, finalize_undo, nFile);
954 if (fileout.IsNull()) {
955 return error(
"WriteBlockToDisk: OpenBlockFile failed");
963 long fileOutPos = ftell(fileout.Get());
964 if (fileOutPos < 0) {
965 return error(
"WriteBlockToDisk: ftell failed");
967 pos.
nPos = (
unsigned int)fileOutPos;
983 return error(
"ConnectBlock(): FindUndoPos failed");
1002 }
else if (_pos.
nFile == cursor.file_num && block.
nHeight > cursor.undo_height) {
1003 cursor.undo_height = block.
nHeight;
1006 block.nUndoPos = _pos.
nPos;
1020 if (filein.IsNull()) {
1021 return error(
"ReadBlockFromDisk: OpenBlockFile failed for %s", pos.
ToString());
1027 }
catch (
const std::exception& e) {
1028 return error(
"%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.
ToString());
1033 return error(
"ReadBlockFromDisk: Errors in block header at %s", pos.
ToString());
1038 return error(
"ReadBlockFromDisk: Errors in block solution at %s", pos.
ToString());
1052 return error(
"ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
1053 index.
ToString(), block_pos.ToString());
1063 if (filein.IsNull()) {
1064 return error(
"%s: OpenBlockFile failed for %s", __func__, pos.
ToString());
1069 unsigned int blk_size;
1071 filein >> blk_start >> blk_size;
1074 return error(
"%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.
ToString(),
1080 return error(
"%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.
ToString(),
1084 block.resize(blk_size);
1086 }
catch (
const std::exception& e) {
1087 return error(
"%s: Read from block file failed: %s for %s", __func__, e.what(), pos.
ToString());
1097 const auto position_known {dbp !=
nullptr};
1098 if (position_known) {
1107 error(
"%s: FindBlockPos failed", __func__);
1110 if (!position_known) {
1148 std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
1155 if (file.IsNull()) {
1158 LogPrintf(
"Reindexing block file blk%05u.dat...\n", (
unsigned int)nFile);
1161 LogPrintf(
"Interrupt requested. Exit %s\n", __func__);
1174 for (
const fs::path& path : vImportFiles) {
1176 if (!file.IsNull()) {
1180 LogPrintf(
"Interrupt requested. Exit %s\n", __func__);
1195 if (!chainstate->ActivateBestChain(state,
nullptr)) {
1205 case BlockfileType::NORMAL: os <<
"normal";
break;
1207 default: os.setstate(std::ios_base::failbit);
bool Exists(const K &key) const
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
std::optional< int > m_snapshot_height
The height of the base block of an assumeutxo snapshot, if one is in use.
std::string ToString() const
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo *>> &fileInfo, int nLastFile, const std::vector< const CBlockIndex *> &blockinfo)
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
std::set< int > m_dirty_fileinfo
Dirty block file entries.
const util::SignalInterrupt & m_interrupt
void ImportBlocks(ChainstateManager &chainman, std::vector< fs::path > vImportFiles)
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 IsPruneMode() const
Whether running in -prune mode.
#define LogPrint(category,...)
FILE * fopen(const fs::path &p, const char *mode)
static constexpr uint8_t DB_FLAG
void CleanupBlockRevFiles() const
descends from failed block
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Batch of changes queued to be written to a CDBWrapper.
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
std::atomic_bool fReindex
static constexpr uint8_t DB_BLOCK_INDEX
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info)
RecursiveMutex cs_LastBlockFile
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
reverse_range< T > reverse_iterate(T &x)
const Consensus::Params & GetConsensus() const
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
void LoadExternalBlockFile(CAutoFile &file_in, FlatFilePos *dbp=nullptr, std::multimap< uint256, FlatFilePos > *blocks_with_unknown_parent=nullptr)
Import blocks from an external file.
bool WriteReindexing(bool fReindexing)
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
int Height() const
Return the maximal height in the chain.
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...
bool FlushBlockFile(int blockfile_num, bool fFinalize, bool finalize_undo)
Return false if block file or undo file flushing fails.
unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
std::atomic< bool > & m_importing
undo data available in rev*.dat
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
bool ReadFlag(const std::string &name, bool &fValue)
CChain m_chain
The current chain of blockheaders we consult and build on.
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune) const
Actually unlink the specified files.
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block. ...
static constexpr uint8_t DB_REINDEX_FLAG
FlatFileSeq BlockFileSeq() const
CAutoFile OpenUndoFile(const FlatFilePos &pos, bool fReadOnly=false) const
Open an undo file (rev?????.dat)
const util::SignalInterrupt & m_interrupt
FILE * Open(const FlatFilePos &pos, bool read_only=false)
Open a handle to the file at the given position.
size_t GetSerializeSize(const T &t, int nVersion=0)
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.
bool ReadLastBlockFile(int &nFile)
bool UndoWriteToDisk(const CBlockUndo &blockundo, FlatFilePos &pos, const uint256 &hashBlock) 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.
std::array< uint8_t, 4 > MessageStartChars
uint256 GetBlockHash() const
void FindFilesToPrune(std::set< int > &setFilesToPrune, int last_prune, const Chainstate &chain, ChainstateManager &chainman)
Prune block and undo files (blk???.dat and rev???.dat) so that the disk space used is less than a use...
void FindFilesToPruneManual(std::set< int > &setFilesToPrune, int nManualPruneHeight, const Chainstate &chain, ChainstateManager &chainman)
int MaxBlockfileNum() const EXCLUSIVE_LOCKS_REQUIRED(cs_LastBlockFile)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
uint64_t PruneAfterHeight() const
static const unsigned int BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(bool LoadBlockIndexDB(const std::optional< uint256 > &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.
unsigned int nTimeMax
(memory only) Maximum nTime in the chain up to and including this block.
static std::string PathToString(const path &path)
Convert path object to a byte string.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE
Size of header written by WriteBlockToDisk before a serialized CBlock.
bool Erase(const K &key, bool fSync=false)
bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize)
std::string ToString() const
bilingual_str _(const char *psz)
Translation function.
FlatFileSeq UndoFileSeq() const
std::optional< AssumeutxoData > AssumeutxoForBlockhash(const uint256 &blockhash) const
A writer stream (for serialization) that computes a 256-bit hash.
ImportingNow(std::atomic< bool > &importing)
kernel::Notifications & GetNotifications() const
const kernel::BlockManagerOpts m_opts
CDBIterator * NewIterator()
BlockfileType BlockfileTypeForHeight(int height)
bool signet_blocks
If true, witness commitments contain a payload equal to a Bitcoin Script solution to the signet chall...
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex &index) const
void Write(const K &key, const V &value)
#define LogPrintLevel(category, level,...)
void BuildSkip()
Build the skiplist pointer for this entry.
Used to marshal pointers into hashes for db storage.
bool LoadBlockIndex(const std::optional< uint256 > &snapshot_blockhash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the blocktree off disk and into memory.
Parameters that influence chain consensus.
bool WriteFlag(const std::string &name, bool fValue)
Notifications & notifications
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool Read(const K &key, V &value) const
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown)
constexpr bool IsNull() const
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
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.
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.
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(
const CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
const CChainParams & GetParams() const
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
int32_t nVersion
block header
const CChainParams & GetParams() const
std::string ToString() const
uint256 ConstructBlockHash() const
bool Write(const K &key, const V &value, bool fSync=false)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
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'...
bool WriteBlockToDisk(const CBlock &block, FlatFilePos &pos) const
fs::path FileName(const FlatFilePos &pos) const
Get the name of the file at the given position.
fs::path GetBlockPosFilename(const FlatFilePos &pos) const
Translation to a filesystem path.
static constexpr uint8_t DB_LAST_BLOCK
bool FlushUndoFile(int block_file, bool finalize=false)
Return false if undo file flushing fails.
MapCheckpoints mapCheckpoints
std::set< CBlockIndex * > m_dirty_blockindex
Dirty block index entries.
bool error(const char *fmt, const Args &... args)
The block chain is a tree shaped structure starting with the genesis block at the root...
Undo information for a CBlock.
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
const fs::path blocks_dir
bool ReadRawBlockFromDisk(std::vector< uint8_t > &block, const FlatFilePos &pos) const
const MessageStartChars & MessageStart() const
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network) ...
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
bool RaiseValidity(enum BlockStatus nUpTo) EXCLUSIVE_LOCKS_REQUIRED(
Raise the validity level of this block index entry.
Holds configuration for use during UTXO snapshot load and validation.
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...
CBlockIndex * InsertBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
bool FlushChainstateBlockFile(int tip_height)
Reads data from an underlying stream, while hashing the read data.
static const unsigned int UNDOFILE_CHUNK_SIZE
The pre-allocation chunk size for rev?????.dat files (since 0.8)
void ReadReindexing(bool &fReindexing)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
arith_uint256 GetBlockProof(const CBlockIndex &block)
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
bool FatalError(Notifications ¬ifications, BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage)
full block available in blk*.dat
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
static bool exists(const path &p)
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
FlatFileSeq represents a sequence of numbered files storing raw data.
static constexpr uint8_t DB_BLOCK_FILES
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::atomic< bool > m_importing
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
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...
bool IsBlockPruned(const CBlockIndex *pblockindex) EXCLUSIVE_LOCKS_REQUIRED(void UpdatePruneLock(const std::string &name, const PruneLockInfo &lock_info) EXCLUSIVE_LOCKS_REQUIRED(CAutoFil OpenBlockFile)(const FlatFilePos &pos, bool fReadOnly=false) const
Check whether the block associated with this index entry is pruned or not.
std::ostream & operator<<(std::ostream &os, const BlockfileType &type)
unsigned int nTx
Number of transactions in this block.
std::map< int, uint256 > MapCheckpoints
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...
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
#define Assert(val)
Identity function.
bool CheckSignetBlockSolution(const CBlock &block, const Consensus::Params &consensusParams)
Extract signature and check whether a block has a valid solution.
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
std::vector< CBlockFileInfo > m_blockfile_info