Trait polkadot_service::Backend

source ·
pub trait Backend<Block>: AuxStore + Send + Sync
where Block: Block,
{ type BlockImportOperation: BlockImportOperation<Block, State = Self::State>; type Blockchain: Backend<Block>; type State: Backend<<<Block as Block>::Header as Header>::Hashing> + Send + AsTrieBackend<<<Block as Block>::Header as Header>::Hashing, TrieBackendStorage = <Self::State as Backend<<<Block as Block>::Header as Header>::Hashing>>::TrieBackendStorage>; type OffchainStorage: OffchainStorage;
Show 18 methods // Required methods fn begin_operation(&self) -> Result<Self::BlockImportOperation, Error>; fn begin_state_operation( &self, operation: &mut Self::BlockImportOperation, block: <Block as Block>::Hash, ) -> Result<(), Error>; fn commit_operation( &self, transaction: Self::BlockImportOperation, ) -> Result<(), Error>; fn finalize_block( &self, hash: <Block as Block>::Hash, justification: Option<([u8; 4], Vec<u8>)>, ) -> Result<(), Error>; fn append_justification( &self, hash: <Block as Block>::Hash, justification: ([u8; 4], Vec<u8>), ) -> Result<(), Error>; fn blockchain(&self) -> &Self::Blockchain; fn usage_info(&self) -> Option<UsageInfo>; fn offchain_storage(&self) -> Option<Self::OffchainStorage>; fn pin_block(&self, hash: <Block as Block>::Hash) -> Result<(), Error>; fn unpin_block(&self, hash: <Block as Block>::Hash); fn state_at( &self, hash: <Block as Block>::Hash, ) -> Result<Self::State, Error>; fn revert( &self, n: <<Block as Block>::Header as Header>::Number, revert_finalized: bool, ) -> Result<(<<Block as Block>::Header as Header>::Number, HashSet<<Block as Block>::Hash>), Error>; fn remove_leaf_block( &self, hash: <Block as Block>::Hash, ) -> Result<(), Error>; fn get_import_lock(&self) -> &RwLock<RawRwLock, ()>; fn requires_full_sync(&self) -> bool; // Provided methods fn have_state_at( &self, hash: <Block as Block>::Hash, _number: <<Block as Block>::Header as Header>::Number, ) -> bool { ... } fn insert_aux<'a, 'b, 'c, I, D>( &self, insert: I, delete: D, ) -> Result<(), Error> where 'b: 'a, 'c: 'a, I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>, D: IntoIterator<Item = &'a &'b [u8]> { ... } fn get_aux(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error> { ... }
}
Expand description

Client backend.

Manages the data layer.

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

§Block Pruning

Users can pin blocks in memory by calling pin_block. When a block would be pruned, its value is kept in an in-memory cache until it is unpinned via unpin_block.

While a block is pinned, its state is also preserved.

The backend should internally reference count the number of pin / unpin calls.

Required Associated Types§

source

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

Associated block insertion operation type.

source

type Blockchain: Backend<Block>

Associated blockchain backend type.

source

type State: Backend<<<Block as Block>::Header as Header>::Hashing> + Send + AsTrieBackend<<<Block as Block>::Header as Header>::Hashing, TrieBackendStorage = <Self::State as Backend<<<Block as Block>::Header as Header>::Hashing>>::TrieBackendStorage>

Associated state backend type.

source

type OffchainStorage: OffchainStorage

Offchain workers local storage.

Required Methods§

source

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

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 as Block>::Hash, ) -> Result<(), Error>

Note an operation to contain state transition.

source

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

Commit block insertion.

source

fn finalize_block( &self, hash: <Block as Block>::Hash, justification: Option<([u8; 4], Vec<u8>)>, ) -> Result<(), Error>

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 as Block>::Hash, justification: ([u8; 4], Vec<u8>), ) -> Result<(), Error>

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 pin_block(&self, hash: <Block as Block>::Hash) -> Result<(), Error>

Pin the block to keep body, justification and state available after pruning. Number of pins are reference counted. Users need to make sure to perform one call to Self::unpin_block per call to Self::pin_block.

source

fn unpin_block(&self, hash: <Block as Block>::Hash)

Unpin the block to allow pruning.

source

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

Returns state backend with post-state of given block.

source

fn revert( &self, n: <<Block as Block>::Header as Header>::Number, revert_finalized: bool, ) -> Result<(<<Block as Block>::Header as Header>::Number, HashSet<<Block as Block>::Hash>), Error>

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 as Block>::Hash) -> Result<(), Error>

Discard non-best, unfinalized leaf block.

source

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

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 as Block>::Hash, _number: <<Block as Block>::Header as Header>::Number, ) -> bool

Returns true if state for given block is available.

source

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

Insert auxiliary data into key-value store.

source

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

Query auxiliary data from key-value store.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<Block> Backend<Block> for Backend<Block>
where Block: Block,

§

type BlockImportOperation = BlockImportOperation<Block>

§

type Blockchain = BlockchainDb<Block>

§

type State = RecordStatsState<RefTrackingState<Block>, Block>

§

type OffchainStorage = LocalStorage

source§

fn begin_operation( &self, ) -> Result<<Backend<Block> as Backend<Block>>::BlockImportOperation, Error>

source§

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

source§

fn commit_operation( &self, operation: <Backend<Block> as Backend<Block>>::BlockImportOperation, ) -> Result<(), Error>

source§

fn finalize_block( &self, hash: <Block as Block>::Hash, justification: Option<([u8; 4], Vec<u8>)>, ) -> Result<(), Error>

source§

fn append_justification( &self, hash: <Block as Block>::Hash, justification: ([u8; 4], Vec<u8>), ) -> Result<(), Error>

source§

fn offchain_storage( &self, ) -> Option<<Backend<Block> as Backend<Block>>::OffchainStorage>

source§

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

source§

fn revert( &self, n: <<Block as Block>::Header as Header>::Number, revert_finalized: bool, ) -> Result<(<<Block as Block>::Header as Header>::Number, HashSet<<Block as Block>::Hash>), Error>

source§

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

source§

fn blockchain(&self) -> &BlockchainDb<Block>

source§

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

source§

fn have_state_at( &self, hash: <Block as Block>::Hash, number: <<Block as Block>::Header as Header>::Number, ) -> bool

source§

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

source§

fn requires_full_sync(&self) -> bool

source§

fn pin_block(&self, hash: <Block as Block>::Hash) -> Result<(), Error>

source§

fn unpin_block(&self, hash: <Block as Block>::Hash)

Implementors§

source§

impl<Block> Backend<Block> for sc_client_api::in_mem::Backend<Block>
where Block: Block,

§

type BlockImportOperation = BlockImportOperation<Block>

§

type Blockchain = Blockchain<Block>

§

type State = TrieBackend<MemoryDB<<<Block as Block>::Header as Header>::Hashing, PrefixedKey<<<Block as Block>::Header as Header>::Hashing>, Vec<u8>>, <<Block as Block>::Header as Header>::Hashing>

§

type OffchainStorage = InMemOffchainStorage