Embed runtime version as a custom section (#8688)

* emit a custom section from impl_runtime_apis!

This change emits a custom section from the impl_runtime_apis! proc macro.

Each implemented API will result to emitting a link section `runtime_apis`.
During linking all sections with this name will be concatenated and
placed into the final wasm binary under the same name.

* Introduce `runtime_version` proc macro

This macro takes an existing `RuntimeVersion` const declaration, parses
it and emits the version information in form of a linking section.
Ultimately such a linking section will result into a custom wasm
section.

* Parse custom wasm section for runtime version

* Apply suggestions from code review

Co-authored-by: David <dvdplm@gmail.com>

* Fix sc-executor integration tests

* Nits

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

* Refactor apis section deserialization

* Fix version decoding

* Reuse uncompressed value for CallInWasm

* Log on decompression error

* Simplify if

* Reexport proc-macro from sp_version

* Merge ReadRuntimeVersionExt

* Export `read_embedded_version`

* Fix test

* Simplify searching for custom section

Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Shulepov
2021-05-12 15:39:08 +02:00
committed by GitHub
parent 4f7c1df31e
commit 0849bcce0e
27 changed files with 833 additions and 289 deletions
@@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
sp-runtime-interface = { version = "3.0.0", path = "../" }
sc-executor = { version = "0.9.0", path = "../../../client/executor" }
sc-executor-common = { version = "0.9.0", path = "../../../client/executor/common" }
sp-runtime-interface-test-wasm = { version = "2.0.0", path = "../test-wasm" }
sp-runtime-interface-test-wasm-deprecated = { version = "2.0.0", path = "../test-wasm-deprecated" }
sp-state-machine = { version = "0.9.0", path = "../../state-machine" }
@@ -24,7 +24,7 @@ use sp_runtime_interface_test_wasm::{wasm_binary_unwrap, test_api::HostFunctions
use sp_runtime_interface_test_wasm_deprecated::wasm_binary_unwrap as wasm_binary_deprecated_unwrap;
use sp_wasm_interface::HostFunctions as HostFunctionsT;
use sc_executor::CallInWasm;
use sc_executor_common::runtime_blob::RuntimeBlob;
use std::{collections::HashSet, sync::{Arc, Mutex}};
@@ -46,14 +46,15 @@ fn call_wasm_method_with_result<HF: HostFunctionsT>(
8,
None,
);
executor.call_in_wasm(
binary,
None,
method,
&[],
&mut ext_ext,
sp_core::traits::MissingHostFunctions::Disallow,
).map_err(|e| format!("Failed to execute `{}`: {}", method, e))?;
executor
.uncached_call(
RuntimeBlob::uncompress_if_needed(binary).expect("Failed to parse binary"),
&mut ext_ext,
false,
method,
&[],
)
.map_err(|e| format!("Failed to execute `{}`: {}", method, e))?;
Ok(ext)
}