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
+14 -13
View File
@@ -18,17 +18,18 @@
use std::collections::{HashMap};
use hash_db::Hasher;
use crate::backend::{InMemory, Backend};
use primitives::storage::well_known_keys::is_child_storage_key;
use crate::changes_trie::{
build_changes_trie, InMemoryStorage as ChangesTrieInMemoryStorage,
BlockNumber as ChangesTrieBlockNumber,
use crate::{
backend::{InMemory, Backend}, OverlayedChanges,
changes_trie::{
build_changes_trie, InMemoryStorage as ChangesTrieInMemoryStorage,
BlockNumber as ChangesTrieBlockNumber,
},
};
use primitives::{
storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES}, traits::BareCryptoStorePtr, offchain
storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key},
traits::{BareCryptoStorePtr, Externalities}, offchain, child_storage_key::ChildStorageKey,
};
use codec::Encode;
use super::{ChildStorageKey, Externalities, OverlayedChanges};
const EXT_NOT_ALLOWED_TO_FAIL: &str = "Externalities not allowed to fail within runtime";
@@ -156,7 +157,7 @@ impl<H, N> Externalities<H> for TestExternalities<H, N>
self.backend.storage(key).expect(EXT_NOT_ALLOWED_TO_FAIL)
}
fn child_storage(&self, storage_key: ChildStorageKey<H>, key: &[u8]) -> Option<Vec<u8>> {
fn child_storage(&self, storage_key: ChildStorageKey, key: &[u8]) -> Option<Vec<u8>> {
self.overlay
.child_storage(storage_key.as_ref(), key)
.map(|x| x.map(|x| x.to_vec()))
@@ -166,7 +167,7 @@ impl<H, N> Externalities<H> for TestExternalities<H, N>
)
}
fn original_child_storage(&self, storage_key: ChildStorageKey<H>, key: &[u8]) -> Option<Vec<u8>> {
fn original_child_storage(&self, storage_key: ChildStorageKey, key: &[u8]) -> Option<Vec<u8>> {
self.backend
.child_storage(storage_key.as_ref(), key)
.map(|x| x.map(|x| x.to_vec()))
@@ -183,14 +184,14 @@ impl<H, N> Externalities<H> for TestExternalities<H, N>
fn place_child_storage(
&mut self,
storage_key: ChildStorageKey<H>,
storage_key: ChildStorageKey,
key: Vec<u8>,
value: Option<Vec<u8>>
) {
self.overlay.set_child_storage(storage_key.into_owned(), key, value);
}
fn kill_child_storage(&mut self, storage_key: ChildStorageKey<H>) {
fn kill_child_storage(&mut self, storage_key: ChildStorageKey) {
let backend = &self.backend;
let overlay = &mut self.overlay;
@@ -214,7 +215,7 @@ impl<H, N> Externalities<H> for TestExternalities<H, N>
});
}
fn clear_child_prefix(&mut self, storage_key: ChildStorageKey<H>, prefix: &[u8]) {
fn clear_child_prefix(&mut self, storage_key: ChildStorageKey, prefix: &[u8]) {
self.overlay.clear_child_prefix(storage_key.as_ref(), prefix);
@@ -249,7 +250,7 @@ impl<H, N> Externalities<H> for TestExternalities<H, N>
}
fn child_storage_root(&mut self, storage_key: ChildStorageKey<H>) -> Vec<u8> {
fn child_storage_root(&mut self, storage_key: ChildStorageKey) -> Vec<u8> {
let storage_key = storage_key.as_ref();
let (root, is_empty, _) = {