Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
505 changes: 261 additions & 244 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ tonic-prost-build = "0.14"
tower-http = { version = "0.6.11", features = ["cors"] }
tower = { version = "0.5.1", features = ["full"] }
wasmparser = "0.118.1"
wasmtime = { version = "38.0.4", features = ["async"] }
wasmtime = { version = "44.0.1", features = ["async"] }
rand = { version = "0.9.2", features = ["os_rng"] }
prometheus = "0.14.0"
url = "2.5.8"
Expand Down
5 changes: 4 additions & 1 deletion runtime/test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ impl WasmInstanceExt for WasmInstance {
.typed(self.store.as_context())
.unwrap()
.clone();
func.call_async(&mut self.store.as_context_mut(), ()).await
func.call_async(&mut self.store.as_context_mut(), ())
.await
.map_err(anyhow::Error::from)
}

async fn invoke_export0<R>(&mut self, f: &str) -> AscPtr<R> {
Expand Down Expand Up @@ -309,6 +311,7 @@ impl WasmInstanceExt for WasmInstance {
(arg0.wasm_ptr(), arg1.wasm_ptr()),
)
.await
.map_err(anyhow::Error::from)
}

async fn invoke_export0_val<V: wasmtime::WasmTy + Sync>(&mut self, func: &str) -> V {
Expand Down
1 change: 0 additions & 1 deletion runtime/wasm/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ impl ValidModule {
graph::env::WasmOptLevel::SpeedAndSize => wasmtime::OptLevel::SpeedAndSize,
});
config.max_wasm_stack(ENV_VARS.mappings.max_stack_size);
config.async_support(true);

let engine = &wasmtime::Engine::new(&config)?;
let module = wasmtime::Module::from_binary(engine, &raw_module)?;
Expand Down
41 changes: 25 additions & 16 deletions runtime/wasm/src/module/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ impl WasmInstance {
self.instance
.get_func(self.store.as_context_mut(), handler_name)
.with_context(|| format!("function {} not found", handler_name))?
.typed::<(u32, u32), ()>(self.store.as_context_mut())?
.typed::<(u32, u32), ()>(self.store.as_context_mut())
.map_err(anyhow::Error::from)?
.call_async(
self.store.as_context_mut(),
(value?.wasm_ptr(), user_data?.wasm_ptr()),
)
.await
.map_err(anyhow::Error::from)
.with_context(|| format!("Failed to handle callback '{}'", handler_name))?;

let mut wasm_ctx = self.store.into_data();
Expand Down Expand Up @@ -159,6 +161,7 @@ impl WasmInstance {

let func = func
.typed(self.store.as_context_mut())
.map_err(anyhow::Error::from)
.context("wasm function has incorrect signature")?;

// Caution: Make sure all exit paths from this function call `exit_handler`.
Expand All @@ -168,6 +171,7 @@ impl WasmInstance {
let deterministic_error: Option<Error> = match func
.call_async(self.store.as_context_mut(), arg.wasm_ptr())
.await
.map_err(anyhow::Error::from)
{
Ok(()) => {
assert!(!self.instance_ctx().as_ref().possible_reorg);
Expand Down Expand Up @@ -281,10 +285,10 @@ fn link_chain_host_fn(
.iter()
.find(|hf| hf.name == name)
.ok_or_else(|| {
anyhow::anyhow!(
wasmtime::Error::msg(format!(
"chain host function '{}' is not available for this chain",
name
)
))
})?
.cheap_clone();

Expand All @@ -302,17 +306,20 @@ fn link_chain_host_fn(
metrics: host_metrics.cheap_clone(),
heap: &mut WasmInstanceContext::new(&mut caller),
};
let ret = (host_fn.func)(ctx, call_ptr).await.map_err(|e| match e {
HostExportError::Deterministic(e) => {
caller.data_mut().deterministic_host_trap = true;
e
}
HostExportError::PossibleReorg(e) => {
caller.data_mut().possible_reorg = true;
e
}
HostExportError::Unknown(e) => e,
})?;
let ret = (host_fn.func)(ctx, call_ptr)
.await
.map_err(|e| match e {
HostExportError::Deterministic(e) => {
caller.data_mut().deterministic_host_trap = true;
e
}
HostExportError::PossibleReorg(e) => {
caller.data_mut().possible_reorg = true;
e
}
HostExportError::Unknown(e) => e,
})
.map_err(wasmtime::Error::from_anyhow)?;
host_metrics.observe_host_fn_execution_time(
start.elapsed().as_secs_f64(),
&name_for_metrics,
Expand Down Expand Up @@ -576,7 +583,9 @@ pub(crate) fn build_linker(
linker.func_wrap(
"gas",
"gas",
|mut caller: wasmtime::Caller<'_, WasmInstanceData>, gas_used: u64| -> anyhow::Result<()> {
|mut caller: wasmtime::Caller<'_, WasmInstanceData>,
gas_used: u64|
-> wasmtime::Result<()> {
// Gas metering has a relevant execution cost cost, being called tens of thousands
// of times per handler, but it's not worth having a stopwatch section here because
// the cost of measuring would be greater than the cost of `consume_host_fn`. Last
Expand All @@ -587,7 +596,7 @@ pub(crate) fn build_linker(
.consume_host_fn_with_metrics(Gas::new(gas_used), "gas")
{
caller.data_mut().deterministic_host_trap = true;
return Err(e.into());
return Err(wasmtime::Error::from_anyhow(e.into()));
}

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion runtime/wasm/src/module/into_wasm_ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ where
T: IntoWasmRet,
T::Ret: wasmtime::WasmTy,
{
type Ret = Result<T::Ret, Error>;
type Ret = Result<T::Ret, wasmtime::Error>;
fn into_wasm_ret(self) -> Self::Ret {
self.map(|x| x.into_wasm_ret())
.map_err(wasmtime::Error::from_anyhow)
}
}
2 changes: 1 addition & 1 deletion runtime/wasm/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl AscHeap for WasmInstanceContext<'_> {
.await
.map_err(|trap| {
host_export_error_from_trap(
trap,
trap.into(),
format!("Failed to call 'asc_type_id' with '{:?}'", type_id_index),
)
})?;
Expand Down
7 changes: 4 additions & 3 deletions server/http/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,10 @@ mod tests {
}

async fn run_query(self: Arc<Self>, _query: Query, _target: QueryTarget) -> QueryResults {
QueryResults::from(Object::from_iter(
vec![(Word::from("name"), r::Value::String(String::from("Jordi")))].into_iter(),
))
QueryResults::from(Object::from_iter(vec![(
Word::from("name"),
r::Value::String(String::from("Jordi")),
)]))
}

fn metrics(&self) -> Arc<dyn GraphQLMetrics> {
Expand Down
14 changes: 8 additions & 6 deletions server/http/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ impl GraphQlRunner for TestGraphQlRunner {
.unwrap()
== &r::Value::String(String::from("John"))
{
Object::from_iter(
vec![(Word::from("name"), r::Value::String(String::from("John")))].into_iter(),
)
Object::from_iter(vec![(
Word::from("name"),
r::Value::String(String::from("John")),
)])
} else {
Object::from_iter(
vec![(Word::from("name"), r::Value::String(String::from("Jordi")))].into_iter(),
)
Object::from_iter(vec![(
Word::from("name"),
r::Value::String(String::from("Jordi")),
)])
}
.into()
}
Expand Down
Loading