Skip to content

Commit

Permalink
print warning when cache size is smaller than module or script size
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Feb 3, 2025
1 parent 6404824 commit 703ef1c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/storage/src/module_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ impl InitiaModuleCache {
) -> VMResult<()> {
// cache is too small to hold this module
if self.capacity < allocated_size {
eprintln!(
"Module cache is too small to hold module with size {}",
allocated_size
);

return Ok(());
}

Expand Down Expand Up @@ -128,6 +133,11 @@ impl InitiaModuleCache {
module_cache
.put_with_weight(key, ModuleWrapper::new(module.clone(), allocated_size))
.unwrap_or_else(|_| None);
} else {
eprintln!(
"Module cache is too small to hold module with size {}",
allocated_size
);
}

Ok(module)
Expand Down Expand Up @@ -170,6 +180,11 @@ impl InitiaModuleCache {
module_cache
.put_with_weight(*checksum, code_wrapper.clone())
.unwrap_or_else(|_| None);
} else {
eprintln!(
"Module cache is too small to hold module with size {}",
allocated_size
);
}

Some(code_wrapper)
Expand Down
10 changes: 10 additions & 0 deletions crates/storage/src/script_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ impl InitiaScriptCache {
let _ = script_cache
.put_with_weight(key, ScriptWrapper::new(new_script, allocated_size))
.unwrap_or_else(|_| None);
} else {
eprintln!(
"Script cache is too small to hold module with size {}",
allocated_size
);
}

Ok(deserialized_script)
Expand Down Expand Up @@ -89,6 +94,11 @@ impl InitiaScriptCache {
let _ = script_cache
.put_with_weight(key, ScriptWrapper::new(new_script, allocated_size))
.unwrap_or_else(|_| None);
} else {
eprintln!(
"Script cache is too small to hold module with size {}",
allocated_size
);
}
}
Ok(verified_script)
Expand Down

0 comments on commit 703ef1c

Please sign in to comment.