Refactor sr_primitives. (#3214)

* refactor sr_primitives.

* Fix try build error.

* Line-width

* Ui test.

* Final fixes.

* Fix build again.

* bring back ui test.

* Fix unsigned import.

* Another ui fix.

* Also refactor substrate-primitives

* Fix benchmarks.

* Fix doc test.

* fix doc tests
This commit is contained in:
Kian Paimani
2019-07-29 14:43:53 +02:00
committed by Bastian Köcher
parent cf80af9255
commit 79feb23a22
259 changed files with 667 additions and 665 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ hash-db = { version = "0.14.0", default-features = false }
kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
parity-codec = { version = "4.1.1", default-features = false, features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
runtime-primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }
sr-primitives = { path = "../sr-primitives", default-features = false }
runtime-version = { package = "sr-version", path = "../sr-version", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
inherents = { package = "substrate-inherents", path = "../inherents", default-features = false }
@@ -38,7 +38,7 @@ std = [
"parity-codec/std",
"primitives/std",
"inherents/std",
"runtime-primitives/std",
"sr-primitives/std",
"runtime-version/std",
"hash-db/std",
"consensus",
+1 -1
View File
@@ -14,7 +14,7 @@ kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b031
linked-hash-map = "0.5"
hash-db = { version = "0.14.0" }
primitives = { package = "substrate-primitives", path = "../../primitives" }
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
sr-primitives = { path = "../../sr-primitives" }
client = { package = "substrate-client", path = "../../client" }
state-machine = { package = "substrate-state-machine", path = "../../state-machine" }
parity-codec = { version = "4.1.1", features = ["derive"] }
+4 -4
View File
@@ -44,7 +44,7 @@ use std::collections::BTreeSet;
use log::warn;
use client::error::{Error as ClientError, Result as ClientResult};
use runtime_primitives::traits::{
use sr_primitives::traits::{
Block as BlockT, NumberFor, Zero, Bounded, CheckedSub
};
@@ -544,7 +544,7 @@ pub fn destroy_fork<Block: BlockT, T: CacheItemT, S: Storage<Block, T>, Tx: Stor
/// Blockchain related functions.
mod chain {
use runtime_primitives::traits::Header as HeaderT;
use sr_primitives::traits::Header as HeaderT;
use super::*;
/// Is the block1 connected both ends of the range.
@@ -618,8 +618,8 @@ fn read_forks<Block: BlockT, T: CacheItemT, S: Storage<Block, T>>(
#[cfg(test)]
pub mod tests {
use test_client::runtime::H256;
use runtime_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
use runtime_primitives::traits::Header as HeaderT;
use sr_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::traits::Header as HeaderT;
use crate::cache::list_storage::tests::{DummyStorage, FaultyStorage, DummyTransaction};
use super::*;
+1 -1
View File
@@ -17,7 +17,7 @@
//! List-cache storage entries.
use client::error::Result as ClientResult;
use runtime_primitives::traits::{Block as BlockT, NumberFor};
use sr_primitives::traits::{Block as BlockT, NumberFor};
use parity_codec::{Encode, Decode};
use crate::cache::{CacheItemT, ComplexBlockId};
+2 -2
View File
@@ -22,8 +22,8 @@ use kvdb::{KeyValueDB, DBTransaction};
use client::error::{Error as ClientError, Result as ClientResult};
use parity_codec::{Encode, Decode};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use crate::utils::{self, db_err, meta_keys};
use crate::cache::{CacheItemT, ComplexBlockId};
+2 -2
View File
@@ -24,8 +24,8 @@ use kvdb::{KeyValueDB, DBTransaction};
use client::blockchain::Cache as BlockchainCache;
use client::error::Result as ClientResult;
use parity_codec::{Encode, Decode};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use consensus_common::well_known_cache_keys::Id as CacheKeyId;
use crate::utils::{self, COLUMN_META, db_err};
+5 -5
View File
@@ -49,11 +49,11 @@ use trie::{MemoryDB, PrefixedMemoryDB, prefixed_key};
use parking_lot::{Mutex, RwLock};
use primitives::{H256, Blake2Hasher, ChangesTrieConfiguration, convert_hash};
use primitives::storage::well_known_keys;
use runtime_primitives::{
use sr_primitives::{
generic::{BlockId, DigestItem}, Justification, StorageOverlay, ChildrenStorageOverlay,
BuildStorage
};
use runtime_primitives::traits::{
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, NumberFor, Zero, One, SaturatedConversion
};
use state_machine::backend::Backend as StateBackend;
@@ -1427,8 +1427,8 @@ mod tests {
use client::backend::Backend as BTrait;
use client::blockchain::Backend as BLBTrait;
use client::backend::BlockImportOperation as Op;
use runtime_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
use runtime_primitives::traits::{Hash, BlakeTwo256};
use sr_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::traits::{Hash, BlakeTwo256};
use state_machine::{TrieMut, TrieDBMut, ChangesTrieRootsStorage, ChangesTrieStorage};
use test_client;
@@ -1457,7 +1457,7 @@ mod tests {
changes: Vec<(Vec<u8>, Vec<u8>)>,
extrinsics_root: H256,
) -> H256 {
use runtime_primitives::testing::Digest;
use sr_primitives::testing::Digest;
let (changes_root, changes_trie_update) = prepare_changes(changes);
let digest = Digest {
+4 -4
View File
@@ -31,8 +31,8 @@ use client::error::{Error as ClientError, Result as ClientResult};
use client::light::blockchain::Storage as LightBlockchainStorage;
use parity_codec::{Decode, Encode};
use primitives::Blake2Hasher;
use runtime_primitives::generic::{DigestItem, BlockId};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, NumberFor};
use sr_primitives::generic::{DigestItem, BlockId};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, NumberFor};
use consensus_common::well_known_cache_keys;
use crate::cache::{DbCacheSync, DbCache, ComplexBlockId, EntryType as CacheEntryType};
use crate::utils::{self, meta_keys, Meta, db_err, read_db, block_id_to_lookup_key, read_meta};
@@ -571,8 +571,8 @@ fn cht_key<N: TryInto<u32>>(cht_type: u8, block: N) -> ClientResult<[u8; 5]> {
#[cfg(test)]
pub(crate) mod tests {
use client::cht;
use runtime_primitives::generic::DigestItem;
use runtime_primitives::testing::{H256 as Hash, Header, Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::generic::DigestItem;
use sr_primitives::testing::{H256 as Hash, Header, Block as RawBlock, ExtrinsicWrapper};
use super::*;
type Block = RawBlock<ExtrinsicWrapper<u32>>;
@@ -21,7 +21,7 @@ use std::sync::Arc;
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
use linked_hash_map::{LinkedHashMap, Entry};
use hash_db::Hasher;
use runtime_primitives::traits::{Block as BlockT, Header};
use sr_primitives::traits::{Block as BlockT, Header};
use state_machine::{backend::Backend as StateBackend, TrieBackend};
use log::trace;
use super::{StorageCollection, ChildStorageCollection};
@@ -105,7 +105,7 @@ impl<K: EstimateSize + Eq + StdHash, V: EstimateSize> LRUMap<K, V> {
// TODO assert k v size fit into limit?? to avoid insert remove?
match lmap.entry(k) {
Entry::Occupied(mut entry) => {
// note that in this case we are not running pure lru as
// note that in this case we are not running pure lru as
// it would require to remove first
*storage_used_size -= entry.get().estimate_size();
entry.insert(v);
@@ -143,7 +143,7 @@ impl<K: EstimateSize + Eq + StdHash, V: EstimateSize> LRUMap<K, V> {
}
}
impl<B: BlockT, H: Hasher> Cache<B, H> {
/// Returns the used memory size of the storage cache in bytes.
pub fn used_storage_cache_size(&self) -> usize {
@@ -563,7 +563,7 @@ impl<H: Hasher, S: StateBackend<H>, B: BlockT> StateBackend<H> for CachingState<
#[cfg(test)]
mod tests {
use super::*;
use runtime_primitives::testing::{H256, Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::testing::{H256, Block as RawBlock, ExtrinsicWrapper};
use state_machine::backend::InMemory;
use primitives::Blake2Hasher;
+4 -4
View File
@@ -29,8 +29,8 @@ use log::debug;
use client;
use parity_codec::Decode;
use trie::DBValue;
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Zero,
UniqueSaturatedFrom, UniqueSaturatedInto,
};
@@ -187,7 +187,7 @@ pub fn block_id_to_lookup_key<Block>(
id: BlockId<Block>
) -> Result<Option<Vec<u8>>, client::error::Error> where
Block: BlockT,
::runtime_primitives::traits::NumberFor<Block>: UniqueSaturatedFrom<u64> + UniqueSaturatedInto<u64>,
::sr_primitives::traits::NumberFor<Block>: UniqueSaturatedFrom<u64> + UniqueSaturatedInto<u64>,
{
let res = match id {
BlockId::Number(n) => db.get(
@@ -332,7 +332,7 @@ pub fn read_meta<Block>(db: &dyn KeyValueDB, col_meta: Option<u32>, col_header:
#[cfg(test)]
mod tests {
use super::*;
use runtime_primitives::testing::{Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::testing::{Block as RawBlock, ExtrinsicWrapper};
type Block = RawBlock<ExtrinsicWrapper<u32>>;
#[test]
+2 -2
View File
@@ -19,8 +19,8 @@
use std::collections::HashMap;
use crate::error;
use primitives::ChangesTrieConfiguration;
use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use runtime_primitives::traits::{Block as BlockT, NumberFor};
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::traits::{Block as BlockT, NumberFor};
use state_machine::backend::Backend as StateBackend;
use state_machine::ChangesTrieStorage as StateChangesTrieStorage;
use consensus::well_known_cache_keys;
@@ -16,7 +16,7 @@
//! The runtime api for building blocks.
use runtime_primitives::{traits::Block as BlockT, ApplyResult};
use sr_primitives::{traits::Block as BlockT, ApplyResult};
use rstd::vec::Vec;
use sr_api_macros::decl_runtime_apis;
pub use inherents::{InherentData, CheckInherentsResult};
@@ -17,9 +17,9 @@
use super::api::BlockBuilder as BlockBuilderApi;
use std::vec::Vec;
use parity_codec::Encode;
use runtime_primitives::ApplyOutcome;
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{
use sr_primitives::ApplyOutcome;
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{
Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef, DigestFor,
};
use primitives::{H256, ExecutionContext};
+4 -4
View File
@@ -18,9 +18,9 @@
use std::sync::Arc;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use runtime_primitives::generic::BlockId;
use runtime_primitives::Justification;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sr_primitives::generic::BlockId;
use sr_primitives::Justification;
use consensus::well_known_cache_keys;
use crate::error::{Error, Result};
@@ -196,7 +196,7 @@ pub fn tree_route<Block: BlockT, Backend: HeaderBackend<Block>>(
from: BlockId<Block>,
to: BlockId<Block>,
) -> Result<TreeRoute<Block>> {
use runtime_primitives::traits::Header;
use sr_primitives::traits::Header;
let load_header = |id: BlockId<Block>| {
match backend.header(id) {
+1 -1
View File
@@ -16,7 +16,7 @@
use std::{sync::Arc, cmp::Ord, panic::UnwindSafe, result, cell::RefCell, rc::Rc};
use parity_codec::{Encode, Decode};
use runtime_primitives::{
use sr_primitives::{
generic::BlockId, traits::Block as BlockT,
};
use state_machine::{
+1 -1
View File
@@ -30,7 +30,7 @@ use parity_codec::Encode;
use trie;
use primitives::{H256, convert_hash};
use runtime_primitives::traits::{Header as HeaderT, SimpleArithmetic, Zero, One};
use sr_primitives::traits::{Header as HeaderT, SimpleArithmetic, Zero, One};
use state_machine::backend::InMemory as InMemoryState;
use state_machine::{MemoryDB, TrieBackend, Backend as StateBackend,
prove_read_on_trie_backend, read_proof_check, read_proof_check_on_proving_backend};
+5 -5
View File
@@ -24,7 +24,7 @@ use crate::error::Error;
use futures::channel::mpsc;
use parking_lot::{Mutex, RwLock};
use primitives::NativeOrEncoded;
use runtime_primitives::{
use sr_primitives::{
Justification,
generic::{BlockId, SignedBlock},
};
@@ -34,13 +34,13 @@ use consensus::{
well_known_cache_keys::Id as CacheKeyId,
SelectChain, self,
};
use runtime_primitives::traits::{
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Zero, NumberFor, CurrentHeight,
BlockNumberToHash, ApiRef, ProvideRuntimeApi,
SaturatedConversion, One, DigestFor,
};
use runtime_primitives::generic::DigestItem;
use runtime_primitives::BuildStorage;
use sr_primitives::generic::DigestItem;
use sr_primitives::BuildStorage;
use crate::runtime_api::{
CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder,
InitializeBlock,
@@ -1851,7 +1851,7 @@ pub(crate) mod tests {
use std::collections::HashMap;
use super::*;
use primitives::blake2_256;
use runtime_primitives::DigestItem;
use sr_primitives::DigestItem;
use consensus::{BlockOrigin, SelectChain};
use test_client::{
prelude::*,
+1 -1
View File
@@ -18,7 +18,7 @@
use std::{self, error, result};
use state_machine;
use runtime_primitives::ApplyError;
use sr_primitives::ApplyError;
use consensus;
use derive_more::{Display, From};
+2 -2
View File
@@ -16,7 +16,7 @@
//! Tool for creating the genesis block.
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, Zero};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, Zero};
/// Create a genesis block, given the initial storage.
pub fn construct_genesis_block<
@@ -49,7 +49,7 @@ mod tests {
runtime::{Hash, Transfer, Block, BlockNumber, Header, Digest},
AccountKeyring, Sr25519Keyring,
};
use runtime_primitives::traits::BlakeTwo256;
use sr_primitives::traits::BlakeTwo256;
use primitives::Blake2Hasher;
use hex::*;
+3 -3
View File
@@ -20,9 +20,9 @@ use std::collections::HashMap;
use std::sync::Arc;
use parking_lot::{RwLock, Mutex};
use primitives::{ChangesTrieConfiguration, storage::well_known_keys};
use runtime_primitives::generic::{BlockId, DigestItem};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, NumberFor};
use runtime_primitives::{Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::generic::{BlockId, DigestItem};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, NumberFor};
use sr_primitives::{Justification, StorageOverlay, ChildrenStorageOverlay};
use state_machine::backend::{Backend as StateBackend, InMemory};
use state_machine::{self, InMemoryChangesTrieStorage, ChangesTrieAnchorBlockId};
use hash_db::Hasher;
+1 -1
View File
@@ -19,7 +19,7 @@
use std::collections::BTreeMap;
use std::cmp::Reverse;
use kvdb::{KeyValueDB, DBTransaction};
use runtime_primitives::traits::SimpleArithmetic;
use sr_primitives::traits::SimpleArithmetic;
use parity_codec::{Encode, Decode};
use crate::error;
+2 -2
View File
@@ -21,9 +21,9 @@ use std::collections::HashMap;
use std::sync::{Arc, Weak};
use parking_lot::{RwLock, Mutex};
use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState};
use runtime_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
use sr_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
use crate::in_mem::{self, check_genesis_storage};
use crate::backend::{
AuxStore, Backend as ClientBackend, BlockImportOperation, RemoteBackend, NewBlockState,
@@ -20,8 +20,8 @@
use std::{sync::{Weak, Arc}, collections::HashMap};
use parking_lot::Mutex;
use runtime_primitives::{Justification, generic::BlockId};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use sr_primitives::{Justification, generic::BlockId};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use consensus::well_known_cache_keys;
use crate::backend::{AuxStore, NewBlockState};
@@ -24,8 +24,8 @@ use std::{
use parity_codec::{Encode, Decode};
use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded};
use runtime_primitives::generic::BlockId;
use runtime_primitives::traits::{One, Block as BlockT, Header as HeaderT};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{One, Block as BlockT, Header as HeaderT};
use state_machine::{
self, Backend as StateBackend, CodeExecutor, OverlayedChanges,
ExecutionStrategy, create_proof_check_backend,
+2 -2
View File
@@ -24,7 +24,7 @@ use std::future::Future;
use hash_db::{HashDB, Hasher};
use parity_codec::{Decode, Encode};
use primitives::{ChangesTrieConfiguration, convert_hash};
use runtime_primitives::traits::{
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
SimpleArithmetic, CheckedConversion,
};
@@ -502,7 +502,7 @@ pub mod tests {
use crate::light::blockchain::tests::{DummyStorage, DummyBlockchain};
use primitives::{blake2_256, Blake2Hasher, H256};
use primitives::storage::{well_known_keys, StorageKey};
use runtime_primitives::generic::BlockId;
use sr_primitives::generic::BlockId;
use state_machine::Backend;
use super::*;
+2 -2
View File
@@ -25,8 +25,8 @@ use std::sync::Arc;
use executor::RuntimeInfo;
use primitives::{H256, Blake2Hasher};
use runtime_primitives::BuildStorage;
use runtime_primitives::traits::Block as BlockT;
use sr_primitives::BuildStorage;
use sr_primitives::traits::Block as BlockT;
use state_machine::CodeExecutor;
use crate::call_executor::LocalCallExecutor;
+2 -2
View File
@@ -24,7 +24,7 @@ use std::{
use fnv::{FnvHashSet, FnvHashMap};
use futures::channel::mpsc;
use primitives::storage::{StorageKey, StorageData};
use runtime_primitives::traits::Block as BlockT;
use sr_primitives::traits::Block as BlockT;
/// Storage change set
#[derive(Debug)]
@@ -307,7 +307,7 @@ impl<Block: BlockT> StorageNotifications<Block> {
#[cfg(test)]
mod tests {
use runtime_primitives::testing::{H256 as Hash, Block as RawBlock, ExtrinsicWrapper};
use sr_primitives::testing::{H256 as Hash, Block as RawBlock, ExtrinsicWrapper};
use super::*;
use std::iter::{empty, Empty};
+1 -1
View File
@@ -23,7 +23,7 @@ pub use state_machine::OverlayedChanges;
#[cfg(feature = "std")]
pub use primitives::NativeOrEncoded;
#[doc(hidden)]
pub use runtime_primitives::{
pub use sr_primitives::{
traits::{
Block as BlockT, GetNodeBlockType, GetRuntimeBlockType,
Header as HeaderT, ApiRef, RuntimeApiInfo, Hash as HashT,