diff --git a/.changelog/unreleased/improvements/2215-vp-less-permissive.md b/.changelog/unreleased/improvements/2215-vp-less-permissive.md new file mode 100644 index 0000000000..57faf65be7 --- /dev/null +++ b/.changelog/unreleased/improvements/2215-vp-less-permissive.md @@ -0,0 +1,2 @@ +- Handle errors on loading WASMs from file-system compilation cache. + ([\#2215](https://github.com/anoma/namada/pull/2215)) \ No newline at end of file diff --git a/shared/src/vm/wasm/compilation_cache/common.rs b/shared/src/vm/wasm/compilation_cache/common.rs index f866188970..cd95100d25 100644 --- a/shared/src/vm/wasm/compilation_cache/common.rs +++ b/shared/src/vm/wasm/compilation_cache/common.rs @@ -156,16 +156,22 @@ impl Cache { return Ok(Some((module.clone(), store()))); } - let (module, store) = file_load_module(&self.dir, hash); - tracing::info!( - "{} found {} in file cache.", - N::name(), - hash.to_string() - ); - // Put into cache, ignore result if it's full - let _ = in_memory.put_with_weight(*hash, module.clone()); + if let Ok((module, store)) = + file_load_module(&self.dir, hash) + { + tracing::info!( + "{} found {} in file cache.", + N::name(), + hash.to_string() + ); + // Put into cache, ignore result if it's full + let _ = + in_memory.put_with_weight(*hash, module.clone()); - return Ok(Some((module, store))); + return Ok(Some((module, store))); + } else { + return Ok(None); + } } Some(Compilation::Compiling) => { drop(progress); @@ -183,11 +189,15 @@ impl Cache { let (module, store) = if module_file_exists(&self.dir, hash) { tracing::info!( - "Loading {} {} from file.", + "Trying to load {} {} from file.", N::name(), hash.to_string() ); - file_load_module(&self.dir, hash) + if let Ok(res) = file_load_module(&self.dir, hash) { + res + } else { + return Ok(None); + } } else { return Ok(None); }; @@ -246,13 +256,18 @@ impl Cache { return Ok(Some((module.clone(), store()))); } - let (module, store) = file_load_module(&self.dir, hash); - tracing::info!( - "{} found {} in file cache.", - N::name(), - hash.to_string() - ); - return Ok(Some((module, store))); + if let Ok((module, store)) = + file_load_module(&self.dir, hash) + { + tracing::info!( + "{} found {} in file cache.", + N::name(), + hash.to_string() + ); + return Ok(Some((module, store))); + } else { + return Ok(None); + } } Some(Compilation::Compiling) => { drop(progress); @@ -270,11 +285,15 @@ impl Cache { return if module_file_exists(&self.dir, hash) { tracing::info!( - "Loading {} {} from file.", + "Trying to load {} {} from file.", N::name(), hash.to_string() ); - Ok(Some(file_load_module(&self.dir, hash))) + if let Ok(res) = file_load_module(&self.dir, hash) { + return Ok(Some(res)); + } else { + return Ok(None); + } } else { Ok(None) }; @@ -478,13 +497,22 @@ fn file_write_module(dir: impl AsRef, module: &Module, hash: &Hash) { fs_cache.store(CacheHash::new(hash.0), module).unwrap(); } -fn file_load_module(dir: impl AsRef, hash: &Hash) -> (Module, Store) { +fn file_load_module( + dir: impl AsRef, + hash: &Hash, +) -> Result<(Module, Store), wasmer::DeserializeError> { use wasmer_cache::Cache; let fs_cache = fs_cache(dir, hash); let store = store(); let hash = CacheHash::new(hash.0); - let module = unsafe { fs_cache.load(&store, hash) }.unwrap(); - (module, store) + let module = unsafe { fs_cache.load(&store, hash) }; + if let Err(err) = module.as_ref() { + tracing::error!( + "Error loading cached wasm {}: {err}.", + hash.to_string() + ); + } + Ok((module?, store)) } fn fs_cache(dir: impl AsRef, hash: &Hash) -> FileSystemCache {