Don't include :code by default in storage proofs (#5179)

* Don't include `:code` by default in storage proofs (#5060)

* Adds test to verify that the runtime currently is always contained in
the proof

* Start passing the runtime wasm code from the outside

* Fix compilation

* More build fixes

* Make the test work as expected now :)

* Last fixes

* Fixes benchmarks

* Review feedback

* Apply suggestions from code review

Co-Authored-By: Sergei Pepyakin <sergei@parity.io>

* Review feedback

* Fix compilation

Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>

* Fix compilation and change the way `RuntimeCode` works

* Fix tests

* Switch to `Cow`

Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
This commit is contained in:
Bastian Köcher
2020-03-10 11:13:20 +01:00
committed by GitHub
parent 0cc3b96076
commit 1cfcf5cbfe
39 changed files with 597 additions and 363 deletions
+1
View File
@@ -36,6 +36,7 @@ pallet-transaction-payment = { version = "2.0.0-alpha.2", path = "../../../frame
pallet-treasury = { version = "2.0.0-alpha.2", path = "../../../frame/treasury" }
sp-application-crypto = { version = "2.0.0-alpha.2", path = "../../../primitives/application-crypto" }
sp-runtime = { version = "2.0.0-alpha.2", path = "../../../primitives/runtime" }
sp-externalities = { version = "0.8.0-alpha.3", path = "../../../primitives/externalities" }
substrate-test-client = { version = "2.0.0-dev", path = "../../../test-utils/client" }
wabt = "0.9.2"
+18 -3
View File
@@ -25,8 +25,8 @@ use node_runtime::constants::currency::*;
use node_testing::keyring::*;
use sp_core::{NativeOrEncoded, NeverNativeValue};
use sp_core::storage::well_known_keys;
use sp_core::traits::CodeExecutor;
use frame_support::Hashable;
use sp_core::traits::{CodeExecutor, RuntimeCode};
use frame_support::Hashable;
use sp_state_machine::TestExternalities as CoreTestExternalities;
use sc_executor::{NativeExecutor, RuntimeInfo, WasmExecutionMethod, Externalities};
use sp_runtime::traits::BlakeTwo256;
@@ -90,9 +90,16 @@ fn construct_block<E: Externalities>(
digest: Default::default(),
};
let runtime_code = RuntimeCode {
code_fetcher: &sp_core::traits::WrappedRuntimeCode(COMPACT_CODE.into()),
hash: vec![1, 2, 3],
heap_pages: None,
};
// execute the block to get the real header.
executor.call::<NeverNativeValue, fn() -> _>(
ext,
&runtime_code,
"Core_initialize_block",
&header.encode(),
true,
@@ -102,6 +109,7 @@ fn construct_block<E: Externalities>(
for i in extrinsics.iter() {
executor.call::<NeverNativeValue, fn() -> _>(
ext,
&runtime_code,
"BlockBuilder_apply_extrinsic",
&i.encode(),
true,
@@ -111,6 +119,7 @@ fn construct_block<E: Externalities>(
let header = match executor.call::<NeverNativeValue, fn() -> _>(
ext,
&runtime_code,
"BlockBuilder_finalize_block",
&[0u8;0],
true,
@@ -162,11 +171,16 @@ fn bench_execute_block(c: &mut Criterion) {
ExecutionMethod::Wasm(wasm_method) => (false, *wasm_method),
};
let executor = NativeExecutor::new(wasm_method, None);
let runtime_code = RuntimeCode {
code_fetcher: &sp_core::traits::WrappedRuntimeCode(COMPACT_CODE.into()),
hash: vec![1, 2, 3],
heap_pages: None,
};
// Get the runtime version to initialize the runtimes cache.
{
let mut test_ext = new_test_ext(&genesis_config);
executor.runtime_version(&mut test_ext.ext()).unwrap();
executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap();
}
let blocks = test_blocks(&genesis_config, &executor);
@@ -177,6 +191,7 @@ fn bench_execute_block(c: &mut Criterion) {
for block in blocks.iter() {
executor.call::<NeverNativeValue, fn() -> _>(
&mut test_ext.ext(),
&runtime_code,
"Core_execute_block",
&block.0,
use_native,
+12 -1
View File
@@ -17,7 +17,7 @@
use codec::{Encode, Decode};
use frame_support::Hashable;
use sp_state_machine::TestExternalities as CoreTestExternalities;
use sp_core::{NeverNativeValue, NativeOrEncoded, traits::CodeExecutor};
use sp_core::{NeverNativeValue, NativeOrEncoded, traits::{CodeExecutor, RuntimeCode}};
use sp_runtime::{ApplyExtrinsicResult, traits::{Header as HeaderT, BlakeTwo256}};
use sc_executor::{NativeExecutor, WasmExecutionMethod};
use sc_executor::error::Result;
@@ -29,6 +29,7 @@ use node_runtime::{
};
use node_primitives::{Hash, BlockNumber};
use node_testing::keyring::*;
use sp_externalities::Externalities;
/// The wasm runtime code.
///
@@ -71,8 +72,18 @@ pub fn executor_call<
native_call: Option<NC>,
) -> (Result<NativeOrEncoded<R>>, bool) {
let mut t = t.ext();
let code = t.storage(sp_core::storage::well_known_keys::CODE).unwrap();
let heap_pages = t.storage(sp_core::storage::well_known_keys::HEAP_PAGES);
let runtime_code = RuntimeCode {
code_fetcher: &sp_core::traits::WrappedRuntimeCode(code.as_slice().into()),
hash: sp_core::blake2_256(&code).to_vec(),
heap_pages: heap_pages.and_then(|hp| Decode::decode(&mut &hp[..]).ok()),
};
executor().call::<R, NC>(
&mut t,
&runtime_code,
method,
data,
use_native,