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
+13 -13
View File
@@ -954,17 +954,17 @@ mod tests {
DefaultTestClientBuilderExt, TestClientBuilder,
runtime::TestAPI,
};
use sp_runtime::{
generic::BlockId,
traits::ProvideRuntimeApi,
};
use sp_api::ProvideRuntimeApi;
use sp_runtime::generic::BlockId;
use sp_core::storage::well_known_keys::HEAP_PAGES;
use sp_state_machine::ExecutionStrategy;
use codec::Encode;
#[test]
fn returns_mutable_static() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
let client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);
@@ -1013,31 +1013,31 @@ mod tests {
// This tests that the on-chain HEAP_PAGES parameter is respected.
// Create a client devoting only 8 pages of wasm memory. This gives us ~512k of heap memory.
let client = TestClientBuilder::new()
let mut client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.set_heap_pages(8)
.build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);
// Try to allocate 1024k of memory on heap. This is going to fail since it is twice larger
// than the heap.
let ret = runtime_api.vec_with_capacity(&block_id, 1048576);
let ret = client.runtime_api().vec_with_capacity(&block_id, 1048576);
assert!(ret.is_err());
// Create a block that sets the `:heap_pages` to 32 pages of memory which corresponds to
// ~2048k of heap memory.
let new_block_id = {
let (new_block_id, block) = {
let mut builder = client.new_block(Default::default()).unwrap();
builder.push_storage_change(HEAP_PAGES.to_vec(), Some(32u64.encode())).unwrap();
let block = builder.bake().unwrap();
let block = builder.build().unwrap().block;
let hash = block.header.hash();
client.import(BlockOrigin::Own, block).unwrap();
BlockId::Hash(hash)
(BlockId::Hash(hash), block)
};
client.import(BlockOrigin::Own, block).unwrap();
// Allocation of 1024k while having ~2048k should succeed.
let ret = runtime_api.vec_with_capacity(&new_block_id, 1048576);
let ret = client.runtime_api().vec_with_capacity(&new_block_id, 1048576);
assert!(ret.is_ok());
}