Skip to content

Commit

Permalink
refactor: streamline contract caching code (#7851)
Browse files Browse the repository at this point in the history
This does two rather big code motions at the same time (sorry!):

* precompilation code is moved from "let's match on VMKind" style to "let's call Runtime's virtual method". To do so, we re-purpose existing `precompile` functions in the trait. Remember, those fns are essentially dead code from "pipelined" compilation
* code to deal with our two-layered caching is moved from `cache.rs` into impls of VM
  • Loading branch information
matklad authored and nikurt committed Nov 9, 2022
1 parent 3dddc04 commit fa988cf
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 451 deletions.
43 changes: 12 additions & 31 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ use std::io;
///
/// See the doc comment on `VMResult` for an explanation what the difference
/// between this and a `FunctionCallError` is.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum VMRunnerError {
/// An error that is caused by an operation on an inconsistent state.
/// E.g. an integer overflow by using a value from the given context.
#[error("{0}")]
InconsistentStateError(InconsistentStateError),
/// Error caused by caching.
CacheError(CacheError),
#[error("cache error: {0}")]
CacheError(#[from] CacheError),
/// Error (eg, resource exhausting) when loading a successfully compiled
/// contract into executable memory.
#[error("loading error: {0}")]
LoadingError(String),
/// Type erased error from `External` trait implementation.
#[error("external error")]
ExternalError(AnyError),
/// Non-deterministic error.
#[error("non-deterministic error during contract execution: {0}")]
Nondeterministic(String),
WasmUnknownError {
debug_message: String,
},
/// Error when requiring an unavailable feature of the WASM compiler.
///
/// The only place this gets emitted today is when calling `precompile`
/// in wasmtime runner.
UnsupportedCompiler {
debug_message: String,
},
#[error("unknown error during contract execution: {debug_message}")]
WasmUnknownError { debug_message: String },
}

/// Permitted errors that cause a function call to fail gracefully.
Expand Down Expand Up @@ -416,25 +416,6 @@ impl fmt::Display for MethodResolveError {
}
}

impl fmt::Display for VMRunnerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
VMRunnerError::ExternalError(_err) => write!(f, "Serialized ExternalError"),
VMRunnerError::InconsistentStateError(err) => fmt::Display::fmt(err, f),
VMRunnerError::CacheError(err) => write!(f, "Cache error: {:?}", err),
VMRunnerError::WasmUnknownError { debug_message } => {
write!(f, "Unknown error during Wasm contract execution: {}", debug_message)
}
VMRunnerError::Nondeterministic(msg) => {
write!(f, "Nondeterministic error during contract execution: {}", msg)
}
VMRunnerError::UnsupportedCompiler { debug_message } => {
write!(f, "Unsupported compiler: {debug_message}")
}
}
}
}

impl std::fmt::Display for InconsistentStateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
Expand Down
Loading

0 comments on commit fa988cf

Please sign in to comment.