pub trait Cache {
    // Required methods
    fn look_up(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader>;
    fn block_connected(
        &mut self,
        block_hash: BlockHash,
        block_header: ValidatedBlockHeader
    );
    fn block_disconnected(
        &mut self,
        block_hash: &BlockHash
    ) -> Option<ValidatedBlockHeader>;
}
Expand description

The Cache trait defines behavior for managing a block header cache, where block headers are keyed by block hash.

Used by ChainNotifier to store headers along the best chain, which is important for ensuring that blocks can be disconnected if they are no longer accessible from a block source (e.g., if the block source does not store stale forks indefinitely).

Implementations may define how long to retain headers such that it’s unlikely they will ever be needed to disconnect a block. In cases where block sources provide access to headers on stale forks reliably, caches may be entirely unnecessary.

Required Methods§

source

fn look_up(&self, block_hash: &BlockHash) -> Option<&ValidatedBlockHeader>

Retrieves the block header keyed by the given block hash.

source

fn block_connected( &mut self, block_hash: BlockHash, block_header: ValidatedBlockHeader )

Called when a block has been connected to the best chain to ensure it is available to be disconnected later if needed.

source

fn block_disconnected( &mut self, block_hash: &BlockHash ) -> Option<ValidatedBlockHeader>

Called when a block has been disconnected from the best chain. Once disconnected, a block’s header is no longer needed and thus can be removed.

Implementors§