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>
impl<A, S, Q> Cache<A, S, Q>
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.
sourcepub fn set_module_unchecked(&mut self, unchecked: bool)
pub fn set_module_unchecked(&mut self, unchecked: bool)
If unchecked
is true, the filesystem cache will use the *_unchecked
wasmer functions for
loading modules from disk.
pub fn stats(&self) -> Stats
pub fn metrics(&self) -> Metrics
sourcepub fn save_wasm(&self, wasm: &[u8]) -> VmResult<Checksum>
pub fn save_wasm(&self, wasm: &[u8]) -> VmResult<Checksum>
Takes a Wasm bytecode and stores it to the cache.
This performs static checks, compiles the bytescode to a module and stores the Wasm file on disk.
This does the same as [save_wasm_unchecked
] plus the static checks.
When a Wasm blob is stored the first time, use this function.
sourcepub fn save_wasm_unchecked(&self, wasm: &[u8]) -> VmResult<Checksum>
pub fn save_wasm_unchecked(&self, wasm: &[u8]) -> VmResult<Checksum>
Takes a Wasm bytecode and stores it to the cache.
This compiles the bytescode to a module and stores the Wasm file on disk.
This does the same as [save_wasm
] but without the static checks.
When a Wasm blob is stored which was previously checked (e.g. as part of state sync),
use this function.
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 file system cache. If not found, the code is loaded from the file system, compiled, and stored into the pinned cache.
If the given contract for the given checksum is not found, or the content does not match the checksum, 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.
Trait Implementations§
Auto Trait Implementations§
impl<A, S, Q> !Freeze for Cache<A, S, Q>
impl<A, S, Q> RefUnwindSafe for Cache<A, S, Q>
impl<A, S, Q> Unpin for Cache<A, S, Q>
impl<A, S, Q> UnwindSafe for Cache<A, S, Q>
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more