node::BlockManager

Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-work tip is.

Synopsis

Declared in <node/blockstorage.h>

class BlockManager;

Description

This data is used mostly in Chainstate - information about, e.g., candidate tips is not maintained here.

Type Aliases

NameDescription
Options Options controlling block storage behavior.
ReadRawBlockResult Result of a raw block read: the bytes on success, or a ReadRawError on failure.

Member Functions

NameDescription
BlockManager [constructor]Construct a block manager.
AddToBlockIndex Add a block header to the in-memory block index, updating the best header.
AddUnlinkedBlock Record a block whose ancestor is still missing transaction data.
CalculateCurrentUsage Calculate the amount of disk space the block & undo files currently use
CheckBlockDataAvailability Check if all blocks in the [upper_block, lower_block]range have data available as defined by the status mask. The caller is responsible for ensuring that lower_block is an ancestor of upper_block (part of the same chain).
CleanupBlockRevFiles Remove leftover block and undo files that no longer belong to the block tree.
DeletePruneLock Delete a prune lock identified by its name. Returns true if the lock existed.
GetAllBlockIndices Return pointers to every block index entry currently held in memory.
GetBlockFileInfo Get block file info entry for one block file
GetBlockPosFilename Translation to a filesystem path
GetFirstBlock Returns the earliest block with specified status_mask flags set after the latest block not having those flags.
GetPruneTarget Attempt to stay below this number of bytes of block files.
InsertBlockIndex Create a new block index entry for a given block hash
IsBlockPruned Check whether the block associated with this index entry is pruned or not.
IsPruneMode Whether running in -prune mode.
LoadBlockIndexDB Load the block index from the database into memory.
LoadingBlocks Report whether blocks are still being imported or indexed.
LookupBlockIndex Look up a block index entry by hash.
OpenBlockFile Open a block file (blk?????.dat)
PruneOneBlockFile Mark one block file as pruned (modify associated database entries)
ReadBlock ReadBlock overloads
ReadBlockUndo Read a block's undo data from disk using its block index entry.
ReadRawBlock Read the raw, still-serialized bytes of a block (or a sub-range) from disk.
ScanAndUnlinkAlreadyPrunedFiles Remove any pruned block & undo files that are still on disk. This could happen on some systems if the file was still being read while unlinked, or if we crash before unlinking.
UnlinkPrunedFiles Actually unlink the specified files
UpdateBlockInfo Update blockfile info while processing a block during reindex. The block must be available on disk.
UpdatePruneLock Create or update a prune lock identified by its name
WriteBlock Store block on disk and update block file statistics.
WriteBlockIndexDB Write the dirty block index and block-file entries to the database.
WriteBlockUndo Write a block's undo data to disk and record it in the block index.

Data Members

NameDescription
m_block_index The in-memory block tree, mapping each block hash to its index entry.
m_block_tree_db Handle to the on-disk block index database (blocks/index/).
m_blockfiles_indexed Whether all blockfiles have been added to the block tree database. Normally true, but set to false when a reindex is requested and the database is wiped. The value is persisted in the database across restarts and will be false until reindexing completes.
m_blocks_unlinked All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
m_have_pruned True if any block files have ever been pruned.
m_importing Whether blocks are currently being imported from disk.
m_interrupt Interrupt used to abort long-running block-loading operations.
m_snapshot_height The height of the base block of an assumeutxo snapshot, if one is in use.

Static Data Members

NameDescription
PRUNE_TARGET_MANUAL Sentinel prune target meaning pruning is manual rather than size-based.

Protected Data Members

NameDescription
m_blockfile_info In-memory statistics for each block file, indexed by file number.
m_dirty_blockindex Dirty block index entries.
m_dirty_fileinfo Dirty block file entries.

Friends

NameDescription
ChainstateManagerInterface for managing multiple Chainstate objects, where each chainstate is associated with chainstate* subdirectory in the data directory and contains a database of UTXOs existing at a different point in history. (See the Chainstate class for more information.)
ChainstateChainstate stores and provides an API to update our local knowledge of the current best chain.

Non-Member Functions

NameDescription
::CheckBlockDataAvailabilityCheck that a block's data (and optionally undo data) is available on disk.
::GetPruneHeightReturn height of highest block that has been pruned, or std::nullopt if no blocks have been pruned
::blockToJSONBlock description to JSON