Skip to content

Commit 60c0880

Browse files
authored
runtime: Bump wasmtime from 38.0.4 to 44.0.1 (#6577)
* build(deps): bump wasmtime from 38.0.4 to 44.0.1 * runtime: Adapt to wasmtime 44 API changes In wasmtime 42 `wasmtime::Error` was split from `anyhow::Error` and `Config::async_support` became a no-op. Convert at the wasmtime boundary so the rest of the runtime keeps using anyhow internally. * server/http: Remove redundant .into_iter() (clippy)
1 parent 51cd0b5 commit 60c0880

9 files changed

Lines changed: 306 additions & 274 deletions

File tree

Cargo.lock

Lines changed: 261 additions & 244 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ tonic-prost-build = "0.14"
114114
tower-http = { version = "0.6.11", features = ["cors"] }
115115
tower = { version = "0.5.1", features = ["full"] }
116116
wasmparser = "0.118.1"
117-
wasmtime = { version = "38.0.4", features = ["async"] }
117+
wasmtime = { version = "44.0.1", features = ["async"] }
118118
rand = { version = "0.9.2", features = ["os_rng"] }
119119
prometheus = "0.14.0"
120120
url = "2.5.8"

runtime/test/src/test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ impl WasmInstanceExt for WasmInstance {
195195
.typed(self.store.as_context())
196196
.unwrap()
197197
.clone();
198-
func.call_async(&mut self.store.as_context_mut(), ()).await
198+
func.call_async(&mut self.store.as_context_mut(), ())
199+
.await
200+
.map_err(anyhow::Error::from)
199201
}
200202

201203
async fn invoke_export0<R>(&mut self, f: &str) -> AscPtr<R> {
@@ -309,6 +311,7 @@ impl WasmInstanceExt for WasmInstance {
309311
(arg0.wasm_ptr(), arg1.wasm_ptr()),
310312
)
311313
.await
314+
.map_err(anyhow::Error::from)
312315
}
313316

314317
async fn invoke_export0_val<V: wasmtime::WasmTy + Sync>(&mut self, func: &str) -> V {

runtime/wasm/src/mapping.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ impl ValidModule {
322322
graph::env::WasmOptLevel::SpeedAndSize => wasmtime::OptLevel::SpeedAndSize,
323323
});
324324
config.max_wasm_stack(ENV_VARS.mappings.max_stack_size);
325-
config.async_support(true);
326325

327326
let engine = &wasmtime::Engine::new(&config)?;
328327
let module = wasmtime::Module::from_binary(engine, &raw_module)?;

runtime/wasm/src/module/instance.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ impl WasmInstance {
9393
self.instance
9494
.get_func(self.store.as_context_mut(), handler_name)
9595
.with_context(|| format!("function {} not found", handler_name))?
96-
.typed::<(u32, u32), ()>(self.store.as_context_mut())?
96+
.typed::<(u32, u32), ()>(self.store.as_context_mut())
97+
.map_err(anyhow::Error::from)?
9798
.call_async(
9899
self.store.as_context_mut(),
99100
(value?.wasm_ptr(), user_data?.wasm_ptr()),
100101
)
101102
.await
103+
.map_err(anyhow::Error::from)
102104
.with_context(|| format!("Failed to handle callback '{}'", handler_name))?;
103105

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

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

164167
// Caution: Make sure all exit paths from this function call `exit_handler`.
@@ -168,6 +171,7 @@ impl WasmInstance {
168171
let deterministic_error: Option<Error> = match func
169172
.call_async(self.store.as_context_mut(), arg.wasm_ptr())
170173
.await
174+
.map_err(anyhow::Error::from)
171175
{
172176
Ok(()) => {
173177
assert!(!self.instance_ctx().as_ref().possible_reorg);
@@ -281,10 +285,10 @@ fn link_chain_host_fn(
281285
.iter()
282286
.find(|hf| hf.name == name)
283287
.ok_or_else(|| {
284-
anyhow::anyhow!(
288+
wasmtime::Error::msg(format!(
285289
"chain host function '{}' is not available for this chain",
286290
name
287-
)
291+
))
288292
})?
289293
.cheap_clone();
290294

@@ -302,17 +306,20 @@ fn link_chain_host_fn(
302306
metrics: host_metrics.cheap_clone(),
303307
heap: &mut WasmInstanceContext::new(&mut caller),
304308
};
305-
let ret = (host_fn.func)(ctx, call_ptr).await.map_err(|e| match e {
306-
HostExportError::Deterministic(e) => {
307-
caller.data_mut().deterministic_host_trap = true;
308-
e
309-
}
310-
HostExportError::PossibleReorg(e) => {
311-
caller.data_mut().possible_reorg = true;
312-
e
313-
}
314-
HostExportError::Unknown(e) => e,
315-
})?;
309+
let ret = (host_fn.func)(ctx, call_ptr)
310+
.await
311+
.map_err(|e| match e {
312+
HostExportError::Deterministic(e) => {
313+
caller.data_mut().deterministic_host_trap = true;
314+
e
315+
}
316+
HostExportError::PossibleReorg(e) => {
317+
caller.data_mut().possible_reorg = true;
318+
e
319+
}
320+
HostExportError::Unknown(e) => e,
321+
})
322+
.map_err(wasmtime::Error::from_anyhow)?;
316323
host_metrics.observe_host_fn_execution_time(
317324
start.elapsed().as_secs_f64(),
318325
&name_for_metrics,
@@ -576,7 +583,9 @@ pub(crate) fn build_linker(
576583
linker.func_wrap(
577584
"gas",
578585
"gas",
579-
|mut caller: wasmtime::Caller<'_, WasmInstanceData>, gas_used: u64| -> anyhow::Result<()> {
586+
|mut caller: wasmtime::Caller<'_, WasmInstanceData>,
587+
gas_used: u64|
588+
-> wasmtime::Result<()> {
580589
// Gas metering has a relevant execution cost cost, being called tens of thousands
581590
// of times per handler, but it's not worth having a stopwatch section here because
582591
// the cost of measuring would be greater than the cost of `consume_host_fn`. Last
@@ -587,7 +596,7 @@ pub(crate) fn build_linker(
587596
.consume_host_fn_with_metrics(Gas::new(gas_used), "gas")
588597
{
589598
caller.data_mut().deterministic_host_trap = true;
590-
return Err(e.into());
599+
return Err(wasmtime::Error::from_anyhow(e.into()));
591600
}
592601

593602
Ok(())

runtime/wasm/src/module/into_wasm_ret.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ where
7171
T: IntoWasmRet,
7272
T::Ret: wasmtime::WasmTy,
7373
{
74-
type Ret = Result<T::Ret, Error>;
74+
type Ret = Result<T::Ret, wasmtime::Error>;
7575
fn into_wasm_ret(self) -> Self::Ret {
7676
self.map(|x| x.into_wasm_ret())
77+
.map_err(wasmtime::Error::from_anyhow)
7778
}
7879
}

runtime/wasm/src/module/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl AscHeap for WasmInstanceContext<'_> {
381381
.await
382382
.map_err(|trap| {
383383
host_export_error_from_trap(
384-
trap,
384+
trap.into(),
385385
format!("Failed to call 'asc_type_id' with '{:?}'", type_id_index),
386386
)
387387
})?;

server/http/src/service.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ mod tests {
492492
}
493493

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

500501
fn metrics(&self) -> Arc<dyn GraphQLMetrics> {

server/http/tests/server.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ impl GraphQlRunner for TestGraphQlRunner {
5656
.unwrap()
5757
== &r::Value::String(String::from("John"))
5858
{
59-
Object::from_iter(
60-
vec![(Word::from("name"), r::Value::String(String::from("John")))].into_iter(),
61-
)
59+
Object::from_iter(vec![(
60+
Word::from("name"),
61+
r::Value::String(String::from("John")),
62+
)])
6263
} else {
63-
Object::from_iter(
64-
vec![(Word::from("name"), r::Value::String(String::from("Jordi")))].into_iter(),
65-
)
64+
Object::from_iter(vec![(
65+
Word::from("name"),
66+
r::Value::String(String::from("Jordi")),
67+
)])
6668
}
6769
.into()
6870
}

0 commit comments

Comments
 (0)