Bitcoin Core  21.99.0
P2P Digital Currency
Classes | Functions | Variables
blockstorage.cpp File Reference
#include <node/blockstorage.h>
#include <chain.h>
#include <chainparams.h>
#include <clientversion.h>
#include <consensus/validation.h>
#include <flatfile.h>
#include <fs.h>
#include <hash.h>
#include <pow.h>
#include <shutdown.h>
#include <signet.h>
#include <streams.h>
#include <undo.h>
#include <util/system.h>
#include <validation.h>
Include dependency graph for blockstorage.cpp:

Go to the source code of this file.

Classes

struct  CImportingNow
 

Functions

std::atomic_bool fImporting (false)
 
std::atomic_bool fReindex (false)
 
static FILE * OpenUndoFile (const FlatFilePos &pos, bool fReadOnly)
 Open an undo file (rev?????.dat) More...
 
static FlatFileSeq BlockFileSeq ()
 
static FlatFileSeq UndoFileSeq ()
 
bool IsBlockPruned (const CBlockIndex *pblockindex)
 Check whether the block associated with this index entry is pruned or not. More...
 
void CleanupBlockRevFiles ()
 
CBlockFileInfoGetBlockFileInfo (size_t n)
 Get block file info entry for one block file. More...
 
static bool UndoWriteToDisk (const CBlockUndo &blockundo, FlatFilePos &pos, const uint256 &hashBlock, const CMessageHeader::MessageStartChars &messageStart)
 
bool UndoReadFromDisk (CBlockUndo &blockundo, const CBlockIndex *pindex)
 
static void FlushUndoFile (int block_file, bool finalize=false)
 
void FlushBlockFile (bool fFinalize=false, bool finalize_undo=false)
 
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...
 
FILE * OpenBlockFile (const FlatFilePos &pos, bool fReadOnly)
 Open a block file (blk?????.dat) More...
 
fs::path GetBlockPosFilename (const FlatFilePos &pos)
 Translation to a filesystem path. More...
 
bool FindBlockPos (FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, CChain &active_chain, uint64_t nTime, bool fKnown=false)
 
static bool FindUndoPos (BlockValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize)
 
static bool WriteBlockToDisk (const CBlock &block, FlatFilePos &pos, const CMessageHeader::MessageStartChars &messageStart)
 
bool WriteUndoDataForBlock (const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex *pindex, const CChainParams &chainparams)
 
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)
 
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

bool fHavePruned = false
 Pruning-related variables and constants. More...
 
bool fPruneMode = false
 True if we're running in -prune mode. More...
 
uint64_t nPruneTarget = 0
 Number of MiB of block files that we're trying to stay below. More...
 
RecursiveMutex cs_LastBlockFile
 
std::vector< CBlockFileInfovinfoBlockFile
 
int nLastBlockFile = 0
 
bool fCheckForPruning = false
 Global flag to indicate we should check to see if there are block/undo files that should be deleted. More...
 
std::set< CBlockIndex * > setDirtyBlockIndex
 Dirty block index entries. More...
 
std::set< int > setDirtyFileInfo
 Dirty block file entries. More...
 

Function Documentation

◆ BlockFileSeq()

static FlatFileSeq BlockFileSeq ( )
static

Definition at line 210 of file blockstorage.cpp.

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

◆ 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:

◆ fImporting()

std::atomic_bool fImporting ( false  )
Here is the caller graph for this function:

◆ FindBlockPos()

bool FindBlockPos ( FlatFilePos pos,
unsigned int  nAddSize,
unsigned int  nHeight,
CChain active_chain,
uint64_t  nTime,
bool  fKnown = false 
)

Definition at line 236 of file blockstorage.cpp.

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

◆ FindUndoPos()

static bool FindUndoPos ( BlockValidationState state,
int  nFile,
FlatFilePos pos,
unsigned int  nAddSize 
)
static

Definition at line 292 of file blockstorage.cpp.

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

◆ FlushBlockFile()

void FlushBlockFile ( bool  fFinalize = false,
bool  finalize_undo = false 
)

Definition at line 177 of file blockstorage.cpp.

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

◆ FlushUndoFile()

static void FlushUndoFile ( int  block_file,
bool  finalize = false 
)
static

Definition at line 169 of file blockstorage.cpp.

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

◆ fReindex()

std::atomic_bool fReindex ( false  )
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 
)

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:

◆ OpenUndoFile()

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

Open an undo file (rev?????.dat)

Definition at line 226 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:

◆ UndoFileSeq()

static FlatFileSeq UndoFileSeq ( )
static

Definition at line 215 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:

◆ UndoWriteToDisk()

static bool UndoWriteToDisk ( const CBlockUndo blockundo,
FlatFilePos pos,
const uint256 hashBlock,
const CMessageHeader::MessageStartChars messageStart 
)
static

Definition at line 108 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:

◆ WriteBlockToDisk()

static bool WriteBlockToDisk ( const CBlock block,
FlatFilePos pos,
const CMessageHeader::MessageStartChars messageStart 
)
static

Definition at line 314 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

◆ cs_LastBlockFile

RecursiveMutex cs_LastBlockFile

Definition at line 29 of file blockstorage.cpp.

◆ fCheckForPruning

bool fCheckForPruning = false

Global flag to indicate we should check to see if there are block/undo files that should be deleted.

Set on startup or if we allocate more file space when we're in prune mode

Definition at line 36 of file blockstorage.cpp.

◆ fHavePruned

bool fHavePruned = false

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 24 of file blockstorage.cpp.

◆ fPruneMode

bool fPruneMode = false

True if we're running in -prune mode.

Definition at line 25 of file blockstorage.cpp.

◆ nLastBlockFile

int nLastBlockFile = 0

Definition at line 31 of file blockstorage.cpp.

◆ nPruneTarget

uint64_t nPruneTarget = 0

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

Definition at line 26 of file blockstorage.cpp.

◆ setDirtyBlockIndex

std::set<CBlockIndex*> setDirtyBlockIndex

Dirty block index entries.

Definition at line 39 of file blockstorage.cpp.

◆ setDirtyFileInfo

std::set<int> setDirtyFileInfo

Dirty block file entries.

Definition at line 42 of file blockstorage.cpp.

◆ vinfoBlockFile

std::vector<CBlockFileInfo> vinfoBlockFile

Definition at line 30 of file blockstorage.cpp.