Bitcoin ABC 0.26.3
P2P Digital Currency
|
Maintains a tree of blocks (stored in m_block_index
) which is consulted to determine where the most-work tip is.
More...
#include <blockstorage.h>
Public Types | |
using | Options = kernel::BlockManagerOpts |
Static Public Attributes | |
static constexpr auto | PRUNE_TARGET_MANUAL |
Private Attributes | |
friend | Chainstate |
friend | ChainstateManager |
RecursiveMutex | cs_LastBlockFile |
std::vector< CBlockFileInfo > | m_blockfile_info |
int | m_last_blockfile = 0 |
bool | m_check_for_pruning = false |
Global flag to indicate we should check to see if there are block/undo files that should be deleted. | |
const bool | m_prune_mode |
std::set< CBlockIndex * > | m_dirty_blockindex |
Dirty block index entries. | |
std::set< int > | m_dirty_fileinfo |
Dirty block file entries. | |
const kernel::BlockManagerOpts | m_opts |
Maintains a tree of blocks (stored in m_block_index
) which is consulted to determine where the most-work tip is.
This data is used mostly in Chainstate
- information about, e.g., candidate tips is not maintained here.
Definition at line 74 of file blockstorage.h.
Definition at line 173 of file blockstorage.h.
|
inlineexplicit |
Definition at line 175 of file blockstorage.h.
CBlockIndex * node::BlockManager::AddToBlockIndex | ( | const CBlockHeader & | block, |
CBlockIndex *& | best_header | ||
) |
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.
Definition at line 55 of file blockstorage.cpp.
|
private |
uint64_t node::BlockManager::CalculateCurrentUsage | ( | ) |
Calculate the amount of disk space the block & undo files currently use.
Definition at line 568 of file blockstorage.cpp.
void node::BlockManager::CleanupBlockRevFiles | ( | ) | const |
|
private |
Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.
The user sets the target (in MB) on the command line or in config file. This will be run on startup and whenever new space is allocated in a block or undo file, staying below the target. Changing back to unpruned requires a reindex (which in this case means the blockchain must be re-downloaded.)
Pruning functions are called from FlushStateToDisk when the m_check_for_pruning flag has been set. Block and undo files are deleted in lock-step (when blk00003.dat is deleted, so is rev00003.dat.) Pruning cannot take place until the longest chain is at least a certain length (CChainParams::nPruneAfterHeight). Pruning will never delete a block within a defined distance (currently 288) from the active chain's tip. The block index is updated by unsetting HAVE_DATA and HAVE_UNDO for any blocks that were stored in the deleted files. A db flag records the fact that at least some block files have been pruned.
[out] | setFilesToPrune | The set of file indices that can be unlinked will be returned |
Definition at line 157 of file blockstorage.cpp.
|
private |
Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain.
Definition at line 129 of file blockstorage.cpp.
|
private |
|
private |
Definition at line 541 of file blockstorage.cpp.
Definition at line 532 of file blockstorage.cpp.
CBlockFileInfo * node::BlockManager::GetBlockFileInfo | ( | size_t | n | ) |
Get block file info entry for one block file.
Definition at line 462 of file blockstorage.cpp.
fs::path node::BlockManager::GetBlockPosFilename | ( | const FlatFilePos & | pos | ) | const |
Translation to a filesystem path.
Definition at line 615 of file blockstorage.cpp.
|
inlineprivate |
Definition at line 80 of file blockstorage.h.
const CBlockIndex * node::BlockManager::GetLastCheckpoint | ( | const CCheckpointData & | data | ) |
Returns last CBlockIndex* that is a checkpoint.
Definition at line 391 of file blockstorage.cpp.
|
inlineprivate |
Definition at line 79 of file blockstorage.h.
|
inline |
Attempt to stay below this number of bytes of block files.
Definition at line 238 of file blockstorage.h.
|
private |
Map from external index name to oldest block that must not be pruned.
std::unique_ptr< CBlockTreeDB > m_block_tree_db node::BlockManager::GUARDED_BY | ( | ::cs_main | ) |
BlockMap m_block_index node::BlockManager::GUARDED_BY | ( | cs_main | ) |
CBlockIndex * node::BlockManager::InsertBlockIndex | ( | const BlockHash & | hash | ) |
Create a new block index entry for a given block hash.
Definition at line 232 of file blockstorage.cpp.
|
inline |
Whether running in -prune mode.
Definition at line 235 of file blockstorage.h.
|
private |
Load the blocktree off disk and into memory.
Populate certain metadata per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral collections like m_dirty_blockindex.
Definition at line 247 of file blockstorage.cpp.
|
inline |
const CBlockIndex * node::BlockManager::LookupBlockIndex | ( | const BlockHash & | hash | ) | const |
CBlockIndex * node::BlockManager::LookupBlockIndex | ( | const BlockHash & | hash | ) |
Definition at line 43 of file blockstorage.cpp.
|
private |
Open an undo file (rev?????.dat)
Definition at line 611 of file blockstorage.cpp.
Mark one block file as pruned (modify associated database entries)
Definition at line 96 of file blockstorage.cpp.
bool node::BlockManager::ReadBlockFromDisk | ( | CBlock & | block, |
const CBlockIndex & | index | ||
) | const |
bool node::BlockManager::ReadBlockFromDisk | ( | CBlock & | block, |
const FlatFilePos & | pos | ||
) | const |
Functions for disk access for blocks.
Definition at line 783 of file blockstorage.cpp.
bool node::BlockManager::ReadTxFromDisk | ( | CMutableTransaction & | tx, |
const FlatFilePos & | pos | ||
) | const |
Functions for disk access for txs.
Definition at line 828 of file blockstorage.cpp.
bool node::BlockManager::ReadTxUndoFromDisk | ( | CTxUndo & | tx, |
const FlatFilePos & | pos | ||
) | const |
|
inline |
|
private |
bool node::BlockManager::UndoReadFromDisk | ( | CBlockUndo & | blockundo, |
const CBlockIndex & | index | ||
) | const |
Definition at line 498 of file blockstorage.cpp.
|
private |
Actually unlink the specified files.
Definition at line 579 of file blockstorage.cpp.
|
private |
|
private |
Definition at line 75 of file blockstorage.h.
|
private |
Definition at line 76 of file blockstorage.h.
|
private |
Definition at line 142 of file blockstorage.h.
|
private |
Definition at line 143 of file blockstorage.h.
std::vector<CBlockIndex *> GetAllBlockIndices () EXCLUSIVE_LOCKS_REQUIRED( std::multimap<CBlockIndex *, CBlockIndex *> node::BlockManager::m_blocks_unlinked |
All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
Pruned nodes may have entries where B is missing data.
Definition at line 190 of file blockstorage.h.
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 150 of file blockstorage.h.
|
private |
Dirty block index entries.
Definition at line 155 of file blockstorage.h.
|
private |
Dirty block file entries.
Definition at line 158 of file blockstorage.h.
const CBlockIndex* GetFirstStoredBlock (const CBlockIndex &start_block) EXCLUSIVE_LOCKS_REQUIRED( bool node::BlockManager::m_have_pruned = false |
Find the first block that is not pruned.
True if any block files have ever been pruned.
Definition at line 264 of file blockstorage.h.
Definition at line 178 of file blockstorage.h.
|
private |
Definition at line 144 of file blockstorage.h.
|
private |
Definition at line 170 of file blockstorage.h.
|
private |
Definition at line 152 of file blockstorage.h.
FILE * node::BlockManager::OpenBlockFile |
Check whether the block associated with this index entry is pruned or not.
Create or update a prune lock identified by its name Open a block file (blk?????.dat)
Definition at line 277 of file blockstorage.h.
Definition at line 241 of file blockstorage.h.
FlatFilePos node::BlockManager::SaveBlockToDisk |
Store block on disk.
If dbp is not nullptr, then it provides the known position of the block within a block file on disk.
Definition at line 231 of file blockstorage.h.