Bitcoin Core  21.99.0
P2P Digital Currency
Namespaces | Functions | Variables
blockstorage.h File Reference
#include <cstdint>
#include <vector>
#include <fs.h>
#include <protocol.h>
Include dependency graph for blockstorage.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 Consensus
 Transaction validation functions.
 

Functions

bool IsBlockPruned (const CBlockIndex *pblockindex)
 Check whether the block associated with this index entry is pruned or not. More...
 
void CleanupBlockRevFiles ()
 
FILE * OpenBlockFile (const FlatFilePos &pos, bool fReadOnly=false)
 Open a block file (blk?????.dat) More...
 
fs::path GetBlockPosFilename (const FlatFilePos &pos)
 Translation to a filesystem path. More...
 
CBlockFileInfoGetBlockFileInfo (size_t n)
 Get block file info entry for one block file. More...
 
uint64_t CalculateCurrentUsage ()
 Calculate the amount of disk space the block & undo files currently use. More...
 
void UnlinkPrunedFiles (const std::set< int > &setFilesToPrune)
 Actually unlink the specified files. More...
 
bool ReadBlockFromDisk (CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
 Functions for disk access for blocks. More...
 
bool ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams)
 
bool ReadRawBlockFromDisk (std::vector< uint8_t > &block, const FlatFilePos &pos, const CMessageHeader::MessageStartChars &message_start)
 
bool ReadRawBlockFromDisk (std::vector< uint8_t > &block, const CBlockIndex *pindex, const CMessageHeader::MessageStartChars &message_start)
 
bool UndoReadFromDisk (CBlockUndo &blockundo, const CBlockIndex *pindex)
 
bool WriteUndoDataForBlock (const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex *pindex, const CChainParams &chainparams)
 
FlatFilePos SaveBlockToDisk (const CBlock &block, int nHeight, CChain &active_chain, const CChainParams &chainparams, const FlatFilePos *dbp)
 Store block on disk. More...
 
void ThreadImport (ChainstateManager &chainman, std::vector< fs::path > vImportFiles, const ArgsManager &args)
 

Variables

static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT {false}
 
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000
 The pre-allocation chunk size for blk?????.dat files (since 0.8) More...
 
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000
 The pre-allocation chunk size for rev?????.dat files (since 0.8) More...
 
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000
 The maximum size of a blk?????.dat file (since 0.8) More...
 
std::atomic_bool fImporting
 
std::atomic_bool fReindex
 
bool fHavePruned
 Pruning-related variables and constants. More...
 
bool fPruneMode
 True if we're running in -prune mode. More...
 
uint64_t nPruneTarget
 Number of MiB of block files that we're trying to stay below. More...
 

Function Documentation

◆ CalculateCurrentUsage()

uint64_t CalculateCurrentUsage ( )

Calculate the amount of disk space the block & undo files currently use.

Definition at line 189 of file blockstorage.cpp.

Here is the caller graph for this function:

◆ CleanupBlockRevFiles()

void CleanupBlockRevFiles ( )

Definition at line 60 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockFileInfo()

CBlockFileInfo* GetBlockFileInfo ( size_t  n)

Get block file info entry for one block file.

Definition at line 101 of file blockstorage.cpp.

Here is the caller graph for this function:

◆ GetBlockPosFilename()

fs::path GetBlockPosFilename ( const FlatFilePos pos)

Translation to a filesystem path.

Definition at line 231 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBlockPruned()

bool IsBlockPruned ( const CBlockIndex pblockindex)

Check whether the block associated with this index entry is pruned or not.

Definition at line 49 of file blockstorage.cpp.

Here is the caller graph for this function:

◆ OpenBlockFile()

FILE* OpenBlockFile ( const FlatFilePos pos,
bool  fReadOnly = false 
)

Open a block file (blk?????.dat)

Definition at line 220 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadBlockFromDisk() [1/2]

bool ReadBlockFromDisk ( CBlock block,
const CBlockIndex pindex,
const Consensus::Params consensusParams 
)

Definition at line 396 of file blockstorage.cpp.

Here is the call graph for this function:

◆ ReadBlockFromDisk() [2/2]

bool ReadBlockFromDisk ( CBlock block,
const FlatFilePos pos,
const Consensus::Params consensusParams 
)

Functions for disk access for blocks.

Definition at line 366 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadRawBlockFromDisk() [1/2]

bool ReadRawBlockFromDisk ( std::vector< uint8_t > &  block,
const CBlockIndex pindex,
const CMessageHeader::MessageStartChars message_start 
)

Definition at line 449 of file blockstorage.cpp.

Here is the call graph for this function:

◆ ReadRawBlockFromDisk() [2/2]

bool ReadRawBlockFromDisk ( std::vector< uint8_t > &  block,
const FlatFilePos pos,
const CMessageHeader::MessageStartChars message_start 
)

Definition at line 414 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveBlockToDisk()

FlatFilePos SaveBlockToDisk ( const CBlock block,
int  nHeight,
CChain active_chain,
const CChainParams chainparams,
const FlatFilePos dbp 
)

Store block on disk.

If dbp is non-nullptr, the file is known to already reside on disk

Definition at line 461 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThreadImport()

void ThreadImport ( ChainstateManager chainman,
std::vector< fs::path >  vImportFiles,
const ArgsManager args 
)

Definition at line 495 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UndoReadFromDisk()

bool UndoReadFromDisk ( CBlockUndo blockundo,
const CBlockIndex pindex 
)

Definition at line 137 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlinkPrunedFiles()

void UnlinkPrunedFiles ( const std::set< int > &  setFilesToPrune)

Actually unlink the specified files.

Definition at line 200 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteUndoDataForBlock()

bool WriteUndoDataForBlock ( const CBlockUndo blockundo,
BlockValidationState state,
CBlockIndex pindex,
const CChainParams chainparams 
)

Definition at line 337 of file blockstorage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ BLOCKFILE_CHUNK_SIZE

const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000
static

The pre-allocation chunk size for blk?????.dat files (since 0.8)

Definition at line 31 of file blockstorage.h.

◆ DEFAULT_STOPAFTERBLOCKIMPORT

constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT {false}
staticconstexpr

Definition at line 28 of file blockstorage.h.

◆ fHavePruned

bool fHavePruned

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 24 of file blockstorage.cpp.

◆ fImporting

std::atomic_bool fImporting

◆ fPruneMode

bool fPruneMode

True if we're running in -prune mode.

Definition at line 25 of file blockstorage.cpp.

◆ fReindex

std::atomic_bool fReindex

◆ MAX_BLOCKFILE_SIZE

const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000
static

The maximum size of a blk?????.dat file (since 0.8)

Definition at line 35 of file blockstorage.h.

◆ nPruneTarget

uint64_t nPruneTarget

Number of MiB of block files that we're trying to stay below.

Definition at line 26 of file blockstorage.cpp.

◆ UNDOFILE_CHUNK_SIZE

const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000
static

The pre-allocation chunk size for rev?????.dat files (since 0.8)

Definition at line 33 of file blockstorage.h.