[−]Trait polymesh::service::Backend
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 BlockImportOperation
s: 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>
Associated block insertion operation type.
type Blockchain: Backend<Block>
Associated blockchain backend type.
type State: Send + Backend<<<Block as Block>::Header as Header>::Hashing>
Associated state backend type.
type OffchainStorage: OffchainStorage
Offchain workers local storage.
Required methods
pub 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.
pub fn begin_state_operation(
&self,
operation: &mut Self::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
&self,
operation: &mut Self::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
Note an operation to contain state transition.
pub fn commit_operation(
&self,
transaction: Self::BlockImportOperation
) -> Result<(), Error>
&self,
transaction: Self::BlockImportOperation
) -> Result<(), Error>
Commit block insertion.
pub fn finalize_block(
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
Finalize block with given Id.
This should only be called if the parent of the given block has been finalized.
pub fn blockchain(&self) -> &Self::Blockchain
Returns reference to blockchain backend.
pub fn usage_info(&self) -> Option<UsageInfo>
Returns current usage statistics.
pub fn changes_trie_storage(
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
Returns reference to changes trie storage.
pub fn offchain_storage(&self) -> Option<Self::OffchainStorage>
Returns a handle to offchain storage.
pub fn state_at(&self, block: BlockId<Block>) -> Result<Self::State, Error>
Returns state backend with post-state of given block.
pub 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, RandomState>), Error>
&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, RandomState>), 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.
Returns the number of blocks that were successfully reverted and the list of finalized blocks that has been reverted.
pub 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.
Provided methods
pub fn have_state_at(
&self,
hash: &<Block as Block>::Hash,
_number: <<Block as Block>::Header as Header>::Number
) -> bool
&self,
hash: &<Block as Block>::Hash,
_number: <<Block as Block>::Header as Header>::Number
) -> bool
Returns true if state for given block is available.
pub fn insert_aux<'a, 'b, 'c, I, D>(
&self,
insert: I,
delete: D
) -> Result<(), Error> where
'b: 'a,
'c: 'a,
D: IntoIterator<Item = &'a &'b [u8]>,
I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
&self,
insert: I,
delete: D
) -> Result<(), Error> where
'b: 'a,
'c: 'a,
D: IntoIterator<Item = &'a &'b [u8]>,
I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
Insert auxiliary data into key-value store.
pub fn get_aux(&self, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Error>
Query auxiliary data from key-value store.
Implementations on Foreign Types
impl<Block> Backend<Block> for Backend<Block> where
Block: Block,
<Block as Block>::Hash: Ord,
Block: Block,
<Block as Block>::Hash: Ord,
type BlockImportOperation = BlockImportOperation<Block>
type Blockchain = Blockchain<Block>
type State = TrieBackend<MemoryDB<<<Block as Block>::Header as Header>::Hashing, HashKey<<<Block as Block>::Header as Header>::Hashing>, Vec<u8, Global>, NoopTracker<Vec<u8, Global>>>, <<Block as Block>::Header as Header>::Hashing>
type OffchainStorage = InMemOffchainStorage
pub fn begin_operation(
&self
) -> Result<<Backend<Block> as Backend<Block>>::BlockImportOperation, Error>
&self
) -> Result<<Backend<Block> as Backend<Block>>::BlockImportOperation, Error>
pub fn begin_state_operation(
&self,
operation: &mut <Backend<Block> as Backend<Block>>::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
&self,
operation: &mut <Backend<Block> as Backend<Block>>::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
pub fn commit_operation(
&self,
operation: <Backend<Block> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
&self,
operation: <Backend<Block> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
pub fn finalize_block(
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
pub fn blockchain(&self) -> &<Backend<Block> as Backend<Block>>::Blockchain
pub fn usage_info(&self) -> Option<UsageInfo>
pub fn changes_trie_storage(
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
pub fn offchain_storage(
&self
) -> Option<<Backend<Block> as Backend<Block>>::OffchainStorage>
&self
) -> Option<<Backend<Block> as Backend<Block>>::OffchainStorage>
pub fn state_at(
&self,
block: BlockId<Block>
) -> Result<<Backend<Block> as Backend<Block>>::State, Error>
&self,
block: BlockId<Block>
) -> Result<<Backend<Block> as Backend<Block>>::State, Error>
pub 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, RandomState>), Error>
&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, RandomState>), Error>
pub fn get_import_lock(&self) -> &RwLock<RawRwLock, ()>
impl<Block> Backend<Block> for Backend<Block> where
Block: Block,
Block: Block,
type BlockImportOperation = BlockImportOperation<Block>
type Blockchain = BlockchainDb<Block>
type State = SyncingCachingState<RefTrackingState<Block>, Block>
type OffchainStorage = LocalStorage
pub fn begin_operation(
&self
) -> Result<<Backend<Block> as Backend<Block>>::BlockImportOperation, Error>
&self
) -> Result<<Backend<Block> as Backend<Block>>::BlockImportOperation, Error>
pub fn begin_state_operation(
&self,
operation: &mut <Backend<Block> as Backend<Block>>::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
&self,
operation: &mut <Backend<Block> as Backend<Block>>::BlockImportOperation,
block: BlockId<Block>
) -> Result<(), Error>
pub fn commit_operation(
&self,
operation: <Backend<Block> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
&self,
operation: <Backend<Block> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
pub fn finalize_block(
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
&self,
block: BlockId<Block>,
justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
pub fn changes_trie_storage(
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
pub fn offchain_storage(
&self
) -> Option<<Backend<Block> as Backend<Block>>::OffchainStorage>
&self
) -> Option<<Backend<Block> as Backend<Block>>::OffchainStorage>
pub fn usage_info(&self) -> Option<UsageInfo>
pub 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, RandomState>), Error>
&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, RandomState>), Error>
pub fn blockchain(&self) -> &BlockchainDb<Block>
pub fn state_at(
&self,
block: BlockId<Block>
) -> Result<<Backend<Block> as Backend<Block>>::State, Error>
&self,
block: BlockId<Block>
) -> Result<<Backend<Block> as Backend<Block>>::State, Error>
pub fn have_state_at(
&self,
hash: &<Block as Block>::Hash,
number: <<Block as Block>::Header as Header>::Number
) -> bool
&self,
hash: &<Block as Block>::Hash,
number: <<Block as Block>::Header as Header>::Number
) -> bool
pub fn get_import_lock(&self) -> &RwLock<RawRwLock, ()>
impl<S, Block> Backend<Block> for Backend<S, <<Block as Block>::Header as Header>::Hashing> where
Block: Block,
S: Storage<Block>,
<Block as Block>::Hash: Ord,
Block: Block,
S: Storage<Block>,
<Block as Block>::Hash: Ord,
type BlockImportOperation = ImportOperation<Block, S>
type Blockchain = Blockchain<S>
type State = GenesisOrUnavailableState<<<Block as Block>::Header as Header>::Hashing>
type OffchainStorage = InMemOffchainStorage
pub fn begin_operation(
&self
) -> Result<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation, Error>
&self
) -> Result<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation, Error>
pub fn begin_state_operation(
&self,
_operation: &mut <Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation,
_block: BlockId<Block>
) -> Result<(), Error>
&self,
_operation: &mut <Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation,
_block: BlockId<Block>
) -> Result<(), Error>
pub fn commit_operation(
&self,
operation: <Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
&self,
operation: <Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::BlockImportOperation
) -> Result<(), Error>
pub fn finalize_block(
&self,
block: BlockId<Block>,
_justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
&self,
block: BlockId<Block>,
_justification: Option<Vec<u8, Global>>
) -> Result<(), Error>
pub fn blockchain(&self) -> &Blockchain<S>
pub fn usage_info(&self) -> Option<UsageInfo>
pub fn changes_trie_storage(
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
&self
) -> Option<&dyn PrunableStateChangesTrieStorage<Block>>
pub fn offchain_storage(
&self
) -> Option<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::OffchainStorage>
&self
) -> Option<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::OffchainStorage>
pub fn state_at(
&self,
block: BlockId<Block>
) -> Result<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::State, Error>
&self,
block: BlockId<Block>
) -> Result<<Backend<S, <<Block as Block>::Header as Header>::Hashing> as Backend<Block>>::State, Error>
pub 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, RandomState>), Error>
&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, RandomState>), Error>