5 #ifndef BITCOIN_NODE_BLOCKSTORAGE_H 6 #define BITCOIN_NODE_BLOCKSTORAGE_H 17 #include <unordered_map> 59 using BlockMap = std::unordered_map<uint256, CBlockIndex, BlockHasher>;
94 void FlushBlockFile(
bool fFinalize =
false,
bool finalize_undo =
false);
100 void FindFilesToPruneManual(std::set<int>& setFilesToPrune,
int nManualPruneHeight,
int chain_tip_height);
117 void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight,
int chain_tip_height,
int prune_height,
bool is_ibd);
140 std::unordered_map<std::string, PruneLockInfo> m_prune_locks
GUARDED_BY(::
cs_main);
217 #endif // BITCOIN_NODE_BLOCKSTORAGE_H RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
void CleanupBlockRevFiles()
std::set< int > m_dirty_fileinfo
Dirty block file 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 ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
std::atomic_bool fReindex
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
RecursiveMutex cs_LastBlockFile
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT
void FindFilesToPrune(std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, int prune_height, bool is_ibd)
Prune block and undo files (blk???.dat and rev???.dat) so that the disk space used is less than a use...
An in-memory indexed chain of blocks.
std::unordered_map< uint256, CBlockIndex, BlockHasher > BlockMap
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Filesystem operations and types.
void FlushUndoFile(int block_file, bool finalize=false)
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.
Transaction validation functions.
bool WriteUndoDataForBlock(const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex *pindex, const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(FlatFilePo SaveBlockToDisk)(const CBlock &block, int nHeight, CChain &active_chain, const CChainParams &chainparams, const FlatFilePos *dbp)
Store block on disk.
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 Consensus::Params &consensus_params) EXCLUSIVE_LOCKS_REQUIRED(CBlockIndex * AddToBlockIndex(const CBlockHeader &block, CBlockIndex *&best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
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/)
bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize)
std::unordered_map< std::string, PruneLockInfo > m_prune_locks GUARDED_BY(::cs_main)
Map from external index name to oldest block that must not be pruned.
void FindFilesToPruneManual(std::set< int > &setFilesToPrune, int nManualPruneHeight, int chain_tip_height)
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Parameters that influence chain consensus.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
const CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
bool fPruneMode
Pruning-related variables and constants.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::set< CBlockIndex * > m_dirty_blockindex
Dirty block index entries.
bool LoadBlockIndex(const Consensus::Params &consensus_params) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the blocktree off disk and into memory.
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...
const CChainParams & Params()
Return the currently selected parameters.
Undo information for a CBlock.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
void ThreadImport(ChainstateManager &chainman, std::vector< fs::path > vImportFiles, const ArgsManager &args, const fs::path &mempool_path)
void FlushBlockFile(bool fFinalize=false, bool finalize_undo=false)
CBlockIndex * InsertBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
fs::path GetBlockPosFilename(const FlatFilePos &pos)
Translation to a filesystem path.
static const unsigned int UNDOFILE_CHUNK_SIZE
The pre-allocation chunk size for rev?????.dat files (since 0.8)
bool ReadRawBlockFromDisk(std::vector< uint8_t > &block, const FlatFilePos &pos, const CMessageHeader::MessageStartChars &message_start)
std::atomic_bool fImporting
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, CChain &active_chain, uint64_t nTime, bool fKnown)
std::vector< CBlockFileInfo > m_blockfile_info