pub trait Storage: Clone {
    type Witness: Witness;
    type RuntimeConfig;
    type Proof: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize;
    type StateUpdate;

    // Required methods
    fn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>;
    fn get(
        &self,
        key: &StorageKey,
        witness: &Self::Witness
    ) -> Option<StorageValue>;
    fn get_state_root(&self, witness: &Self::Witness) -> Result<[u8; 32]>;
    fn compute_state_update(
        &self,
        state_accesses: OrderedReadsAndWrites,
        witness: &Self::Witness
    ) -> Result<([u8; 32], Self::StateUpdate), Error>;
    fn commit(
        &self,
        node_batch: &Self::StateUpdate,
        accessory_update: &OrderedReadsAndWrites
    );
    fn open_proof(
        &self,
        state_root: [u8; 32],
        proof: StorageProof<Self::Proof>
    ) -> Result<(StorageKey, Option<StorageValue>), Error>;
    fn is_empty(&self) -> bool;

    // Provided methods
    fn get_accessory(&self, _key: &StorageKey) -> Option<StorageValue> { ... }
    fn validate_and_commit(
        &self,
        state_accesses: OrderedReadsAndWrites,
        witness: &Self::Witness
    ) -> Result<[u8; 32], Error> { ... }
    fn validate_and_commit_with_accessory_update(
        &self,
        state_accesses: OrderedReadsAndWrites,
        witness: &Self::Witness,
        accessory_update: &OrderedReadsAndWrites
    ) -> Result<[u8; 32], Error> { ... }
    fn verify_proof<K, V, Codec>(
        &self,
        state_root: [u8; 32],
        proof: StorageProof<Self::Proof>,
        expected_key: &K,
        storage_map: &StateMap<K, V, Codec>
    ) -> Result<Option<StorageValue>, Error>
       where Codec: StateKeyCodec<K> { ... }
}
Expand description

An interface for storing and retrieving values in the storage.

Required Associated Types§

source

type Witness: Witness

The witness type for this storage instance.

source

type RuntimeConfig

The runtime config for this storage instance.

source

type Proof: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize

A cryptographic proof that a particular key has a particular value, or is absent.

source

type StateUpdate

State update that will be committed to the database.

Required Methods§

source

fn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>

source

fn get(&self, key: &StorageKey, witness: &Self::Witness) -> Option<StorageValue>

Returns the value corresponding to the key or None if key is absent.

source

fn get_state_root(&self, witness: &Self::Witness) -> Result<[u8; 32]>

Returns the latest state root hash from the storage.

source

fn compute_state_update( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness ) -> Result<([u8; 32], Self::StateUpdate), Error>

Calculates new state root but does not commit any changes to the database.

source

fn commit( &self, node_batch: &Self::StateUpdate, accessory_update: &OrderedReadsAndWrites )

Commits state changes to the database.

source

fn open_proof( &self, state_root: [u8; 32], proof: StorageProof<Self::Proof> ) -> Result<(StorageKey, Option<StorageValue>), Error>

Opens a storage access proof and validates it against a state root. It returns a result with the opened leaf (key, value) pair in case of success.

source

fn is_empty(&self) -> bool

Indicates if storage is empty or not. Useful during initialization

Provided Methods§

source

fn get_accessory(&self, _key: &StorageKey) -> Option<StorageValue>

Returns the value corresponding to the key or None if key is absent.

source

fn validate_and_commit( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness ) -> Result<[u8; 32], Error>

Validate all of the storage accesses in a particular cache log, returning the new state root after applying all writes. This function is equivalent to calling: self.compute_state_update & self.commit

source

fn validate_and_commit_with_accessory_update( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness, accessory_update: &OrderedReadsAndWrites ) -> Result<[u8; 32], Error>

A version of Storage::validate_and_commit that allows for “accessory” non-JMT updates. See sov_db::NativeDB for more information about accessory state.

source

fn verify_proof<K, V, Codec>( &self, state_root: [u8; 32], proof: StorageProof<Self::Proof>, expected_key: &K, storage_map: &StateMap<K, V, Codec> ) -> Result<Option<StorageValue>, Error>where Codec: StateKeyCodec<K>,

Implementors§