Struct bitcoin_chainman::ChainstateManager
source · pub struct ChainstateManager {
pub snapshot_validated: bool,
pub load_block: Thread,
pub total_coinstip_cache: i64,
pub total_coinsdb_cache: i64,
pub inner: ChainstateManagerInner,
}
Expand description
| Provides an interface for creating | and interacting with one or two chainstates: | an IBD chainstate generated by downloading | blocks, and an optional snapshot chainstate | loaded from a UTXO snapshot. Managed | chainstates can be maintained at different | heights simultaneously. | | This class provides abstractions that | allow the retrieval of the current most-work | chainstate (“Active”) as well as chainstates | which may be in background use to validate | UTXO snapshots. | | Definitions: | | -IBD chainstate*: a chainstate whose | current state has been “fully” validated | by the initial block download process. | | -Snapshot chainstate*: a chainstate | populated by loading in an assumeutxo | UTXO snapshot. | | -Active chainstate*: the chainstate | containing the current most-work chain. | Consulted by most parts of the system | (net_processing, wallet) as a reflection | of the current chain and UTXO set. | | This may either be an IBD chainstate | or a snapshot chainstate. | | -Background IBD chainstate*: an IBD | chainstate for which the | | IBD process is happening in the background | while use of the active (snapshot) chainstate | allows the rest of the system to function. |
Fields§
§snapshot_validated: bool
| If true, the assumed-valid chainstate | has been fully validated by the background | validation chainstate. |
load_block: Thread
§total_coinstip_cache: i64
| The total number of bytes available | for us to use across all in-memory coins | caches. This will be split somehow across | chainstates. |
total_coinsdb_cache: i64
| The total number of bytes available | for us to use across all leveldb coins | databases. This will be split somehow | across chainstates. |
inner: ChainstateManagerInner
Implementations§
source§impl ChainstateManager
impl ChainstateManager
pub fn active_chain(&self) -> &mut dyn ChainInterface
pub fn active_height(&self) -> i32
pub fn active_tip(&self) -> *mut BlockIndex
pub fn block_index(&mut self) -> &mut BlockMap
sourcepub fn is_snapshot_validated(&self) -> bool
pub fn is_snapshot_validated(&self) -> bool
| Is there a snapshot in use and has it been | fully validated? |
sourcepub fn process_new_block_headers(
&mut self,
headers: &Vec<BlockHeader>,
state: &mut BlockValidationState,
chainparams: &ChainParams,
ppindex: Option<Arc<BlockIndex>>
) -> bool
pub fn process_new_block_headers( &mut self, headers: &Vec<BlockHeader>, state: &mut BlockValidationState, chainparams: &ChainParams, ppindex: Option<Arc<BlockIndex>> ) -> bool
| Exposed wrapper for AcceptBlockHeader | | Process incoming block headers. | | May not be called in a validationinterface | callback. | | ———– | @param[in] block | | The block headers themselves | ––––– | @param[out] state | | This may be set to an Error state if any | error occurred processing them | ––––– | @param[in] chainparams | | The params for the chain we want to connect | to | ––––– | @param[out] ppindex | | If set, the pointer will be set to point | to the last new block index object for | the given headers |
sourcepub fn process_new_block(
&mut self,
chainparams: &ChainParams,
block: Amo<Block>,
force_processing: bool,
new_block: *mut bool
) -> bool
pub fn process_new_block( &mut self, chainparams: &ChainParams, block: Amo<Block>, force_processing: bool, new_block: *mut bool ) -> bool
| Process an incoming block. This only | returns after the best known valid block | is made active. Note that it does not, | however, guarantee that the specific | block passed to it has been checked for | validity! | | If you want to possibly get feedback | on whether block is valid, you must install | a CValidationInterface (see validationinterface.h) | - this will have its BlockChecked method | called whenever any block completes | validation. | | ———– | @note | | we guarantee that either the proof-of-work | is valid on block, or (and possibly also) | BlockChecked will have been called. | | May not be called in a validationinterface | callback. | | ———– | @param[in] block | | The block we want to process. | ––––– | @param[in] force_processing | | Process this block even if unrequested; | used for non-network block sources. | ––––– | @param[out] new_block | | A boolean which is set to indicate if | the block was first received via this | call | | ———– | @return | | If the block was processed, independently | of block validity |
sourcepub fn load_block_index(&mut self) -> bool
pub fn load_block_index(&mut self) -> bool
| Load the block tree and coins database | from disk, initializing state if we’re | running with -reindex |
pub fn snapshot_blockhash(&self) -> Option<u256>
sourcepub fn get_all(&mut self) -> Vec<*mut dyn ChainStateInterface>
pub fn get_all(&mut self) -> Vec<*mut dyn ChainStateInterface>
| Get all chainstates currently being | used. |
sourcepub fn initialize_chainstate(
&mut self,
mempool: Arc<Mutex<dyn ITxMemPool>>,
snapshot_blockhash: &Option<u256>
) -> &mut dyn ChainStateInterface
pub fn initialize_chainstate( &mut self, mempool: Arc<Mutex<dyn ITxMemPool>>, snapshot_blockhash: &Option<u256> ) -> &mut dyn ChainStateInterface
| Instantiate a new chainstate and assign | it based upon whether it is from a snapshot. | | ———– | @param[in] mempool | | The mempool to pass to the chainstate | constructor | ––––– | @param[in] snapshot_blockhash | | If given, signify that this chainstate | is based on a snapshot. |
sourcepub fn activate_snapshot(
&mut self,
coins_file: &mut AutoFile,
metadata: &SnapshotMetadata,
in_memory: bool
) -> bool
pub fn activate_snapshot( &mut self, coins_file: &mut AutoFile, metadata: &SnapshotMetadata, in_memory: bool ) -> bool
| Construct and activate a Chainstate on the
| basis of UTXO snapshot data.
|
| Steps:
|
| - Initialize an unused ChainState.
|
| - Load its CoinsViews
contents from
| coins_file
.
|
| - Verify that the hash of the resulting
| coinsdb matches the expected hash per
| assumeutxo chain parameters.
|
| - Wait for our headers chain to include
| the base block of the snapshot.
|
| - “Fast forward” the tip of the new
| chainstate to the base of the snapshot,
| faking nTx* block index data along the
| way.
|
| - Move the new chainstate to
| m_snapshot_chainstate
and make it our
| ChainstateActive().
sourcepub fn populate_and_validate_snapshot(
&mut self,
snapshot_chainstate: &mut dyn ChainStateInterface,
coins_file: &mut AutoFile,
metadata: &SnapshotMetadata
) -> bool
pub fn populate_and_validate_snapshot( &mut self, snapshot_chainstate: &mut dyn ChainStateInterface, coins_file: &mut AutoFile, metadata: &SnapshotMetadata ) -> bool
| Internal helper for ActivateSnapshot(). |
sourcepub fn active_chainstate(&self) -> &mut dyn ChainStateInterface
pub fn active_chainstate(&self) -> &mut dyn ChainStateInterface
| The most-work chain. |
sourcepub fn is_snapshot_active(&self) -> bool
pub fn is_snapshot_active(&self) -> bool
| @return | | true if a snapshot-based chainstate | is in use. Also implies that a background | validation chainstate is also in use. |
sourcepub fn maybe_rebalance_caches(&mut self)
pub fn maybe_rebalance_caches(&mut self)
| Check to see if caches are out of balance | and if so, call ResizeCoinsCaches() | as needed. |