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

Opt-out from fast instance reuse and foundation for other refactorings #8394

Merged
merged 15 commits into from
Apr 6, 2021

Conversation

pepyakin
Copy link
Contributor

This PR proposes several changes to the executor. Mostly it is motivated by #8153.

First change is establishing a single place where inspections and instrumentation would live: runtime_blob module. Basically, it is a wrapper around a parity-wasm's Module with instrumentation and inspection related functionality. As a nice side-effect, a place where we deserialized into a pwasm module, then serialized and deserialized in the wasmtime backend, was fixed and now we deserialize and serialize a module only once.

Then, we move a custom instrumentation that is needed for mutable globals (introduced by #6759) into the runtime_blob module.

And finally, two most important changes in the wasmtime backend:

  1. we allow for opting-out from the fast instance reuse optimization. It is important for PVF execution since this feature introduces a possibility to observe non-determinism due to the fact that it doesn't clean the most of the heap.
  2. we expose API to create compiled artifacts that could be persisted on disk and API that would allow to create an wasm runtime/PVF instance from a compiled artifact, avoiding the need for compilation. This feature will be used for the upcoming PVF cache implementation on polkadot side.

@pepyakin pepyakin 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. A1-needs_burnin Pull request needs to be tested on a live validator node before merge. DevOps is notified via matrix labels Mar 18, 2021
@@ -0,0 +1,109 @@
// This file is part of Substrate.

// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That file is technically moved, not created, so I left this.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Some nitpicks, but looks good in general.

client/executor/wasmtime/src/util.rs Outdated Show resolved Hide resolved
/// The runtime is instantiated using the given runtime blob.
Verbatim {
// Rationale to take the `RuntimeBlob` here is so that the client will be able to reuse
// the blob e.g. if they did a prevalidation. If they didn't they can `RuntimeBlob`
Copy link
Member

Choose a reason for hiding this comment

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

If they didn't they can RuntimeBlob

Needs to be fixed.

In general I'm a little bit confused by this whole docs in 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.

What is confusing? Do you have a suggestions how to improve that?

So what I am trying to say there, is that there are two use cases how sc-executor-wasmtime is going to be invoked: the traditional substrate path that uses this fast instance reuse thing and PVF execution. Both of those require to do some instrumentation under the hood, meaning that RuntimeBlob will be required.

However, I cannot say that this will be the case forever, at some point we may not need to do instrumentation nor prevalidation in which case creation of the runtime blob will be superfluous. In that case I suggest in the comment we can introduce a Cow like thing, which will create RuntimeBlob only if it's not provided and if it is required.

/// of limit: some may count the number of calls or values, others would rely on the host machine
/// stack and trap on reaching a guard page.
///
/// This obviously is a source of non-determinism during execution. This feature can be used
Copy link
Member

Choose a reason for hiding this comment

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

First you say it is non deterministic and than you speak about it being able to be setup in a deterministic way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's right. The stack depth is not deterministic, but if you enable that feature (i.e. set stack_depth_metering) it will become deterministic.

client/executor/wasmtime/src/runtime.rs Show resolved Hide resolved
client/executor/wasmtime/src/runtime.rs Outdated Show resolved Hide resolved
client/executor/common/src/runtime_blob/mod.rs Outdated Show resolved Hide resolved
pepyakin and others added 3 commits March 30, 2021 00:09
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@rphmeier rphmeier merged commit 97f1b63 into master Apr 6, 2021
@rphmeier rphmeier deleted the ser-instrument branch April 6, 2021 16:21
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
paritytech#8394)

* Establish the runtime_blob module

Seed it with the existing contents of the `util` module.

* Port wasmtime mutable globals instrumentation into runtime blob APIs

* Opt-out from fast instance reuse

* Minor clean up

* Spaces

* Docs clean up

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Factor out the expects

* Fix the suggestion

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
KalitaAlexey pushed a commit to KalitaAlexey/substrate that referenced this pull request Jul 9, 2021
paritytech#8394)

* Establish the runtime_blob module

Seed it with the existing contents of the `util` module.

* Port wasmtime mutable globals instrumentation into runtime blob APIs

* Opt-out from fast instance reuse

* Minor clean up

* Spaces

* Docs clean up

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Factor out the expects

* Fix the suggestion

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
jordy25519 pushed a commit to cennznet/substrate that referenced this pull request Sep 20, 2021
paritytech#8394)

* Establish the runtime_blob module

Seed it with the existing contents of the `util` module.

* Port wasmtime mutable globals instrumentation into runtime blob APIs

* Opt-out from fast instance reuse

* Minor clean up

* Spaces

* Docs clean up

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Factor out the expects

* Fix the suggestion

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
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. A1-needs_burnin Pull request needs to be tested on a live validator node before merge. DevOps is notified via matrix 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants