referrerpolicy=no-referrer-when-downgrade

StateBackend

Trait StateBackend 

pub trait StateBackend<H>: Debug
where H: Hasher,
{ type Error: Error; type TrieBackendStorage: TrieBackendStorage<H>; type RawIter: StorageIterator<H, Backend = Self, Error = Self::Error>;
Show 29 methods // Required methods fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>; fn storage_hash( &self, key: &[u8], ) -> Result<Option<<H as Hasher>::Out>, Self::Error>; fn closest_merkle_value( &self, key: &[u8], ) -> Result<Option<MerkleValue<<H as Hasher>::Out>>, Self::Error>; fn child_closest_merkle_value( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<MerkleValue<<H as Hasher>::Out>>, Self::Error>; fn child_storage( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<Vec<u8>>, 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>>, Self::Error>; fn next_child_storage_key( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>; fn storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, state_version: StateVersion, ) -> (<H as Hasher>::Out, MemoryDB<H, PrefixedKey<H>, Vec<u8>>) 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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>) where <H as Hasher>::Out: Ord; fn record_proof_for_dirty_keys<'a>( &self, delta: impl Iterator<Item = (&'a [u8], DeltaKeyOp)>, estimation_trie: &mut Option<EstimationTrie<H>>, state_version: StateVersion, ) where <H as Hasher>::Out: Ord; fn record_proof_for_child_dirty_keys<'a>( &self, child_info: &ChildInfo, delta: impl Iterator<Item = (&'a [u8], DeltaKeyOp)>, estimation_trie: &mut Option<EstimationTrie<H>>, state_version: StateVersion, ) where <H as Hasher>::Out: Ord; fn raw_iter(&self, args: IterArgs<'_>) -> Result<Self::RawIter, Self::Error>; 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 pairs<'a>( &'a self, args: IterArgs<'_>, ) -> Result<PairsIter<'a, H, Self::RawIter>, Self::Error> { ... } fn keys<'a>( &'a self, args: IterArgs<'_>, ) -> Result<KeysIter<'a, H, Self::RawIter>, Self::Error> { ... } 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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>) where <H as Hasher>::Out: Ord + Encode { ... } fn full_storage_root_with_child_roots<'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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>, BTreeMap<Vec<u8>, <H as Hasher>::Out>) where <H as Hasher>::Out: Ord + Encode { ... } fn wipe(&self) -> Result<(), Self::Error> { ... } fn commit( &self, _: <H as Hasher>::Out, _: MemoryDB<H, PrefixedKey<H>, Vec<u8>>, _: Vec<(Vec<u8>, Option<Vec<u8>>)>, _: Vec<(Vec<u8>, Vec<(Vec<u8>, Option<Vec<u8>>)>)>, ) -> Result<(), Self::Error> { ... } fn read_write_count(&self) -> (u32, u32, u32, u32) { ... } fn reset_read_write_count(&self) { ... } fn get_whitelist(&self) -> Vec<TrackedStorageKey> { ... } fn set_whitelist(&self, _: Vec<TrackedStorageKey>) { ... } fn proof_size(&self) -> Option<u32> { ... } fn get_read_and_written_keys(&self) -> Vec<(Vec<u8>, u32, u32, bool)> { ... }
}
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§

type Error: Error

An error type when fetching data is not possible.

type TrieBackendStorage: TrieBackendStorage<H>

Type of trie backend storage.

type RawIter: StorageIterator<H, Backend = Self, Error = Self::Error>

Type of the raw storage iterator.

Required Methods§

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

Get keyed storage or None if there is nothing associated.

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.

fn closest_merkle_value( &self, key: &[u8], ) -> Result<Option<MerkleValue<<H as Hasher>::Out>>, Self::Error>

Get the merkle value or None if there is nothing associated.

fn child_closest_merkle_value( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<MerkleValue<<H as Hasher>::Out>>, Self::Error>

Get the child merkle value or None if there is nothing associated.

fn child_storage( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>

Get child keyed child storage or None if there is nothing associated.

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.

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

Return the next key in storage in lexicographic order or None if there is no value.

fn next_child_storage_key( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>

Return the next key in child storage in lexicographic order or None if there is no value.

fn storage_root<'a>( &self, delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>, state_version: StateVersion, ) -> (<H as Hasher>::Out, MemoryDB<H, PrefixedKey<H>, Vec<u8>>)
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.

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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>)
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.

fn record_proof_for_dirty_keys<'a>( &self, delta: impl Iterator<Item = (&'a [u8], DeltaKeyOp)>, estimation_trie: &mut Option<EstimationTrie<H>>, state_version: StateVersion, )
where <H as Hasher>::Out: Ord,

Updates the recorder’s proof size by recording trie nodes for a given delta.

Does not include child storage updates. The estimation_trie carries the removals of earlier calls, see [EstimationTrie].

fn record_proof_for_child_dirty_keys<'a>( &self, child_info: &ChildInfo, delta: impl Iterator<Item = (&'a [u8], DeltaKeyOp)>, estimation_trie: &mut Option<EstimationTrie<H>>, state_version: StateVersion, )
where <H as Hasher>::Out: Ord,

Updates the recorder’s proof size by recording child trie nodes for a given delta.

fn raw_iter(&self, args: IterArgs<'_>) -> Result<Self::RawIter, Self::Error>

Returns a lifetimeless raw storage iterator.

fn register_overlay_stats(&self, _stats: &StateMachineStats)

Register stats from overlay of state machine.

By default nothing is registered.

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§

fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error>

true if a key exists in storage.

fn exists_child_storage( &self, child_info: &ChildInfo, key: &[u8], ) -> Result<bool, Self::Error>

true if a key exists in child storage.

fn pairs<'a>( &'a self, args: IterArgs<'_>, ) -> Result<PairsIter<'a, H, Self::RawIter>, Self::Error>

Get an iterator over key/value pairs.

fn keys<'a>( &'a self, args: IterArgs<'_>, ) -> Result<KeysIter<'a, H, Self::RawIter>, Self::Error>

Get an iterator over keys.

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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>)
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.

fn full_storage_root_with_child_roots<'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, MemoryDB<H, PrefixedKey<H>, Vec<u8>>, BTreeMap<Vec<u8>, <H as Hasher>::Out>)
where <H as Hasher>::Out: Ord + Encode,

Like Self::full_storage_root, but also returns the root of every child trie in child_deltas, keyed by its storage key.

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

Wipe the state database.

fn commit( &self, _: <H as Hasher>::Out, _: MemoryDB<H, PrefixedKey<H>, Vec<u8>>, _: Vec<(Vec<u8>, Option<Vec<u8>>)>, _: Vec<(Vec<u8>, Vec<(Vec<u8>, Option<Vec<u8>>)>)>, ) -> Result<(), Self::Error>

Commit given transaction to storage.

fn read_write_count(&self) -> (u32, u32, u32, u32)

Get the read/write count of the db

fn reset_read_write_count(&self)

Get the read/write count of the db

fn get_whitelist(&self) -> Vec<TrackedStorageKey>

Get the whitelist for tracking db reads/writes

fn set_whitelist(&self, _: Vec<TrackedStorageKey>)

Update the whitelist for tracking db reads/writes

fn proof_size(&self) -> Option<u32>

Estimate proof size

fn get_read_and_written_keys(&self) -> Vec<(Vec<u8>, u32, u32, bool)>

Extend storage info for benchmarking db

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<S, H, C, R> Backend<H> for TrieBackend<S, H, C, R>
where S: TrieBackendStorage<H>, H: Hasher, C: TrieCacheProvider<H> + Send + Sync, R: TrieRecorderProvider<H> + Send + Sync, <H as Hasher>::Out: Ord + Codec,

§

type Error = String

§

type TrieBackendStorage = S

§

type RawIter = RawIter<S, H, C, R>