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 unsafe fn new_with_config(config: Config) -> VmResult<Self>
pub unsafe fn new_with_config(config: Config) -> VmResult<Self>
Creates a new cache with the given configuration. This allows configuring lots of limits and sizes.
§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 pinned_metrics(&self) -> PinnedMetrics
pub fn metrics(&self) -> Metrics
Sourcepub fn save_wasm(&self, wasm: &[u8]) -> VmResult<Checksum>
👎Deprecated: Use store_code(wasm, true, true)
instead
pub fn save_wasm(&self, wasm: &[u8]) -> VmResult<Checksum>
store_code(wasm, true, true)
insteadTakes 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 Cache::save_wasm_unchecked
plus the static checks.
When a Wasm blob is stored the first time, use this function.
Sourcepub fn store_code(
&self,
wasm: &[u8],
checked: bool,
persist: bool,
) -> VmResult<Checksum>
pub fn store_code( &self, wasm: &[u8], checked: bool, persist: bool, ) -> VmResult<Checksum>
Takes a Wasm bytecode and stores it to the cache.
This performs static checks if checked
is true
,
compiles the bytescode to a module and
stores the Wasm file on disk if persist
is true
.
Only set checked = false
when a Wasm blob is stored which was previously checked
(e.g. as part of state sync).
Sourcepub fn save_wasm_unchecked(&self, wasm: &[u8]) -> VmResult<Checksum>
👎Deprecated: Use store_code(wasm, false, true)
instead
pub fn save_wasm_unchecked(&self, wasm: &[u8]) -> VmResult<Checksum>
store_code(wasm, false, true)
insteadTakes 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 Cache::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 Cache::store_code
.
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 Cache::store_code
, 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 Cache::store_code
.
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
Source§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