[][src]Trait substrate_client::backend::Backend

pub trait Backend<Block, H>: AuxStore + Send + Sync where
    Block: BlockT,
    H: Hasher<Out = Block::Hash>, 
{ type BlockImportOperation: BlockImportOperation<Block, H, State = Self::State>; type Blockchain: Backend<Block>; type State: StateBackend<H>; type ChangesTrieStorage: PrunableStateChangesTrieStorage<Block, H>; type OffchainStorage: OffchainStorage; fn begin_operation(&self) -> Result<Self::BlockImportOperation>;
fn begin_state_operation(
        &self,
        operation: &mut Self::BlockImportOperation,
        block: BlockId<Block>
    ) -> Result<()>;
fn commit_operation(
        &self,
        transaction: Self::BlockImportOperation
    ) -> Result<()>;
fn finalize_block(
        &self,
        block: BlockId<Block>,
        justification: Option<Justification>
    ) -> Result<()>;
fn blockchain(&self) -> &Self::Blockchain;
fn used_state_cache_size(&self) -> Option<usize>;
fn changes_trie_storage(&self) -> Option<&Self::ChangesTrieStorage>;
fn offchain_storage(&self) -> Option<Self::OffchainStorage>;
fn state_at(&self, block: BlockId<Block>) -> Result<Self::State>;
fn revert(&self, n: NumberFor<Block>) -> Result<NumberFor<Block>>;
fn get_import_lock(&self) -> &Mutex<()>; fn have_state_at(
        &self,
        hash: &Block::Hash,
        _number: NumberFor<Block>
    ) -> bool { ... }
fn destroy_state(&self, _state: Self::State) -> Result<()> { ... }
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>>> { ... } }

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.

Associated Types

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

Associated block insertion operation type.

type Blockchain: Backend<Block>

Associated blockchain backend type.

type State: StateBackend<H>

Associated state backend type.

type ChangesTrieStorage: PrunableStateChangesTrieStorage<Block, H>

Changes trie storage.

type OffchainStorage: OffchainStorage

Offchain workers local storage.

Loading content...

Required methods

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.

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

Note an operation to contain state transition.

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

Commit block insertion.

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

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

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

Returns reference to blockchain backend.

fn used_state_cache_size(&self) -> Option<usize>

Returns the used state cache, if existent.

fn changes_trie_storage(&self) -> Option<&Self::ChangesTrieStorage>

Returns reference to changes trie storage.

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

Returns a handle to offchain storage.

fn state_at(&self, block: BlockId<Block>) -> Result<Self::State>

Returns state backend with post-state of given block.

fn revert(&self, n: NumberFor<Block>) -> Result<NumberFor<Block>>

Attempts to revert the chain by n blocks. Returns the number of blocks that were successfully reverted.

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

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.

Loading content...

Provided methods

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

Returns true if state for given block is available.

fn destroy_state(&self, _state: Self::State) -> Result<()>

Destroy state and save any useful data, such as cache.

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.

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

Query auxiliary data from key-value store.

Loading content...

Implementors

impl<Block, H> Backend<Block, H> for substrate_client::in_mem::Backend<Block, H> where
    Block: BlockT,
    H: Hasher<Out = Block::Hash>,
    H::Out: Ord
[src]

type BlockImportOperation = BlockImportOperation<Block, H>

type Blockchain = Blockchain<Block>

type State = InMemory<H>

type ChangesTrieStorage = ChangesTrieStorage<Block, H>

type OffchainStorage = OffchainStorage

impl<S, Block, H> Backend<Block, H> for substrate_client::light::backend::Backend<S, H> where
    Block: BlockT,
    S: BlockchainStorage<Block>,
    H: Hasher<Out = Block::Hash>,
    H::Out: Ord
[src]

type BlockImportOperation = ImportOperation<Block, S, H>

type Blockchain = Blockchain<S>

type State = GenesisOrUnavailableState<H>

type ChangesTrieStorage = ChangesTrieStorage<Block, H>

type OffchainStorage = OffchainStorage

Loading content...