Skip to content

Commit

Permalink
Support code blobs compressed with zstd (paritytech#8549)
Browse files Browse the repository at this point in the history
* begin maybe-compressed-blob

* fix build

* implement blob compression / decompression

* add some tests

* decode -> decompress

* decompress code if compressed

* make API of compresseed blob crate take limit as parameter

* use new API in sc-executro

* wasm-builder: compress wasm

* fix typo

* simplify

* address review

* fix wasm_project.rs

* Update primitives/maybe-compressed-blob/Cargo.toml

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
  • Loading branch information
2 people authored and jordy25519 committed Sep 20, 2021
1 parent eda0512 commit f6ecc4c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ members = [
"primitives/io",
"primitives/keyring",
"primitives/keystore",
"primitives/maybe-compressed-blob",
"primitives/npos-elections",
"primitives/npos-elections/compact",
"primitives/npos-elections/fuzzer",
Expand Down
1 change: 1 addition & 0 deletions client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sp-api = { version = "3.0.0", path = "../../primitives/api" }
sp-wasm-interface = { version = "3.0.0", path = "../../primitives/wasm-interface" }
sp-runtime-interface = { version = "3.0.0", path = "../../primitives/runtime-interface" }
sp-externalities = { version = "0.9.0", path = "../../primitives/externalities" }
sp-maybe-compressed-blob = { version = "3.0.0", path = "../../primitives/maybe-compressed-blob" }
sc-executor-common = { version = "0.9.0", path = "common" }
sc-executor-wasmi = { version = "0.9.0", path = "wasmi" }
sc-executor-wasmtime = { version = "0.9.0", path = "wasmtime", optional = true }
Expand Down
9 changes: 7 additions & 2 deletions client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ pub fn create_wasm_runtime_with_code(
allow_missing_func_imports: bool,
cache_path: Option<&Path>,
) -> Result<Arc<dyn WasmModule>, WasmError> {
use sp_maybe_compressed_blob::CODE_BLOB_BOMB_LIMIT;

let code = sp_maybe_compressed_blob::decompress(code, CODE_BLOB_BOMB_LIMIT)
.map_err(|e| WasmError::Other(format!("Decompression error: {:?}", e)))?;

match wasm_method {
WasmExecutionMethod::Interpreted => {
// Wasmi doesn't have any need in a cache directory.
Expand All @@ -292,7 +297,7 @@ pub fn create_wasm_runtime_with_code(
drop(cache_path);

sc_executor_wasmi::create_runtime(
code,
&code,
heap_pages,
host_functions,
allow_missing_func_imports,
Expand All @@ -301,7 +306,7 @@ pub fn create_wasm_runtime_with_code(
}
#[cfg(feature = "wasmtime")]
WasmExecutionMethod::Compiled => {
let blob = sc_executor_common::runtime_blob::RuntimeBlob::new(code)?;
let blob = sc_executor_common::runtime_blob::RuntimeBlob::new(&code)?;
sc_executor_wasmtime::create_runtime(
sc_executor_wasmtime::CodeSupplyMode::Verbatim { blob },
sc_executor_wasmtime::Config {
Expand Down

0 comments on commit f6ecc4c

Please sign in to comment.