pub trait Storage: Clone {
type Witness: Witness + Send + Sync;
type RuntimeConfig;
type Proof: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize;
type Root: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize + Eq + AsRef<[u8]> + Into<[u8; 32]>;
type StateUpdate;
// Required methods
fn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>;
fn get(
&self,
key: &StorageKey,
witness: &Self::Witness,
) -> Option<StorageValue>;
fn compute_state_update(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness,
) -> Result<(Self::Root, Self::StateUpdate), Error>;
fn commit(
&self,
node_batch: &Self::StateUpdate,
accessory_update: &OrderedReadsAndWrites,
);
fn open_proof(
state_root: Self::Root,
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<Self::Root, Error> { ... }
fn validate_and_commit_with_accessory_update(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness,
accessory_update: &OrderedReadsAndWrites,
) -> Result<Self::Root, Error> { ... }
}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 Root: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize + Eq + AsRef<[u8]> + Into<[u8; 32]>
type Root: Serialize + DeserializeOwned + Debug + Clone + BorshSerialize + BorshDeserialize + Eq + AsRef<[u8]> + Into<[u8; 32]>
A cryptographic commitment to the contents of this storage
Sourcetype StateUpdate
type StateUpdate
State update that will be committed to the database.
Required Methods§
Sourcefn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>
fn with_config(config: Self::RuntimeConfig) -> Result<Self, Error>
Creates a new instance of this Storage type, with some configuration
options.
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 compute_state_update(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness,
) -> Result<(Self::Root, Self::StateUpdate), Error>
fn compute_state_update( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness, ) -> Result<(Self::Root, 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(
state_root: Self::Root,
proof: StorageProof<Self::Proof>,
) -> Result<(StorageKey, Option<StorageValue>), Error>
fn open_proof( state_root: Self::Root, 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.
§About accessory state
This method is blanket-implemented to return None. Only native
execution environments (i.e. outside of the zmVM) SHOULD override
this method to return a value. This is because accessory state MUST
NOT be readable from within the zmVM.
Sourcefn validate_and_commit(
&self,
state_accesses: OrderedReadsAndWrites,
witness: &Self::Witness,
) -> Result<Self::Root, Error>
fn validate_and_commit( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness, ) -> Result<Self::Root, 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<Self::Root, Error>
fn validate_and_commit_with_accessory_update( &self, state_accesses: OrderedReadsAndWrites, witness: &Self::Witness, accessory_update: &OrderedReadsAndWrites, ) -> Result<Self::Root, 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".