pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
    type BlockImportOperation: BlockImportOperation<Block, State = Self::State>;
    type Blockchain: BlockchainBackend<Block>;
    type State: StateBackend<HashFor<Block>> + Send + AsTrieBackend<HashFor<Block>, TrieBackendStorage = <Self::State as StateBackend<HashFor<Block>>>::TrieBackendStorage>;
    type OffchainStorage: OffchainStorage;

Show 16 methods // Required methods fn begin_operation(&self) -> Result<Self::BlockImportOperation>; fn begin_state_operation( &self, operation: &mut Self::BlockImportOperation, block: Block::Hash ) -> Result<()>; fn commit_operation( &self, transaction: Self::BlockImportOperation ) -> Result<()>; fn finalize_block( &self, hash: Block::Hash, justification: Option<Justification> ) -> Result<()>; fn append_justification( &self, hash: Block::Hash, justification: Justification ) -> Result<()>; fn blockchain(&self) -> &Self::Blockchain; fn usage_info(&self) -> Option<UsageInfo>; fn offchain_storage(&self) -> Option<Self::OffchainStorage>; fn state_at(&self, hash: Block::Hash) -> Result<Self::State>; fn revert( &self, n: NumberFor<Block>, revert_finalized: bool ) -> Result<(NumberFor<Block>, HashSet<Block::Hash>)>; fn remove_leaf_block(&self, hash: Block::Hash) -> Result<()>; fn get_import_lock(&self) -> &RwLock<()>; fn requires_full_sync(&self) -> bool; // Provided methods fn have_state_at( &self, hash: Block::Hash, _number: NumberFor<Block> ) -> bool { ... } fn insert_aux<'a, 'b: 'a, 'c: 'a, I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]>>( &self, insert: I, delete: D ) -> Result<()> { ... } fn get_aux(&self, key: &[u8]) -> Result<Option<Vec<u8>>> { ... }
}
Expand description

Client backend.

Manages the data layer.

Note on state pruning: while an object from state_at is alive, the state should not be pruned. The backend should internally reference-count its state objects.

The same applies for live BlockImportOperations: while an import operation building on a parent P is alive, the state for P should not be pruned.

Required Associated Types§

source

type BlockImportOperation: BlockImportOperation<Block, State = Self::State>

Associated block insertion operation type.

source

type Blockchain: BlockchainBackend<Block>

Associated blockchain backend type.

source

type State: StateBackend<HashFor<Block>> + Send + AsTrieBackend<HashFor<Block>, TrieBackendStorage = <Self::State as StateBackend<HashFor<Block>>>::TrieBackendStorage>

Associated state backend type.

source

type OffchainStorage: OffchainStorage

Offchain workers local storage.

Required Methods§

source

fn begin_operation(&self) -> Result<Self::BlockImportOperation>

Begin a new block insertion transaction with given parent block id.

When constructing the genesis, this is called with all-zero hash.

source

fn begin_state_operation( &self, operation: &mut Self::BlockImportOperation, block: Block::Hash ) -> Result<()>

Note an operation to contain state transition.

source

fn commit_operation( &self, transaction: Self::BlockImportOperation ) -> Result<()>

Commit block insertion.

source

fn finalize_block( &self, hash: Block::Hash, justification: Option<Justification> ) -> Result<()>

Finalize block with given hash.

This should only be called if the parent of the given block has been finalized.

source

fn append_justification( &self, hash: Block::Hash, justification: Justification ) -> Result<()>

Append justification to the block with the given hash.

This should only be called for blocks that are already finalized.

source

fn blockchain(&self) -> &Self::Blockchain

Returns reference to blockchain backend.

source

fn usage_info(&self) -> Option<UsageInfo>

Returns current usage statistics.

source

fn offchain_storage(&self) -> Option<Self::OffchainStorage>

Returns a handle to offchain storage.

source

fn state_at(&self, hash: Block::Hash) -> Result<Self::State>

Returns state backend with post-state of given block.

source

fn revert( &self, n: NumberFor<Block>, revert_finalized: bool ) -> Result<(NumberFor<Block>, HashSet<Block::Hash>)>

Attempts to revert the chain by n blocks. If revert_finalized is set it will attempt to revert past any finalized block, this is unsafe and can potentially leave the node in an inconsistent state. All blocks higher than the best block are also reverted and not counting towards n.

Returns the number of blocks that were successfully reverted and the list of finalized blocks that has been reverted.

source

fn remove_leaf_block(&self, hash: Block::Hash) -> Result<()>

Discard non-best, unfinalized leaf block.

source

fn get_import_lock(&self) -> &RwLock<()>

Gain access to the import lock around this backend.

Note Backend isn’t expected to acquire the lock by itself ever. Rather the using components should acquire and hold the lock whenever they do something that the import of a block would interfere with, e.g. importing a new block or calculating the best head.

source

fn requires_full_sync(&self) -> bool

Tells whether the backend requires full-sync mode.

Provided Methods§

source

fn have_state_at(&self, hash: Block::Hash, _number: NumberFor<Block>) -> bool

Returns true if state for given block is available.

source

fn insert_aux<'a, 'b: 'a, 'c: 'a, I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]>>( &self, insert: I, delete: D ) -> Result<()>

Insert auxiliary data into key-value store.

source

fn get_aux(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Query auxiliary data from key-value store.

Implementors§

source§

impl<Block: BlockT> Backend<Block> for Backend<Block>where Block::Hash: Ord,