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
+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]