Struct bitcoin_blockman::BlockManager
source · pub struct BlockManager { /* private fields */ }
Expand description
| 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.
|
Implementations§
source§impl BlockManager
impl BlockManager
pub fn add_to_block_index(&mut self, block: &BlockHeader) -> *mut BlockIndex
sourcepub fn get_last_checkpoint(&mut self, data: &CheckpointData) -> *mut BlockIndex
pub fn get_last_checkpoint(&mut self, data: &CheckpointData) -> *mut BlockIndex
| Returns last CBlockIndex* that is a | checkpoint |
sourcepub fn accept_block_header(
&mut self,
block: &BlockHeader,
state: &mut BlockValidationState,
chainparams: &ChainParams,
ppindex: *mut *mut BlockIndex
) -> bool
pub fn accept_block_header( &mut self, block: &BlockHeader, state: &mut BlockValidationState, chainparams: &ChainParams, ppindex: *mut *mut BlockIndex ) -> bool
| If a block header hasn’t already been | seen, call CheckBlockHeader on it, | ensure that it doesn’t descend from | an invalid block, and then add it to m_block_index. |
sourcepub fn find_files_to_prune(
&mut self,
set_files_to_prune: &mut HashSet<i32>,
n_prune_after_height: u64,
chain_tip_height: i32,
prune_height: i32,
is_ibd: bool
)
pub fn find_files_to_prune( &mut self, set_files_to_prune: &mut HashSet<i32>, n_prune_after_height: u64, chain_tip_height: i32, prune_height: i32, is_ibd: bool )
| 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 global fCheckForPruning 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 | (100000 on mainnet, 1000 on testnet, | 1000 on regtest). | | 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. | | ———– | @param[out] setFilesToPrune | | The set of file indices that can be unlinked | will be returned |
sourcepub fn insert_block_index(&mut self, hash: &u256) -> *mut BlockIndex
pub fn insert_block_index(&mut self, hash: &u256) -> *mut BlockIndex
| Create a new block index entry for a given | block hash |
sourcepub fn load_block_index(
&mut self,
consensus_params: &ChainConsensusParams,
block_index_candidates: &mut HashSet<*mut BlockIndex, BlockIndexWorkComparator>
) -> bool
pub fn load_block_index( &mut self, consensus_params: &ChainConsensusParams, block_index_candidates: &mut HashSet<*mut BlockIndex, BlockIndexWorkComparator> ) -> bool
| Load the blocktree off disk and into | memory. Populate certain metadata | per index entry (nStatus, nChainWork, | nTimeMax, etc.) as well as peripheral | collections like setDirtyBlockIndex. | | ———– | @param[out] block_index_candidates | | Fill this set with any valid blocks for | which we’ve downloaded all transactions. |
pub fn load_block_indexdb( &mut self, set_block_index_candidates: &mut HashSet<*mut BlockIndex, BlockIndexWorkComparator> ) -> bool
sourcepub fn prune_one_block_file(&mut self, file_number: i32)
pub fn prune_one_block_file(&mut self, file_number: i32)
| Mark one block file as pruned (modify | associated database entries) |
sourcepub fn find_files_to_prune_manual(
&mut self,
set_files_to_prune: &mut HashSet<i32>,
n_manual_prune_height: i32,
chain_tip_height: i32
)
pub fn find_files_to_prune_manual( &mut self, set_files_to_prune: &mut HashSet<i32>, n_manual_prune_height: i32, chain_tip_height: i32 )
| Calculate the block/rev files to delete | based on height specified by user with | RPC command pruneblockchain |
sourcepub fn get_spend_height(&mut self, inputs: &CoinsViewCache) -> i32
pub fn get_spend_height(&mut self, inputs: &CoinsViewCache) -> i32
| Return the spend height, which is one | more than the inputs.GetBestBlock(). | | While checking, GetBestBlock() refers | to the parent block. (protected by cs_main) | | This is also true for mempool checks. |