Remove requirement on Hash = H256, make Proposer return StorageChanges and Proof (#3860)

* Extend `Proposer` to optionally generate a proof of the proposal

* Something

* Refactor sr-api to not depend on client anymore

* Fix benches

* Apply suggestions from code review

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Apply suggestions from code review

* Introduce new `into_storage_changes` function

* Switch to runtime api for `execute_block` and don't require `H256`
anywhere in the code

* Put the `StorageChanges` into the `Proposal`

* Move the runtime api error to its own trait

* Adds `StorageTransactionCache` to the runtime api

This requires that we add `type NodeBlock = ` to the
`impl_runtime_apis!` macro to work around some bugs in rustc :(

* Remove `type NodeBlock` and switch to a "better" hack

* Start using the transaction cache from the runtime api

* Make it compile

* Move `InMemory` to its own file

* Make all tests work again

* Return block, storage_changes and proof from Blockbuilder::bake()

* Make sure that we use/set `storage_changes` when possible

* Add test

* Fix deadlock

* Remove accidentally added folders

* Introduce `RecordProof` as argument type to be more explicit

* Update client/src/client.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update primitives/state-machine/src/ext.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Integrates review feedback

* Remove `unsafe` usage

* Update client/block-builder/src/lib.rs

Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org>

* Update client/src/call_executor.rs

* Bump versions

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Benjamin Kampmann <ben.kampmann@googlemail.com>
This commit is contained in:
Bastian Köcher
2020-01-10 10:48:32 +01:00
committed by GitHub
parent 74d6e660c6
commit fd6b29dd2c
140 changed files with 4860 additions and 3339 deletions
+59 -56
View File
@@ -32,7 +32,7 @@ pub use self::block_builder_ext::BlockBuilderExt;
use sp_core::sr25519;
use sp_core::storage::{ChildInfo, Storage, StorageChild};
use substrate_test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor, HasherFor};
use sc_client::{
light::fetcher::{
Fetcher,
@@ -45,7 +45,10 @@ use sc_client::{
/// A prelude to import in tests.
pub mod prelude {
// Trait extensions
pub use super::{BlockBuilderExt, DefaultTestClientBuilderExt, TestClientBuilderExt, ClientExt};
pub use super::{
BlockBuilderExt, DefaultTestClientBuilderExt, TestClientBuilderExt, ClientExt,
ClientBlockImportExt,
};
// Client structs
pub use super::{
TestClient, TestClientBuilder, Backend, LightBackend,
@@ -88,7 +91,7 @@ pub type LightExecutor = sc_client::light::call_executor::GenesisCallExecutor<
sc_client::LocalCallExecutor<
sc_client::light::backend::Backend<
sc_client_db::light::LightStorage<substrate_test_runtime::Block>,
Blake2Hasher,
HasherFor<substrate_test_runtime::Block>
>,
NativeExecutor<LocalExecutor>
>
@@ -165,10 +168,7 @@ pub trait DefaultTestClientBuilderExt: Sized {
fn new() -> Self;
}
impl DefaultTestClientBuilderExt for TestClientBuilder<
Executor,
Backend,
> {
impl DefaultTestClientBuilderExt for TestClientBuilder<Executor, Backend> {
fn new() -> Self {
Self::with_default_backend()
}
@@ -176,64 +176,26 @@ impl DefaultTestClientBuilderExt for TestClientBuilder<
/// A `test-runtime` extensions to `TestClientBuilder`.
pub trait TestClientBuilderExt<B>: Sized {
/// Returns a mutable reference to the genesis parameters.
fn genesis_init_mut(&mut self) -> &mut GenesisParameters;
/// Enable or disable support for changes trie in genesis.
fn set_support_changes_trie(self, support_changes_trie: bool) -> Self;
fn set_support_changes_trie(mut self, support_changes_trie: bool) -> Self {
self.genesis_init_mut().support_changes_trie = support_changes_trie;
self
}
/// Override the default value for Wasm heap pages.
fn set_heap_pages(self, heap_pages: u64) -> Self;
fn set_heap_pages(mut self, heap_pages: u64) -> Self {
self.genesis_init_mut().heap_pages_override = Some(heap_pages);
self
}
/// Add an extra value into the genesis storage.
///
/// # Panics
///
/// Panics if the key is empty.
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
self,
storage_key: SK,
child_info: ChildInfo,
key: K,
value: V,
) -> Self;
/// Add an extra child value into the genesis storage.
///
/// # Panics
///
/// Panics if the key is empty.
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(self, key: K, value: V) -> Self;
/// Build the test client.
fn build(self) -> Client<B> {
self.build_with_longest_chain().0
}
/// Build the test client and longest chain selector.
fn build_with_longest_chain(self) -> (Client<B>, sc_client::LongestChain<B, substrate_test_runtime::Block>);
}
impl<B> TestClientBuilderExt<B> for TestClientBuilder<
sc_client::LocalCallExecutor<B, sc_executor::NativeExecutor<LocalExecutor>>,
B
> where
B: sc_client_api::backend::Backend<substrate_test_runtime::Block, Blake2Hasher>,
{
fn set_heap_pages(mut self, heap_pages: u64) -> Self {
self.genesis_init_mut().heap_pages_override = Some(heap_pages);
self
}
fn set_support_changes_trie(mut self, support_changes_trie: bool) -> Self {
self.genesis_init_mut().support_changes_trie = support_changes_trie;
self
}
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(mut self, key: K, value: V) -> Self {
let key = key.into();
assert!(!key.is_empty());
self.genesis_init_mut().extra_storage.top.insert(key, value.into());
self
}
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
mut self,
storage_key: SK,
@@ -254,10 +216,51 @@ impl<B> TestClientBuilderExt<B> for TestClientBuilder<
self
}
/// Add an extra child value into the genesis storage.
///
/// # Panics
///
/// Panics if the key is empty.
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(mut self, key: K, value: V) -> Self {
let key = key.into();
assert!(!key.is_empty());
self.genesis_init_mut().extra_storage.top.insert(key, value.into());
self
}
/// Build the test client.
fn build(self) -> Client<B> {
self.build_with_longest_chain().0
}
/// Build the test client and longest chain selector.
fn build_with_longest_chain(self) -> (Client<B>, sc_client::LongestChain<B, substrate_test_runtime::Block>);
/// Build the test client and the backend.
fn build_with_backend(self) -> (Client<B>, Arc<B>);
}
impl<B> TestClientBuilderExt<B> for TestClientBuilder<
sc_client::LocalCallExecutor<B, sc_executor::NativeExecutor<LocalExecutor>>,
B
> where
B: sc_client_api::backend::Backend<substrate_test_runtime::Block>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
<B as sc_client_api::backend::Backend<substrate_test_runtime::Block>>::State:
sp_api::StateBackend<HasherFor<substrate_test_runtime::Block>>,
{
fn genesis_init_mut(&mut self) -> &mut GenesisParameters {
Self::genesis_init_mut(self)
}
fn build_with_longest_chain(self) -> (Client<B>, sc_client::LongestChain<B, substrate_test_runtime::Block>) {
self.build_with_native_executor(None)
}
fn build_with_backend(self) -> (Client<B>, Arc<B>) {
let backend = self.backend();
(self.build_with_native_executor(None).0, backend)
}
}
/// Type of optional fetch callback.