Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasmer 3 follow up #1693

Merged
merged 8 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to
- cosmwasm-vm: Add `Instance::set_debug_handler`/`unset_debug_handler` to allow
customizing the handling of debug messages emitted by the contract ([#1667]).
- cosmwasm-vm: Add `.wasm` extension to stored wasm files ([#1686]).
- cosmwasm-vm: Upgrade Wasmer to version 3.3.0.
- cosmwasm-check: Update clap dependency to version 4 ([#1677])

[#1511]: https://github.com/CosmWasm/cosmwasm/issues/1511
Expand Down
12 changes: 7 additions & 5 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,12 @@ where

/// 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
/// 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 ID is not found, or the content does not match the hash (=ID), an error is returned.
///
/// If the given contract for the given checksum is not found, or the content
/// does not match the checksum, an error is returned.
pub fn pin(&self, checksum: &Checksum) -> VmResult<()> {
let mut cache = self.inner.lock().unwrap();
if cache.pinned_memory_cache.has(checksum) {
Expand All @@ -255,7 +257,7 @@ where

// We don't load from the memory cache because we had to create new store here and
// serialize/deserialize the artifact to get a full clone. Could be done but adds some code
// for a no-so-relevant use case.
// for a not-so-relevant use case.

// Try to get module from file system cache
let engine = Engine::headless();
Expand Down Expand Up @@ -730,7 +732,7 @@ mod tests {
let backend5 = mock_backend(&[]);

// from file system
let _instance1: Instance<MockApi, MockStorage, MockQuerier> = cache
let _instance1 = cache
.get_instance(&checksum, backend1, TESTING_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/modules/in_memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::hash_map::RandomState;
use std::num::NonZeroUsize;
use wasmer::{Engine, Module};

use super::sized_module::CachedModule;
use super::cached_module::CachedModule;
use crate::{Checksum, Size, VmError, VmResult};

// Minimum module size.
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod cached_module;
mod file_system_cache;
mod in_memory_cache;
mod pinned_memory_cache;
mod sized_module;
mod versioning;

pub use cached_module::CachedModule;
pub use file_system_cache::{FileSystemCache, NewFileSystemCacheError};
pub use in_memory_cache::InMemoryCache;
pub use pinned_memory_cache::PinnedMemoryCache;
pub use sized_module::CachedModule;
pub use versioning::current_wasmer_module_version;
2 changes: 1 addition & 1 deletion packages/vm/src/modules/pinned_memory_cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use wasmer::{Engine, Module};

use super::sized_module::CachedModule;
use super::cached_module::CachedModule;
use crate::{Checksum, VmResult};

/// An pinned in memory module cache
Expand Down
25 changes: 8 additions & 17 deletions packages/vm/src/wasm_backend/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,17 @@ pub fn make_engine(middlewares: &[Arc<dyn ModuleMiddleware>]) -> Engine {
let metering = Arc::new(Metering::new(gas_limit, cost));

#[cfg(feature = "cranelift")]
{
let mut compiler = Cranelift::default();
for middleware in middlewares {
compiler.push_middleware(middleware.clone());
}
compiler.push_middleware(deterministic);
compiler.push_middleware(metering);
compiler.into()
}
let mut compiler = Cranelift::default();

#[cfg(not(feature = "cranelift"))]
{
let mut compiler = Singlepass::default();
for middleware in middlewares {
compiler.push_middleware(middleware.clone());
}
compiler.push_middleware(deterministic);
compiler.push_middleware(metering);
compiler.into()
let mut compiler = Singlepass::default();

for middleware in middlewares {
compiler.push_middleware(middleware.clone());
}
compiler.push_middleware(deterministic);
compiler.push_middleware(metering);
compiler.into()
}

/// Created a store with no compiler and the given memory limit (in bytes)
Expand Down
Loading