Skip to content

Commit ae07df7

Browse files
authored
Merge pull request CosmWasm#1223 from CosmWasm/MODULE_SERIALIZATION_VERSION-v2
Bump module serialization format to v2
2 parents 19d3fb0 + 4ffa110 commit ae07df7

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to
2121
### Fixed
2222

2323
- cosmwasm-vm: Fix `AddAssign` implementation of `GasInfo`.
24+
- cosmwasm-vm: Bump `MODULE_SERIALIZATION_VERSION` to "v2" because the module
25+
serialization format changed between Wasmer 2.0.0 and 2.1.x.
2426

2527
## [1.0.0-beta4] - 2021-12-23
2628

packages/vm/src/modules/file_system_cache.rs

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ use crate::errors::{VmError, VmResult};
1414
/// The string is used as a folder and should be named in a way that is
1515
/// easy to interprete for system admins. It should allow easy clearing
1616
/// of old versions.
17-
const MODULE_SERIALIZATION_VERSION: &str = "v1";
17+
///
18+
/// See https://github.com/wasmerio/wasmer/issues/2781 for more information
19+
/// on Wasmer's module stability concept.
20+
///
21+
/// ## Version history:
22+
/// - **v1**:<br>
23+
/// cosmwasm_vm < 1.0.0-beta5. This is working well up to Wasmer 2.0.0 as
24+
/// [in wasmvm 1.0.0-beta2](https://github.com/CosmWasm/wasmvm/blob/v1.0.0-beta2/libwasmvm/Cargo.lock#L1412-L1413)
25+
/// and [wasmvm 0.16.3](https://github.com/CosmWasm/wasmvm/blob/v0.16.3/libwasmvm/Cargo.lock#L1408-L1409).
26+
/// Versions that ship with Wasmer 2.1.x such [as wasmvm 1.0.0-beta3](https://github.com/CosmWasm/wasmvm/blob/v1.0.0-beta3/libwasmvm/Cargo.lock#L1534-L1535)
27+
/// to [wasmvm 1.0.0-beta5](https://github.com/CosmWasm/wasmvm/blob/v1.0.0-beta5/libwasmvm/Cargo.lock#L1530-L1531)
28+
/// are broken, i.e. they will crash when reading older v1 modules.
29+
/// - **v2**:<br>
30+
/// Version for cosmwasm_vm 1.0.0-beta5 / wasmvm 1.0.0-beta6 that ships with Wasmer 2.1.1.
31+
/// - **v3**:<br>
32+
/// Version for Wasmer 2.2.0 which contains a [module breaking change to 2.1.x](https://github.com/wasmerio/wasmer/pull/2747).
33+
const MODULE_SERIALIZATION_VERSION: &str = "v2";
1834

1935
/// Representation of a directory that contains compiled Wasm artifacts.
2036
pub struct FileSystemCache {
@@ -116,22 +132,21 @@ mod tests {
116132
const TESTING_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));
117133
const TESTING_GAS_LIMIT: u64 = 500_000_000;
118134

135+
const SOME_WAT: &str = r#"(module
136+
(type $t0 (func (param i32) (result i32)))
137+
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
138+
get_local $p0
139+
i32.const 1
140+
i32.add))
141+
"#;
142+
119143
#[test]
120144
fn file_system_cache_run() {
121145
let tmp_dir = TempDir::new().unwrap();
122146
let mut cache = unsafe { FileSystemCache::new(tmp_dir.path()).unwrap() };
123147

124148
// Create module
125-
let wasm = wat::parse_str(
126-
r#"(module
127-
(type $t0 (func (param i32) (result i32)))
128-
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
129-
get_local $p0
130-
i32.const 1
131-
i32.add))
132-
"#,
133-
)
134-
.unwrap();
149+
let wasm = wat::parse_str(SOME_WAT).unwrap();
135150
let checksum = Checksum::generate(&wasm);
136151

137152
// Module does not exist
@@ -160,4 +175,22 @@ mod tests {
160175
assert_eq!(result[0].unwrap_i32(), 43);
161176
}
162177
}
178+
179+
#[test]
180+
fn file_system_cache_store_uses_expected_path() {
181+
let tmp_dir = TempDir::new().unwrap();
182+
let mut cache = unsafe { FileSystemCache::new(tmp_dir.path()).unwrap() };
183+
184+
// Create module
185+
let wasm = wat::parse_str(SOME_WAT).unwrap();
186+
let checksum = Checksum::generate(&wasm);
187+
188+
// Store module
189+
let module = compile(&wasm, None, &[]).unwrap();
190+
cache.store(&checksum, &module).unwrap();
191+
192+
let file_path = format!("{}/v2/{}", tmp_dir.path().to_string_lossy(), checksum);
193+
let serialized_module = fs::read(file_path).unwrap();
194+
assert_eq!(serialized_module.len(), 1040);
195+
}
163196
}

0 commit comments

Comments
 (0)