Bitcoin Core 22.99.0
P2P Digital Currency
Namespaces | Functions | Variables
blockstorage.h File Reference
#include <fs.h>
#include <protocol.h>
#include <atomic>
#include <cstdint>
#include <vector>
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

namespace  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...
 
CBlockFileInfo * GetBlockFileInfo (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 191 of file blockstorage.cpp.

Here is the caller graph for this function:

◆ CleanupBlockRevFiles()

void CleanupBlockRevFiles ( )

Definition at line 61 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 103 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 233 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 50 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 222 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 397 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 367 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 446 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 411 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 458 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 492 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 139 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 202 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 338 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 32 of file blockstorage.h.

◆ DEFAULT_STOPAFTERBLOCKIMPORT

constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT {false}
staticconstexpr

Definition at line 29 of file blockstorage.h.

◆ fHavePruned

bool fHavePruned
extern

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 25 of file blockstorage.cpp.

◆ fImporting

std::atomic_bool fImporting
extern

◆ fPruneMode

bool fPruneMode
extern

True if we're running in -prune mode.

Definition at line 26 of file blockstorage.cpp.

◆ fReindex

std::atomic_bool fReindex
extern

◆ 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 36 of file blockstorage.h.

◆ nPruneTarget

uint64_t nPruneTarget
extern

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

Definition at line 27 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 34 of file blockstorage.h.