Skip to content

Commit d6725e9

Browse files
dependabot[bot]lutter
authored andcommitted
build(deps): bump wasm-instrument from 0.2.0 to 0.4.0
Bumps [wasm-instrument](https://github.com/paritytech/wasm-instrument) from 0.2.0 to 0.4.0. - [Changelog](https://github.com/paritytech/wasm-instrument/blob/master/CHANGELOG.md) - [Commits](paritytech/wasm-instrument@0.2.0...v0.4.0) The new version switches the per-block gas counter and the `memory.grow` charge helper from 32-bit to 64-bit arithmetic. Our call sites were adjusted accordingly: - `runtime/wasm/src/mapping.rs`: use the new `host_function::Injector` backend API for `gas_metering::inject`. - `runtime/wasm/src/gas_rules.rs`: implement the new `call_per_local_cost()` method, returning 0 so locals initialization remains free. - `runtime/wasm/src/module/instance.rs`: the injected `gas` host function now receives an `i64` cost argument instead of `i32`; update the Rust handler signature from `u32` to `u64`. The 64-bit arithmetic in the grow-counter helper also fixes an overflow that was previously under-charging gas for large `memory.grow` calls. In 0.2.0 the helper multiplied the page count by `gas_per_page` (~50.8M in our rules) using `I32Mul`, which wrapped mod 2^32 for any grow larger than ~84 pages (~5.25 MiB). 0.4.0 extends the page count to `i64` before the multiplication, so the full cost is charged. The two `yaml_parsing_v0_0_*` tests in `runtime/test/src/test.rs` pin exact `gas_used` totals. The YAML input `"x".repeat(10_000_001)` causes three large grow events, so each test reports exactly `3 * 2^32 = 12,884,901,888` more gas than before. Update the expected values to match the now-correct totals. Note for downstream: this is a semantic change in gas accounting for subgraph handlers that grow memory past ~5.25 MiB in a single call. Such handlers will consume more gas than they did on 0.2.0; this may warrant a release note or API-version gating, which is out of scope for this dependency bump. Signed-off-by: dependabot[bot] <support@github.com>
1 parent 545cd70 commit d6725e9

6 files changed

Lines changed: 16 additions & 10 deletions

File tree

Cargo.lock

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

runtime/test/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,10 +1844,10 @@ async fn test_yaml_parsing(api_version: Version, gas_used: u64) {
18441844

18451845
#[graph::test]
18461846
async fn yaml_parsing_v0_0_4() {
1847-
test_yaml_parsing(API_VERSION_0_0_4, 1053927678771).await;
1847+
test_yaml_parsing(API_VERSION_0_0_4, 1066812580659).await;
18481848
}
18491849

18501850
#[graph::test]
18511851
async fn yaml_parsing_v0_0_5() {
1852-
test_yaml_parsing(API_VERSION_0_0_5, 1053946160531).await;
1852+
test_yaml_parsing(API_VERSION_0_0_5, 1066831062419).await;
18531853
}

runtime/wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ anyhow = { workspace = true }
1414
never = "0.1"
1515

1616
wasmtime.workspace = true
17-
wasm-instrument = { version = "0.2.0", features = ["std", "sign_ext"] }
17+
wasm-instrument = { version = "0.4.0", features = ["std", "sign_ext"] }
1818

1919
# AssemblyScript uses sign extensions
2020
parity-wasm = { version = "0.45", features = ["std", "sign_ext"] }

runtime/wasm/src/gas_rules.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,8 @@ impl Rules for GasRules {
165165

166166
MemoryGrowCost::Linear(gas_per_page)
167167
}
168+
169+
fn call_per_local_cost(&self) -> u32 {
170+
0
171+
}
168172
}

runtime/wasm/src/mapping.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ impl ValidModule {
302302

303303
name
304304
});
305-
let parity_module = wasm_instrument::gas_metering::inject(parity_module, &GasRules, "gas")
306-
.map_err(|_| anyhow!("Failed to inject gas counter"))?;
305+
let backend = wasm_instrument::gas_metering::host_function::Injector::new("gas", "gas");
306+
let parity_module =
307+
wasm_instrument::gas_metering::inject(parity_module, backend, &GasRules)
308+
.map_err(|_| anyhow!("Failed to inject gas counter"))?;
307309
let raw_module = parity_module.into_bytes()?;
308310

309311
// We use Cranelift as a compilation engine. Cranelift is an optimizing compiler, but that

runtime/wasm/src/module/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use graph::data_source::{MappingTrigger, TriggerWithHandler};
1616
use graph::prelude::*;
1717
use graph::runtime::{
1818
HostExportError, asc_new,
19-
gas::{Gas, GasCounter, SaturatingInto},
19+
gas::{Gas, GasCounter},
2020
};
2121
use graph::{components::subgraph::MappingError, runtime::AscPtr};
2222

@@ -576,15 +576,15 @@ pub(crate) fn build_linker(
576576
linker.func_wrap(
577577
"gas",
578578
"gas",
579-
|mut caller: wasmtime::Caller<'_, WasmInstanceData>, gas_used: u32| -> anyhow::Result<()> {
579+
|mut caller: wasmtime::Caller<'_, WasmInstanceData>, gas_used: u64| -> anyhow::Result<()> {
580580
// Gas metering has a relevant execution cost cost, being called tens of thousands
581581
// of times per handler, but it's not worth having a stopwatch section here because
582582
// the cost of measuring would be greater than the cost of `consume_host_fn`. Last
583583
// time this was benchmarked it took < 100ns to run.
584584
if let Err(e) = caller
585585
.data()
586586
.gas
587-
.consume_host_fn_with_metrics(gas_used.saturating_into(), "gas")
587+
.consume_host_fn_with_metrics(Gas::new(gas_used), "gas")
588588
{
589589
caller.data_mut().deterministic_host_trap = true;
590590
return Err(e.into());

0 commit comments

Comments
 (0)