Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts: update wasmi to 0.32 #3679

Merged
merged 104 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
94fe749
Only load module once when validating
pgherveou Mar 22, 2024
a38c8a6
bump wasmi to 0.32
pgherveou Mar 22, 2024
bada63e
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou Apr 10, 2024
0b96f38
fix lock
pgherveou Apr 10, 2024
88abfcf
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 10, 2024
21e5e33
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou Apr 11, 2024
4503590
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 11, 2024
c275207
Use eager compilation mode when benchmarking a host fn
pgherveou Apr 11, 2024
3e835d0
tmp: Use eager compilation
pgherveou Apr 11, 2024
3892688
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 11, 2024
63d8663
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 11, 2024
59138ba
Disable unchecked compilation for now
pgherveou Apr 11, 2024
4d5b935
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 11, 2024
b1db093
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 11, 2024
213c84e
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou Apr 16, 2024
1f6f926
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 16, 2024
4c84d87
Merge branch 'master' into pg/wasmi-to-v0.3t 2.0-beta.7
athei Apr 17, 2024
6b0acbd
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 17, 2024
829d590
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou Apr 17, 2024
0de9713
wip
pgherveou Apr 22, 2024
d4ab2a8
wip
pgherveou Apr 22, 2024
ecedf8c
wip
pgherveou Apr 22, 2024
00fa306
Merge branch 'master' into pg/rework-host-benchs
pgherveou Apr 22, 2024
f2152fe
wip
pgherveou Apr 23, 2024
75f1c8c
wip
pgherveou Apr 25, 2024
d3921cd
Fixes
pgherveou Apr 26, 2024
c727dd2
Fixes
pgherveou Apr 26, 2024
cf3362f
Update
pgherveou Apr 26, 2024
aed88a9
fixes
pgherveou Apr 26, 2024
f20aed7
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 29, 2024
450ca08
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 29, 2024
c2cd365
Fixes
pgherveou Apr 29, 2024
19fb7bf
fix
pgherveou Apr 29, 2024
5edcd18
Rm unused
pgherveou Apr 29, 2024
837b2d6
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 29, 2024
b2eb314
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 29, 2024
41b5f3a
add ;
pgherveou Apr 29, 2024
f4d65f6
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 29, 2024
9ceb549
Undo
pgherveou May 3, 2024
c6df46a
Merge branch 'pg/rework-host-benchs' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 3, 2024
47b5291
restore unchecked & lazy compilation
pgherveou May 3, 2024
50c3b66
bump to latest beta
pgherveou May 3, 2024
92a27a1
Update fuel syncing.
pgherveou May 3, 2024
a75fa25
nit
pgherveou May 3, 2024
3466434
set_fuel can't error
pgherveou May 3, 2024
f398a9c
nit
pgherveou May 3, 2024
28acc56
Add PRdoc
pgherveou May 15, 2024
6d87585
Fix PRdoc
pgherveou May 15, 2024
8364456
Merge branch 'master' into pg/rework-host-benchs
athei May 16, 2024
0586b4a
benchmarks: whitelist account_id and contract_info for the root contract
pgherveou May 16, 2024
fbdc565
fix
pgherveou May 16, 2024
58517ee
PR review merge set_storage_per_new_byte & _old_bytes
pgherveou May 16, 2024
825a434
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 16, 2024
2cc19fb
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 16, 2024
a11e74b
Fix terminate
pgherveou May 17, 2024
da17374
Merge branch 'master' into pg/rework-host-benchs
pgherveou May 17, 2024
b806834
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 17, 2024
799134f
Merge branch 'pg/rework-host-benchs' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 17, 2024
ae17165
Bump beta version
pgherveou May 17, 2024
80dc606
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 17, 2024
87fa082
Merge branch 'master' into pg/rework-host-benchs
athei May 17, 2024
d235dfa
Remove internal events
pgherveou May 17, 2024
7ae8ac1
Add prdoc
pgherveou May 17, 2024
737e956
Fix tests
pgherveou May 17, 2024
2f34c0f
use whitelisted root contract origin for cross contract benchmarks
pgherveou May 17, 2024
8b24c9a
Merge branch 'pg/fix_legacy_bench' into pg/rework-host-benchs
pgherveou May 17, 2024
efd75a8
Merge branch 'pg/fix_legacy_bench' into pg/rework-host-benchs
pgherveou May 17, 2024
d5b08bb
Merge branch 'master' into pg/rework-host-benchs
pgherveou May 17, 2024
2926901
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 17, 2024
fb9355f
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 19, 2024
6b4eea3
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 19, 2024
2fa8edc
Simplify clone call
pgherveou May 20, 2024
46650ca
Fix weights
pgherveou May 20, 2024
d7ea304
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 20, 2024
8f15947
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 20, 2024
3532367
Bump wasmi beta
pgherveou May 23, 2024
1b186f6
Merge branch 'pg/rework-host-benchs' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 23, 2024
7ff3655
Update prdoc
pgherveou May 23, 2024
d054fcd
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 23, 2024
e2ec3cd
Add debug statement
pgherveou May 23, 2024
8e25cc9
Update to latest beta
pgherveou May 23, 2024
ca9da25
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 23, 2024
d47a0d2
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 23, 2024
c116c66
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 27, 2024
a058d38
Add assert
pgherveou May 27, 2024
ba61f59
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 27, 2024
8b7ca41
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 27, 2024
8fd1875
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_contr…
May 27, 2024
2d40ddd
Update wasmi version
pgherveou May 29, 2024
49e3c78
Merge branch 'pg/wasmi-to-v0.32.0-beta.7' of https://github.com/parit…
pgherveou May 29, 2024
99fb78c
Update PR doc
pgherveou May 30, 2024
ca61d1b
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou May 30, 2024
78abbea
test roll-back beta
pgherveou May 30, 2024
72de0b5
fix lock
pgherveou May 30, 2024
6eae263
fix lock
pgherveou May 30, 2024
cf02fd7
roll back 0.32
pgherveou May 30, 2024
acd6dfb
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 30, 2024
08ea90b
Bump wasmi
pgherveou Jun 3, 2024
ac9f81c
Remove transfer_surcharge from instantiate
pgherveou Jun 3, 2024
b960a6d
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jun 3, 2024
c2b7441
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 3, 2024
7efe1e7
Fix PR doc and bump wasmi one last time
pgherveou Jun 7, 2024
99cd79e
Merge branch 'master' into pg/wasmi-to-v0.32.0-beta.7
pgherveou Jun 7, 2024
ee1a7ca
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jun 7, 2024
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
98 changes: 83 additions & 15 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions prdoc/pr_3679.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: "[pallet-contracts] bump wasmi to 0.32"

doc:
- audience: Runtime Dev
description: |
- Bump wasmi to 0.32
- Turn on lazy and unchecked compilation when calling a contract.
See https://docs.rs/wasmi/0.32.0/wasmi/enum.CompilationMode.html#variant.Lazy
See https://docs.rs/wasmi/0.32.0/wasmi/struct.Module.html#method.new_unchecked
See https://wasmi-labs.github.io/blog/posts/wasmi-v0.32 for more details, on the wasmi update.

crates:
- name: pallet-contracts
- name: pallet-contracts-proc-macro
2 changes: 1 addition & 1 deletion substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ serde = { optional = true, features = ["derive"], workspace = true, default-feat
smallvec = { version = "1", default-features = false, features = [
"const_generics",
] }
wasmi = { version = "0.31", default-features = false }
wasmi = { version = "0.32.3", default-features = false }
impl-trait-for-tuples = "0.2"

# Only used in benchmarking to generate contract code
Expand Down
21 changes: 12 additions & 9 deletions substrate/frame/contracts/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl HostFnReturn {
Self::U64 => quote! { ::core::primitive::u64 },
};
quote! {
::core::result::Result<#ok, ::wasmi::core::Trap>
::core::result::Result<#ok, ::wasmi::Error>
}
}
}
Expand Down Expand Up @@ -694,7 +694,7 @@ fn expand_functions(def: &EnvDef, expand_mode: ExpandMode) -> TokenStream2 {
let into_host = if expand_blocks {
quote! {
|reason| {
::wasmi::core::Trap::from(reason)
::wasmi::Error::host(reason)
}
}
} else {
Expand All @@ -711,13 +711,13 @@ fn expand_functions(def: &EnvDef, expand_mode: ExpandMode) -> TokenStream2 {
quote! {
// Write gas from wasmi into pallet-contracts before entering the host function.
let __gas_left_before__ = {
let executor_total =
__caller__.fuel_consumed().expect("Fuel metering is enabled; qed");
let fuel =
__caller__.get_fuel().expect("Fuel metering is enabled; qed");
__caller__
.data_mut()
.ext()
.gas_meter_mut()
.sync_from_executor(executor_total)
.sync_from_executor(fuel)
.map_err(TrapReason::from)
.map_err(#into_host)?
};
Expand All @@ -733,15 +733,18 @@ fn expand_functions(def: &EnvDef, expand_mode: ExpandMode) -> TokenStream2 {
// Write gas from pallet-contracts into wasmi after leaving the host function.
let sync_gas_after = if expand_blocks {
quote! {
let fuel_consumed = __caller__
let fuel = __caller__
.data_mut()
.ext()
.gas_meter_mut()
.sync_to_executor(__gas_left_before__)
.map_err(TrapReason::from)?;
.map_err(|err| {
let err = TrapReason::from(err);
wasmi::Error::host(err)
})?;
__caller__
.consume_fuel(fuel_consumed.into())
.map_err(|_| TrapReason::from(Error::<E::T>::OutOfGas))?;
.set_fuel(fuel.into())
.expect("Fuel metering is enabled; qed");
}
} else {
quote! { }
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,15 +1278,14 @@ mod benchmarks {
// s: size of salt in bytes
#[benchmark(pov_mode = Measured)]
fn seal_instantiate(
t: Linear<0, 1>,
i: Linear<0, { (code::max_pages::<T>() - 1) * 64 * 1024 }>,
s: Linear<0, { (code::max_pages::<T>() - 1) * 64 * 1024 }>,
) -> Result<(), BenchmarkError> {
let hash = Contract::<T>::with_index(1, WasmModule::dummy(), vec![])?.info()?.code_hash;
let hash_bytes = hash.encode();
let hash_len = hash_bytes.len() as u32;

let value: BalanceOf<T> = t.into();
let value: BalanceOf<T> = 1u32.into();
let value_bytes = value.encode();
let value_len = value_bytes.len() as u32;

Expand Down Expand Up @@ -1341,6 +1340,7 @@ mod benchmarks {

assert_ok!(result);
assert!(ContractInfoOf::<T>::get(&addr).is_some());
assert_eq!(T::Currency::balance(&addr), Pallet::<T>::min_balance() + value);
Ok(())
}

Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/contracts/src/benchmarking/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::wasm::{
LoadingMode, WasmBlob,
};
use sp_core::Get;
use wasmi::{errors::LinkerError, Func, Linker, StackLimits, Store};
use wasmi::{errors::LinkerError, CompilationMode, Func, Linker, StackLimits, Store};

/// Minimal execution environment without any imported functions.
pub struct Sandbox {
Expand All @@ -48,6 +48,7 @@ impl<T: Config> From<&WasmModule<T>> for Sandbox {
Determinism::Relaxed,
Some(StackLimits::default()),
LoadingMode::Checked,
CompilationMode::Eager,
)
.expect("Failed to load Wasm module");

Expand All @@ -62,7 +63,7 @@ impl<T: Config> From<&WasmModule<T>> for Sandbox {

// Set fuel for wasmi execution.
store
.add_fuel(u64::MAX)
.set_fuel(u64::MAX)
.expect("We've set up engine to fuel consuming mode; qed");

let entry_point = instance
Expand Down
Loading
Loading