Skip to content

Commit

Permalink
Hotfix: Enable wasmetime (#210)
Browse files Browse the repository at this point in the history
* fix to enable wasmetime

* fmt
  • Loading branch information
kobayurii authored Mar 19, 2024
1 parent c32cc4e commit 3d6d978
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 55 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.2.3"
version = "0.2.4"
authors = ["Near Inc <[email protected]>"]
edition = "2021"
rust-version = "1.76.0"
Expand Down Expand Up @@ -37,7 +37,9 @@ near-chain-configs = { git = 'https://github.com/near/nearcore.git', rev = '5114
near-crypto = { git = 'https://github.com/near/nearcore.git', rev = '511414a5091c3bef5c447a5644ba903dc050b715' }
near-jsonrpc-primitives = { git = 'https://github.com/near/nearcore.git', rev = '511414a5091c3bef5c447a5644ba903dc050b715' }
near-parameters = { git = 'https://github.com/near/nearcore.git', rev = '511414a5091c3bef5c447a5644ba903dc050b715' }
near-vm-runner = { git = 'https://github.com/near/nearcore.git', rev = '511414a5091c3bef5c447a5644ba903dc050b715' }
near-vm-runner = { git = 'https://github.com/near/nearcore.git', rev = '511414a5091c3bef5c447a5644ba903dc050b715', features = [
"wasmer0_vm", "wasmer2_vm", "near_vm", "wasmtime_vm"
] }

near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.9' }
near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.8.3'}
52 changes: 8 additions & 44 deletions rpc-server/src/modules/queries/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ async fn run_code_in_vm_runner(
mut code_storage: CodeStorage,
protocol_version: near_primitives::types::ProtocolVersion,
compiled_contract_code_cache: &std::sync::Arc<CompiledCodeCache>,
) -> Result<near_vm_runner::logic::VMOutcome, near_primitives::errors::RuntimeError> {
) -> Result<near_vm_runner::logic::VMOutcome, near_vm_runner::logic::errors::VMRunnerError> {
let contract_method_name = String::from(method_name);
let code_cache = std::sync::Arc::clone(compiled_contract_code_cache);

let store = near_parameters::RuntimeConfigStore::free();
let config = store.get_config(protocol_version).wasm_config.clone();
let mut vm_config = near_parameters::vm::Config {
let vm_config = near_parameters::vm::Config {
vm_kind: config.vm_kind.replace_with_wasmtime_if_unsupported(),
..config
};
vm_config.make_free();
let results = tokio::task::spawn_blocking(move || {
near_vm_runner::run(
&contract_code,
Expand All @@ -135,47 +134,12 @@ async fn run_code_in_vm_runner(
})
.await;
match results {
Ok(result) => {
// There are many specific errors that the runtime can encounter.
// Some can be translated to the more general `RuntimeError`, which allows to pass
// the error up to the caller. For all other cases, panicking here is better
// than leaking the exact details further up.
// Note that this does not include errors caused by user code / input, those are
// stored in outcome.aborted.
result.map_err(|e| match e {
near_vm_runner::logic::errors::VMRunnerError::ExternalError(any_err) => {
let err = any_err
.downcast()
.expect("Downcasting AnyError should not fail");
near_primitives::errors::RuntimeError::ValidatorError(err)
}
near_vm_runner::logic::errors::VMRunnerError::InconsistentStateError(
err @ near_vm_runner::logic::errors::InconsistentStateError::IntegerOverflow,
) => {
near_primitives::errors::StorageError::StorageInconsistentState(err.to_string())
.into()
}
near_vm_runner::logic::errors::VMRunnerError::CacheError(err) => {
near_primitives::errors::StorageError::StorageInconsistentState(err.to_string())
.into()
}
near_vm_runner::logic::errors::VMRunnerError::LoadingError(msg) => {
panic!("Contract runtime failed to load a contract: {msg}")
}
near_vm_runner::logic::errors::VMRunnerError::Nondeterministic(msg) => {
panic!(
"Contract runner returned non-deterministic error '{}', aborting",
msg
)
}
near_vm_runner::logic::errors::VMRunnerError::WasmUnknownError {
debug_message,
} => {
panic!("Wasmer returned unknown message: {}", debug_message)
}
})
}
Err(_) => Err(near_primitives::errors::RuntimeError::UnexpectedIntegerOverflow),
Ok(result) => result,
Err(err) => Err(
near_vm_runner::logic::errors::VMRunnerError::WasmUnknownError {
debug_message: format!("Failed to run contract: {:?}", err),
},
),
}
}

Expand Down

0 comments on commit 3d6d978

Please sign in to comment.