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

source

pub fn active_chain(&self) -> &mut dyn ChainInterface

source

pub fn active_height(&self) -> i32

source

pub fn active_tip(&self) -> *mut BlockIndex

source

pub fn block_index(&mut self) -> &mut BlockMap

source

pub fn is_snapshot_validated(&self) -> bool

| Is there a snapshot in use and has it been | fully validated? |

source

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 |

source

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 |

source

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 |

source

pub fn snapshot_blockhash(&self) -> Option<u256>

source

pub fn get_all(&mut self) -> Vec<*mut dyn ChainStateInterface>

| Get all chainstates currently being | used. |

source

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. |

source

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().

source

pub fn populate_and_validate_snapshot( &mut self, snapshot_chainstate: &mut dyn ChainStateInterface, coins_file: &mut AutoFile, metadata: &SnapshotMetadata ) -> bool

| Internal helper for ActivateSnapshot(). |

source

pub fn active_chainstate(&self) -> &mut dyn ChainStateInterface

| The most-work chain. |

source

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. |

source

pub fn unload(&mut self)

| Unload block index and chain data before | shutdown. |

source

pub fn reset(&mut self)

| Clear (deconstruct) chainstate data. |

source

pub fn maybe_rebalance_caches(&mut self)

| Check to see if caches are out of balance | and if so, call ResizeCoinsCaches() | as needed. |

Trait Implementations§

source§

impl Drop for ChainstateManager

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, U> CastInto<U> for Twhere U: CastFrom<T>,

§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> StaticUpcast<T> for T

§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V