From a519f82435ec918d9df1ab4b452b972e4a18cd7d Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 10 Oct 2023 08:55:24 +0200 Subject: [PATCH 1/4] Bump module serialization version --- packages/vm/src/modules/file_system_cache.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index b634007087..e4b39eb1e3 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -49,7 +49,10 @@ use crate::modules::current_wasmer_module_version; /// - **v7**:
/// New version because of Wasmer 2.3.0 -> 4 upgrade. /// This internally changes how rkyv is used for module serialization, making compatibility unlikely. -const MODULE_SERIALIZATION_VERSION: &str = "v7"; +/// - **v8**:
+/// New version because of Wasmer 4.1.2 -> 4.2.2 upgrade. +/// Module compatibility between wasmer versions is not guaranteed. +const MODULE_SERIALIZATION_VERSION: &str = "v8"; /// Representation of a directory that contains compiled Wasm artifacts. pub struct FileSystemCache { @@ -287,7 +290,7 @@ mod tests { cache.store(&checksum, &module).unwrap(); let mut globber = glob::glob(&format!( - "{}/v7-wasmer5/**/{}", + "{}/v8-wasmer5/**/{}", tmp_dir.path().to_string_lossy(), checksum )) @@ -365,9 +368,9 @@ mod tests { assert_eq!( p.as_os_str(), if cfg!(windows) { - "modules\\v7-wasmer17\\x86_64-nintendo-fuchsia-gnu-coff-01E9F9FE" + "modules\\v8-wasmer17\\x86_64-nintendo-fuchsia-gnu-coff-01E9F9FE" } else { - "modules/v7-wasmer17/x86_64-nintendo-fuchsia-gnu-coff-01E9F9FE" + "modules/v8-wasmer17/x86_64-nintendo-fuchsia-gnu-coff-01E9F9FE" } ); } From 9e362a313e10b4c93916d36b40eb669aee86e181 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 10 Oct 2023 10:54:38 +0200 Subject: [PATCH 2/4] Add .module file extension --- packages/vm/src/modules/file_system_cache.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index e4b39eb1e3..e49063384f 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -121,6 +121,14 @@ impl FileSystemCache { self.unchecked_modules = unchecked; } + /// Returns the path to the serialized module with the given checksum. + fn module_file(&self, checksum: &Checksum) -> PathBuf { + let mut path = self.modules_path.clone(); + path.push(checksum.to_hex()); + path.set_extension("module"); + path + } + /// Loads a serialized module from the file system and returns a module (i.e. artifact + store), /// along with the size of the serialized module. pub fn load( @@ -128,8 +136,7 @@ impl FileSystemCache { checksum: &Checksum, engine: &impl AsEngineRef, ) -> VmResult> { - let filename = checksum.to_hex(); - let file_path = self.modules_path.join(filename); + let file_path = self.module_file(checksum); let result = if self.unchecked_modules { unsafe { Module::deserialize_from_file_unchecked(engine, &file_path) } @@ -158,8 +165,7 @@ impl FileSystemCache { mkdir_p(&self.modules_path) .map_err(|_e| VmError::cache_err("Error creating modules directory"))?; - let filename = checksum.to_hex(); - let path = self.modules_path.join(filename); + let path = self.module_file(checksum); module .serialize_to_file(&path) .map_err(|e| VmError::cache_err(format!("Error writing module to disk: {e}")))?; @@ -171,8 +177,7 @@ impl FileSystemCache { /// /// Returns true if the file existed and false if the file did not exist. pub fn remove(&mut self, checksum: &Checksum) -> VmResult { - let filename = checksum.to_hex(); - let file_path = self.modules_path.join(filename); + let file_path = self.module_file(checksum); if file_path.exists() { fs::remove_file(file_path) @@ -290,7 +295,7 @@ mod tests { cache.store(&checksum, &module).unwrap(); let mut globber = glob::glob(&format!( - "{}/v8-wasmer5/**/{}", + "{}/v8-wasmer5/**/{}.module", tmp_dir.path().to_string_lossy(), checksum )) From 9b378df358592b95846ed7ad4bdc30f547878679 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 11 Oct 2023 10:08:46 +0200 Subject: [PATCH 3/4] Fix typo Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> --- packages/vm/src/modules/file_system_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index e49063384f..60d8ddaf56 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -51,7 +51,7 @@ use crate::modules::current_wasmer_module_version; /// This internally changes how rkyv is used for module serialization, making compatibility unlikely. /// - **v8**:
/// New version because of Wasmer 4.1.2 -> 4.2.2 upgrade. -/// Module compatibility between wasmer versions is not guaranteed. +/// Module compatibility between Wasmer versions is not guaranteed. const MODULE_SERIALIZATION_VERSION: &str = "v8"; /// Representation of a directory that contains compiled Wasm artifacts. From b3bd56c908f625d2620c3540a51b72b7aaed944c Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 11 Oct 2023 10:31:42 +0200 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f866f6751..cccf3c20ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,13 @@ and this project adheres to [#1807]: https://github.com/CosmWasm/cosmwasm/pull/1807 [#1864]: https://github.com/CosmWasm/cosmwasm/pull/1864 +### Changed + +- cosmwasm-vm: Added `.module` extension to file names in the file system cache + ([#1913]). + +[#1913]: https://github.com/CosmWasm/cosmwasm/pull/1913 + ## [1.4.1] - 2023-10-09 ## Fixed