Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Bump wasmtime to 0.31.0 #10149

Merged
merged 5 commits into from
Nov 9, 2021

Conversation

koute
Copy link
Contributor

@koute koute commented Nov 2, 2021

polkadot companion: paritytech/polkadot#4210

@koute koute added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Nov 2, 2021
@koute koute requested review from pepyakin and bkchr November 2, 2021 08:35
@koute koute added C1-low PR touches the given topic and has a low impact on builders. and removed C1-low PR touches the given topic and has a low impact on builders. labels Nov 2, 2021
@@ -333,6 +333,7 @@ impl<'a, 'b, 'c, 'd> sandbox::SandboxContext for SandboxContext<'a, 'b, 'c, 'd>
state: u32,
func_idx: SupervisorFuncIndex,
) -> Result<i64> {
let mut ret_vals = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think we do know the signature.

extern "C" fn dispatch_thunk<T>(
	serialized_args_ptr: *const u8,
	serialized_args_len: usize,
	state: usize,
	f: ffi::HostFuncIndex,
) -> u64 { ... }

so we can actually get away with an array of one item here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think I screwed up here, because Func::call takes a &mut [Val] instead of a &mut Vec<Val>, so it can't work, and yet... no tests actually fail? I'll check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I had to dig through many unfamiliar layers of code, but I can confirm this is indeed not being tested at all.

In the sp-sandbox we have two alternative codepaths which are picked during compile time: embedded_executor and host_executor. Only the host_executor goes through the Sandbox runtime interface and actually triggers this code. However it is not(feature = "std")-only, and the std feature is always enabled on that crate, so in consequence the embedded_executor codepath is always compiled in.

The sp-sandbox itself is (in the tests which are supposed to test this code, according to what @pepyakin told me) invoked from a #[cfg(not(feature = "std"))] function in sc-runtime-test, so I'm guessing the current situation is totally unintended and (for these tests) the host_executor should always be used; maybe someone somewhere accidentally transitively enabled the std feature on sp-sandbox and we just never noticed since nothing actually failed?

I'll fix it so that this actually gets tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @athei

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koute

and the std feature is always enabled on that crate

Are you talking about this logic?

mod imp {
	#[cfg(all(feature = "wasmer-sandbox", not(feature = "std")))]
	include!("../host_executor.rs");

	#[cfg(not(all(feature = "wasmer-sandbox", not(feature = "std"))))]
	include!("../embedded_executor.rs");
}

I was under the impression that std is not activated when it is compiled as part of the wasm runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. I think the problem is more that currently host_executor is not being used because wasmer is deactivated.

Copy link
Member

@athei athei Nov 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is on purpose. Generally, we want the embedded executor for contracts (which is wasmi) because polkadot validators are missing the sandboxing host functions.

However, the experimental wasmer-sandbox feature can be enabled on the command line (it is done by one CI test) in order to to testing and benchmarking with wasmer. The intention is to keep it around until we can fully switch to wasmer. wasmer cannot be embedded because it is a compiler which is inherently platform dependent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@athei Yes; for the sandbox integration tests the embedded_executor is always selected. I might have not been entirely correct when I said the std feature is always enabled, but there is something weird going on with the feature flags.

Anyway, I've put up a separate PR to try and get both codepaths tested:

#10173

@koute koute changed the title Bump wasmtime to 0.31.0 [WIP] Bump wasmtime to 0.31.0 Nov 3, 2021
@koute koute changed the title [WIP] Bump wasmtime to 0.31.0 Bump wasmtime to 0.31.0 Nov 8, 2021
@koute
Copy link
Contributor Author

koute commented Nov 8, 2021

Now that this is properly tested (test now fail when SandboxContext::invoke is broken) and fixed this should be good to go once the CI goes green.

@koute
Copy link
Contributor Author

koute commented Nov 9, 2021

bot merge

@paritytech-processbot
Copy link

Error: It's not possible to meet the minimal approval count of 1 in paritytech/polkadot#4210

@gilescope
Copy link
Contributor

bot merge

@paritytech-processbot
Copy link

Error: It's not possible to meet the minimal approval count of 1 in paritytech/polkadot#4210

@ordian
Copy link
Member

ordian commented Nov 9, 2021

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 5cb8a6d into paritytech:master Nov 9, 2021
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* Bump `wasmtime` to 0.31.0

* Bump `itoa` to 0.4.8

* sc-executor-wasmtime: fix `SandboxContext::invoke` which I've broke

* sc-executor-wasmtime: cargo fmt
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Bump `wasmtime` to 0.31.0

* Bump `itoa` to 0.4.8

* sc-executor-wasmtime: fix `SandboxContext::invoke` which I've broke

* sc-executor-wasmtime: cargo fmt
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants