Add cli option --wasmtime-precompiled and subcommand precompile-wasm#1641
Add cli option --wasmtime-precompiled and subcommand precompile-wasm#1641librelois wants to merge 29 commits into
--wasmtime-precompiled and subcommand precompile-wasm#1641Conversation
|
What's your motivation to add this? Is this only supposed to be used for tests? I'd be fine to have this to speed up tests, but I'm not convinced we should support this for running normal nodes, as it would add extra complexity and be yet another place where something can go wrong for not much benefit. There's also the issue that for PVFs in Polkadot we already have caching implemented, so this would essentially duplicate that functionality in an incompatible way. (Although the requirements are different, as for PVFs we need sandboxing, so it's not really obvious how you would unify those.) How about we fundamentally simplify this and do something like this instead?
This would be, I think, simpler, need less code, be more maintainable, be more foolproof, and be easier to use. |
|
Yeah I was proposing to go this route. They are running a lot of tests in their CI and that got really slow with the removal of I'm not sure that a env variable is the way to go here either. No one will find out about this env variable besides the three of us :P I would propose that you extend |
Yeah, that also sounds good to me. |
|
The command should output the name of the file also IMO |
|
The expected wasm and the generated one don't have the same hash: |
|
The wasm is actually loaded at multiple places with different hashes: The other one is initiated by grandpa where it retrieve the runtime and hash in the call_executor, computed in the state-machine using the This mean that for the same code, we have 2 different hashes and so we won't load the precompiled wasm |
|
The CI pipeline was cancelled due to failure one of the required jobs. |
|
Something to verify. I replaced the hasher of the genesis code to use the Blake2Hasher to be compatible with the precompiled and on-chain wasm calculated hash: After that change and marking allow_missing_func_imports to false, I was able on Moonbeam to boot the node without any compilation. Something to note also, by default the "precompile-wasm" command will use the default base-path if none is provided, making this command: |
|
The |
This isn't a problem specific to moonbeam, it concerns all substrate chains that need to spawn a lot of nodes for their end2end tests. For example, Tanssi also has many end2end typescrit tests.
This is linked to the fact that the command doesn't know if you want to retrieve the runtime code from the DB or not, so it has to be initialized. Adding an explicit flag to retrieve from chain spec should solve the problem. |
|
Any update on this? as @librelois this would be heplful for other ecosystem projects as well (like Tanssi in this case) |
This cherry-pick should match this pull request: paritytech#1641
This reverts commit fe0b4db.
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
This cherry-pick should match this pull request: paritytech#1641
Introduces a new subcommand that precompiles a runtime's WASM blob and caches the result on disk, so subsequent node startups skip the JIT compilation step entirely. Moonbeam's CI runs Moonwall integration tests that spawn the node many times per pipeline. Without precompilation, each spawn pays the WASM compile cost (several seconds) and the cumulative wall-clock time becomes the dominant factor in test duration. Precompiling once and reusing the cached blob across all spawns reduces total CI time significantly on this workload. Adapted to stable2603's `BackendRuntimeCode::new(state, TryPendingCode::No)` signature change. Upstream: paritytech#1641 (not merged).
Description
What does this PR do?
This PR adds the possibility of starting the node with a precompiled WASM runtime.
This eliminates the need to compile the runtime at startup, making it possible to launch the node much more quickly.
Why are these changes needed?
A practical example of where this feature is useful is when you need to run a large number of end2end tests quickly: you precompile the runtime once in the same environment, then use the precompiled artifact every time you need to spawn the node (potentially hundreds of times).
How were these changes implemented and what do they affect?
As a security measure, a hash of the wasmtime configuration is inserted into the precompiled artifact and checked by wasmtime at startup, to ensure that, to ensure that the precompiled artifact has been generated under the same conditions.
This check is delegated to wasmtime directly thanks to the module_version function.
How to use
precompile-wasm:This will precompile the on-chain wasm at the last finalized block and save the precompiled artifact in
path/to/artifacts/folder.--wasmtime-precompiled path/to/artifacts/folder