Trait sc_client_api::backend::StateBackend
source · pub trait StateBackend<H>: Debugwhere
H: Hasher,{
type Error: Error;
type Transaction: Consolidate + Default + Send;
type TrieBackendStorage: TrieBackendStorage<H, Overlay = Self::Transaction>;
Show 29 methods
// Required methods
fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Self::Error>;
fn storage_hash(
&self,
key: &[u8]
) -> Result<Option<<H as Hasher>::Out>, Self::Error>;
fn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>;
fn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<<H as Hasher>::Out>, Self::Error>;
fn next_storage_key(
&self,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>;
fn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>;
fn apply_to_key_values_while<F>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F,
allow_missing: bool
) -> Result<bool, Self::Error>
where F: FnMut(Vec<u8, Global>, Vec<u8, Global>) -> bool;
fn apply_to_keys_while<F>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F
)
where F: FnMut(&[u8]) -> bool;
fn for_key_values_with_prefix<F>(&self, prefix: &[u8], f: F)
where F: FnMut(&[u8], &[u8]);
fn for_child_keys_with_prefix<F>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F
)
where F: FnMut(&[u8]);
fn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, Self::Transaction)
where <H as Hasher>::Out: Ord;
fn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, bool, Self::Transaction)
where <H as Hasher>::Out: Ord;
fn pairs(&self) -> Vec<(Vec<u8, Global>, Vec<u8, Global>), Global> ⓘ;
fn register_overlay_stats(&self, _stats: &StateMachineStats);
fn usage_info(&self) -> UsageInfo;
// Provided methods
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> { ... }
fn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<bool, Self::Error> { ... }
fn for_keys_with_prefix<F>(&self, prefix: &[u8], f: F)
where F: FnMut(&[u8]) { ... }
fn keys(&self, prefix: &[u8]) -> Vec<Vec<u8, Global>, Global> ⓘ { ... }
fn child_keys(
&self,
child_info: &ChildInfo,
prefix: &[u8]
) -> Vec<Vec<u8, Global>, Global> ⓘ { ... }
fn full_storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, Self::Transaction)
where <H as Hasher>::Out: Ord + Encode { ... }
fn wipe(&self) -> Result<(), Self::Error> { ... }
fn commit(
&self,
_: <H as Hasher>::Out,
_: Self::Transaction,
_: Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>,
_: Vec<(Vec<u8, Global>, Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>), Global>
) -> Result<(), Self::Error> { ... }
fn read_write_count(&self) -> (u32, u32, u32, u32) { ... }
fn reset_read_write_count(&self) { ... }
fn get_whitelist(&self) -> Vec<TrackedStorageKey, Global> ⓘ { ... }
fn set_whitelist(&self, _: Vec<TrackedStorageKey, Global>) { ... }
fn proof_size(&self) -> Option<u32> { ... }
fn get_read_and_written_keys(
&self
) -> Vec<(Vec<u8, Global>, u32, u32, bool), Global> ⓘ { ... }
}
Expand description
A state backend is used to read state data and can have changes committed to it.
The clone operation (if implemented) should be cheap.
Required Associated Types§
sourcetype Transaction: Consolidate + Default + Send
type Transaction: Consolidate + Default + Send
Storage changes to be applied if committing
sourcetype TrieBackendStorage: TrieBackendStorage<H, Overlay = Self::Transaction>
type TrieBackendStorage: TrieBackendStorage<H, Overlay = Self::Transaction>
Type of trie backend storage.
Required Methods§
sourcefn storage(&self, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Self::Error>
fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Self::Error>
Get keyed storage or None if there is nothing associated.
sourcefn storage_hash(
&self,
key: &[u8]
) -> Result<Option<<H as Hasher>::Out>, Self::Error>
fn storage_hash( &self, key: &[u8] ) -> Result<Option<<H as Hasher>::Out>, Self::Error>
Get keyed storage value hash or None if there is nothing associated.
sourcefn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>
fn child_storage( &self, child_info: &ChildInfo, key: &[u8] ) -> Result<Option<Vec<u8, Global>>, Self::Error>
Get keyed child storage or None if there is nothing associated.
sourcefn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<<H as Hasher>::Out>, Self::Error>
fn child_storage_hash( &self, child_info: &ChildInfo, key: &[u8] ) -> Result<Option<<H as Hasher>::Out>, Self::Error>
Get child keyed storage value hash or None if there is nothing associated.
sourcefn next_storage_key(
&self,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>
fn next_storage_key( &self, key: &[u8] ) -> Result<Option<Vec<u8, Global>>, Self::Error>
Return the next key in storage in lexicographic order or None
if there is no value.
sourcefn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Self::Error>
fn next_child_storage_key( &self, child_info: &ChildInfo, key: &[u8] ) -> Result<Option<Vec<u8, Global>>, Self::Error>
Return the next key in child storage in lexicographic order or None
if there is no value.
sourcefn apply_to_key_values_while<F>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F,
allow_missing: bool
) -> Result<bool, Self::Error>where
F: FnMut(Vec<u8, Global>, Vec<u8, Global>) -> bool,
fn apply_to_key_values_while<F>( &self, child_info: Option<&ChildInfo>, prefix: Option<&[u8]>, start_at: Option<&[u8]>, f: F, allow_missing: bool ) -> Result<bool, Self::Error>where F: FnMut(Vec<u8, Global>, Vec<u8, Global>) -> bool,
Iterate over storage starting at key, for a given prefix and child trie.
Aborts as soon as f
returns false.
Warning, this fails at first error when usual iteration skips errors.
If allow_missing
is true, iteration stops when it reaches a missing trie node.
Otherwise an error is produced.
Returns true
if trie end is reached.
sourcefn apply_to_keys_while<F>(
&self,
child_info: Option<&ChildInfo>,
prefix: Option<&[u8]>,
start_at: Option<&[u8]>,
f: F
)where
F: FnMut(&[u8]) -> bool,
fn apply_to_keys_while<F>( &self, child_info: Option<&ChildInfo>, prefix: Option<&[u8]>, start_at: Option<&[u8]>, f: F )where F: FnMut(&[u8]) -> bool,
Retrieve all entries keys of storage and call f
for each of those keys.
Aborts as soon as f
returns false.
sourcefn for_key_values_with_prefix<F>(&self, prefix: &[u8], f: F)where
F: FnMut(&[u8], &[u8]),
fn for_key_values_with_prefix<F>(&self, prefix: &[u8], f: F)where F: FnMut(&[u8], &[u8]),
Retrieve all entries keys and values of which start with the given prefix and
call f
for each of those keys.
sourcefn for_child_keys_with_prefix<F>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F
)where
F: FnMut(&[u8]),
fn for_child_keys_with_prefix<F>( &self, child_info: &ChildInfo, prefix: &[u8], f: F )where F: FnMut(&[u8]),
Retrieve all child entries keys which start with the given prefix and
call f
for each of those keys.
sourcefn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, Self::Transaction)where
<H as Hasher>::Out: Ord,
fn storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, state_version: StateVersion ) -> (<H as Hasher>::Out, Self::Transaction)where <H as Hasher>::Out: Ord,
Calculate the storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. Does not include child storage updates.
sourcefn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, bool, Self::Transaction)where
<H as Hasher>::Out: Ord,
fn child_storage_root<'a>( &self, child_info: &ChildInfo, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, state_version: StateVersion ) -> (<H as Hasher>::Out, bool, Self::Transaction)where <H as Hasher>::Out: Ord,
Calculate the child storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. The second argument is true if child storage root equals default storage root.
sourcefn pairs(&self) -> Vec<(Vec<u8, Global>, Vec<u8, Global>), Global> ⓘ
fn pairs(&self) -> Vec<(Vec<u8, Global>, Vec<u8, Global>), Global> ⓘ
Get all key/value pairs into a Vec.
sourcefn register_overlay_stats(&self, _stats: &StateMachineStats)
fn register_overlay_stats(&self, _stats: &StateMachineStats)
Register stats from overlay of state machine.
By default nothing is registered.
sourcefn usage_info(&self) -> UsageInfo
fn usage_info(&self) -> UsageInfo
Query backend usage statistics (i/o, memory)
Not all implementations are expected to be able to do this. In the case when they don’t, empty statistics is returned.
Provided Methods§
sourcefn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error>
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error>
true if a key exists in storage.
sourcefn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8]
) -> Result<bool, Self::Error>
fn exists_child_storage( &self, child_info: &ChildInfo, key: &[u8] ) -> Result<bool, Self::Error>
true if a key exists in child storage.
sourcefn for_keys_with_prefix<F>(&self, prefix: &[u8], f: F)where
F: FnMut(&[u8]),
fn for_keys_with_prefix<F>(&self, prefix: &[u8], f: F)where F: FnMut(&[u8]),
Retrieve all entries keys which start with the given prefix and
call f
for each of those keys.
sourcefn child_keys(
&self,
child_info: &ChildInfo,
prefix: &[u8]
) -> Vec<Vec<u8, Global>, Global> ⓘ
fn child_keys( &self, child_info: &ChildInfo, prefix: &[u8] ) -> Vec<Vec<u8, Global>, Global> ⓘ
Get all keys of child storage with given prefix
sourcefn full_storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>,
state_version: StateVersion
) -> (<H as Hasher>::Out, Self::Transaction)where
<H as Hasher>::Out: Ord + Encode,
fn full_storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, child_deltas: impl Iterator<Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>)>, state_version: StateVersion ) -> (<H as Hasher>::Out, Self::Transaction)where <H as Hasher>::Out: Ord + Encode,
Calculate the storage root, with given delta over what is already stored in the backend, and produce a “transaction” that can be used to commit. Does include child storage updates.
sourcefn commit(
&self,
_: <H as Hasher>::Out,
_: Self::Transaction,
_: Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>,
_: Vec<(Vec<u8, Global>, Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>), Global>
) -> Result<(), Self::Error>
fn commit( &self, _: <H as Hasher>::Out, _: Self::Transaction, _: Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>, _: Vec<(Vec<u8, Global>, Vec<(Vec<u8, Global>, Option<Vec<u8, Global>>), Global>), Global> ) -> Result<(), Self::Error>
Commit given transaction to storage.
sourcefn reset_read_write_count(&self)
fn reset_read_write_count(&self)
Get the read/write count of the db
sourcefn get_whitelist(&self) -> Vec<TrackedStorageKey, Global> ⓘ
fn get_whitelist(&self) -> Vec<TrackedStorageKey, Global> ⓘ
Get the whitelist for tracking db reads/writes
sourcefn set_whitelist(&self, _: Vec<TrackedStorageKey, Global>)
fn set_whitelist(&self, _: Vec<TrackedStorageKey, Global>)
Update the whitelist for tracking db reads/writes
sourcefn proof_size(&self) -> Option<u32>
fn proof_size(&self) -> Option<u32>
Estimate proof size