pub trait UpdatableChainstate {
    // Required methods
    fn connect_block(
        &self,
        block: &Block,
        proof: Proof,
        inputs: HashMap<OutPoint, TxOut>,
        del_hashes: Vec<Hash>
    ) -> Result<u32, BlockchainError>;
    fn switch_chain(&self, new_tip: BlockHash) -> Result<(), BlockchainError>;
    fn accept_header(&self, header: BlockHeader) -> Result<(), BlockchainError>;
    fn handle_transaction(&self) -> Result<(), BlockchainError>;
    fn flush(&self) -> Result<(), BlockchainError>;
    fn toggle_ibd(&self, is_ibd: bool);
    fn invalidate_block(&self, block: BlockHash) -> Result<(), BlockchainError>;
    fn mark_block_as_valid(
        &self,
        block: BlockHash
    ) -> Result<(), BlockchainError>;
    fn process_rescan_block(&self, block: &Block) -> Result<(), BlockchainError>;
    fn get_root_hashes(&self) -> Vec<NodeHash>;
    fn get_partial_chain(
        &self,
        initial_height: u32,
        final_height: u32,
        acc: Stump
    ) -> Result<PartialChainState, BlockchainError>;
    fn mark_chain_as_assumed(
        &self,
        acc: Stump,
        tip: BlockHash
    ) -> Result<bool, BlockchainError>;
}
Expand description

UpdatableChainstate is a contract that a is expected from a chainstate implementation, that wishes to be updated. Using those methods, a backend like the p2p-node, can notify new blocks and transactions to a chainstate, allowing it to update it’s state.

Required Methods§

source

fn connect_block( &self, block: &Block, proof: Proof, inputs: HashMap<OutPoint, TxOut>, del_hashes: Vec<Hash> ) -> Result<u32, BlockchainError>

This is one of the most important methods for a ChainState, it gets a block and some utreexo data, validates this block and connects to our chain of blocks. This function is meant to be atomic and prone of running in parallel.

source

fn switch_chain(&self, new_tip: BlockHash) -> Result<(), BlockchainError>

source

fn accept_header(&self, header: BlockHeader) -> Result<(), BlockchainError>

Accepts a new header to our chain. This method is called before connect_block, and makes some basic checks on a header and saves it on disk. We only accept a block as valid after calling connect_block.

This function returns whether this block is on our best-known chain, or in a fork

source

fn handle_transaction(&self) -> Result<(), BlockchainError>

Not used for now, but in a future blockchain with mempool, we can process transactions that are not in a block yet.

source

fn flush(&self) -> Result<(), BlockchainError>

Persists our data. Should be invoked periodically.

source

fn toggle_ibd(&self, is_ibd: bool)

Toggle ibd on/off

source

fn invalidate_block(&self, block: BlockHash) -> Result<(), BlockchainError>

Tells this blockchain to consider this block invalid, and not build on top of it

source

fn mark_block_as_valid(&self, block: BlockHash) -> Result<(), BlockchainError>

Marks one block as being fully validated, this overrides a block that was explicitly marked as invalid.

source

fn process_rescan_block(&self, block: &Block) -> Result<(), BlockchainError>

Gives a requested block for rescan

source

fn get_root_hashes(&self) -> Vec<NodeHash>

Returns the root hashes of our utreexo forest

source

fn get_partial_chain( &self, initial_height: u32, final_height: u32, acc: Stump ) -> Result<PartialChainState, BlockchainError>

Returns a partial chainstate from a range of blocks.

PartialChainState is a simplified version of ChainState that is used during IBD. It doesn’t suport reorgs, only hold headers for a subset of blocks and isn’t Sync. The idea here is that you take a OS thread or some async task that will drive one PartialChainState to completion by downloading blocks inside that chainstate’s range. If all goes right, it’ll end without error, and you should mark blocks in this range as valid.

Since this chainstate may start from a height with an existing UTXO set, you need to provide a Stump for that block.

source

fn mark_chain_as_assumed( &self, acc: Stump, tip: BlockHash ) -> Result<bool, BlockchainError>

Marks a chain as fully-valid

This mimics the behavour of checking every block before this block, and continues from this point

Implementations on Foreign Types§

source§

impl<T: UpdatableChainstate> UpdatableChainstate for Arc<T>

Implementors§