From 4dfb897a26d76a08c3b9ce3d7da3002b0702153e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 6 Jan 2020 20:52:52 +0100 Subject: [PATCH 01/13] Implement runtime version checks in `set_code` Check that the new runtime code given to `set_code` fullfills some requirements: - `spec_name` matches - `spec_version` does not decreases - `impl_version` does not decreases - Either `spec_version` and `impl_version` increase --- Cargo.lock | 225 +++++++++++---------- client/executor/common/src/wasm_runtime.rs | 4 +- client/executor/src/lib.rs | 14 +- client/executor/src/native_executor.rs | 44 +++- client/executor/src/wasm_runtime.rs | 5 +- client/executor/wasmi/Cargo.toml | 1 - client/executor/wasmi/src/lib.rs | 17 +- client/executor/wasmtime/Cargo.toml | 1 - client/executor/wasmtime/src/runtime.rs | 13 +- client/src/call_executor.rs | 4 +- client/src/client.rs | 36 ++-- client/src/light/call_executor.rs | 6 +- client/src/light/fetcher.rs | 2 +- client/src/light/mod.rs | 2 +- frame/system/Cargo.toml | 3 + frame/system/src/lib.rs | 149 +++++++++++++- primitives/core/src/traits.rs | 29 ++- primitives/io/src/lib.rs | 14 +- primitives/runtime/src/lib.rs | 89 +++++++- primitives/sandbox/with_std.rs | 22 +- primitives/state-machine/src/lib.rs | 16 +- primitives/version/Cargo.toml | 2 +- primitives/version/src/lib.rs | 28 +-- test-utils/runtime/src/lib.rs | 3 + 24 files changed, 498 insertions(+), 231 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69f168eba2057..f656142d30c47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1205,7 +1205,7 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1262,7 +1262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fork-tree" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1275,7 +1275,7 @@ dependencies = [ "pallet-balances 2.0.0", "pallet-indices 2.0.0", "pallet-transaction-payment 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -1287,7 +1287,7 @@ dependencies = [ name = "frame-metadata" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-std 2.0.0", @@ -1304,7 +1304,7 @@ dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1353,7 +1353,7 @@ name = "frame-support-test" version = "2.0.0" dependencies = [ "frame-support 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -1371,21 +1371,24 @@ dependencies = [ "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "frame-support 2.0.0", "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sc-executor 2.0.0", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", + "sp-externalities 2.0.0", "sp-io 2.0.0", "sp-runtime 2.0.0", "sp-std 2.0.0", "sp-version 2.0.0", + "substrate-test-runtime 2.0.0", ] [[package]] name = "frame-system-rpc-runtime-api" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", ] @@ -1999,7 +2002,7 @@ name = "impl-codec" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3005,7 +3008,7 @@ dependencies = [ "pallet-indices 2.0.0", "pallet-timestamp 2.0.0", "pallet-transaction-payment 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-authority-discovery 2.0.0", @@ -3065,7 +3068,7 @@ dependencies = [ "pallet-timestamp 2.0.0", "pallet-transaction-payment 2.0.0", "pallet-treasury 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-executor 2.0.0", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3151,7 +3154,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api 2.0.0", "pallet-treasury 2.0.0", "pallet-utility 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3182,7 +3185,7 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "node-template-runtime 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-basic-authority 2.0.0", "sc-cli 2.0.0", @@ -3222,7 +3225,7 @@ dependencies = [ "pallet-sudo 2.0.0", "pallet-timestamp 2.0.0", "pallet-transaction-payment 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", @@ -3258,7 +3261,7 @@ dependencies = [ "pallet-timestamp 2.0.0", "pallet-transaction-payment 2.0.0", "pallet-treasury 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", "sc-executor 2.0.0", "sp-core 2.0.0", @@ -3274,7 +3277,7 @@ name = "node-transaction-factory" version = "2.0.0" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-cli 2.0.0", "sc-client 2.0.0", "sc-client-api 2.0.0", @@ -3437,7 +3440,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3454,7 +3457,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-session 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-application-crypto 2.0.0", @@ -3474,7 +3477,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-session 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-application-crypto 2.0.0", "sp-authority-discovery 2.0.0", @@ -3492,7 +3495,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-authorship 2.0.0", "sp-core 2.0.0", "sp-inherents 2.0.0", @@ -3511,7 +3514,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-session 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-consensus-babe 0.8.0", @@ -3533,7 +3536,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-transaction-payment 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3550,7 +3553,7 @@ dependencies = [ "frame-system 2.0.0", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3570,7 +3573,7 @@ dependencies = [ "pallet-balances 2.0.0", "pallet-randomness-collective-flip 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3591,7 +3594,7 @@ dependencies = [ "jsonrpc-core-client 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-derive 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-contracts-rpc-runtime-api 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "sp-blockchain 2.0.0", @@ -3604,7 +3607,7 @@ dependencies = [ name = "pallet-contracts-rpc-runtime-api" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-runtime 2.0.0", "sp-std 2.0.0", @@ -3617,7 +3620,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3634,7 +3637,7 @@ dependencies = [ "frame-system 2.0.0", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3651,7 +3654,7 @@ dependencies = [ "frame-system 2.0.0", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3670,7 +3673,7 @@ dependencies = [ "frame-system 2.0.0", "pallet-balances 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3688,7 +3691,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3703,7 +3706,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-finality-tracker 2.0.0", @@ -3719,7 +3722,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3735,7 +3738,7 @@ dependencies = [ "frame-system 2.0.0", "pallet-finality-tracker 2.0.0", "pallet-session 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-finality-grandpa 2.0.0", @@ -3753,7 +3756,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3769,7 +3772,7 @@ dependencies = [ "frame-system 2.0.0", "pallet-authorship 2.0.0", "pallet-session 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-application-crypto 2.0.0", "sp-core 2.0.0", @@ -3785,7 +3788,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3801,7 +3804,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3816,7 +3819,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3831,7 +3834,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3846,7 +3849,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3861,7 +3864,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3878,7 +3881,7 @@ dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-application-crypto 2.0.0", @@ -3901,7 +3904,7 @@ dependencies = [ "pallet-session 2.0.0", "pallet-staking-reward-curve 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -3931,7 +3934,7 @@ version = "2.0.0" dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -3946,7 +3949,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-inherents 2.0.0", @@ -3964,7 +3967,7 @@ dependencies = [ "frame-system 2.0.0", "pallet-balances 2.0.0", "pallet-transaction-payment-rpc-runtime-api 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", "sp-runtime 2.0.0", @@ -3979,7 +3982,7 @@ dependencies = [ "jsonrpc-core-client 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-derive 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-transaction-payment-rpc-runtime-api 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-blockchain 2.0.0", "sp-core 2.0.0", @@ -3992,7 +3995,7 @@ name = "pallet-transaction-payment-rpc-runtime-api" version = "2.0.0" dependencies = [ "frame-support 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", @@ -4007,7 +4010,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -4022,7 +4025,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -4099,7 +4102,7 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4916,7 +4919,7 @@ dependencies = [ "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "prost-build 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4940,7 +4943,7 @@ version = "2.0.0" dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-block-builder 2.0.0", "sc-client 2.0.0", @@ -4961,7 +4964,7 @@ dependencies = [ name = "sc-block-builder" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-block-builder 2.0.0", "sp-blockchain 2.0.0", @@ -5042,7 +5045,7 @@ dependencies = [ "kvdb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-block-builder 2.0.0", "sc-client-api 2.0.0", @@ -5077,7 +5080,7 @@ dependencies = [ "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-executor 2.0.0", "sc-telemetry 2.0.0", @@ -5108,7 +5111,7 @@ dependencies = [ "kvdb-rocksdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", @@ -5135,7 +5138,7 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", "sc-client-api 2.0.0", @@ -5179,7 +5182,7 @@ dependencies = [ "num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5220,7 +5223,7 @@ dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", "sp-block-builder 2.0.0", "sp-blockchain 2.0.0", @@ -5239,7 +5242,7 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", "sc-telemetry 2.0.0", @@ -5274,7 +5277,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-executor-common 2.0.0", @@ -5303,7 +5306,7 @@ version = "2.0.0" dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-runtime-interface 2.0.0", "sp-serializer 2.0.0", @@ -5316,11 +5319,10 @@ name = "sc-executor-wasmi" version = "2.0.0" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-executor-common 2.0.0", "sp-core 2.0.0", - "sp-externalities 2.0.0", "sp-runtime-interface 2.0.0", "sp-wasm-interface 2.0.0", "wasmi 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5337,11 +5339,10 @@ dependencies = [ "cranelift-native 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-wasm 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-executor-common 2.0.0", "sp-core 2.0.0", - "sp-externalities 2.0.0", "sp-runtime-interface 2.0.0", "sp-wasm-interface 2.0.0", "wasmi 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5361,7 +5362,7 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", @@ -5423,7 +5424,7 @@ dependencies = [ "linked_hash_set 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5511,7 +5512,7 @@ dependencies = [ "hyper-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", @@ -5551,7 +5552,7 @@ dependencies = [ "jsonrpc-core 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", @@ -5587,7 +5588,7 @@ dependencies = [ "jsonrpc-derive 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5635,7 +5636,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-chain-spec 2.0.0", "sc-client 2.0.0", @@ -5700,7 +5701,7 @@ version = "2.0.0" dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", ] @@ -5751,7 +5752,7 @@ dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -5767,7 +5768,7 @@ dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", "sc-transaction-graph 2.0.0", @@ -6067,7 +6068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "sp-api" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api-proc-macro 2.0.0", "sp-core 2.0.0", "sp-runtime 2.0.0", @@ -6093,7 +6094,7 @@ name = "sp-api-test" version = "2.0.0" dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-blockchain 2.0.0", @@ -6109,7 +6110,7 @@ dependencies = [ name = "sp-application-crypto" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", @@ -6133,7 +6134,7 @@ dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6145,7 +6146,7 @@ dependencies = [ name = "sp-authority-discovery" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-application-crypto 2.0.0", "sp-runtime 2.0.0", @@ -6156,7 +6157,7 @@ dependencies = [ name = "sp-authorship" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-inherents 2.0.0", "sp-runtime 2.0.0", "sp-std 2.0.0", @@ -6166,7 +6167,7 @@ dependencies = [ name = "sp-block-builder" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-inherents 2.0.0", "sp-runtime 2.0.0", @@ -6180,7 +6181,7 @@ dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-block-builder 2.0.0", "sp-consensus 0.8.0", @@ -6197,7 +6198,7 @@ dependencies = [ "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-inherents 2.0.0", @@ -6211,7 +6212,7 @@ dependencies = [ name = "sp-consensus-aura" version = "0.8.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-application-crypto 2.0.0", "sp-inherents 2.0.0", @@ -6224,7 +6225,7 @@ dependencies = [ name = "sp-consensus-babe" version = "0.8.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-application-crypto 2.0.0", @@ -6239,7 +6240,7 @@ dependencies = [ name = "sp-consensus-pow" version = "0.8.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-core 2.0.0", "sp-runtime 2.0.0", @@ -6264,7 +6265,7 @@ dependencies = [ "libsecp256k1 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6311,7 +6312,7 @@ dependencies = [ name = "sp-finality-grandpa" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-application-crypto 2.0.0", @@ -6323,7 +6324,7 @@ dependencies = [ name = "sp-finality-tracker" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-inherents 2.0.0", "sp-std 2.0.0", ] @@ -6333,7 +6334,7 @@ name = "sp-inherents" version = "2.0.0" dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-std 2.0.0", @@ -6346,7 +6347,7 @@ dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-externalities 2.0.0", "sp-runtime-interface 2.0.0", @@ -6408,7 +6409,7 @@ version = "2.0.0" dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6426,7 +6427,7 @@ name = "sp-runtime-interface" version = "2.0.0" dependencies = [ "environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -6480,7 +6481,7 @@ name = "sp-sandbox" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", "sp-std 2.0.0", @@ -6509,7 +6510,7 @@ dependencies = [ name = "sp-staking" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-runtime 2.0.0", "sp-std 2.0.0", ] @@ -6522,7 +6523,7 @@ dependencies = [ "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", @@ -6551,7 +6552,7 @@ dependencies = [ name = "sp-test-primitives" version = "2.0.0" dependencies = [ - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-application-crypto 2.0.0", "sp-core 2.0.0", @@ -6563,7 +6564,7 @@ name = "sp-timestamp" version = "2.0.0" dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-inherents 2.0.0", "sp-runtime 2.0.0", @@ -6577,7 +6578,7 @@ dependencies = [ "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-api 2.0.0", "sp-runtime 2.0.0", @@ -6591,7 +6592,7 @@ dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-std 2.0.0", "trie-bench 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6605,7 +6606,7 @@ name = "sp-version" version = "2.0.0" dependencies = [ "impl-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-runtime 2.0.0", "sp-std 2.0.0", @@ -6720,7 +6721,7 @@ dependencies = [ "node-runtime 2.0.0", "pallet-balances 2.0.0", "pallet-transaction-payment 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6755,7 +6756,7 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-client-transports 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-rpc-api 2.0.0", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-storage 2.0.0", @@ -6773,7 +6774,7 @@ dependencies = [ "jsonrpc-core-client 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-derive 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", "sc-transaction-pool 2.0.0", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6790,7 +6791,7 @@ version = "2.0.0" dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", "sc-client-api 2.0.0", "sc-client-db 2.0.0", @@ -6816,7 +6817,7 @@ dependencies = [ "memory-db 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-babe 2.0.0", "pallet-timestamp 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client 2.0.0", "sc-executor 2.0.0", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6848,7 +6849,7 @@ name = "substrate-test-runtime-client" version = "2.0.0" dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sc-block-builder 2.0.0", "sc-client 2.0.0", "sc-client-api 2.0.0", @@ -7396,7 +7397,7 @@ dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-standardmap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -8436,7 +8437,7 @@ dependencies = [ "checksum parity-multiaddr 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82afcb7461eae5d122543d8be1c57d306ed89af2d6ff7f8b0f5a3cc8f7e511bc" "checksum parity-multihash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "df3a17dc27848fd99e4f87eb0f8c9baba6ede0a6d555400c850ca45254ef4ce3" "checksum parity-multihash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c70cad855872dd51ce6679e823efb6434061a2c1782a1686438aabf506392cdd" -"checksum parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9f9d99dae413590a5f37e43cd99b94d4e62a244160562899126913ea7108673" +"checksum parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f747c06d9f3b2ad387ac881b9667298c81b1243aa9833f086e05996937c35507" "checksum parity-scale-codec-derive 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34e513ff3e406f3ede6796dcdc83d0b32ffb86668cea1ccf7363118abeb00476" "checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-util-mem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8174d85e62c4d615fddd1ef67966bdc5757528891d0742f15b131ad04667b3f9" diff --git a/client/executor/common/src/wasm_runtime.rs b/client/executor/common/src/wasm_runtime.rs index 0df7d21ac2f37..bae261430fc7c 100644 --- a/client/executor/common/src/wasm_runtime.rs +++ b/client/executor/common/src/wasm_runtime.rs @@ -17,7 +17,6 @@ //! Definitions for a wasm runtime. use crate::error::Error; -use sp_core::traits::Externalities; use sp_wasm_interface::Function; /// A trait that defines an abstract wasm runtime. @@ -34,6 +33,5 @@ pub trait WasmRuntime { fn host_functions(&self) -> &[&'static dyn Function]; /// Call a method in the Substrate runtime by name. Returns the encoded result on success. - fn call(&mut self, ext: &mut dyn Externalities, method: &str, data: &[u8]) - -> Result, Error>; + fn call(&mut self, method: &str, data: &[u8]) -> Result, Error>; } diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index c343e97b44c3a..0ee7f6eb03bc5 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -57,14 +57,15 @@ pub use sc_executor_common::{error, allocator, sandbox}; /// - `call_data`: Will be given as input parameters to `function` /// - `execution_method`: The execution method to use. /// - `ext`: The externalities that should be set while executing the wasm function. +/// If `None` is given, no externalities will be set. /// - `heap_pages`: The number of heap pages to allocate. /// /// Returns the `Vec` that contains the return value of the function. -pub fn call_in_wasm( +pub fn call_in_wasm( function: &str, call_data: &[u8], execution_method: WasmExecutionMethod, - ext: &mut E, + ext: Option<&mut dyn Externalities>, code: &[u8], heap_pages: u64, ) -> error::Result> { @@ -74,7 +75,14 @@ pub fn call_in_wasm( code, HF::host_functions(), )?; - instance.call(ext, function, call_data) + + match ext { + Some(ext) => sp_externalities::set_and_run_with_externalities( + ext, + || instance.call(function, call_data), + ), + None => instance.call(function, call_data) + } } /// Provides runtime information. diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 73e3e8da8d3c8..87cd70b0baa91 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -22,7 +22,7 @@ use sp_version::{NativeVersion, RuntimeVersion}; use codec::{Decode, Encode}; use sp_core::{NativeOrEncoded, traits::{CodeExecutor, Externalities}}; use log::trace; -use std::{result, cell::RefCell, panic::{UnwindSafe, AssertUnwindSafe}}; +use std::{result, cell::RefCell, panic::{UnwindSafe, AssertUnwindSafe}, sync::Arc}; use sp_wasm_interface::{HostFunctions, Function}; use sc_executor_common::wasm_runtime::WasmRuntime; @@ -80,7 +80,7 @@ pub struct NativeExecutor { /// The number of 64KB pages to allocate for Wasm execution. default_heap_pages: u64, /// The host functions registered with this instance. - host_functions: Vec<&'static dyn Function>, + host_functions: Arc>, } impl NativeExecutor { @@ -107,7 +107,7 @@ impl NativeExecutor { fallback_method, native_version: D::native_version(), default_heap_pages: default_heap_pages.unwrap_or(DEFAULT_HEAP_PAGES), - host_functions, + host_functions: Arc::new(host_functions), } } @@ -139,7 +139,7 @@ impl NativeExecutor { ext, self.fallback_method, self.default_heap_pages, - &self.host_functions, + &*self.host_functions, )?; let runtime = AssertUnwindSafe(runtime); @@ -212,13 +212,15 @@ impl CodeExecutor for NativeExecutor { onchain_version, ); - safe_call( - move || runtime.call(&mut **ext, method, data).map(NativeOrEncoded::Encoded) + with_native_environment( + &mut **ext, + move || runtime.call(method, data).map(NativeOrEncoded::Encoded) ) } (false, _, _) => { - safe_call( - move || runtime.call(&mut **ext, method, data).map(NativeOrEncoded::Encoded) + with_native_environment( + &mut **ext, + move || runtime.call(method, data).map(NativeOrEncoded::Encoded) ) }, (true, true, Some(call)) => { @@ -255,6 +257,32 @@ impl CodeExecutor for NativeExecutor { } } +impl sp_core::traits::CallInWasm for NativeExecutor { + fn call_in_wasm( + &self, + wasm_blob: &[u8], + method: &str, + call_data: &[u8], + ext: Option<&mut dyn Externalities>, + ) -> std::result::Result, String> { + let instance = crate::wasm_runtime::create_wasm_runtime_with_code( + self.fallback_method, + self.default_heap_pages, + wasm_blob, + (*self.host_functions).clone(), + ).map_err(|e| e.to_string())?; + + let mut instance = AssertUnwindSafe(instance); + + match ext { + Some(ext) => with_native_environment(ext, move || instance.call(method, call_data)) + .and_then(|r| r) + .map_err(|e| e.to_string()), + None => instance.call(method, call_data).map_err(|e| e.to_string()), + } + } +} + /// Implements a `NativeExecutionDispatch` for provided parameters. /// /// # Example diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index 4c7e80f925337..c1832731defe2 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -222,8 +222,9 @@ fn create_versioned_wasm_runtime( // The following unwind safety assertion is OK because if the method call panics, the // runtime will be dropped. let mut runtime = AssertUnwindSafe(runtime.as_mut()); - crate::native_executor::safe_call( - move || runtime.call(&mut **ext, "Core_version", &[]) + crate::native_executor::with_native_environment( + &mut **ext, + move || runtime.call("Core_version", &[]) ).map_err(|_| WasmError::Instantiation("panic in call to get runtime version".into()))? }; let encoded_version = version_result diff --git a/client/executor/wasmi/Cargo.toml b/client/executor/wasmi/Cargo.toml index 7a13d7ea97e26..9b6f4ec5bc8ff 100644 --- a/client/executor/wasmi/Cargo.toml +++ b/client/executor/wasmi/Cargo.toml @@ -13,4 +13,3 @@ sc-executor-common = { version = "2.0.0", path = "../common" } sp-wasm-interface = { version = "2.0.0", path = "../../../primitives/wasm-interface" } sp-runtime-interface = { version = "2.0.0", path = "../../../primitives/runtime-interface" } sp-core = { version = "2.0.0", path = "../../../primitives/core" } -sp-externalities = { version = "2.0.0", path = "../../../primitives/externalities" } diff --git a/client/executor/wasmi/src/lib.rs b/client/executor/wasmi/src/lib.rs index 97191531041f5..a5a4b27e962d4 100644 --- a/client/executor/wasmi/src/lib.rs +++ b/client/executor/wasmi/src/lib.rs @@ -27,7 +27,7 @@ use wasmi::{ memory_units::Pages, RuntimeValue::{I32, I64, self}, }; use codec::{Encode, Decode}; -use sp_core::{sandbox as sandbox_primitives, traits::Externalities}; +use sp_core::sandbox as sandbox_primitives; use log::{error, trace}; use parity_wasm::elements::{deserialize_buffer, DataSegment, Instruction, Module as RawModule}; use sp_wasm_interface::{ @@ -346,7 +346,6 @@ fn get_heap_base(module: &ModuleRef) -> Result { /// Call a given method in the given wasm-module runtime. fn call_in_wasm_module( - ext: &mut dyn Externalities, module_instance: &ModuleRef, method: &str, data: &[u8], @@ -366,13 +365,10 @@ fn call_in_wasm_module( let offset = fec.allocate_memory(data.len() as u32)?; fec.write_memory(offset, data)?; - let result = sp_externalities::set_and_run_with_externalities( - ext, - || module_instance.invoke_export( - method, - &[I32(u32::from(offset) as i32), I32(data.len() as i32)], - &mut fec, - ), + let result = module_instance.invoke_export( + method, + &[I32(u32::from(offset) as i32), I32(data.len() as i32)], + &mut fec, ); match result { @@ -549,7 +545,6 @@ impl WasmRuntime for WasmiRuntime { fn call( &mut self, - ext: &mut dyn Externalities, method: &str, data: &[u8], ) -> Result, Error> { @@ -561,7 +556,7 @@ impl WasmRuntime for WasmiRuntime { error!(target: "wasm-executor", "snapshot restoration failed: {}", e); e })?; - call_in_wasm_module(ext, &self.instance, method, data, &self.host_functions) + call_in_wasm_module(&self.instance, method, data, &self.host_functions) } } diff --git a/client/executor/wasmtime/Cargo.toml b/client/executor/wasmtime/Cargo.toml index 0d6bede016e66..5ca83edb319e2 100644 --- a/client/executor/wasmtime/Cargo.toml +++ b/client/executor/wasmtime/Cargo.toml @@ -13,7 +13,6 @@ sc-executor-common = { version = "2.0.0", path = "../common" } sp-wasm-interface = { version = "2.0.0", path = "../../../primitives/wasm-interface" } sp-runtime-interface = { version = "2.0.0", path = "../../../primitives/runtime-interface" } sp-core = { version = "2.0.0", path = "../../../primitives/core" } -sp-externalities = { version = "2.0.0", path = "../../../primitives/externalities" } cranelift-codegen = "0.50" cranelift-entity = "0.50" diff --git a/client/executor/wasmtime/src/runtime.rs b/client/executor/wasmtime/src/runtime.rs index 9395d0049cc2d..8a60c9b8ed20a 100644 --- a/client/executor/wasmtime/src/runtime.rs +++ b/client/executor/wasmtime/src/runtime.rs @@ -24,7 +24,6 @@ use sc_executor_common::{ error::{Error, Result, WasmError}, wasm_runtime::WasmRuntime, }; -use sp_core::traits::Externalities; use sp_wasm_interface::{Pointer, WordSize, Function}; use sp_runtime_interface::unpack_ptr_and_len; @@ -70,11 +69,10 @@ impl WasmRuntime for WasmtimeRuntime { &self.host_functions } - fn call(&mut self, ext: &mut dyn Externalities, method: &str, data: &[u8]) -> Result> { + fn call(&mut self, method: &str, data: &[u8]) -> Result> { call_method( &mut self.context, &mut self.module, - ext, method, data, self.heap_pages, @@ -146,7 +144,6 @@ fn create_compiled_unit( fn call_method( context: &mut Context, module: &mut CompiledModule, - ext: &mut dyn Externalities, method: &str, data: &[u8], heap_pages: u32, @@ -176,11 +173,9 @@ fn call_method( let args = [RuntimeValue::I32(u32::from(data_ptr) as i32), RuntimeValue::I32(data_len as i32)]; // Invoke the function in the runtime. - let outcome = sp_externalities::set_and_run_with_externalities(ext, || { - context - .invoke(&mut instance, method, &args[..]) - .map_err(|e| Error::Other(format!("error calling runtime: {}", e))) - })?; + let outcome = context + .invoke(&mut instance, method, &args[..]) + .map_err(|e| Error::Other(format!("error calling runtime: {}", e)))?; let trap_error = reset_env_state_and_take_trap(context, None)?; let (output_ptr, output_len) = match outcome { ActionOutcome::Returned { values } => match values.as_slice() { diff --git a/client/src/call_executor.rs b/client/src/call_executor.rs index 3115c78103558..1a81de6e494c0 100644 --- a/client/src/call_executor.rs +++ b/client/src/call_executor.rs @@ -65,7 +65,7 @@ impl Clone for LocalCallExecutor where E: Clone { impl CallExecutor for LocalCallExecutor where B: backend::Backend, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + Clone + 'static, Block: BlockT, { type Error = E::Error; @@ -272,7 +272,7 @@ impl CallExecutor for LocalCallExecutor impl sp_version::GetRuntimeVersion for LocalCallExecutor where B: backend::Backend, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + Clone + 'static, Block: BlockT, { fn native_version(&self) -> &sp_version::NativeVersion { diff --git a/client/src/client.rs b/client/src/client.rs index c8868d4fd2e5e..9ad581913cdb4 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -151,7 +151,7 @@ pub fn new_in_mem( Block, RA >> where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + Clone + 'static, S: BuildStorage, Block: BlockT, { @@ -167,10 +167,10 @@ pub fn new_with_backend( keystore: Option, ) -> sp_blockchain::Result, Block, RA>> where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + Clone + 'static, S: BuildStorage, Block: BlockT, - B: backend::LocalBackend + B: backend::LocalBackend + 'static, { let call_executor = LocalCallExecutor::new(backend.clone(), executor); let extensions = ExecutionExtensions::new(Default::default(), keystore); @@ -179,7 +179,7 @@ pub fn new_with_backend( impl BlockOf for Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { type Type = Block; @@ -187,7 +187,7 @@ impl BlockOf for Client where impl Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { /// Creates new Substrate Client with given blockchain and code executor. @@ -1284,7 +1284,7 @@ impl HeaderMetadata for Client where impl ProvideUncles for Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor) -> sp_blockchain::Result> { @@ -1378,7 +1378,7 @@ impl ProvideCache for Client where impl ProvideRuntimeApi for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync, + E: CallExecutor + Clone + Send + Sync + 'static, Block: BlockT, RA: ConstructRuntimeApi { @@ -1391,7 +1391,7 @@ impl ProvideRuntimeApi for Client where impl CallRuntimeAt for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync, + E: CallExecutor + Clone + Send + Sync + 'static, Block: BlockT, { type Error = Error; @@ -1438,7 +1438,7 @@ impl CallRuntimeAt for Client where /// important verification work. impl<'a, B, E, Block, RA> sp_consensus::BlockImport for &'a Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync, + E: CallExecutor + Clone + Send + Sync + Clone + 'static, Block: BlockT, { type Error = ConsensusError; @@ -1513,7 +1513,7 @@ impl<'a, B, E, Block, RA> sp_consensus::BlockImport for &'a Client sp_consensus::BlockImport for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync, + E: CallExecutor + Clone + Send + Sync + Clone + 'static, Block: BlockT, { type Error = ConsensusError; @@ -1536,7 +1536,7 @@ impl sp_consensus::BlockImport for Client Finalizer for Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { fn apply_finality( @@ -1560,7 +1560,7 @@ impl Finalizer for Client Finalizer for &Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { fn apply_finality( @@ -1580,7 +1580,7 @@ impl Finalizer for &Client BlockchainEvents for Client where - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { /// Get block import event stream. @@ -1683,7 +1683,7 @@ where impl BlockBody for Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { fn block_body(&self, id: &BlockId) -> sp_blockchain::Result::Extrinsic>>> { @@ -1694,7 +1694,7 @@ impl BlockBody for Client impl backend::AuxStore for Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { /// Insert auxiliary data into key-value store. @@ -1723,7 +1723,7 @@ impl backend::AuxStore for Client impl backend::AuxStore for &Client where B: backend::Backend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, Block: BlockT, { @@ -1765,8 +1765,8 @@ where impl sp_consensus::block_validation::Chain for Client where BE: backend::Backend, - E: CallExecutor, - B: BlockT + E: CallExecutor + Clone + 'static, + B: BlockT, { fn block_status(&self, id: &BlockId) -> Result> { Client::block_status(self, id).map_err(|e| Box::new(e) as Box<_>) diff --git a/client/src/light/call_executor.rs b/client/src/light/call_executor.rs index 656271b9324a0..9cbabbf70e498 100644 --- a/client/src/light/call_executor.rs +++ b/client/src/light/call_executor.rs @@ -205,7 +205,7 @@ pub fn prove_execution( where Block: BlockT, S: StateBackend, - E: CallExecutor, + E: CallExecutor + Clone + 'static, { let trie_state = state.as_trie_backend() .ok_or_else(|| Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as Box)?; @@ -237,7 +237,7 @@ pub fn check_execution_proof( ) -> ClientResult> where Header: HeaderT, - E: CodeExecutor, + E: CodeExecutor + Clone + 'static, H: Hasher, { check_execution_proof_with_make_header::( @@ -262,7 +262,7 @@ fn check_execution_proof_with_make_header ClientResult> where Header: HeaderT, - E: CodeExecutor, + E: CodeExecutor + Clone + 'static, H: Hasher, { let local_state_root = request.header.state_root(); diff --git a/client/src/light/fetcher.rs b/client/src/light/fetcher.rs index cf08c8b471284..003c5c15a110f 100644 --- a/client/src/light/fetcher.rs +++ b/client/src/light/fetcher.rs @@ -196,7 +196,7 @@ impl> LightDataChecker { impl FetchChecker for LightDataChecker where Block: BlockT, - E: CodeExecutor, + E: CodeExecutor + Clone + 'static, H: Hasher, S: BlockchainStorage, { diff --git a/client/src/light/mod.rs b/client/src/light/mod.rs index cc27bc698b77f..feec265a485d6 100644 --- a/client/src/light/mod.rs +++ b/client/src/light/mod.rs @@ -66,7 +66,7 @@ pub fn new_light( B: BlockT, S: BlockchainStorage + 'static, GS: BuildStorage, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + Clone + 'static, { let local_executor = LocalCallExecutor::new(backend.clone(), code_executor); let executor = GenesisCallExecutor::new(backend.clone(), local_executor); diff --git a/frame/system/Cargo.toml b/frame/system/Cargo.toml index 227aecee2ee43..9bff9bc8f5887 100644 --- a/frame/system/Cargo.toml +++ b/frame/system/Cargo.toml @@ -18,6 +18,9 @@ impl-trait-for-tuples = "0.1.3" [dev-dependencies] criterion = "0.2.11" +sp-externalities = { version = "2.0.0", path = "../../primitives/externalities" } +sc-executor = { version = "2.0.0", path = "../../client/executor" } +substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" } [features] default = ["std"] diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 903523fdf82c5..64978bd6611f4 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -259,11 +259,38 @@ decl_module! { storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode()); } - /// Set the new code. + /// Set the new runtime code. #[weight = SimpleDispatchInfo::FixedOperational(200_000)] - pub fn set_code(origin, new: Vec) { + pub fn set_code(origin, code: Vec) { ensure_root(origin)?; - storage::unhashed::put_raw(well_known_keys::CODE, &new); + + let current_version = T::Version::get(); + let new_version = sp_io::misc::runtime_version(&code) + .and_then(|v| RuntimeVersion::decode(&mut &v[..]).ok()) + .ok_or_else(|| Error::::FailedToExtractRuntimeVersion)?; + + if new_version.spec_name != current_version.spec_name { + Err(Error::::InvalidSpecName)? + } + + if new_version.spec_version < current_version.spec_version { + Err(Error::::SpecVersionNotAllowedToDecrease)? + } else if new_version.spec_version == current_version.spec_version { + if new_version.impl_version < current_version.impl_version { + Err(Error::::ImplVersionNotAllowedToDecrease)? + } else if new_version.impl_version == current_version.impl_version { + Err(Error::::SpecOrImplVersionNeedToIncrease)? + } + } + + storage::unhashed::put_raw(well_known_keys::CODE, &code); + } + + /// Set the new runtime code without doing any checks of the given `code`. + #[weight = SimpleDispatchInfo::FixedOperational(200_000)] + pub fn set_code_without_checks(origin, code: Vec) { + ensure_root(origin)?; + storage::unhashed::put_raw(well_known_keys::CODE, &code); } /// Set some items of storage. @@ -327,7 +354,24 @@ decl_event!( decl_error! { /// Error for the System module - pub enum Error for Module {} + pub enum Error for Module { + /// The name of specification does not match between the current runtime + /// and the new runtime. + InvalidSpecName, + /// The specification version is not allowed to decrease between the current runtime + /// and the new runtime. + SpecVersionNotAllowedToDecrease, + /// The implementation version is not allowed to decrease between the current runtime + /// and the new runtime. + ImplVersionNotAllowedToDecrease, + /// The specification or the implementation version need to increase between the + /// current runtime and the new runtime. + SpecOrImplVersionNeedToIncrease, + /// Failed to extract the runtime version from the new runtime. + /// + /// Either calling `Core_version` or decoding `RuntimeVersion` failed. + FailedToExtractRuntimeVersion, + } } /// Origin for the System module. @@ -1161,6 +1205,14 @@ mod tests { pub const MaximumBlockWeight: Weight = 1024; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const MaximumBlockLength: u32 = 1024; + pub const Version: RuntimeVersion = RuntimeVersion { + spec_name: sp_version::create_runtime_str!("test"), + impl_name: sp_version::create_runtime_str!("system-test"), + authoring_version: 1, + spec_version: 1, + impl_version: 1, + apis: sp_version::create_apis_vec!([]), + }; } impl Trait for Test { @@ -1178,7 +1230,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; - type Version = (); + type Version = Version; type ModuleToIndex = (); } @@ -1461,7 +1513,7 @@ mod tests { .validate(&1, CALL, op, len) .unwrap() .priority; - assert_eq!(priority, Bounded::max_value()); + assert_eq!(priority, u64::max_value()); }) } @@ -1520,4 +1572,89 @@ mod tests { assert_eq!(ext.validate(&1, CALL, normal, len).unwrap().longevity, 15); }) } + + + #[test] + fn set_code_checks_works() { + struct CallInWasm(Vec); + + impl sp_core::traits::CallInWasm for CallInWasm { + fn call_in_wasm( + &self, + _: &[u8], + _: &str, + _: &[u8], + _: Option<&mut dyn sp_externalities::Externalities>, + ) -> Result, String> { + Ok(self.0.clone()) + } + } + + let test_data = vec![ + ("test", 1, 2, Ok(())), + ("test", 1, 1, Err(Error::::SpecOrImplVersionNeedToIncrease)), + ("test2", 1, 1, Err(Error::::InvalidSpecName)), + ("test", 2, 1, Ok(())), + ("test", 0, 1, Err(Error::::SpecVersionNotAllowedToDecrease)), + ("test", 1, 0, Err(Error::::ImplVersionNotAllowedToDecrease)), + ]; + + for (spec_name, spec_version, impl_version, expected) in test_data.into_iter() { + let version = RuntimeVersion { + spec_name: spec_name.into(), + spec_version, + impl_version, + ..Default::default() + }; + let call_in_wasm = CallInWasm(version.encode()); + + let mut ext = new_test_ext(); + ext.register_extension(sp_core::traits::CallInWasmExt::new(call_in_wasm)); + ext.execute_with(|| { + let res = System::set_code( + RawOrigin::Root.into(), + vec![1, 2, 3, 4], + ); + + assert_eq!(expected.map_err(DispatchError::from), res); + }); + } + } + + #[test] + fn set_code_with_real_wasm_blob() { + struct CallInWasm; + + impl sp_core::traits::CallInWasm for CallInWasm { + fn call_in_wasm( + &self, + blob: &[u8], + method: &str, + call_data: &[u8], + ext: Option<&mut dyn sp_externalities::Externalities>, + ) -> Result, String> { + type HostFunctions = ( + sp_io::SubstrateHostFunctions, + sc_executor::deprecated_host_interface::SubstrateExternals + ); + sc_executor::call_in_wasm::( + method, + call_data, + sc_executor::WasmExecutionMethod::Interpreted, + ext, + blob, + 8, + ).map_err(|e| { println!("{:?}", e); e.to_string() }) + } + } + + let mut ext = new_test_ext(); + ext.register_extension(sp_core::traits::CallInWasmExt::new(CallInWasm)); + ext.execute_with(|| { + System::set_code( + RawOrigin::Root.into(), + substrate_test_runtime::WASM_BINARY.to_vec(), + ).unwrap(); + }); + } } diff --git a/primitives/core/src/traits.rs b/primitives/core/src/traits.rs index 2f78c8a708f57..3adbf6ce83466 100644 --- a/primitives/core/src/traits.rs +++ b/primitives/core/src/traits.rs @@ -80,7 +80,7 @@ sp_externalities::decl_extension! { } /// Code execution engine. -pub trait CodeExecutor: Sized + Send + Sync { +pub trait CodeExecutor: Sized + Send + Sync + CallInWasm { /// Externalities error type. type Error: Display + Debug + Send + 'static; @@ -99,3 +99,30 @@ pub trait CodeExecutor: Sized + Send + Sync { native_call: Option, ) -> (Result, Self::Error>, bool); } + +/// Something that can call a method in a WASM blob. +pub trait CallInWasm: Send + Sync { + /// Call the given `method` in the given `wasm_blob` using `call_data` (SCALE encoded arguments) + /// to decode the arguments for the method. + /// + /// Returns the SCALE encoded return value of the method. + fn call_in_wasm( + &self, + wasm_blob: &[u8], + method: &str, + call_data: &[u8], + ext: Option<&mut dyn Externalities>, + ) -> Result, String>; +} + +sp_externalities::decl_extension! { + /// The call-in-wasm extension to register/retrieve from the externalities. + pub struct CallInWasmExt(Box); +} + +impl CallInWasmExt { + /// Creates a new instance of `Self`. + pub fn new(inner: T) -> Self { + Self(Box::new(inner)) + } +} diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 8763a122df551..9c1273b918e05 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -36,7 +36,7 @@ use sp_std::ops::Deref; #[cfg(feature = "std")] use sp_core::{ crypto::Pair, - traits::KeystoreExt, + traits::{KeystoreExt, CallInWasmExt}, offchain::{OffchainExt, TransactionPoolExt}, hexdisplay::HexDisplay, storage::{ChildStorageKey, ChildInfo}, @@ -50,7 +50,7 @@ use sp_core::{ }; #[cfg(feature = "std")] -use ::sp_trie::{TrieConfiguration, trie_types::Layout}; +use sp_trie::{TrieConfiguration, trie_types::Layout}; use sp_runtime_interface::{runtime_interface, Pointer}; @@ -351,6 +351,16 @@ pub trait Misc { fn print_hex(data: &[u8]) { log::debug!(target: "runtime", "{}", HexDisplay::from(&data)); } + + /// Extract the runtime version of the given wasm blob by calling `Core_version`. + /// + /// Returns the SCALE encoded runtime version and `None` if the call failed. + fn runtime_version(&mut self, wasm: &[u8]) -> Option> { + self.extension::() + .expect("No `CallInWasmExt` associated for the current context!") + .call_in_wasm(wasm, "Core_version", &[], None) + .ok() + } } /// Interfaces for working with crypto related types from within the runtime. diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index 80ef992f6b928..40569d5aed43b 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -92,25 +92,92 @@ impl TypeId for ModuleId { const TYPE_ID: [u8; 4] = *b"modl"; } -/// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`. +/// A string that wraps a `&'static str` in the runtime and `String`/`Vec` on decode. +#[derive(Eq, RuntimeDebug, Clone)] +pub enum RuntimeString { + /// The borrowed mode that wraps a `&'static str`. + Borrowed(&'static str), + /// The owned mode that wraps a `String`. + #[cfg(feature = "std")] + Owned(String), + /// The owned mode that wraps a `Vec`. + #[cfg(not(feature = "std"))] + Owned(Vec), +} + +impl From<&'static str> for RuntimeString { + fn from(data: &'static str) -> Self { + Self::Borrowed(data) + } +} + +impl Default for RuntimeString { + fn default() -> Self { + Self::Borrowed(Default::default()) + } +} + +impl PartialEq for RuntimeString { + fn eq(&self, other: &Self) -> bool { + self.as_ref() == other.as_ref() + } +} + +impl AsRef<[u8]> for RuntimeString { + fn as_ref(&self) -> &[u8] { + match self { + Self::Borrowed(val) => val.as_ref(), + Self::Owned(val) => val.as_ref(), + } + } +} + +impl Encode for RuntimeString { + fn encode(&self) -> Vec { + match self { + Self::Borrowed(val) => val.encode(), + Self::Owned(val) => val.encode(), + } + } +} + +impl Decode for RuntimeString { + fn decode(value: &mut I) -> Result { + Decode::decode(value).map(Self::Owned) + } +} + #[cfg(feature = "std")] -pub type RuntimeString = std::borrow::Cow<'static, str>; -/// A String that is a `&'static str` on `no_std` and a `Cow<'static, str>` on `std`. -#[cfg(not(feature = "std"))] -pub type RuntimeString = &'static str; +impl std::fmt::Display for RuntimeString { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Borrowed(val) => write!(f, "{}", val), + Self::Owned(val) => write!(f, "{}", val), + } + } +} -/// Create a const [`RuntimeString`]. #[cfg(feature = "std")] -#[macro_export] -macro_rules! create_runtime_str { - ( $y:expr ) => {{ std::borrow::Cow::Borrowed($y) }} +impl serde::Serialize for RuntimeString { + fn serialize(&self, serializer: S) -> Result { + match self { + Self::Borrowed(val) => val.serialize(serializer), + Self::Owned(val) => val.serialize(serializer), + } + } +} + +#[cfg(feature = "std")] +impl<'de> serde::Deserialize<'de> for RuntimeString { + fn deserialize>(de: D) -> Result { + String::deserialize(de).map(Self::Owned) + } } /// Create a const [`RuntimeString`]. -#[cfg(not(feature = "std"))] #[macro_export] macro_rules! create_runtime_str { - ( $y:expr ) => {{ $y }} + ( $y:expr ) => {{ $crate::RuntimeString::Borrowed($y) }} } #[cfg(feature = "std")] diff --git a/primitives/sandbox/with_std.rs b/primitives/sandbox/with_std.rs index dacaa3a198df2..2a2616cd987d9 100755 --- a/primitives/sandbox/with_std.rs +++ b/primitives/sandbox/with_std.rs @@ -121,6 +121,7 @@ impl<'a, T> Externals for GuestExternals<'a, T> { index: usize, args: RuntimeArgs, ) -> Result, Trap> { + println!("Lol: {:?}", args); let args = args.as_ref() .iter() .cloned() @@ -187,9 +188,12 @@ impl ImportResolver for EnvironmentDefinitionBuilder { module_name.as_bytes().to_owned(), field_name.as_bytes().to_owned(), ); - let externval = self.map.get(&key).ok_or_else(|| { - wasmi::Error::Instantiation(format!("Export {}:{} not found", module_name, field_name)) - })?; + println!("{} {}", module_name, field_name); + let lol = ExternVal::HostFunc(HostFuncIndex(100)); + let externval = self.map.get(&key).unwrap_or_else(|| { + // wasmi::Error::Instantiation(format!("Export {}:{} not found", module_name, field_name)) + &lol + }); let host_func_idx = match *externval { ExternVal::HostFunc(ref idx) => idx, _ => { @@ -262,10 +266,9 @@ impl Instance { env_def_builder: &EnvironmentDefinitionBuilder, state: &mut T, ) -> Result, Error> { - let module = Module::from_buffer(code).map_err(|_| Error::Module)?; + let module = Module::from_buffer(code).map_err(|e| { println!("{:?}", e); Error::Module})?; let not_started_instance = ModuleInstance::new(&module, env_def_builder) - .map_err(|_| Error::Module)?; - + .map_err(|e| { println!("Hello {:?}", e); Error::Module})?; let defined_host_functions = env_def_builder.defined_host_functions.clone(); let instance = { @@ -274,7 +277,7 @@ impl Instance { defined_host_functions: &defined_host_functions, }; let instance = not_started_instance.run_start(&mut externals) - .map_err(|_| Error::Execution)?; + .map_err(|e| { println!("Hello {:?}", e); Error::Execution})?; instance }; @@ -303,7 +306,10 @@ impl Instance { match result { Ok(None) => Ok(ReturnValue::Unit), Ok(Some(val)) => Ok(ReturnValue::Value(val.into())), - Err(_err) => Err(Error::Execution), + Err(_err) => { + println!("{:?}", _err); + Err(Error::Execution) + } } } } diff --git a/primitives/state-machine/src/lib.rs b/primitives/state-machine/src/lib.rs index 86cae2dfbbcaf..c67ed5bcba961 100644 --- a/primitives/state-machine/src/lib.rs +++ b/primitives/state-machine/src/lib.rs @@ -24,7 +24,7 @@ use hash_db::Hasher; use codec::{Decode, Encode, Codec}; use sp_core::{ storage::{well_known_keys, ChildInfo}, NativeOrEncoded, NeverNativeValue, - traits::CodeExecutor, hexdisplay::HexDisplay, hash::H256, + traits::{CodeExecutor, CallInWasmExt}, hexdisplay::HexDisplay, hash::H256, }; use overlayed_changes::OverlayedChangeSet; use sp_externalities::Extensions; @@ -177,7 +177,7 @@ pub struct StateMachine<'a, B, H, N, T, Exec> where H: Hasher, B: Back impl<'a, B, H, N, T, Exec> StateMachine<'a, B, H, N, T, Exec> where H: Hasher, - Exec: CodeExecutor, + Exec: CodeExecutor + Clone + 'static, B: Backend, T: ChangesTrieStorage, N: crate::changes_trie::BlockNumber, @@ -190,8 +190,10 @@ impl<'a, B, H, N, T, Exec> StateMachine<'a, B, H, N, T, Exec> where exec: &'a Exec, method: &'a str, call_data: &'a [u8], - extensions: Extensions, + mut extensions: Extensions, ) -> Self { + extensions.register(CallInWasmExt::new(exec.clone())); + Self { backend, exec, @@ -456,7 +458,7 @@ pub fn prove_execution( where B: Backend, H: Hasher, - Exec: CodeExecutor, + Exec: CodeExecutor + Clone + 'static, { let trie_backend = backend.as_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; @@ -482,7 +484,7 @@ pub fn prove_execution_on_trie_backend( where S: trie_backend_essence::TrieBackendStorage, H: Hasher, - Exec: CodeExecutor, + Exec: CodeExecutor + Clone + 'static, { let proving_backend = proving_backend::ProvingBackend::new(trie_backend); let mut sm = StateMachine::<_, H, _, InMemoryChangesTrieStorage, Exec>::new( @@ -509,7 +511,7 @@ pub fn execution_proof_check( ) -> Result, Box> where H: Hasher, - Exec: CodeExecutor, + Exec: CodeExecutor + Clone + 'static, H::Out: Ord + 'static, { let trie_backend = create_proof_check_backend::(root.into(), proof)?; @@ -526,7 +528,7 @@ pub fn execution_proof_check_on_trie_backend( ) -> Result, Box> where H: Hasher, - Exec: CodeExecutor, + Exec: CodeExecutor + Clone + 'static, { let mut sm = StateMachine::<_, H, _, InMemoryChangesTrieStorage, Exec>::new( trie_backend, None, overlay, exec, method, call_data, Extensions::default(), diff --git a/primitives/version/Cargo.toml b/primitives/version/Cargo.toml index fbbf0cfa94607..784051b56e5e1 100644 --- a/primitives/version/Cargo.toml +++ b/primitives/version/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] impl-serde = { version = "0.2.3", optional = true } serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.1.2", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0", default-features = false, path = "../std" } sp-runtime = { version = "2.0.0", default-features = false, path = "../runtime" } diff --git a/primitives/version/src/lib.rs b/primitives/version/src/lib.rs index edb4aa851e7e8..4b8ab9e520c0c 100644 --- a/primitives/version/src/lib.rs +++ b/primitives/version/src/lib.rs @@ -26,10 +26,10 @@ use std::fmt; use std::collections::HashSet; #[cfg(feature = "std")] use sp_runtime::traits::RuntimeApiInfo; +#[doc(hidden)] +pub use sp_std; -use codec::Encode; -#[cfg(feature = "std")] -use codec::Decode; +use codec::{Encode, Decode}; use sp_runtime::RuntimeString; pub use sp_runtime::create_runtime_str; @@ -39,25 +39,13 @@ use sp_runtime::{traits::Block as BlockT, generic::BlockId}; /// The identity of a particular API interface that the runtime might provide. pub type ApiId = [u8; 8]; -/// A vector of pairs of `ApiId` and a `u32` for version. For `"std"` builds, this -/// is a `Cow`. -#[cfg(feature = "std")] -pub type ApisVec = ::std::borrow::Cow<'static, [(ApiId, u32)]>; -/// A vector of pairs of `ApiId` and a `u32` for version. For `"no-std"` builds, this -/// is just a reference. -#[cfg(not(feature = "std"))] -pub type ApisVec = &'static [(ApiId, u32)]; +/// A vector of pairs of `ApiId` and a `u32` for version. +pub type ApisVec = sp_std::borrow::Cow<'static, [(ApiId, u32)]>; /// Create a vector of Api declarations. #[macro_export] -#[cfg(feature = "std")] -macro_rules! create_apis_vec { - ( $y:expr ) => { std::borrow::Cow::Borrowed(& $y) } -} -#[macro_export] -#[cfg(not(feature = "std"))] macro_rules! create_apis_vec { - ( $y:expr ) => { & $y } + ( $y:expr ) => { $crate::sp_std::borrow::Cow::Borrowed(& $y) } } /// Runtime version. @@ -65,8 +53,8 @@ macro_rules! create_apis_vec { /// This triplet have different semantics and mis-interpretation could cause problems. /// In particular: bug fixes should result in an increment of `spec_version` and possibly `authoring_version`, /// absolutely not `impl_version` since they change the semantics of the runtime. -#[derive(Clone, PartialEq, Eq, Encode, Default, sp_runtime::RuntimeDebug)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Decode))] +#[derive(Clone, PartialEq, Eq, Encode, Decode, Default, sp_runtime::RuntimeDebug)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] pub struct RuntimeVersion { /// Identifies the different Substrate runtimes. There'll be at least polkadot and node. diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index cfb1f9df537d1..500fb6bdc13a6 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -65,7 +65,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("parity-test"), authoring_version: 1, spec_version: 1, + #[cfg(feature = "std")] impl_version: 1, + #[cfg(not(feature = "std"))] + impl_version: 2, apis: RUNTIME_API_VERSIONS, }; From 79edfd130b8df94b6db50800c849e95bb3c99f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 10 Jan 2020 17:55:49 +0100 Subject: [PATCH 02/13] Make tests almost work --- Cargo.lock | 7 +- .../transaction-factory/src/complex_mode.rs | 2 +- bin/node/transaction-factory/src/lib.rs | 6 +- .../transaction-factory/src/simple_modes.rs | 2 +- client/consensus/babe/src/lib.rs | 4 +- client/db/src/lib.rs | 2 +- client/executor/src/integration_tests/mod.rs | 2 +- client/executor/src/lib.rs | 43 ++++++--- client/executor/src/native_executor.rs | 51 +++++------ client/executor/src/wasm_runtime.rs | 2 +- client/finality-grandpa/src/environment.rs | 2 +- client/finality-grandpa/src/justification.rs | 2 +- client/finality-grandpa/src/lib.rs | 2 +- client/finality-grandpa/src/observer.rs | 2 +- client/service/src/builder.rs | 2 +- client/src/client.rs | 38 ++++---- client/src/genesis.rs | 2 +- client/src/light/call_executor.rs | 2 +- frame/system/src/lib.rs | 33 ++----- primitives/core/src/traits.rs | 4 +- primitives/externalities/Cargo.toml | 2 +- primitives/io/src/lib.rs | 5 +- primitives/runtime-interface/Cargo.toml | 2 - primitives/runtime-interface/test/src/lib.rs | 1 - primitives/runtime/src/lib.rs | 91 +------------------ primitives/state-machine/src/lib.rs | 13 +++ test-utils/client/src/client_ext.rs | 2 +- test-utils/client/src/lib.rs | 6 +- test-utils/runtime/client/src/lib.rs | 2 +- 29 files changed, 129 insertions(+), 205 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f656142d30c47..f5a35fd393b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1055,7 +1055,7 @@ dependencies = [ [[package]] name = "environmental" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -6303,7 +6303,7 @@ dependencies = [ name = "sp-externalities" version = "2.0.0" dependencies = [ - "environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "environmental 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sp-std 2.0.0", "sp-storage 2.0.0", ] @@ -6426,7 +6426,6 @@ dependencies = [ name = "sp-runtime-interface" version = "2.0.0" dependencies = [ - "environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -8244,7 +8243,7 @@ dependencies = [ "checksum enumflags2_derive 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ecf634c5213044b8d54a46dd282cf5dd1f86bb5cb53e92c409cb4680a7fb9894" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -"checksum environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "34f8467a0284de039e6bd0e25c14519538462ba5beb548bb1f03e645097837a8" +"checksum environmental 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "516aa8d7a71cb00a1c4146f0798549b93d083d4f189b3ced8f3de6b8f11ee6c4" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" diff --git a/bin/node/transaction-factory/src/complex_mode.rs b/bin/node/transaction-factory/src/complex_mode.rs index 61be2ab98756e..c26ad1d604351 100644 --- a/bin/node/transaction-factory/src/complex_mode.rs +++ b/bin/node/transaction-factory/src/complex_mode.rs @@ -60,7 +60,7 @@ pub fn next( ) -> Option where Block: BlockT::Out>, - Exec: sc_client::CallExecutor + Send + Sync + Clone, + Exec: sc_client::CallExecutor + Send + Sync + 'static + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: diff --git a/bin/node/transaction-factory/src/lib.rs b/bin/node/transaction-factory/src/lib.rs index effb9c6d80313..91a4d3a0a92ba 100644 --- a/bin/node/transaction-factory/src/lib.rs +++ b/bin/node/transaction-factory/src/lib.rs @@ -101,7 +101,7 @@ pub fn factory( ) -> sc_cli::error::Result<()> where Block: BlockT::Out>, - Exec: sc_client::CallExecutor + Send + Sync + Clone, + Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: @@ -160,7 +160,7 @@ pub fn create_block( ) -> Block where Block: BlockT::Out>, - Exec: sc_client::CallExecutor + Send + Sync + Clone, + Exec: sc_client::CallExecutor + Send + Sync + 'static + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, RtApi: ConstructRuntimeApi> + Send + Sync, @@ -186,7 +186,7 @@ fn import_block( block: Block ) -> () where Block: BlockT::Out>, - Exec: sc_client::CallExecutor + Send + Sync + Clone, + Exec: sc_client::CallExecutor + Send + Sync + 'static, Backend: sc_client_api::backend::Backend + Send, { let import = BlockImportParams { diff --git a/bin/node/transaction-factory/src/simple_modes.rs b/bin/node/transaction-factory/src/simple_modes.rs index c8ea77f5fea9c..99f4b6f031033 100644 --- a/bin/node/transaction-factory/src/simple_modes.rs +++ b/bin/node/transaction-factory/src/simple_modes.rs @@ -55,7 +55,7 @@ pub fn next( ) -> Option where Block: BlockT::Out>, - Exec: sc_client::CallExecutor + Send + Sync + Clone, + Exec: sc_client::CallExecutor + Send + Sync + 'static + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index a2038a003e6b2..b8ba779bbfe2e 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -1100,7 +1100,7 @@ fn prune_finalized( epoch_changes: &mut EpochChangesFor, ) -> Result<(), ConsensusError> where Block: BlockT, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, B: Backend, RA: Send + Sync, { @@ -1140,7 +1140,7 @@ pub fn block_import, I, RA, PRA>( api: Arc, ) -> ClientResult<(BabeBlockImport, BabeLink)> where B: Backend, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, RA: Send + Sync, { let epoch_changes = aux_schema::load_epoch_changes(&*client)?; diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index e812d2dc46450..359a533a3738b 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -290,7 +290,7 @@ pub fn new_client( > where Block: BlockT, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo + 'static, S: BuildStorage, { let backend = Arc::new(Backend::new(settings, CANONICALIZATION_DELAY)?); diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 24e9e022f7063..26b9b2ebf46a9 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -40,7 +40,7 @@ fn call_in_wasm( code: &[u8], heap_pages: u64, ) -> crate::error::Result> { - crate::call_in_wasm::( + crate::call_in_wasm::( function, call_data, execution_method, diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 0ee7f6eb03bc5..707cae7e25d8e 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -39,7 +39,7 @@ mod wasm_runtime; mod integration_tests; pub use wasmi; -pub use native_executor::{with_native_environment, NativeExecutor, NativeExecutionDispatch}; +pub use native_executor::{with_externalities_safe, NativeExecutor, NativeExecutionDispatch}; pub use sp_version::{RuntimeVersion, NativeVersion}; pub use codec::Codec; #[doc(hidden)] @@ -65,24 +65,43 @@ pub fn call_in_wasm( function: &str, call_data: &[u8], execution_method: WasmExecutionMethod, - ext: Option<&mut dyn Externalities>, + ext: &mut dyn Externalities, code: &[u8], heap_pages: u64, ) -> error::Result> { - let mut instance = wasm_runtime::create_wasm_runtime_with_code( + call_in_wasm_with_host_functions( + function, + call_data, execution_method, - heap_pages, + ext, code, + heap_pages, HF::host_functions(), + ) +} + +/// Non-generic version of [`call_in_wasm`] that takes the `host_functions` as parameter. +/// For more information please see [`call_in_wasm`]. +pub fn call_in_wasm_with_host_functions( + function: &str, + call_data: &[u8], + execution_method: WasmExecutionMethod, + ext: &mut dyn Externalities, + code: &[u8], + heap_pages: u64, + host_functions: Vec<&'static dyn sp_wasm_interface::Function>, +) -> error::Result> { + let instance = wasm_runtime::create_wasm_runtime_with_code( + execution_method, + heap_pages, + code, + host_functions, )?; - match ext { - Some(ext) => sp_externalities::set_and_run_with_externalities( - ext, - || instance.call(function, call_data), - ), - None => instance.call(function, call_data) - } + // It is safe, as we delete the instance afterwards. + let mut instance = std::panic::AssertUnwindSafe(instance); + + with_externalities_safe(ext, move || instance.call(function, call_data)).and_then(|r| r) } /// Provides runtime information. @@ -104,7 +123,7 @@ mod tests { fn call_in_interpreted_wasm_works() { let mut ext = TestExternalities::default(); let mut ext = ext.ext(); - let res = call_in_wasm::<_, sp_io::SubstrateHostFunctions>( + let res = call_in_wasm::( "test_empty_return", &[], WasmExecutionMethod::Interpreted, diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 87cd70b0baa91..03fab050306dd 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -33,22 +33,21 @@ thread_local! { /// Default num of pages for the heap const DEFAULT_HEAP_PAGES: u64 = 1024; -pub(crate) fn safe_call(f: F) -> Result - where F: UnwindSafe + FnOnce() -> U -{ - // Substrate uses custom panic hook that terminates process on panic. Disable - // termination for the native call. - let _guard = sp_panic_handler::AbortGuard::force_unwind(); - std::panic::catch_unwind(f).map_err(|_| Error::Runtime) -} - -/// Set up the externalities and safe calling environment to execute calls to a native runtime. +/// Set up the externalities and safe calling environment to execute runtime calls. /// /// If the inner closure panics, it will be caught and return an error. -pub fn with_native_environment(ext: &mut dyn Externalities, f: F) -> Result +pub fn with_externalities_safe(ext: &mut dyn Externalities, f: F) -> Result where F: UnwindSafe + FnOnce() -> U { - sp_externalities::set_and_run_with_externalities(ext, move || safe_call(f)) + sp_externalities::set_and_run_with_externalities( + ext, + move || { + // Substrate uses custom panic hook that terminates process on panic. Disable + // termination for the native call. + let _guard = sp_panic_handler::AbortGuard::force_unwind(); + std::panic::catch_unwind(f).map_err(|_| Error::Runtime) + }, + ) } /// Delegate for dispatching a CodeExecutor call. @@ -212,13 +211,13 @@ impl CodeExecutor for NativeExecutor { onchain_version, ); - with_native_environment( + with_externalities_safe( &mut **ext, move || runtime.call(method, data).map(NativeOrEncoded::Encoded) ) } (false, _, _) => { - with_native_environment( + with_externalities_safe( &mut **ext, move || runtime.call(method, data).map(NativeOrEncoded::Encoded) ) @@ -232,7 +231,7 @@ impl CodeExecutor for NativeExecutor { ); used_native = true; - let res = with_native_environment(&mut **ext, move || (call)()) + let res = with_externalities_safe(&mut **ext, move || (call)()) .and_then(|r| r .map(NativeOrEncoded::Native) .map_err(|s| Error::ApiError(s.to_string())) @@ -263,23 +262,17 @@ impl sp_core::traits::CallInWasm for NativeExecutor< wasm_blob: &[u8], method: &str, call_data: &[u8], - ext: Option<&mut dyn Externalities>, + ext: &mut dyn Externalities, ) -> std::result::Result, String> { - let instance = crate::wasm_runtime::create_wasm_runtime_with_code( + crate::call_in_wasm_with_host_functions( + method, + call_data, self.fallback_method, - self.default_heap_pages, + ext, wasm_blob, + self.default_heap_pages, (*self.host_functions).clone(), - ).map_err(|e| e.to_string())?; - - let mut instance = AssertUnwindSafe(instance); - - match ext { - Some(ext) => with_native_environment(ext, move || instance.call(method, call_data)) - .and_then(|r| r) - .map_err(|e| e.to_string()), - None => instance.call(method, call_data).map_err(|e| e.to_string()), - } + ).map_err(|e| e.to_string()) } } @@ -346,7 +339,7 @@ macro_rules! native_executor_instance { method: &str, data: &[u8] ) -> $crate::error::Result> { - $crate::with_native_environment(ext, move || $dispatcher(method, data))? + $crate::with_externalities_safe(ext, move || $dispatcher(method, data))? .ok_or_else(|| $crate::error::Error::MethodNotFound(method.to_owned())) } diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index c1832731defe2..1b6d1648cd113 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -222,7 +222,7 @@ fn create_versioned_wasm_runtime( // The following unwind safety assertion is OK because if the method call panics, the // runtime will be dropped. let mut runtime = AssertUnwindSafe(runtime.as_mut()); - crate::native_executor::with_native_environment( + crate::native_executor::with_externalities_safe( &mut **ext, move || runtime.call("Core_version", &[]) ).map_err(|_| WasmError::Instantiation("panic in call to get runtime version".into()))? diff --git a/client/finality-grandpa/src/environment.rs b/client/finality-grandpa/src/environment.rs index 1d0532cc28d9e..627a79c77a970 100644 --- a/client/finality-grandpa/src/environment.rs +++ b/client/finality-grandpa/src/environment.rs @@ -956,7 +956,7 @@ pub(crate) fn finalize_block, E, RA>( justification_or_commit: JustificationOrCommit, ) -> Result<(), CommandOrError>> where B: Backend, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, RA: Send + Sync, { // NOTE: lock must be held through writing to DB to avoid race. this lock diff --git a/client/finality-grandpa/src/justification.rs b/client/finality-grandpa/src/justification.rs index d7650a39f8736..308bec0110a55 100644 --- a/client/finality-grandpa/src/justification.rs +++ b/client/finality-grandpa/src/justification.rs @@ -54,7 +54,7 @@ impl> GrandpaJustification { commit: Commit, ) -> Result, Error> where B: Backend, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, RA: Send + Sync, { let mut votes_ancestries_hashes = HashSet::new(); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index f123995552633..9593cd00e3829 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -463,7 +463,7 @@ fn global_communication, B, E, N, RA>( >, ) where B: Backend, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, N: NetworkT, RA: Send + Sync, NumberFor: BlockNumberOps, diff --git a/client/finality-grandpa/src/observer.rs b/client/finality-grandpa/src/observer.rs index 6ce91c9e4e963..3e5cd36ed902e 100644 --- a/client/finality-grandpa/src/observer.rs +++ b/client/finality-grandpa/src/observer.rs @@ -68,7 +68,7 @@ fn grandpa_observer, RA, S, F>( ) -> impl Future>> where NumberFor: BlockNumberOps, B: Backend, - E: CallExecutor + Send + Sync, + E: CallExecutor + Send + Sync + 'static, RA: Send + Sync, S: Stream< Item = CommunicationIn, diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e95717ebface5..60c3b23fc3784 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -142,7 +142,7 @@ pub type TLightCallExecutor = sc_client::light::call_executor::G impl ServiceBuilder<(), (), TCfg, TGen, TCSExt, (), (), (), (), (), (), (), (), (), ()> where TGen: RuntimeGenesis, TCSExt: Extension { /// Start the service builder with a configuration. - pub fn new_full, TRtApi, TExecDisp: NativeExecutionDispatch>( + pub fn new_full, TRtApi, TExecDisp: NativeExecutionDispatch + 'static>( config: Configuration ) -> Result( Block, RA >> where - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + RuntimeInfo + 'static, S: BuildStorage, Block: BlockT, { @@ -167,7 +167,7 @@ pub fn new_with_backend( keystore: Option, ) -> sp_blockchain::Result, Block, RA>> where - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + RuntimeInfo + 'static, S: BuildStorage, Block: BlockT, B: backend::LocalBackend + 'static, @@ -179,7 +179,7 @@ pub fn new_with_backend( impl BlockOf for Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { type Type = Block; @@ -187,7 +187,7 @@ impl BlockOf for Client where impl Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { /// Creates new Substrate Client with given blockchain and code executor. @@ -750,7 +750,7 @@ impl Client where import_block: BlockImportParams, new_cache: HashMap>, ) -> sp_blockchain::Result where - E: CallExecutor + Send + Sync + Clone, + E: CallExecutor + Send + Sync, { let BlockImportParams { origin, @@ -838,7 +838,7 @@ impl Client where enact_state: bool, import_existing: bool, ) -> sp_blockchain::Result where - E: CallExecutor + Send + Sync + Clone, + E: CallExecutor + Send + Sync, { let parent_hash = import_headers.post().parent_hash().clone(); let status = self.backend.blockchain().status(BlockId::Hash(hash))?; @@ -968,7 +968,7 @@ impl Client where )> )> where - E: CallExecutor + Send + Sync + Clone, + E: CallExecutor + Send + Sync, { match transaction.state()? { Some(transaction_state) => { @@ -1284,7 +1284,7 @@ impl HeaderMetadata for Client where impl ProvideUncles for Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor) -> sp_blockchain::Result> { @@ -1378,7 +1378,7 @@ impl ProvideCache for Client where impl ProvideRuntimeApi for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, RA: ConstructRuntimeApi { @@ -1391,7 +1391,7 @@ impl ProvideRuntimeApi for Client where impl CallRuntimeAt for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, { type Error = Error; @@ -1438,7 +1438,7 @@ impl CallRuntimeAt for Client where /// important verification work. impl<'a, B, E, Block, RA> sp_consensus::BlockImport for &'a Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync + Clone + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, { type Error = ConsensusError; @@ -1513,7 +1513,7 @@ impl<'a, B, E, Block, RA> sp_consensus::BlockImport for &'a Client sp_consensus::BlockImport for Client where B: backend::Backend, - E: CallExecutor + Clone + Send + Sync + Clone + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, { type Error = ConsensusError; @@ -1536,7 +1536,7 @@ impl sp_consensus::BlockImport for Client Finalizer for Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { fn apply_finality( @@ -1560,7 +1560,7 @@ impl Finalizer for Client Finalizer for &Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { fn apply_finality( @@ -1580,7 +1580,7 @@ impl Finalizer for &Client BlockchainEvents for Client where - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { /// Get block import event stream. @@ -1683,7 +1683,7 @@ where impl BlockBody for Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { fn block_body(&self, id: &BlockId) -> sp_blockchain::Result::Extrinsic>>> { @@ -1694,7 +1694,7 @@ impl BlockBody for Client impl backend::AuxStore for Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { /// Insert auxiliary data into key-value store. @@ -1723,7 +1723,7 @@ impl backend::AuxStore for Client impl backend::AuxStore for &Client where B: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, Block: BlockT, { @@ -1765,7 +1765,7 @@ where impl sp_consensus::block_validation::Chain for Client where BE: backend::Backend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, B: BlockT, { fn block_status(&self, id: &BlockId) -> Result> { diff --git a/client/src/genesis.rs b/client/src/genesis.rs index 506771217d79f..a623bc6d2db38 100644 --- a/client/src/genesis.rs +++ b/client/src/genesis.rs @@ -59,7 +59,7 @@ mod tests { native_executor_instance!( Executor, substrate_test_runtime_client::runtime::api::dispatch, - substrate_test_runtime_client::runtime::native_version + substrate_test_runtime_client::runtime::native_version, ); fn executor() -> sc_executor::NativeExecutor { diff --git a/client/src/light/call_executor.rs b/client/src/light/call_executor.rs index 9cbabbf70e498..132d1e7baf65e 100644 --- a/client/src/light/call_executor.rs +++ b/client/src/light/call_executor.rs @@ -205,7 +205,7 @@ pub fn prove_execution( where Block: BlockT, S: StateBackend, - E: CallExecutor + Clone + 'static, + E: CallExecutor + 'static, { let trie_state = state.as_trie_backend() .ok_or_else(|| Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as Box)?; diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 64978bd6611f4..3b253827a93e1 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -1584,7 +1584,7 @@ mod tests { _: &[u8], _: &str, _: &[u8], - _: Option<&mut dyn sp_externalities::Externalities>, + _: &mut dyn sp_externalities::Externalities, ) -> Result, String> { Ok(self.0.clone()) } @@ -1623,33 +1623,18 @@ mod tests { #[test] fn set_code_with_real_wasm_blob() { - struct CallInWasm; + sc_executor::native_executor_instance!( + Executor, + substrate_test_runtime::api::dispatch, + substrate_test_runtime::native_version, + ); - impl sp_core::traits::CallInWasm for CallInWasm { - fn call_in_wasm( - &self, - blob: &[u8], - method: &str, - call_data: &[u8], - ext: Option<&mut dyn sp_externalities::Externalities>, - ) -> Result, String> { - type HostFunctions = ( - sp_io::SubstrateHostFunctions, - sc_executor::deprecated_host_interface::SubstrateExternals - ); - sc_executor::call_in_wasm::( - method, - call_data, - sc_executor::WasmExecutionMethod::Interpreted, - ext, - blob, - 8, - ).map_err(|e| { println!("{:?}", e); e.to_string() }) - } + fn executor() -> sc_executor::NativeExecutor { + sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None) } let mut ext = new_test_ext(); - ext.register_extension(sp_core::traits::CallInWasmExt::new(CallInWasm)); + ext.register_extension(sp_core::traits::CallInWasmExt::new(executor())); ext.execute_with(|| { System::set_code( RawOrigin::Root.into(), diff --git a/primitives/core/src/traits.rs b/primitives/core/src/traits.rs index 3adbf6ce83466..d4cf460fb4bfd 100644 --- a/primitives/core/src/traits.rs +++ b/primitives/core/src/traits.rs @@ -80,7 +80,7 @@ sp_externalities::decl_extension! { } /// Code execution engine. -pub trait CodeExecutor: Sized + Send + Sync + CallInWasm { +pub trait CodeExecutor: Sized + Send + Sync + CallInWasm + Clone { /// Externalities error type. type Error: Display + Debug + Send + 'static; @@ -111,7 +111,7 @@ pub trait CallInWasm: Send + Sync { wasm_blob: &[u8], method: &str, call_data: &[u8], - ext: Option<&mut dyn Externalities>, + ext: &mut dyn Externalities, ) -> Result, String>; } diff --git a/primitives/externalities/Cargo.toml b/primitives/externalities/Cargo.toml index 09ce3253f2d98..7aa5bba8b8979 100644 --- a/primitives/externalities/Cargo.toml +++ b/primitives/externalities/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" [dependencies] sp-storage = { version = "2.0.0", path = "../storage" } sp-std = { version = "2.0.0", path = "../std" } -environmental = { version = "1.0.2" } +environmental = { version = "1.1.1" } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 9c1273b918e05..f140096e14bd5 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -356,9 +356,12 @@ pub trait Misc { /// /// Returns the SCALE encoded runtime version and `None` if the call failed. fn runtime_version(&mut self, wasm: &[u8]) -> Option> { + // Create some dummy externalities, `Core_version` should not write data anyway. + let mut ext = sp_state_machine::BasicExternalities::default(); + self.extension::() .expect("No `CallInWasmExt` associated for the current context!") - .call_in_wasm(wasm, "Core_version", &[], None) + .call_in_wasm(wasm, "Core_version", &[], &mut ext) .ok() } } diff --git a/primitives/runtime-interface/Cargo.toml b/primitives/runtime-interface/Cargo.toml index cdc94b6a2f226..22126a89526ea 100644 --- a/primitives/runtime-interface/Cargo.toml +++ b/primitives/runtime-interface/Cargo.toml @@ -10,7 +10,6 @@ sp-std = { version = "2.0.0", default-features = false, path = "../std" } sp-runtime-interface-proc-macro = { version = "2.0.0", path = "proc-macro" } sp-externalities = { version = "2.0.0", optional = true, path = "../externalities" } codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false } -environmental = { version = "1.0.2", optional = true } static_assertions = "1.0.0" primitive-types = { version = "0.6.1", default-features = false } @@ -29,7 +28,6 @@ std = [ "sp-std/std", "codec/std", "sp-externalities", - "environmental", "primitive-types/std", ] diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index fb3d10b0234cf..dee8e1b1dda98 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -28,7 +28,6 @@ fn call_wasm_method(method: &str) -> TestExternalities { let mut ext_ext = ext.ext(); sc_executor::call_in_wasm::< - _, ( HF, sp_io::SubstrateHostFunctions, diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index 40569d5aed43b..bdbab5652fa2b 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -53,6 +53,9 @@ pub mod testing; pub mod traits; pub mod transaction_validity; pub mod random_number_generator; +mod runtime_string; + +pub use crate::runtime_string::*; /// Re-export these since they're only "kind of" generic. pub use generic::{DigestItem, Digest}; @@ -92,94 +95,6 @@ impl TypeId for ModuleId { const TYPE_ID: [u8; 4] = *b"modl"; } -/// A string that wraps a `&'static str` in the runtime and `String`/`Vec` on decode. -#[derive(Eq, RuntimeDebug, Clone)] -pub enum RuntimeString { - /// The borrowed mode that wraps a `&'static str`. - Borrowed(&'static str), - /// The owned mode that wraps a `String`. - #[cfg(feature = "std")] - Owned(String), - /// The owned mode that wraps a `Vec`. - #[cfg(not(feature = "std"))] - Owned(Vec), -} - -impl From<&'static str> for RuntimeString { - fn from(data: &'static str) -> Self { - Self::Borrowed(data) - } -} - -impl Default for RuntimeString { - fn default() -> Self { - Self::Borrowed(Default::default()) - } -} - -impl PartialEq for RuntimeString { - fn eq(&self, other: &Self) -> bool { - self.as_ref() == other.as_ref() - } -} - -impl AsRef<[u8]> for RuntimeString { - fn as_ref(&self) -> &[u8] { - match self { - Self::Borrowed(val) => val.as_ref(), - Self::Owned(val) => val.as_ref(), - } - } -} - -impl Encode for RuntimeString { - fn encode(&self) -> Vec { - match self { - Self::Borrowed(val) => val.encode(), - Self::Owned(val) => val.encode(), - } - } -} - -impl Decode for RuntimeString { - fn decode(value: &mut I) -> Result { - Decode::decode(value).map(Self::Owned) - } -} - -#[cfg(feature = "std")] -impl std::fmt::Display for RuntimeString { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Self::Borrowed(val) => write!(f, "{}", val), - Self::Owned(val) => write!(f, "{}", val), - } - } -} - -#[cfg(feature = "std")] -impl serde::Serialize for RuntimeString { - fn serialize(&self, serializer: S) -> Result { - match self { - Self::Borrowed(val) => val.serialize(serializer), - Self::Owned(val) => val.serialize(serializer), - } - } -} - -#[cfg(feature = "std")] -impl<'de> serde::Deserialize<'de> for RuntimeString { - fn deserialize>(de: D) -> Result { - String::deserialize(de).map(Self::Owned) - } -} - -/// Create a const [`RuntimeString`]. -#[macro_export] -macro_rules! create_runtime_str { - ( $y:expr ) => {{ $crate::RuntimeString::Borrowed($y) }} -} - #[cfg(feature = "std")] pub use serde::{Serialize, Deserialize, de::DeserializeOwned}; use crate::traits::IdentifyAccount; diff --git a/primitives/state-machine/src/lib.rs b/primitives/state-machine/src/lib.rs index c67ed5bcba961..e1ccffc91eb2c 100644 --- a/primitives/state-machine/src/lib.rs +++ b/primitives/state-machine/src/lib.rs @@ -749,6 +749,7 @@ mod tests { }; use sp_core::{Blake2Hasher, map, traits::Externalities, storage::ChildStorageKey}; + #[derive(Clone)] struct DummyCodeExecutor { change_changes_trie_config: bool, native_available: bool, @@ -805,6 +806,18 @@ mod tests { } } + impl sp_core::traits::CallInWasm for DummyCodeExecutor { + fn call_in_wasm( + &self, + _: &[u8], + _: &str, + _: &[u8], + _: &mut dyn Externalities, + ) -> std::result::Result, String> { + unimplemented!("Not required in tests.") + } + } + #[test] fn execute_works() { let backend = trie_backend::tests::test_trie(); diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index f560d0f97b0ae..7d94d9d93d58f 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -65,7 +65,7 @@ pub trait ClientExt: Sized { impl ClientExt for Client where B: sc_client_api::backend::Backend, - E: sc_client::CallExecutor, + E: sc_client::CallExecutor + 'static, for<'r> &'r Self: BlockImport, Block: BlockT::Out>, { diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index 2496409f8718a..2a1ccccd14206 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -177,7 +177,7 @@ impl TestClientBuilder >, sc_client::LongestChain, ) where - Executor: sc_client::CallExecutor, + Executor: sc_client::CallExecutor + 'static, Backend: sc_client_api::backend::Backend, Block: BlockT::Out>, { @@ -235,8 +235,8 @@ impl TestClientBuilder< sc_client::LongestChain, ) where I: Into>>, - E: sc_executor::NativeExecutionDispatch, - Backend: sc_client_api::backend::Backend, + E: sc_executor::NativeExecutionDispatch + 'static, + Backend: sc_client_api::backend::Backend + 'static, Block: BlockT::Out>, { let executor = executor.into().unwrap_or_else(|| diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 988fa5667818b..3b2dfef2511ff 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -215,7 +215,7 @@ impl TestClientBuilderExt for TestClientBuilder< sc_client::LocalCallExecutor>, B > where - B: sc_client_api::backend::Backend, + B: sc_client_api::backend::Backend + 'static, { fn set_heap_pages(mut self, heap_pages: u64) -> Self { self.genesis_init_mut().heap_pages_override = Some(heap_pages); From 5fd35a19ebe395a898bbf9849073d118f2d65071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 11:57:28 +0100 Subject: [PATCH 03/13] Some fixes after master merge --- client/consensus/babe/src/lib.rs | 2 +- client/executor/src/lib.rs | 6 +++--- client/executor/src/native_executor.rs | 1 + client/executor/wasmi/src/lib.rs | 1 - client/service/src/builder.rs | 4 ++-- client/src/light/call_executor.rs | 4 ++-- primitives/version/src/lib.rs | 2 ++ test-utils/client/src/client_ext.rs | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index dcc456988fb09..98212b2ac9f12 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -1160,7 +1160,7 @@ pub fn block_import( api: Arc, ) -> ClientResult<(BabeBlockImport, BabeLink)> where B: Backend, - E: CallExecutor + Send + Sync, + 'static, + E: CallExecutor + Send + Sync + 'static, RA: Send + Sync, Client: AuxStore, { diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 8902fd3510f58..4f97efa9b661e 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -78,7 +78,7 @@ pub fn call_in_wasm( code, heap_pages, HF::host_functions(), - allow_missing_imports, + allow_missing_imports, ) } @@ -92,14 +92,14 @@ pub fn call_in_wasm_with_host_functions( code: &[u8], heap_pages: u64, host_functions: Vec<&'static dyn sp_wasm_interface::Function>, - allow_missing_imports: bool, + allow_missing_imports: bool, ) -> error::Result> { let instance = wasm_runtime::create_wasm_runtime_with_code( execution_method, heap_pages, code, host_functions, - allow_missing_imports, + allow_missing_imports, )?; // It is safe, as we delete the instance afterwards. diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 08c2b9b7cc5b9..78e3532b760f5 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -272,6 +272,7 @@ impl sp_core::traits::CallInWasm for NativeExecutor< wasm_blob, self.default_heap_pages, (*self.host_functions).clone(), + false, ).map_err(|e| e.to_string()) } } diff --git a/client/executor/wasmi/src/lib.rs b/client/executor/wasmi/src/lib.rs index c2399fd31c668..c10698fea46ad 100644 --- a/client/executor/wasmi/src/lib.rs +++ b/client/executor/wasmi/src/lib.rs @@ -607,7 +607,6 @@ impl WasmRuntime for WasmiRuntime { e })?; call_in_wasm_module( - ext, &self.instance, method, data, diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index b769f6a88adc4..3938be356e174 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -148,7 +148,7 @@ pub fn new_full_client( config: &Configuration, ) -> Result, Error> where TBl: BlockT, - TExecDisp: NativeExecutionDispatch, + TExecDisp: NativeExecutionDispatch + 'static, TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>, TCSExt: Extension, { @@ -159,7 +159,7 @@ fn new_full_parts( config: &Configuration, ) -> Result, Error> where TBl: BlockT, - TExecDisp: NativeExecutionDispatch, + TExecDisp: NativeExecutionDispatch + 'static, TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>, TCSExt: Extension, { diff --git a/client/src/light/call_executor.rs b/client/src/light/call_executor.rs index 74e6350498b85..c2f85f2ba6517 100644 --- a/client/src/light/call_executor.rs +++ b/client/src/light/call_executor.rs @@ -181,8 +181,8 @@ pub fn prove_execution( ) -> ClientResult<(Vec, StorageProof)> where Block: BlockT, - S: StateBackend> + 'static, - E: CallExecutor, + S: StateBackend>, + E: CallExecutor + 'static, { let trie_state = state.as_trie_backend() .ok_or_else(|| diff --git a/primitives/version/src/lib.rs b/primitives/version/src/lib.rs index abb37ee31618f..0534f87490868 100644 --- a/primitives/version/src/lib.rs +++ b/primitives/version/src/lib.rs @@ -28,6 +28,8 @@ use std::collections::HashSet; use codec::{Encode, Decode}; use sp_runtime::RuntimeString; pub use sp_runtime::create_runtime_str; +#[doc(hidden)] +pub use sp_std; #[cfg(feature = "std")] use sp_runtime::{traits::Block as BlockT, generic::BlockId}; diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index 67d08c5fa600f..aa7383e3ab367 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -64,7 +64,7 @@ pub trait ClientBlockImportExt: Sized { impl ClientExt for Client where B: sc_client_api::backend::Backend, - E: sc_client::CallExecutor, + E: sc_client::CallExecutor + 'static, Self: BlockImport, Block: BlockT, { From 0ad8df5c210559c8cd3a625f05e574f25a24ea96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 12:52:24 +0100 Subject: [PATCH 04/13] Fix tests --- client/executor/common/src/error.rs | 4 ++++ client/executor/src/native_executor.rs | 10 +++++++++- client/rpc/src/state/tests.rs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/executor/common/src/error.rs b/client/executor/common/src/error.rs index fca17bd88c8ea..f7de0af9685d7 100644 --- a/client/executor/common/src/error.rs +++ b/client/executor/common/src/error.rs @@ -57,6 +57,10 @@ pub enum Error { /// Runtime failed. #[display(fmt="Runtime error")] Runtime, + /// Runtime panicked. + #[display(fmt="Runtime panicked: {}", _0)] + #[from(ignore)] + RuntimePanicked(String), /// Invalid memory reference. #[display(fmt="Invalid memory reference")] InvalidMemoryReference, diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 78e3532b760f5..8c15133bf3693 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -45,7 +45,15 @@ pub fn with_externalities_safe(ext: &mut dyn Externalities, f: F) -> Resul // Substrate uses custom panic hook that terminates process on panic. Disable // termination for the native call. let _guard = sp_panic_handler::AbortGuard::force_unwind(); - std::panic::catch_unwind(f).map_err(|_| Error::Runtime) + std::panic::catch_unwind(f).map_err(|e| { + if let Some(err) = e.downcast_ref::() { + Error::RuntimePanicked(err.clone()) + } else if let Some(err) = e.downcast_ref::<&'static str>() { + Error::RuntimePanicked(err.to_string()) + } else { + Error::RuntimePanicked("Unknown panic".into()) + } + }) }, ) } diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 5951ee86a93ce..848e80d4fbd53 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -399,7 +399,7 @@ fn should_return_runtime_version() { let api = new_full(client.clone(), Subscriptions::new(Arc::new(core.executor()))); let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\ - \"specVersion\":1,\"implVersion\":1,\"apis\":[[\"0xdf6acb689907609b\",2],\ + \"specVersion\":1,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",2],\ [\"0x37e397fc7c91f5e4\",1],[\"0xd2bc9897eed08f15\",1],[\"0x40fe3ad401f8959a\",4],\ [\"0xc6e9a76309f39b09\",1],[\"0xdd718d5cc53262d4\",1],[\"0xcbca25e39f142387\",1],\ [\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]]}"; From ca5df1bdd6f1be520604ec210eed3fee0df73bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 13:05:56 +0100 Subject: [PATCH 05/13] Add missed file --- primitives/runtime/src/runtime_string.rs | 117 +++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 primitives/runtime/src/runtime_string.rs diff --git a/primitives/runtime/src/runtime_string.rs b/primitives/runtime/src/runtime_string.rs new file mode 100644 index 0000000000000..e7ee927e087be --- /dev/null +++ b/primitives/runtime/src/runtime_string.rs @@ -0,0 +1,117 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use codec::{Encode, Decode}; +use sp_core::RuntimeDebug; +use sp_std::vec::Vec; + +/// A string that wraps a `&'static str` in the runtime and `String`/`Vec` on decode. +#[derive(Eq, RuntimeDebug, Clone)] +pub enum RuntimeString { + /// The borrowed mode that wraps a `&'static str`. + Borrowed(&'static str), + /// The owned mode that wraps a `String`. + #[cfg(feature = "std")] + Owned(String), + /// The owned mode that wraps a `Vec`. + #[cfg(not(feature = "std"))] + Owned(Vec), +} + +impl From<&'static str> for RuntimeString { + fn from(data: &'static str) -> Self { + Self::Borrowed(data) + } +} + +#[cfg(feature = "std")] +impl From for String { + fn from(string: RuntimeString) -> Self { + match string { + RuntimeString::Borrowed(data) => data.to_owned(), + RuntimeString::Owned(data) => data, + } + } +} + +impl Default for RuntimeString { + fn default() -> Self { + Self::Borrowed(Default::default()) + } +} + +impl PartialEq for RuntimeString { + fn eq(&self, other: &Self) -> bool { + self.as_ref() == other.as_ref() + } +} + +impl AsRef<[u8]> for RuntimeString { + fn as_ref(&self) -> &[u8] { + match self { + Self::Borrowed(val) => val.as_ref(), + Self::Owned(val) => val.as_ref(), + } + } +} + +impl Encode for RuntimeString { + fn encode(&self) -> Vec { + match self { + Self::Borrowed(val) => val.encode(), + Self::Owned(val) => val.encode(), + } + } +} + +impl Decode for RuntimeString { + fn decode(value: &mut I) -> Result { + Decode::decode(value).map(Self::Owned) + } +} + +#[cfg(feature = "std")] +impl std::fmt::Display for RuntimeString { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Borrowed(val) => write!(f, "{}", val), + Self::Owned(val) => write!(f, "{}", val), + } + } +} + +#[cfg(feature = "std")] +impl serde::Serialize for RuntimeString { + fn serialize(&self, serializer: S) -> Result { + match self { + Self::Borrowed(val) => val.serialize(serializer), + Self::Owned(val) => val.serialize(serializer), + } + } +} + +#[cfg(feature = "std")] +impl<'de> serde::Deserialize<'de> for RuntimeString { + fn deserialize>(de: D) -> Result { + String::deserialize(de).map(Self::Owned) + } +} + +/// Create a const [`RuntimeString`]. +#[macro_export] +macro_rules! create_runtime_str { + ( $y:expr ) => {{ $crate::RuntimeString::Borrowed($y) }} +} From 045547c829271c5a0dc03c0d64cd334995e04d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 13:47:07 +0100 Subject: [PATCH 06/13] Make depedency check happy? --- Cargo.lock | 2 +- frame/system/Cargo.toml | 2 +- frame/system/src/lib.rs | 15 +++------------ test-utils/runtime/client/src/lib.rs | 24 ++++++++++-------------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 155f8d43b2465..51b319af8c76a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1412,7 +1412,7 @@ dependencies = [ "sp-runtime 2.0.0", "sp-std 2.0.0", "sp-version 2.0.0", - "substrate-test-runtime 2.0.0", + "substrate-test-runtime-client 2.0.0", ] [[package]] diff --git a/frame/system/Cargo.toml b/frame/system/Cargo.toml index 9bff9bc8f5887..d57f23ec5e805 100644 --- a/frame/system/Cargo.toml +++ b/frame/system/Cargo.toml @@ -20,7 +20,7 @@ impl-trait-for-tuples = "0.1.3" criterion = "0.2.11" sp-externalities = { version = "2.0.0", path = "../../primitives/externalities" } sc-executor = { version = "2.0.0", path = "../../client/executor" } -substrate-test-runtime = { version = "2.0.0", path = "../../test-utils/runtime" } +substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } [features] default = ["std"] diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index bf9e8c1b174e2..174eb733afb30 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -1665,22 +1665,13 @@ mod tests { #[test] fn set_code_with_real_wasm_blob() { - sc_executor::native_executor_instance!( - Executor, - substrate_test_runtime::api::dispatch, - substrate_test_runtime::native_version, - ); - - fn executor() -> sc_executor::NativeExecutor { - sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None) - } - + let executor = substrate_test_runtime_client::new_native_executor(); let mut ext = new_test_ext(); - ext.register_extension(sp_core::traits::CallInWasmExt::new(executor())); + ext.register_extension(sp_core::traits::CallInWasmExt::new(executor)); ext.execute_with(|| { System::set_code( RawOrigin::Root.into(), - substrate_test_runtime::WASM_BINARY.to_vec(), + substrate_test_runtime_client::runtime::WASM_BINARY.to_vec(), ).unwrap(); }); } diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 29703ca7644b2..0476be2f60201 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -59,21 +59,12 @@ pub mod prelude { pub use super::{AccountKeyring, Sr25519Keyring}; } -mod local_executor { - #![allow(missing_docs)] - use substrate_test_runtime; - use crate::sc_executor::native_executor_instance; - // FIXME #1576 change the macro and pass in the `BlakeHasher` that dispatch needs from here instead - native_executor_instance!( - pub LocalExecutor, - substrate_test_runtime::api::dispatch, - substrate_test_runtime::native_version - ); +sc_executor::native_executor_instance! { + pub LocalExecutor, + substrate_test_runtime::api::dispatch, + substrate_test_runtime::native_version, } -/// Native executor used for tests. -pub use self::local_executor::LocalExecutor; - /// Test client database backend. pub type Backend = substrate_test_client::Backend; @@ -353,7 +344,7 @@ pub fn new_light() -> ( let storage = sc_client_db::light::LightStorage::new_test(); let blockchain = Arc::new(sc_client::light::blockchain::Blockchain::new(storage)); let backend = Arc::new(LightBackend::new(blockchain.clone())); - let executor = NativeExecutor::new(WasmExecutionMethod::Interpreted, None); + let executor = new_native_executor(); let local_call_executor = sc_client::LocalCallExecutor::new(backend.clone(), executor); let call_executor = LightExecutor::new( backend.clone(), @@ -372,3 +363,8 @@ pub fn new_light() -> ( pub fn new_light_fetcher() -> LightFetcher { LightFetcher::default() } + +/// Create a new native executor. +pub fn new_native_executor() -> sc_executor::NativeExecutor { + sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None) +} From 88d8b933f058ad02a5c30298fe8f59fcd6fd5734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 13:50:25 +0100 Subject: [PATCH 07/13] Remove leftover `sc-executor` --- frame/system/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/system/Cargo.toml b/frame/system/Cargo.toml index d57f23ec5e805..bb8aa3b8dfab1 100644 --- a/frame/system/Cargo.toml +++ b/frame/system/Cargo.toml @@ -19,7 +19,6 @@ impl-trait-for-tuples = "0.1.3" [dev-dependencies] criterion = "0.2.11" sp-externalities = { version = "2.0.0", path = "../../primitives/externalities" } -sc-executor = { version = "2.0.0", path = "../../client/executor" } substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } [features] From 27be8c5407a12f7a6045e12ea2a52ab11408a266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 13:53:45 +0100 Subject: [PATCH 08/13] AHHHHH --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 51b319af8c76a..7353f5254b0be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1404,7 +1404,6 @@ dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sc-executor 2.0.0", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-externalities 2.0.0", From 44c7d174869bcf8360ce0c21b602e67e895b6be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 15:32:21 +0100 Subject: [PATCH 09/13] Reset debug stuff --- primitives/sandbox/with_std.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/primitives/sandbox/with_std.rs b/primitives/sandbox/with_std.rs index d025732c5fed3..5f20342a5a9e4 100755 --- a/primitives/sandbox/with_std.rs +++ b/primitives/sandbox/with_std.rs @@ -121,7 +121,6 @@ impl<'a, T> Externals for GuestExternals<'a, T> { index: usize, args: RuntimeArgs, ) -> Result, Trap> { - println!("Lol: {:?}", args); let args = args.as_ref() .iter() .cloned() @@ -188,12 +187,9 @@ impl ImportResolver for EnvironmentDefinitionBuilder { module_name.as_bytes().to_owned(), field_name.as_bytes().to_owned(), ); - println!("{} {}", module_name, field_name); - let lol = ExternVal::HostFunc(HostFuncIndex(100)); - let externval = self.map.get(&key).unwrap_or_else(|| { - // wasmi::Error::Instantiation(format!("Export {}:{} not found", module_name, field_name)) - &lol - }); + let externval = self.map.get(&key).ok_or_else(|| { + wasmi::Error::Instantiation(format!("Export {}:{} not found", module_name, field_name)) + })?; let host_func_idx = match *externval { ExternVal::HostFunc(ref idx) => idx, _ => { @@ -266,9 +262,10 @@ impl Instance { env_def_builder: &EnvironmentDefinitionBuilder, state: &mut T, ) -> Result, Error> { - let module = Module::from_buffer(code).map_err(|e| { println!("{:?}", e); Error::Module})?; + let module = Module::from_buffer(code).map_err(|_| Error::Module)?; let not_started_instance = ModuleInstance::new(&module, env_def_builder) - .map_err(|e| { println!("Hello {:?}", e); Error::Module})?; + .map_err(|_| Error::Module)?; + let defined_host_functions = env_def_builder.defined_host_functions.clone(); let instance = { @@ -277,7 +274,7 @@ impl Instance { defined_host_functions: &defined_host_functions, }; let instance = not_started_instance.run_start(&mut externals) - .map_err(|e| { println!("Hello {:?}", e); Error::Execution})?; + .map_err(|_| Error::Execution)?; instance }; @@ -306,10 +303,7 @@ impl Instance { match result { Ok(None) => Ok(ReturnValue::Unit), Ok(Some(val)) => Ok(ReturnValue::Value(val.into())), - Err(_err) => { - println!("{:?}", _err); - Err(Error::Execution) - } + Err(_err) => Err(Error::Execution), } } } From a30d94b5f3b9fabdb06a95ab88c56879fd841cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 13 Jan 2020 23:19:52 +0100 Subject: [PATCH 10/13] Remove some 'static --- client/executor/src/native_executor.rs | 2 +- client/src/client.rs | 34 ++++++++++++-------------- client/src/light/call_executor.rs | 2 +- primitives/core/src/traits.rs | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 8c15133bf3693..4fe7a205f53f9 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -188,7 +188,7 @@ impl RuntimeInfo for NativeExecutor { } } -impl CodeExecutor for NativeExecutor { +impl CodeExecutor for NativeExecutor { type Error = Error; fn call diff --git a/client/src/client.rs b/client/src/client.rs index 1b5aebe16312a..c31a2274f1c48 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -137,7 +137,7 @@ pub fn new_in_mem( Block, RA >> where - E: CodeExecutor + RuntimeInfo + 'static, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, Block: BlockT, { @@ -153,7 +153,7 @@ pub fn new_with_backend( keystore: Option, ) -> sp_blockchain::Result, Block, RA>> where - E: CodeExecutor + RuntimeInfo + 'static, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, Block: BlockT, B: backend::LocalBackend + 'static, @@ -172,7 +172,7 @@ pub fn new_with_backend( impl BlockOf for Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { type Type = Block; @@ -180,7 +180,7 @@ impl BlockOf for Client where impl Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { /// Creates new Substrate Client with given blockchain and code executor. @@ -750,7 +750,6 @@ impl Client where import_block: BlockImportParams>, new_cache: HashMap>, ) -> sp_blockchain::Result where - E: CallExecutor + Send + Sync, Self: ProvideRuntimeApi, >::Api: CoreApi + ApiExt, @@ -829,7 +828,6 @@ impl Client where fork_choice: ForkChoiceStrategy, import_existing: bool, ) -> sp_blockchain::Result where - E: CallExecutor + Send + Sync, Self: ProvideRuntimeApi, >::Api: CoreApi + ApiExt, @@ -1293,7 +1291,7 @@ impl HeaderMetadata for Client where impl ProvideUncles for Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor) -> sp_blockchain::Result> { @@ -1387,7 +1385,7 @@ impl ProvideCache for Client where impl ProvideRuntimeApi for Client where B: backend::Backend, - E: CallExecutor + 'static + Send + Sync, + E: CallExecutor + Send + Sync, Block: BlockT, RA: ConstructRuntimeApi, { @@ -1400,7 +1398,7 @@ impl ProvideRuntimeApi for Client where impl CallApiAt for Client where B: backend::Backend, - E: CallExecutor + 'static + Send + Sync, + E: CallExecutor + Send + Sync, Block: BlockT, { type Error = Error; @@ -1448,7 +1446,7 @@ impl CallApiAt for Client where /// important verification work. impl sp_consensus::BlockImport for &Client where B: backend::Backend, - E: CallExecutor + 'static + Send + Sync, + E: CallExecutor + Send + Sync, Block: BlockT, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: CoreApi + @@ -1552,7 +1550,7 @@ impl sp_consensus::BlockImport for &Client sp_consensus::BlockImport for Client where B: backend::Backend, - E: CallExecutor + 'static + Send + Sync, + E: CallExecutor + Send + Sync, Block: BlockT, Self: ProvideRuntimeApi, >::Api: CoreApi + @@ -1579,7 +1577,7 @@ impl sp_consensus::BlockImport for Client Finalizer for Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { fn apply_finality( @@ -1615,7 +1613,7 @@ impl Finalizer for Client where impl Finalizer for &Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { fn apply_finality( @@ -1640,7 +1638,7 @@ impl Finalizer for &Client where impl BlockchainEvents for Client where - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { /// Get block import event stream. @@ -1743,7 +1741,7 @@ where impl BlockBody for Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, { fn block_body( @@ -1757,7 +1755,7 @@ impl BlockBody for Client impl backend::AuxStore for Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, Self: ProvideRuntimeApi, >::Api: CoreApi, @@ -1787,7 +1785,7 @@ impl backend::AuxStore for Client impl backend::AuxStore for &Client where B: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, Block: BlockT, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: CoreApi, @@ -1829,7 +1827,7 @@ where impl sp_consensus::block_validation::Chain for Client where BE: backend::Backend, - E: CallExecutor + 'static, + E: CallExecutor, B: BlockT { fn block_status( diff --git a/client/src/light/call_executor.rs b/client/src/light/call_executor.rs index c2f85f2ba6517..9ac88103e8e04 100644 --- a/client/src/light/call_executor.rs +++ b/client/src/light/call_executor.rs @@ -182,7 +182,7 @@ pub fn prove_execution( where Block: BlockT, S: StateBackend>, - E: CallExecutor + 'static, + E: CallExecutor, { let trie_state = state.as_trie_backend() .ok_or_else(|| diff --git a/primitives/core/src/traits.rs b/primitives/core/src/traits.rs index eea495da98d28..020b5e2dc5461 100644 --- a/primitives/core/src/traits.rs +++ b/primitives/core/src/traits.rs @@ -80,7 +80,7 @@ sp_externalities::decl_extension! { } /// Code execution engine. -pub trait CodeExecutor: Sized + Send + Sync + CallInWasm + Clone { +pub trait CodeExecutor: Sized + Send + Sync + CallInWasm + Clone + 'static { /// Externalities error type. type Error: Display + Debug + Send + 'static; From 2c6eaa0859074110a152fd25a21cb4ed5a054f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 14 Jan 2020 00:48:09 +0100 Subject: [PATCH 11/13] More 'static --- bin/node/transaction-factory/src/complex_mode.rs | 2 +- bin/node/transaction-factory/src/lib.rs | 6 +++--- bin/node/transaction-factory/src/simple_modes.rs | 2 +- client/consensus/babe/src/lib.rs | 4 ++-- client/db/src/lib.rs | 2 +- client/finality-grandpa/src/environment.rs | 4 ++-- client/finality-grandpa/src/justification.rs | 2 +- client/finality-grandpa/src/lib.rs | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/node/transaction-factory/src/complex_mode.rs b/bin/node/transaction-factory/src/complex_mode.rs index b44eb646e3258..6d7e60c8d3c1f 100644 --- a/bin/node/transaction-factory/src/complex_mode.rs +++ b/bin/node/transaction-factory/src/complex_mode.rs @@ -59,7 +59,7 @@ pub fn next( ) -> Option where Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, + Exec: sc_client::CallExecutor + Send + Sync + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: diff --git a/bin/node/transaction-factory/src/lib.rs b/bin/node/transaction-factory/src/lib.rs index 63c700aa5d890..f3dcdb0875002 100644 --- a/bin/node/transaction-factory/src/lib.rs +++ b/bin/node/transaction-factory/src/lib.rs @@ -99,7 +99,7 @@ pub fn factory( ) -> sc_cli::error::Result<()> where Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, + Exec: sc_client::CallExecutor + Send + Sync + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: @@ -159,7 +159,7 @@ pub fn create_block( ) -> Block where Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, + Exec: sc_client::CallExecutor + Send + Sync + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, RtApi: ConstructRuntimeApi> + Send + Sync, @@ -186,7 +186,7 @@ fn import_block( block: Block ) -> () where Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, + Exec: sc_client::CallExecutor + Send + Sync + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: diff --git a/bin/node/transaction-factory/src/simple_modes.rs b/bin/node/transaction-factory/src/simple_modes.rs index 34ff64fee23fb..fba328731a98f 100644 --- a/bin/node/transaction-factory/src/simple_modes.rs +++ b/bin/node/transaction-factory/src/simple_modes.rs @@ -54,7 +54,7 @@ pub fn next( ) -> Option where Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone + 'static, + Exec: sc_client::CallExecutor + Send + Sync + Clone, Backend: sc_client_api::backend::Backend + Send, Client: ProvideRuntimeApi, as ProvideRuntimeApi>::Api: diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 98212b2ac9f12..bbf19b706601f 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -1120,7 +1120,7 @@ fn prune_finalized( epoch_changes: &mut EpochChangesFor, ) -> Result<(), ConsensusError> where Block: BlockT, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, B: Backend, RA: Send + Sync, { @@ -1160,7 +1160,7 @@ pub fn block_import( api: Arc, ) -> ClientResult<(BabeBlockImport, BabeLink)> where B: Backend, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, RA: Send + Sync, Client: AuxStore, { diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index c6712f893c957..06d0dc18ffa36 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -291,7 +291,7 @@ pub fn new_client( > where Block: BlockT, - E: CodeExecutor + RuntimeInfo + 'static, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, { let backend = Arc::new(Backend::new(settings, CANONICALIZATION_DELAY)?); diff --git a/client/finality-grandpa/src/environment.rs b/client/finality-grandpa/src/environment.rs index 567f8e1d04a98..372229001dd19 100644 --- a/client/finality-grandpa/src/environment.rs +++ b/client/finality-grandpa/src/environment.rs @@ -412,7 +412,7 @@ for Environment where Block: 'static, B: Backend + 'static, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, N: NetworkT + 'static + Send, SC: SelectChain + 'static, VR: VotingRule>, @@ -951,7 +951,7 @@ pub(crate) fn finalize_block( justification_or_commit: JustificationOrCommit, ) -> Result<(), CommandOrError>> where B: Backend, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, RA: Send + Sync, { // NOTE: lock must be held through writing to DB to avoid race. this lock diff --git a/client/finality-grandpa/src/justification.rs b/client/finality-grandpa/src/justification.rs index 0449af99b8716..308056725f67b 100644 --- a/client/finality-grandpa/src/justification.rs +++ b/client/finality-grandpa/src/justification.rs @@ -53,7 +53,7 @@ impl GrandpaJustification { commit: Commit, ) -> Result, Error> where B: Backend, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, RA: Send + Sync, { let mut votes_ancestries_hashes = HashSet::new(); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 9f56c05012a41..d6e1d9cc456cb 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -371,7 +371,7 @@ pub trait GenesisAuthoritySetProvider { impl GenesisAuthoritySetProvider for Client where B: Backend + Send + Sync + 'static, - E: CallExecutor + 'static + Clone + Send + Sync, + E: CallExecutor + Send + Sync, RA: Send + Sync, { fn get(&self) -> Result { @@ -407,7 +407,7 @@ pub fn block_import( ), ClientError> where B: Backend + 'static, - E: CallExecutor + 'static + Clone + Send + Sync, + E: CallExecutor + Send + Sync, RA: Send + Sync, SC: SelectChain, Client: AuxStore, @@ -464,7 +464,7 @@ fn global_communication( >, ) where B: Backend, - E: CallExecutor + Send + Sync + 'static, + E: CallExecutor + Send + Sync, N: NetworkT, RA: Send + Sync, NumberFor: BlockNumberOps, From 7484d66bb69a7b2911e383484577671d86150c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 14 Jan 2020 22:41:26 +0100 Subject: [PATCH 12/13] Some docs --- primitives/io/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index fd32567e6bb5e..704477b1fb2bc 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -355,6 +355,12 @@ pub trait Misc { /// Extract the runtime version of the given wasm blob by calling `Core_version`. /// /// Returns the SCALE encoded runtime version and `None` if the call failed. + /// + /// # Performance + /// + /// Calling this function is very expensive and should only be done very occasionally. + /// For getting the runtime version, it requires instantiating the wasm blob and calling a + /// function in this blob. fn runtime_version(&mut self, wasm: &[u8]) -> Option> { // Create some dummy externalities, `Core_version` should not write data anyway. let mut ext = sp_state_machine::BasicExternalities::default(); From 8b5906859f7734ac43dc24123b6c1682e74bb9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 14 Jan 2020 22:43:03 +0100 Subject: [PATCH 13/13] Update `Cargo.lock` --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a6b2b5ab35268..c415904a0b0b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3904,7 +3904,7 @@ dependencies = [ "frame-support 2.0.0", "frame-system 2.0.0", "pallet-balances 2.0.0", - "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0",