Struct cosmwasm_vm::Cache
source · pub struct Cache<A: BackendApi, S: Storage, Q: Querier> { /* private fields */ }
Implementations§
source§impl<A, S, Q> Cache<A, S, Q>where
A: BackendApi + 'static,
S: Storage + 'static,
Q: Querier + 'static,
impl<A, S, Q> Cache<A, S, Q>where
A: BackendApi + 'static,
S: Storage + 'static,
Q: Querier + 'static,
sourcepub unsafe fn new(options: CacheOptions) -> VmResult<Self>
pub unsafe fn new(options: CacheOptions) -> VmResult<Self>
Creates a new cache that stores data in base_dir
.
Safety
This function is marked unsafe due to FileSystemCache::new
, which implicitly
assumes the disk contents are correct, and there’s no way to ensure the artifacts
stored in the cache haven’t been corrupted or tampered with.
pub fn stats(&self) -> Stats
pub fn metrics(&self) -> Metrics
pub fn save_wasm(&self, wasm: &[u8]) -> VmResult<Checksum>
sourcepub fn remove_wasm(&self, checksum: &Checksum) -> VmResult<()>
pub fn remove_wasm(&self, checksum: &Checksum) -> VmResult<()>
Removes the Wasm blob for the given checksum from disk and its compiled module from the file system cache.
The existence of the original code is required since the caller (wasmd) has to keep track of which entries we have here.
sourcepub fn load_wasm(&self, checksum: &Checksum) -> VmResult<Vec<u8>>
pub fn load_wasm(&self, checksum: &Checksum) -> VmResult<Vec<u8>>
Retrieves a Wasm blob that was previously stored via save_wasm. When the cache is instantiated with the same base dir, this finds Wasm files on disc across multiple cache instances (i.e. node restarts). This function is public to allow a checksum to Wasm lookup in the blockchain.
If the given ID is not found or the content does not match the hash (=ID), an error is returned.
sourcepub fn analyze(&self, checksum: &Checksum) -> VmResult<AnalysisReport>
pub fn analyze(&self, checksum: &Checksum) -> VmResult<AnalysisReport>
Performs static anlyzation on this Wasm without compiling or instantiating it.
Once the contract was stored via [save_wasm
], this can be called at any point in time.
It does not depend on any caching of the contract.
sourcepub fn pin(&self, checksum: &Checksum) -> VmResult<()>
pub fn pin(&self, checksum: &Checksum) -> VmResult<()>
Pins a Module that was previously stored via save_wasm.
The module is lookup first in the memory cache, and then in the file system cache. If not found, the code is loaded from the file system, compiled, and stored into the pinned cache. If the given ID is not found, or the content does not match the hash (=ID), an error is returned.
sourcepub fn unpin(&self, checksum: &Checksum) -> VmResult<()>
pub fn unpin(&self, checksum: &Checksum) -> VmResult<()>
Unpins a Module, i.e. removes it from the pinned memory cache.
Not found IDs are silently ignored, and no integrity check (checksum validation) is done on the removed value.
sourcepub fn get_instance(
&self,
checksum: &Checksum,
backend: Backend<A, S, Q>,
options: InstanceOptions
) -> VmResult<Instance<A, S, Q>>
pub fn get_instance(
&self,
checksum: &Checksum,
backend: Backend<A, S, Q>,
options: InstanceOptions
) -> VmResult<Instance<A, S, Q>>
Returns an Instance tied to a previously saved Wasm.
It takes a module from cache or Wasm code and instantiates it.