Bitcoin ABC  0.26.3
P2P Digital Currency
blockstorage.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_NODE_BLOCKSTORAGE_H
6 #define BITCOIN_NODE_BLOCKSTORAGE_H
7 
8 #include <cstdint>
9 #include <vector>
10 
11 #include <fs.h>
12 #include <protocol.h> // For CMessageHeader::MessageStartChars
13 
14 class ArgsManager;
16 class CBlock;
17 class CBlockFileInfo;
18 class CBlockIndex;
19 class CBlockUndo;
20 class CChain;
21 class CChainParams;
22 class ChainstateManager;
23 class Config;
24 struct FlatFilePos;
25 namespace Consensus {
26 struct Params;
27 }
28 
29 static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
30 
32 static constexpr unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
34 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
36 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
37 
38 extern std::atomic_bool fImporting;
39 extern std::atomic_bool fReindex;
42 extern bool fHavePruned;
44 extern bool fPruneMode;
46 extern uint64_t nPruneTarget;
47 
49 bool IsBlockPruned(const CBlockIndex *pblockindex);
50 
52 
54 FILE *OpenBlockFile(const FlatFilePos &pos, bool fReadOnly = false);
57 
60 
62 uint64_t CalculateCurrentUsage();
63 
67 void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune);
68 
70 bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos,
71  const Consensus::Params &consensusParams);
72 bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex,
73  const Consensus::Params &consensusParams);
74 bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex);
75 bool WriteUndoDataForBlock(const CBlockUndo &blockundo,
76  BlockValidationState &state, CBlockIndex *pindex,
77  const CChainParams &chainparams);
78 
79 FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight,
80  CChain &active_chain,
81  const CChainParams &chainparams,
82  const FlatFilePos *dbp);
83 
84 void ThreadImport(const Config &config, ChainstateManager &chainman,
85  std::vector<fs::path> vImportFiles, const ArgsManager &args);
86 
87 #endif // BITCOIN_NODE_BLOCKSTORAGE_H
static const unsigned int UNDOFILE_CHUNK_SIZE
The pre-allocation chunk size for rev?????.dat files (since 0.8)
Definition: blockstorage.h:34
std::atomic_bool fReindex
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
bool fHavePruned
Pruning-related variables and constants.
std::atomic_bool fImporting
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
static constexpr unsigned int BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
Definition: blockstorage.h:32
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
void CleanupBlockRevFiles()
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
void ThreadImport(const Config &config, ChainstateManager &chainman, std::vector< fs::path > vImportFiles, const ArgsManager &args)
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
fs::path GetBlockPosFilename(const FlatFilePos &pos)
Translation to a filesystem path.
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT
Definition: blockstorage.h:29
bool WriteUndoDataForBlock(const CBlockUndo &blockundo, BlockValidationState &state, CBlockIndex *pindex, const CChainParams &chainparams)
bool fPruneMode
True if we're running in -prune mode.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: blockstorage.h:36
FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight, CChain &active_chain, const CChainParams &chainparams, const FlatFilePos *dbp)
Store block on disk.
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
const CChainParams & Params()
Return the currently selected parameters.
Definition: block.h:55
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
Undo information for a CBlock.
Definition: undo.h:73
An in-memory indexed chain of blocks.
Definition: chain.h:152
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1145
Definition: config.h:17
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:33
unsigned int nHeight
Parameters that influence chain consensus.
Definition: params.h:59