Cleanup of the state-machine crate (#3524)

* Start refactoring state-machine crate

* More improvement to state-machine

* Fix tests compilation on master and remove warnings

* Fix compilation

* Apply suggestions from code review

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

* Update core/state-machine/src/basic.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Line width

* Update core/primitives/src/storage.rs

Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com>

* Update core/state-machine/src/error.rs

Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com>

* Review feedback
This commit is contained in:
Bastian Köcher
2019-09-10 17:00:00 +02:00
committed by GitHub
parent 2beeda1488
commit 9607afd629
37 changed files with 781 additions and 674 deletions
@@ -23,13 +23,15 @@ use std::{
};
use codec::{Encode, Decode};
use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded};
use primitives::{
offchain::{self, NeverOffchainExt}, H256, Blake2Hasher, convert_hash, NativeOrEncoded,
traits::CodeExecutor,
};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{One, Block as BlockT, Header as HeaderT, NumberFor};
use state_machine::{
self, Backend as StateBackend, CodeExecutor, OverlayedChanges,
ExecutionStrategy, ChangesTrieTransaction, create_proof_check_backend,
execution_proof_check_on_trie_backend, ExecutionManager, NeverOffchainExt
self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend,
execution_proof_check_on_trie_backend, ExecutionManager, ChangesTrieTransaction,
};
use hash_db::Hasher;
@@ -451,7 +453,7 @@ pub fn prove_execution<Block, S, E>(
pub fn check_execution_proof<Header, E, H>(
executor: &E,
request: &RemoteCallRequest<Header>,
remote_proof: Vec<Vec<u8>>
remote_proof: Vec<Vec<u8>>,
) -> ClientResult<Vec<u8>>
where
Header: HeaderT,
@@ -482,16 +484,14 @@ pub fn check_execution_proof<Header, E, H>(
)?;
// execute method
let local_result = execution_proof_check_on_trie_backend::<H, _>(
execution_proof_check_on_trie_backend::<H, _>(
&trie_backend,
&mut changes,
executor,
&request.method,
&request.call_data,
None,
)?;
Ok(local_result)
).map_err(Into::into)
}
#[cfg(test)]
@@ -568,8 +568,14 @@ mod tests {
backend.blockchain().insert(hash0, header0, None, None, NewBlockState::Final).unwrap();
backend.blockchain().insert(hash1, header1, None, None, NewBlockState::Final).unwrap();
let local_executor = RemoteCallExecutor::new(Arc::new(backend.blockchain().clone()), Arc::new(OkCallFetcher::new(vec![1])));
let remote_executor = RemoteCallExecutor::new(Arc::new(backend.blockchain().clone()), Arc::new(OkCallFetcher::new(vec![2])));
let local_executor = RemoteCallExecutor::new(
Arc::new(backend.blockchain().clone()),
Arc::new(OkCallFetcher::new(vec![1])),
);
let remote_executor = RemoteCallExecutor::new(
Arc::new(backend.blockchain().clone()),
Arc::new(OkCallFetcher::new(vec![2])),
);
let remote_or_local = RemoteOrLocalCallExecutor::new(backend, remote_executor, local_executor);
assert_eq!(
remote_or_local.call(
+4 -5
View File
@@ -23,16 +23,15 @@ use std::future::Future;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use codec::{Decode, Encode};
use primitives::{ChangesTrieConfiguration, convert_hash};
use primitives::{ChangesTrieConfiguration, convert_hash, traits::CodeExecutor};
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
SimpleArithmetic, CheckedConversion, Zero,
};
use state_machine::{
CodeExecutor, ChangesTrieRootsStorage,
ChangesTrieAnchorBlockId, ChangesTrieConfigurationRange,
TrieBackend, read_proof_check, key_changes_proof_check,
create_proof_check_backend_storage, read_child_proof_check,
ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, ChangesTrieConfigurationRange,
TrieBackend, read_proof_check, key_changes_proof_check, create_proof_check_backend_storage,
read_child_proof_check,
};
use crate::cht;
+1 -2
View File
@@ -24,10 +24,9 @@ pub mod fetcher;
use std::sync::Arc;
use executor::RuntimeInfo;
use primitives::{H256, Blake2Hasher};
use primitives::{H256, Blake2Hasher, traits::CodeExecutor};
use sr_primitives::BuildStorage;
use sr_primitives::traits::Block as BlockT;
use state_machine::CodeExecutor;
use crate::call_executor::LocalCallExecutor;
use crate::client::Client;