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
+16 -1
View File
@@ -7353,7 +7353,6 @@ dependencies = [
"sp-core",
"sp-externalities",
"sp-io",
"sp-maybe-compressed-blob",
"sp-panic-handler",
"sp-runtime",
"sp-runtime-interface",
@@ -7381,6 +7380,7 @@ dependencies = [
"pwasm-utils 0.14.0",
"sp-allocator",
"sp-core",
"sp-maybe-compressed-blob",
"sp-serializer",
"sp-wasm-interface",
"thiserror",
@@ -8883,6 +8883,7 @@ dependencies = [
"sp-core",
"sp-externalities",
"sp-keystore",
"sp-maybe-compressed-blob",
"sp-runtime-interface",
"sp-state-machine",
"sp-std",
@@ -9063,6 +9064,7 @@ name = "sp-runtime-interface-test"
version = "2.0.0"
dependencies = [
"sc-executor",
"sc-executor-common",
"sp-core",
"sp-io",
"sp-runtime",
@@ -9291,6 +9293,19 @@ dependencies = [
"serde",
"sp-runtime",
"sp-std",
"sp-version-proc-macro",
]
[[package]]
name = "sp-version-proc-macro"
version = "3.0.0"
dependencies = [
"parity-scale-codec",
"proc-macro-crate 1.0.0",
"proc-macro2",
"quote",
"sp-version",
"syn",
]
[[package]]