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§
sourcetype RuntimeConfig
type RuntimeConfig
The runtime config for this storage instance.
sourcetype Proof: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize
type Proof: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize
A cryptographic proof that a particular key has a particular value, or is absent.
sourcetype StateUpdate
type StateUpdate
State update that will be committed to the database.
Required Methods§
fn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>
sourcefn get(&self, key: &StorageKey, witness: &Self::Witness) -> Option<StorageValue>
fn get(&self, key: &StorageKey, witness: &Self::Witness) -> Option<StorageValue>
Returns the value corresponding to the key or None if key is absent.
sourcefn get_state_root(&self, witness: &Self::Witness) -> Result<[u8; 32]>
fn get_state_root(&self, witness: &Self::Witness) -> Result<[u8; 32]>
Returns the latest state root hash from the storage.
sourcefn compute_state_update(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness
) -> Result<([u8; 32], Self::StateUpdate), Error>
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.
sourcefn commit(
&self,
node_batch: &Self::StateUpdate,
accessory_update: &OrderedReadsAndWrites
)
fn commit( &self, node_batch: &Self::StateUpdate, accessory_update: &OrderedReadsAndWrites )
Commits state changes to the database.
sourcefn open_proof(
&self,
state_root: [u8; 32],
proof: StorageProof<Self::Proof>
) -> Result<(StorageKey, Option<StorageValue>), Error>
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.
Provided Methods§
sourcefn get_accessory(&self, _key: &StorageKey) -> Option<StorageValue>
fn get_accessory(&self, _key: &StorageKey) -> Option<StorageValue>
Returns the value corresponding to the key or None if key is absent.
sourcefn validate_and_commit(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness
) -> Result<[u8; 32], Error>
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
sourcefn validate_and_commit_with_accessory_update(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness,
accessory_update: &OrderedReadsAndWrites
) -> 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>
A version of Storage::validate_and_commit that allows for
“accessory” non-JMT updates. See sov_db::NativeDB for more information
about accessory state.