diff --git a/substrate/core/basic-authorship/src/basic_authorship.rs b/substrate/core/basic-authorship/src/basic_authorship.rs index 5f8d189878..0464d96dc4 100644 --- a/substrate/core/basic-authorship/src/basic_authorship.rs +++ b/substrate/core/basic-authorship/src/basic_authorship.rs @@ -26,8 +26,8 @@ use client::{self, error, Client as SubstrateClient, CallExecutor}; use client::{block_builder::api::BlockBuilder as BlockBuilderApi, runtime_api::Core}; use codec::{Decode, Encode}; use consensus_common::{self, evaluation}; -use primitives::{H256, AuthorityId, ed25519, Blake2Hasher}; -use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi}; +use primitives::{H256, Ed25519AuthorityId, ed25519, Blake2Hasher}; +use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, AuthorityIdFor}; use runtime_primitives::generic::BlockId; use runtime_primitives::BasicInherentData; use transaction_pool::txpool::{self, Pool as TransactionPool}; @@ -125,8 +125,7 @@ impl consensus_common::Environment<::Blo fn init( &self, parent_header: &<::Block as BlockT>::Header, - _: &[AuthorityId], - _: Arc, + _: &[AuthorityIdFor<::Block>], ) -> Result { let parent_hash = parent_header.hash(); diff --git a/substrate/core/client/db/src/cache/mod.rs b/substrate/core/client/db/src/cache/mod.rs index db2a1762db..11fbd93392 100644 --- a/substrate/core/client/db/src/cache/mod.rs +++ b/substrate/core/client/db/src/cache/mod.rs @@ -24,9 +24,8 @@ use kvdb::{KeyValueDB, DBTransaction}; use client::blockchain::Cache as BlockchainCache; use client::error::Result as ClientResult; use codec::{Encode, Decode}; -use primitives::AuthorityId; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, As}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, As, AuthorityIdFor}; use utils::{self, COLUMN_META}; use self::list_cache::ListCache; @@ -65,7 +64,7 @@ impl CacheItemT for T where T: Clone + Decode + Encode + PartialEq {} /// Database-backed blockchain data cache. pub struct DbCache { - authorities_at: ListCache, self::list_storage::DbStorage>, + authorities_at: ListCache>, self::list_storage::DbStorage>, } impl DbCache { @@ -112,14 +111,14 @@ impl DbCache { /// Cache operations that are to be committed after database transaction is committed. pub struct DbCacheTransactionOps { - authorities_at_op: Option>>, + authorities_at_op: Option>>>, } /// Database-backed blockchain data cache transaction valid for single block import. pub struct DbCacheTransaction<'a, Block: BlockT> { cache: &'a mut DbCache, tx: &'a mut DBTransaction, - authorities_at_op: Option>>, + authorities_at_op: Option>>>, } impl<'a, Block: BlockT> DbCacheTransaction<'a, Block> { @@ -135,7 +134,7 @@ impl<'a, Block: BlockT> DbCacheTransaction<'a, Block> { mut self, parent: ComplexBlockId, block: ComplexBlockId, - authorities_at: Option>, + authorities_at: Option>>, is_final: bool, ) -> ClientResult { assert!(self.authorities_at_op.is_none()); @@ -179,7 +178,7 @@ impl<'a, Block: BlockT> DbCacheTransaction<'a, Block> { pub struct DbCacheSync(pub RwLock>); impl BlockchainCache for DbCacheSync { - fn authorities_at(&self, at: BlockId) -> Option> { + fn authorities_at(&self, at: BlockId) -> Option>> { let cache = self.0.read(); let storage = cache.authorities_at.storage(); let db = storage.db(); diff --git a/substrate/core/client/db/src/lib.rs b/substrate/core/client/db/src/lib.rs index 9df93e45b5..371f0a4013 100644 --- a/substrate/core/client/db/src/lib.rs +++ b/substrate/core/client/db/src/lib.rs @@ -64,10 +64,10 @@ use hash_db::Hasher; use kvdb::{KeyValueDB, DBTransaction}; use trie::MemoryDB; use parking_lot::RwLock; -use primitives::{H256, AuthorityId, Blake2Hasher, ChangesTrieConfiguration, convert_hash}; +use primitives::{H256, Blake2Hasher, ChangesTrieConfiguration, convert_hash}; use primitives::storage::well_known_keys; use runtime_primitives::{generic::BlockId, Justification, StorageMap, ChildrenStorageMap}; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, NumberFor, Zero, Digest, DigestItem}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, NumberFor, Zero, Digest, DigestItem, AuthorityIdFor}; use runtime_primitives::BuildStorage; use state_machine::backend::Backend as StateBackend; use executor::RuntimeInfo; @@ -315,7 +315,7 @@ where Block: BlockT, Ok(()) } - fn update_authorities(&mut self, _authorities: Vec) { + fn update_authorities(&mut self, _authorities: Vec>) { // currently authorities are not cached on full nodes } diff --git a/substrate/core/client/db/src/light.rs b/substrate/core/client/db/src/light.rs index 729519020c..cbed1348a9 100644 --- a/substrate/core/client/db/src/light.rs +++ b/substrate/core/client/db/src/light.rs @@ -28,10 +28,10 @@ use client::{cht, LeafSet}; use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult}; use client::light::blockchain::Storage as LightBlockchainStorage; use codec::{Decode, Encode}; -use primitives::{AuthorityId, Blake2Hasher}; +use primitives::Blake2Hasher; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, - Zero, One, As, NumberFor, Digest, DigestItem}; + Zero, One, As, NumberFor, Digest, DigestItem, AuthorityIdFor}; use cache::{DbCacheSync, DbCache, ComplexBlockId}; use utils::{meta_keys, Meta, db_err, open_database, read_db, block_id_to_lookup_key, read_meta}; @@ -306,7 +306,7 @@ impl LightBlockchainStorage for LightStorage fn import_header( &self, header: Block::Header, - authorities: Option>, + authorities: Option>>, leaf_state: NewBlockState, aux_ops: Vec<(Vec, Option>)>, ) -> ClientResult<()> { @@ -510,7 +510,7 @@ pub(crate) mod tests { pub fn insert_block Header>( db: &LightStorage, - authorities: Option>, + authorities: Option>>, header: F, ) -> Hash { let header = header(); @@ -521,7 +521,7 @@ pub(crate) mod tests { fn insert_final_block Header>( db: &LightStorage, - authorities: Option>, + authorities: Option>>, header: F, ) -> Hash { let header = header(); @@ -532,7 +532,7 @@ pub(crate) mod tests { fn insert_non_best_block Header>( db: &LightStorage, - authorities: Option>, + authorities: Option>>, header: F, ) -> Hash { let header = header(); @@ -762,7 +762,7 @@ pub(crate) mod tests { fn authorites_are_cached() { let db = LightStorage::new_test(); - fn run_checks(db: &LightStorage, max: u64, checks: &[(u64, Option>)]) { + fn run_checks(db: &LightStorage, max: u64, checks: &[(u64, Option>>)]) { for (at, expected) in checks.iter().take_while(|(at, _)| *at <= max) { let actual = db.cache().authorities_at(BlockId::Number(*at)); assert_eq!(*expected, actual); diff --git a/substrate/core/client/src/backend.rs b/substrate/core/client/src/backend.rs index 290159bdc5..1f370f0e1b 100644 --- a/substrate/core/client/src/backend.rs +++ b/substrate/core/client/src/backend.rs @@ -17,9 +17,8 @@ //! Substrate Client data backend use error; -use primitives::AuthorityId; use runtime_primitives::{generic::BlockId, Justification, StorageMap, ChildrenStorageMap}; -use runtime_primitives::traits::{Block as BlockT, NumberFor}; +use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT, NumberFor}; use state_machine::backend::Backend as StateBackend; use state_machine::ChangesTrieStorage as StateChangesTrieStorage; use hash_db::Hasher; @@ -67,7 +66,7 @@ pub trait BlockImportOperation where /// Append authorities set to the transaction. This is a set of parent block (set which /// has been used to check justification of this block). - fn update_authorities(&mut self, authorities: Vec); + fn update_authorities(&mut self, authorities: Vec>); /// Inject storage data into the database. fn update_storage(&mut self, update: >::Transaction) -> error::Result<()>; /// Inject storage data into the database replacing any existing data. diff --git a/substrate/core/client/src/blockchain.rs b/substrate/core/client/src/blockchain.rs index ddc8ba866a..7ff395113b 100644 --- a/substrate/core/client/src/blockchain.rs +++ b/substrate/core/client/src/blockchain.rs @@ -16,8 +16,7 @@ //! Substrate blockchain trait -use primitives::AuthorityId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; +use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT, Header as HeaderT, NumberFor}; use runtime_primitives::generic::BlockId; use runtime_primitives::Justification; @@ -90,7 +89,7 @@ pub trait Backend: HeaderBackend { /// Blockchain optional data cache. pub trait Cache: Send + Sync { /// Returns the set of authorities, that was active at given block or None if there's no entry in the cache. - fn authorities_at(&self, block: BlockId) -> Option>; + fn authorities_at(&self, block: BlockId) -> Option>>; } /// Block import outcome diff --git a/substrate/core/client/src/client.rs b/substrate/core/client/src/client.rs index b0dfb939d0..79a112e616 100644 --- a/substrate/core/client/src/client.rs +++ b/substrate/core/client/src/client.rs @@ -20,7 +20,6 @@ use std::{marker::PhantomData, collections::{HashSet, BTreeMap}, sync::Arc}; use error::Error; use futures::sync::mpsc; use parking_lot::{Mutex, RwLock}; -use primitives::AuthorityId; use runtime_primitives::{ Justification, generic::{BlockId, SignedBlock}, @@ -28,7 +27,7 @@ use runtime_primitives::{ use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, BlockOrigin, ForkChoiceStrategy}; use runtime_primitives::traits::{ Block as BlockT, Header as HeaderT, Zero, As, NumberFor, CurrentHeight, BlockNumberToHash, - ApiRef, ProvideRuntimeApi, Digest, DigestItem, + ApiRef, ProvideRuntimeApi, Digest, DigestItem, AuthorityIdFor }; use runtime_primitives::BuildStorage; use runtime_api::{Core as CoreAPI, CallRuntimeAt, ConstructRuntimeApi}; @@ -281,11 +280,11 @@ impl Client where } /// Get the set of authorities at a given block. - pub fn authorities_at(&self, id: &BlockId) -> error::Result> { + pub fn authorities_at(&self, id: &BlockId) -> error::Result>> { match self.backend.blockchain().cache().and_then(|cache| cache.authorities_at(*id)) { Some(cached_value) => Ok(cached_value), None => self.executor.call(id, "Core_authorities", &[]) - .and_then(|r| Vec::::decode(&mut &r.return_data[..]) + .and_then(|r| Vec::>::decode(&mut &r.return_data[..]) .ok_or(error::ErrorKind::InvalidAuthoritiesSet.into())) } } @@ -541,7 +540,7 @@ impl Client where import_headers: PrePostHeader, justification: Option, body: Option>, - authorities: Option>, + authorities: Option>>, finalized: bool, aux: Vec<(Vec, Option>)>, fork_choice: ForkChoiceStrategy, @@ -1030,7 +1029,7 @@ impl consensus::BlockImport for Client fn import_block( &self, import_block: ImportBlock, - new_authorities: Option>, + new_authorities: Option>>, ) -> Result { use runtime_primitives::traits::Digest; @@ -1098,7 +1097,7 @@ impl consensus::Authorities for Client Block: BlockT, { type Error = Error; - fn authorities(&self, at: &BlockId) -> Result, Self::Error> { + fn authorities(&self, at: &BlockId) -> Result>, Self::Error> { self.authorities_at(at).map_err(|e| e.into()) } } diff --git a/substrate/core/client/src/in_mem.rs b/substrate/core/client/src/in_mem.rs index 1bf50d715d..896f9821de 100644 --- a/substrate/core/client/src/in_mem.rs +++ b/substrate/core/client/src/in_mem.rs @@ -22,10 +22,10 @@ use parking_lot::RwLock; use error; use backend::{self, NewBlockState}; use light; -use primitives::{AuthorityId, storage::well_known_keys}; +use primitives::storage::well_known_keys; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, - NumberFor, As, Digest, DigestItem}; + NumberFor, As, Digest, DigestItem, AuthorityIdFor}; use runtime_primitives::{Justification, StorageMap, ChildrenStorageMap}; use blockchain::{self, BlockStatus, HeaderBackend}; use state_machine::backend::{Backend as StateBackend, InMemory, Consolidate}; @@ -108,7 +108,7 @@ pub struct Blockchain { struct Cache { storage: Arc>>, - authorities_at: RwLock>>>, + authorities_at: RwLock>>>>, } impl Clone for Blockchain { @@ -368,7 +368,7 @@ impl light::blockchain::Storage for Blockchain fn import_header( &self, header: Block::Header, - authorities: Option>, + authorities: Option>>, state: NewBlockState, aux_ops: Vec<(Vec, Option>)>, ) -> error::Result<()> { @@ -409,7 +409,7 @@ impl light::blockchain::Storage for Blockchain /// In-memory operation. pub struct BlockImportOperation { pending_block: Option>, - pending_authorities: Option>, + pending_authorities: Option>>, old_state: InMemory, new_state: Option>, changes_trie_update: Option>, @@ -444,7 +444,7 @@ where Ok(()) } - fn update_authorities(&mut self, authorities: Vec) { + fn update_authorities(&mut self, authorities: Vec>) { self.pending_authorities = Some(authorities); } @@ -632,13 +632,13 @@ where {} impl Cache { - fn insert(&self, at: Block::Hash, authorities: Option>) { + fn insert(&self, at: Block::Hash, authorities: Option>>) { self.authorities_at.write().insert(at, authorities); } } impl blockchain::Cache for Cache { - fn authorities_at(&self, block: BlockId) -> Option> { + fn authorities_at(&self, block: BlockId) -> Option>> { let hash = match block { BlockId::Hash(hash) => hash, BlockId::Number(number) => self.storage.read().hashes.get(&number).cloned()?, @@ -652,7 +652,7 @@ impl blockchain::Cache for Cache { pub fn cache_authorities_at( blockchain: &Blockchain, at: Block::Hash, - authorities: Option> + authorities: Option>> ) { blockchain.cache.insert(at, authorities); } diff --git a/substrate/core/client/src/light/backend.rs b/substrate/core/client/src/light/backend.rs index 185b7cfa06..79a636bfbc 100644 --- a/substrate/core/client/src/light/backend.rs +++ b/substrate/core/client/src/light/backend.rs @@ -21,10 +21,9 @@ use std::sync::{Arc, Weak}; use futures::{Future, IntoFuture}; use parking_lot::RwLock; -use primitives::AuthorityId; use runtime_primitives::{generic::BlockId, Justification, StorageMap, ChildrenStorageMap}; use state_machine::{Backend as StateBackend, InMemoryChangesTrieStorage, TrieBackend}; -use runtime_primitives::traits::{Block as BlockT, NumberFor}; +use runtime_primitives::traits::{Block as BlockT, NumberFor, AuthorityIdFor}; use in_mem; use backend::{AuxStore, Backend as ClientBackend, BlockImportOperation, RemoteBackend, NewBlockState}; @@ -44,7 +43,7 @@ pub struct Backend { /// Light block (header and justification) import operation. pub struct ImportOperation { header: Option, - authorities: Option>, + authorities: Option>>, leaf_state: NewBlockState, aux_ops: Vec<(Vec, Option>)>, _phantom: ::std::marker::PhantomData<(S, F)>, @@ -185,7 +184,7 @@ where Ok(()) } - fn update_authorities(&mut self, authorities: Vec) { + fn update_authorities(&mut self, authorities: Vec>) { self.authorities = Some(authorities); } diff --git a/substrate/core/client/src/light/blockchain.rs b/substrate/core/client/src/light/blockchain.rs index ed75043164..62e40c579e 100644 --- a/substrate/core/client/src/light/blockchain.rs +++ b/substrate/core/client/src/light/blockchain.rs @@ -21,9 +21,8 @@ use std::sync::Weak; use futures::{Future, IntoFuture}; use parking_lot::Mutex; -use primitives::AuthorityId; use runtime_primitives::{Justification, generic::BlockId}; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT,NumberFor, Zero}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero, AuthorityIdFor}; use backend::{AuxStore, NewBlockState}; use blockchain::{Backend as BlockchainBackend, BlockStatus, Cache as BlockchainCache, @@ -41,7 +40,7 @@ pub trait Storage: AuxStore + BlockchainHeaderBackend { fn import_header( &self, header: Block::Header, - authorities: Option>, + authorities: Option>>, state: NewBlockState, aux_ops: Vec<(Vec, Option>)>, ) -> ClientResult<()>; @@ -227,7 +226,7 @@ pub mod tests { fn import_header( &self, _header: Header, - _authorities: Option>, + _authorities: Option>>, _state: NewBlockState, _aux_ops: Vec<(Vec, Option>)>, ) -> ClientResult<()> { diff --git a/substrate/core/client/src/runtime_api.rs b/substrate/core/client/src/runtime_api.rs index 9ad92fb493..596b355ddf 100644 --- a/substrate/core/client/src/runtime_api.rs +++ b/substrate/core/client/src/runtime_api.rs @@ -21,7 +21,7 @@ pub use state_machine::OverlayedChanges; #[doc(hidden)] pub use runtime_primitives::{ - traits::{Block as BlockT, GetNodeBlockType, GetRuntimeBlockType, ApiRef, RuntimeApiInfo}, + traits::{AuthorityIdFor, Block as BlockT, GetNodeBlockType, GetRuntimeBlockType, ApiRef, RuntimeApiInfo}, generic::BlockId, transaction_validity::TransactionValidity }; #[doc(hidden)] @@ -34,7 +34,7 @@ pub use codec::{Encode, Decode}; #[cfg(feature = "std")] use error; use rstd::vec::Vec; -use primitives::{AuthorityId, OpaqueMetadata}; +use primitives::OpaqueMetadata; /// Something that can be constructed to a runtime api. @@ -91,7 +91,7 @@ decl_runtime_apis! { /// Returns the version of the runtime. fn version() -> RuntimeVersion; /// Returns the authorities. - fn authorities() -> Vec; + fn authorities() -> Vec>; /// Execute the given block. fn execute_block(block: Block); /// Initialise a block with the given header. diff --git a/substrate/core/consensus/aura/src/lib.rs b/substrate/core/consensus/aura/src/lib.rs index b57dab030c..f544c2f0e7 100644 --- a/substrate/core/consensus/aura/src/lib.rs +++ b/substrate/core/consensus/aura/src/lib.rs @@ -67,8 +67,8 @@ use client::ChainHead; use client::block_builder::api::BlockBuilder as BlockBuilderApi; use consensus_common::{ImportBlock, BlockOrigin}; use runtime_primitives::{generic, generic::BlockId, Justification, BasicInherentData}; -use runtime_primitives::traits::{Block, Header, Digest, DigestItemFor, ProvideRuntimeApi}; -use primitives::{AuthorityId, ed25519}; +use runtime_primitives::traits::{Block, Header, Digest, DigestItemFor, DigestItem, ProvideRuntimeApi}; +use primitives::{Ed25519AuthorityId, ed25519}; use futures::{Stream, Future, IntoFuture, future::{self, Either}}; use tokio::timer::Timeout; @@ -91,7 +91,7 @@ pub trait Network: Clone { } /// Get slot author for given block along with authorities. -fn slot_author(slot_num: u64, authorities: &[AuthorityId]) -> Option { +fn slot_author(slot_num: u64, authorities: &[Ed25519AuthorityId]) -> Option { if authorities.is_empty() { return None } let idx = slot_num % (authorities.len() as u64); @@ -168,7 +168,7 @@ pub fn start_aura_thread( I: BlockImport + Send + Sync + 'static, Error: From + From + 'static, SO: SyncOracle + Send + Clone + 'static, - DigestItemFor: CompatibleDigestItem + 'static, + DigestItemFor: CompatibleDigestItem + DigestItem + 'static, Error: ::std::error::Error + Send + From<::consensus_common::Error> + 'static, { use tokio::runtime::current_thread::Runtime; @@ -211,7 +211,7 @@ pub fn start_aura( I: BlockImport, Error: From + From, SO: SyncOracle + Send + Clone, - DigestItemFor: CompatibleDigestItem, + DigestItemFor: CompatibleDigestItem + DigestItem, Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>, { let make_authorship = move || { @@ -266,7 +266,7 @@ pub fn start_aura( slot_num, timestamp); // we are the slot author. make a block and sign it. - let proposer = match env.init(&chain_head, &authorities, pair.clone()) { + let proposer = match env.init(&chain_head, &authorities) { Ok(p) => p, Err(e) => { warn!("Unable to author block in slot {:?}: {:?}", slot_num, e); @@ -373,7 +373,7 @@ enum CheckedHeader { /// if it's successful, returns the pre-header, the slot number, and the signat. // // FIXME: needs misbehavior types - https://github.com/paritytech/substrate/issues/1018 -fn check_header(slot_now: u64, mut header: B::Header, hash: B::Hash, authorities: &[AuthorityId]) +fn check_header(slot_now: u64, mut header: B::Header, hash: B::Hash, authorities: &[Ed25519AuthorityId]) -> Result, String> where DigestItemFor: CompatibleDigestItem { @@ -446,7 +446,7 @@ impl ExtraVerification for NothingExtra { impl Verifier for AuraVerifier where C: Authorities + BlockImport + ProvideRuntimeApi + Send + Sync, C::Api: BlockBuilderApi, - DigestItemFor: CompatibleDigestItem, + DigestItemFor: CompatibleDigestItem + DigestItem, E: ExtraVerification, MakeInherent: Fn(u64, u64) -> Inherent + Send + Sync, { @@ -456,7 +456,7 @@ impl Verifier for AuraVerifier, mut body: Option>, - ) -> Result<(ImportBlock, Option>), String> { + ) -> Result<(ImportBlock, Option>), String> { use runtime_primitives::CheckInherentError; const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60; @@ -600,7 +600,7 @@ pub fn import_queue( B: Block, C: Authorities + BlockImport + ProvideRuntimeApi + Send + Sync, C::Api: BlockBuilderApi, - DigestItemFor: CompatibleDigestItem, + DigestItemFor: CompatibleDigestItem + DigestItem, E: ExtraVerification, MakeInherent: Fn(u64, u64) -> Inherent + Send + Sync, { @@ -633,7 +633,7 @@ mod tests { type Proposer = DummyProposer; type Error = Error; - fn init(&self, parent_header: &::Header, _authorities: &[AuthorityId], _sign_with: Arc) + fn init(&self, parent_header: &::Header, _authorities: &[Ed25519AuthorityId]) -> Result { Ok(DummyProposer(parent_header.number + 1, self.0.clone())) diff --git a/substrate/core/consensus/common/src/block_import.rs b/substrate/core/consensus/common/src/block_import.rs index 488112f0eb..f4a60d435d 100644 --- a/substrate/core/consensus/common/src/block_import.rs +++ b/substrate/core/consensus/common/src/block_import.rs @@ -16,8 +16,7 @@ //! Block import helpers. -use primitives::AuthorityId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, DigestItemFor}; +use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT, Header as HeaderT, DigestItemFor}; use runtime_primitives::Justification; use std::borrow::Cow; @@ -146,6 +145,6 @@ pub trait BlockImport { /// Import a Block alongside the new authorities valid form this block forward fn import_block(&self, block: ImportBlock, - new_authorities: Option> + new_authorities: Option>> ) -> Result; } diff --git a/substrate/core/consensus/common/src/error.rs b/substrate/core/consensus/common/src/error.rs index 14a3fb81e1..ec378d24cb 100644 --- a/substrate/core/consensus/common/src/error.rs +++ b/substrate/core/consensus/common/src/error.rs @@ -44,13 +44,13 @@ error_chain! { } /// Error checking signature - InvalidSignature(s: ::primitives::ed25519::Signature, a: ::primitives::AuthorityId) { + InvalidSignature(s: ::primitives::ed25519::Signature, a: ::primitives::Ed25519AuthorityId) { description("Message signature is invalid"), display("Message signature {:?} by {:?} is invalid.", s, a), } /// Account is not an authority. - InvalidAuthority(a: ::primitives::AuthorityId) { + InvalidAuthority(a: ::primitives::Ed25519AuthorityId) { description("Message sender is not a valid authority"), display("Message sender {:?} is not a valid authority.", a), } diff --git a/substrate/core/consensus/common/src/import_queue.rs b/substrate/core/consensus/common/src/import_queue.rs index 3a048f781a..5264b29cef 100644 --- a/substrate/core/consensus/common/src/import_queue.rs +++ b/substrate/core/consensus/common/src/import_queue.rs @@ -29,10 +29,9 @@ use std::collections::{HashSet, VecDeque}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use parking_lot::{Condvar, Mutex, RwLock}; -use primitives::AuthorityId; use runtime_primitives::Justification; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero, AuthorityIdFor}; use error::Error as ConsensusError; @@ -68,7 +67,7 @@ pub trait Verifier: Send + Sync + Sized { header: B::Header, justification: Option, body: Option> - ) -> Result<(ImportBlock, Option>), String>; + ) -> Result<(ImportBlock, Option>>), String>; } /// Blocks import queue API. diff --git a/substrate/core/consensus/common/src/lib.rs b/substrate/core/consensus/common/src/lib.rs index e9b5d82951..23bde0c056 100644 --- a/substrate/core/consensus/common/src/lib.rs +++ b/substrate/core/consensus/common/src/lib.rs @@ -40,9 +40,8 @@ extern crate error_chain; use std::sync::Arc; -use primitives::{ed25519, AuthorityId}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::Block; +use runtime_primitives::traits::{AuthorityIdFor, Block}; use futures::prelude::*; pub mod offline_tracker; @@ -60,7 +59,7 @@ pub use block_import::{BlockImport, ImportBlock, BlockOrigin, ImportResult, Fork /// Trait for getting the authorities at a given block. pub trait Authorities { type Error: ::std::error::Error + Send + 'static; /// Get the authorities at the given block. - fn authorities(&self, at: &BlockId) -> Result, Self::Error>; + fn authorities(&self, at: &BlockId) -> Result>, Self::Error>; } /// Environment producer for a Consensus instance. Creates proposer instance and communication streams. @@ -71,9 +70,8 @@ pub trait Environment { type Error: From; /// Initialize the proposal logic on top of a specific header. Provide - /// the authorities at that header, and a local key to sign any additional - /// consensus messages with as well. - fn init(&self, parent_header: &B::Header, authorities: &[AuthorityId], sign_with: Arc) + /// the authorities at that header. + fn init(&self, parent_header: &B::Header, authorities: &[AuthorityIdFor]) -> Result; } diff --git a/substrate/core/consensus/common/src/offline_tracker.rs b/substrate/core/consensus/common/src/offline_tracker.rs index bd8eab8b1b..1ed923da2c 100644 --- a/substrate/core/consensus/common/src/offline_tracker.rs +++ b/substrate/core/consensus/common/src/offline_tracker.rs @@ -16,8 +16,6 @@ //! Tracks offline validators. -use primitives::AuthorityId; - use std::collections::HashMap; use std::time::{Instant, Duration}; @@ -55,11 +53,11 @@ impl Observed { } /// Tracks offline validators and can issue a report for those offline. -pub struct OfflineTracker { +pub struct OfflineTracker { observed: HashMap, } -impl OfflineTracker { +impl OfflineTracker { /// Create a new tracker. pub fn new() -> Self { OfflineTracker { observed: HashMap::new() } @@ -114,10 +112,11 @@ impl OfflineTracker { #[cfg(test)] mod tests { use super::*; + use primitives::Ed25519AuthorityId; #[test] fn validator_offline() { - let mut tracker = OfflineTracker::new(); + let mut tracker = OfflineTracker::::new(); let v = [0; 32].into(); let v2 = [1; 32].into(); let v3 = [2; 32].into(); diff --git a/substrate/core/finality-grandpa/primitives/src/lib.rs b/substrate/core/finality-grandpa/primitives/src/lib.rs index df224fa9d4..15e4a027f6 100644 --- a/substrate/core/finality-grandpa/primitives/src/lib.rs +++ b/substrate/core/finality-grandpa/primitives/src/lib.rs @@ -34,7 +34,7 @@ extern crate substrate_client as client; extern crate sr_std as rstd; -use substrate_primitives::AuthorityId; +use substrate_primitives::Ed25519AuthorityId; use sr_primitives::traits::{DigestFor, NumberFor}; use rstd::vec::Vec; @@ -43,7 +43,7 @@ use rstd::vec::Vec; #[derive(Clone, Encode, Decode)] pub struct ScheduledChange { /// The new authorities after the change, along with their respective weights. - pub next_authorities: Vec<(AuthorityId, u64)>, + pub next_authorities: Vec<(Ed25519AuthorityId, u64)>, /// The number of blocks to delay. pub delay: N, } @@ -97,6 +97,6 @@ decl_runtime_apis! { /// Get the current GRANDPA authorities and weights. This should not change except /// for when changes are scheduled and the corresponding delay has passed. - fn grandpa_authorities() -> Vec<(AuthorityId, u64)>; + fn grandpa_authorities() -> Vec<(Ed25519AuthorityId, u64)>; } } diff --git a/substrate/core/finality-grandpa/src/authorities.rs b/substrate/core/finality-grandpa/src/authorities.rs index 64e9f36906..ca9bd61a88 100644 --- a/substrate/core/finality-grandpa/src/authorities.rs +++ b/substrate/core/finality-grandpa/src/authorities.rs @@ -17,7 +17,7 @@ //! Utilities for dealing with authorities, authority sets, and handoffs. use parking_lot::RwLock; -use substrate_primitives::AuthorityId; +use substrate_primitives::Ed25519AuthorityId; use std::cmp::Ord; use std::collections::HashMap; @@ -38,7 +38,7 @@ impl Clone for SharedAuthoritySet { impl SharedAuthoritySet { /// The genesis authority set. - pub(crate) fn genesis(initial: Vec<(AuthorityId, u64)>) -> Self { + pub(crate) fn genesis(initial: Vec<(Ed25519AuthorityId, u64)>) -> Self { SharedAuthoritySet { inner: Arc::new(RwLock::new(AuthoritySet::genesis(initial))) } @@ -66,7 +66,7 @@ where } /// Get the current authorities and their weights (for the current set ID). - pub(crate) fn current_authorities(&self) -> HashMap { + pub(crate) fn current_authorities(&self) -> HashMap { self.inner.read().current_authorities.iter().cloned().collect() } } @@ -89,14 +89,14 @@ pub(crate) struct Status { /// A set of authorities. #[derive(Debug, Clone, Encode, Decode)] pub(crate) struct AuthoritySet { - current_authorities: Vec<(AuthorityId, u64)>, + current_authorities: Vec<(Ed25519AuthorityId, u64)>, set_id: u64, pending_changes: Vec>, } impl AuthoritySet { /// Get a genesis set with given authorities. - pub(crate) fn genesis(initial: Vec<(AuthorityId, u64)>) -> Self { + pub(crate) fn genesis(initial: Vec<(Ed25519AuthorityId, u64)>) -> Self { AuthoritySet { current_authorities: initial, set_id: 0, @@ -105,7 +105,7 @@ impl AuthoritySet { } /// Get the current set id and a reference to the current authority set. - pub(crate) fn current(&self) -> (u64, &[(AuthorityId, u64)]) { + pub(crate) fn current(&self) -> (u64, &[(Ed25519AuthorityId, u64)]) { (self.set_id, &self.current_authorities[..]) } } @@ -249,7 +249,7 @@ where #[derive(Debug, Clone, Encode, Decode, PartialEq)] pub(crate) struct PendingChange { /// The new authorities and weights to apply. - pub(crate) next_authorities: Vec<(AuthorityId, u64)>, + pub(crate) next_authorities: Vec<(Ed25519AuthorityId, u64)>, /// How deep in the finalized chain the announcing block must be /// before the change is applied. pub(crate) finalization_depth: N, diff --git a/substrate/core/finality-grandpa/src/communication.rs b/substrate/core/finality-grandpa/src/communication.rs index 02a079b909..b8435cef6c 100644 --- a/substrate/core/finality-grandpa/src/communication.rs +++ b/substrate/core/finality-grandpa/src/communication.rs @@ -20,7 +20,7 @@ use futures::prelude::*; use futures::sync::mpsc; use codec::{Encode, Decode}; -use substrate_primitives::{ed25519, AuthorityId}; +use substrate_primitives::{ed25519, Ed25519AuthorityId}; use runtime_primitives::traits::Block as BlockT; use {Error, Network, Message, SignedMessage, Commit, CompactCommit}; @@ -34,7 +34,7 @@ fn localized_payload(round: u64, set_id: u64, message: &E) -> Vec // check a message. pub(crate) fn check_message_sig( message: &Message, - id: &AuthorityId, + id: &Ed25519AuthorityId, signature: &ed25519::Signature, round: u64, set_id: u64, @@ -55,7 +55,7 @@ pub(crate) fn checked_message_stream( round: u64, set_id: u64, inner: S, - voters: Arc>, + voters: Arc>, ) -> impl Stream,Error=Error> where S: Stream,Error=()> @@ -92,7 +92,7 @@ pub(crate) fn checked_message_stream( struct OutgoingMessages { round: u64, set_id: u64, - locals: Option<(Arc, AuthorityId)>, + locals: Option<(Arc, Ed25519AuthorityId)>, sender: mpsc::UnboundedSender>, network: N, } @@ -143,7 +143,7 @@ pub(crate) fn outgoing_messages( round: u64, set_id: u64, local_key: Option>, - voters: Arc>, + voters: Arc>, network: N, ) -> ( impl Stream,Error=Error>, @@ -151,7 +151,7 @@ pub(crate) fn outgoing_messages( ) { let locals = local_key.and_then(|pair| { let public = pair.public(); - let id = AuthorityId(public.0); + let id = Ed25519AuthorityId(public.0); if voters.contains_key(&id) { Some((pair, id)) } else { @@ -177,7 +177,7 @@ pub(crate) fn outgoing_messages( fn check_compact_commit( msg: CompactCommit, - voters: &HashMap, + voters: &HashMap, round: u64, set_id: u64, ) -> Option> { @@ -216,7 +216,7 @@ fn check_compact_commit( pub(crate) fn checked_commit_stream( set_id: u64, inner: S, - voters: Arc>, + voters: Arc>, ) -> impl Stream),Error=Error> where S: Stream,Error=()> diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index abd737d357..00ea6734af 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -92,10 +92,11 @@ use codec::{Encode, Decode}; use consensus_common::{BlockImport, Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, Authorities}; use runtime_primitives::traits::{ NumberFor, Block as BlockT, Header as HeaderT, DigestFor, ProvideRuntimeApi, Hash as HashT, + DigestItemFor, DigestItem, }; use fg_primitives::GrandpaApi; use runtime_primitives::generic::BlockId; -use substrate_primitives::{ed25519, H256, AuthorityId, Blake2Hasher}; +use substrate_primitives::{ed25519, H256, Ed25519AuthorityId, Blake2Hasher}; use tokio::timer::Delay; use grandpa::Error as GrandpaError; @@ -138,7 +139,7 @@ pub type SignedMessage = grandpa::SignedMessage< ::Hash, NumberFor, ed25519::Signature, - AuthorityId, + Ed25519AuthorityId, >; /// A prevote message for this chain's block type. pub type Prevote = grandpa::Prevote<::Hash, NumberFor>; @@ -149,14 +150,14 @@ pub type Commit = grandpa::Commit< ::Hash, NumberFor, ed25519::Signature, - AuthorityId + Ed25519AuthorityId >; /// A compact commit message for this chain's block type. pub type CompactCommit = grandpa::CompactCommit< ::Hash, NumberFor, ed25519::Signature, - AuthorityId + Ed25519AuthorityId >; /// Configuration for the GRANDPA service. @@ -306,7 +307,7 @@ impl, RA> BlockStatus for Arc { inner: Arc>, - voters: Arc>, + voters: Arc>, config: Config, authority_set: SharedAuthoritySet>, network: N, @@ -381,7 +382,7 @@ struct NewAuthoritySet { canon_number: N, canon_hash: H, set_id: u64, - authorities: Vec<(AuthorityId, u64)>, + authorities: Vec<(Ed25519AuthorityId, u64)>, } /// Signals either an early exit of a voter or an error. @@ -432,7 +433,7 @@ impl, N, RA> voter::Environment: BlockNumberOps, { type Timer = Box + Send>; - type Id = AuthorityId; + type Id = Ed25519AuthorityId; type Signature = ed25519::Signature; // regular round message streams @@ -611,7 +612,7 @@ impl> GrandpaJustification { fn decode_and_verify( encoded: Vec, set_id: u64, - voters: &HashMap, + voters: &HashMap, ) -> Result, ClientError> where NumberFor: grandpa::BlockNumberOps, { @@ -830,13 +831,14 @@ impl, RA, PRA> BlockImport B: Backend + 'static, E: CallExecutor + 'static + Clone + Send + Sync, DigestFor: Encode, + DigestItemFor: DigestItem, RA: Send + Sync, PRA: ProvideRuntimeApi, PRA::Api: GrandpaApi, { type Error = ConsensusError; - fn import_block(&self, mut block: ImportBlock, new_authorities: Option>) + fn import_block(&self, mut block: ImportBlock, new_authorities: Option>) -> Result { use authorities::PendingChange; @@ -1030,10 +1032,11 @@ impl, RA, PRA> Authorities for GrandpaBloc where B: Backend + 'static, E: CallExecutor + 'static + Clone + Send + Sync, + DigestItemFor: DigestItem, { type Error = as Authorities>::Error; - fn authorities(&self, at: &BlockId) -> Result, Self::Error> { + fn authorities(&self, at: &BlockId) -> Result, Self::Error> { self.inner.authorities_at(at) } } @@ -1158,16 +1161,16 @@ pub fn block_import, RA, PRA>( fn committer_communication, B, E, N, RA>( set_id: u64, - voters: &Arc>, + voters: &Arc>, client: &Arc>, network: &N, ) -> ( impl Stream< - Item = (u64, ::grandpa::CompactCommit, ed25519::Signature, AuthorityId>), + Item = (u64, ::grandpa::CompactCommit, ed25519::Signature, Ed25519AuthorityId>), Error = ExitOrError>, >, impl Sink< - SinkItem = (u64, ::grandpa::Commit, ed25519::Signature, AuthorityId>), + SinkItem = (u64, ::grandpa::Commit, ed25519::Signature, Ed25519AuthorityId>), SinkError = ExitOrError>, >, ) where @@ -1176,6 +1179,7 @@ fn committer_communication, B, E, N, RA>( N: Network, RA: Send + Sync, NumberFor: BlockNumberOps, + DigestItemFor: DigestItem, { // verification stream let commit_in = ::communication::checked_commit_stream::( @@ -1217,6 +1221,7 @@ pub fn run_grandpa, N, RA>( N::In: Send + 'static, NumberFor: BlockNumberOps, DigestFor: Encode, + DigestItemFor: DigestItem, RA: Send + Sync + 'static, { use futures::future::{self, Loop as FutureLoop}; diff --git a/substrate/core/finality-grandpa/src/tests.rs b/substrate/core/finality-grandpa/src/tests.rs index a357fa81da..18bfaef1a5 100644 --- a/substrate/core/finality-grandpa/src/tests.rs +++ b/substrate/core/finality-grandpa/src/tests.rs @@ -230,12 +230,12 @@ impl Network for MessageRouting { #[derive(Default, Clone)] struct TestApi { - genesis_authorities: Vec<(AuthorityId, u64)>, + genesis_authorities: Vec<(Ed25519AuthorityId, u64)>, scheduled_changes: Arc>>>, } impl TestApi { - fn new(genesis_authorities: Vec<(AuthorityId, u64)>) -> Self { + fn new(genesis_authorities: Vec<(Ed25519AuthorityId, u64)>) -> Self { TestApi { genesis_authorities, scheduled_changes: Arc::new(Mutex::new(HashMap::new())), @@ -260,7 +260,7 @@ impl Core for RuntimeApi { unimplemented!("Not required for testing!") } - fn authorities(&self, _: &BlockId) -> Result> { + fn authorities(&self, _: &BlockId) -> Result> { unimplemented!("Not required for testing!") } @@ -300,7 +300,7 @@ impl GrandpaApi for RuntimeApi { fn grandpa_authorities( &self, at: &BlockId - ) -> Result> { + ) -> Result> { if at == &BlockId::Number(0) { Ok(self.inner.genesis_authorities.clone()) } else { @@ -325,9 +325,9 @@ impl GrandpaApi for RuntimeApi { const TEST_GOSSIP_DURATION: Duration = Duration::from_millis(500); const TEST_ROUTING_INTERVAL: Duration = Duration::from_millis(50); -fn make_ids(keys: &[Keyring]) -> Vec<(AuthorityId, u64)> { +fn make_ids(keys: &[Keyring]) -> Vec<(Ed25519AuthorityId, u64)> { keys.iter() - .map(|key| AuthorityId(key.to_raw_public())) + .map(|key| Ed25519AuthorityId(key.to_raw_public())) .map(|id| (id, 1)) .collect() } diff --git a/substrate/core/finality-grandpa/src/until_imported.rs b/substrate/core/finality-grandpa/src/until_imported.rs index 028b710acb..8cb825ac84 100644 --- a/substrate/core/finality-grandpa/src/until_imported.rs +++ b/substrate/core/finality-grandpa/src/until_imported.rs @@ -27,7 +27,7 @@ use futures::prelude::*; use futures::stream::Fuse; use parking_lot::Mutex; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; -use substrate_primitives::AuthorityId; +use substrate_primitives::Ed25519AuthorityId; use tokio::timer::Interval; use std::collections::{HashMap, VecDeque}; @@ -181,7 +181,7 @@ impl Stream for UntilImported } } -fn warn_authority_wrong_target(hash: H, id: AuthorityId) { +fn warn_authority_wrong_target(hash: H, id: Ed25519AuthorityId) { warn!( target: "afg", "Authority {:?} signed GRANDPA message with \ diff --git a/substrate/core/network/src/chain.rs b/substrate/core/network/src/chain.rs index 166dfe55a7..457f8852b2 100644 --- a/substrate/core/network/src/chain.rs +++ b/substrate/core/network/src/chain.rs @@ -20,16 +20,16 @@ use client::{self, Client as SubstrateClient, ClientInfo, BlockStatus, CallExecu use client::error::Error; use client::light::fetcher::ChangesProof; use consensus::{BlockImport, Error as ConsensusError}; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, AuthorityIdFor}; use runtime_primitives::generic::{BlockId}; use consensus::{ImportBlock, ImportResult}; use runtime_primitives::Justification; -use primitives::{H256, Blake2Hasher, AuthorityId}; +use primitives::{H256, Blake2Hasher}; /// Local client abstraction for the network. pub trait Client: Send + Sync { /// Import a new block. Parent is supposed to be existing in the blockchain. - fn import(&self, block: ImportBlock, new_authorities: Option>) + fn import(&self, block: ImportBlock, new_authorities: Option>>) -> Result; /// Get blockchain info. @@ -77,7 +77,7 @@ impl Client for SubstrateClient where Block: BlockT, RA: Send + Sync { - fn import(&self, block: ImportBlock, new_authorities: Option>) + fn import(&self, block: ImportBlock, new_authorities: Option>>) -> Result { (self as &SubstrateClient).import_block(block, new_authorities) diff --git a/substrate/core/network/src/test/mod.rs b/substrate/core/network/src/test/mod.rs index 94518978bc..48b401b21a 100644 --- a/substrate/core/network/src/test/mod.rs +++ b/substrate/core/network/src/test/mod.rs @@ -29,9 +29,8 @@ use client; use client::block_builder::BlockBuilder; use runtime_primitives::Justification; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Zero}; +use runtime_primitives::traits::{Block as BlockT, Zero, AuthorityIdFor}; use io::SyncIo; -use primitives::AuthorityId; use protocol::{Context, Protocol, ProtocolContext}; use config::ProtocolConfig; use service::{NetworkLink, TransactionPool}; @@ -92,7 +91,7 @@ impl Verifier for PassThroughVerifier { header: B::Header, justification: Option, body: Option> - ) -> Result<(ImportBlock, Option>), String> { + ) -> Result<(ImportBlock, Option>>), String> { Ok((ImportBlock { origin, header, diff --git a/substrate/core/primitives/src/authority_id.rs b/substrate/core/primitives/src/authority_id.rs index 9a6abf1f03..7773e1a930 100644 --- a/substrate/core/primitives/src/authority_id.rs +++ b/substrate/core/primitives/src/authority_id.rs @@ -20,17 +20,17 @@ use H256; /// An identifier for an authority in the consensus algorithm. The same size as ed25519::Public. #[derive(Clone, Copy, PartialEq, Eq, Default, Encode, Decode)] -pub struct AuthorityId(pub [u8; 32]); +pub struct Ed25519AuthorityId(pub [u8; 32]); #[cfg(feature = "std")] -impl ::std::fmt::Display for AuthorityId { +impl ::std::fmt::Display for Ed25519AuthorityId { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{}", ::ed25519::Public(self.0).to_ss58check()) } } #[cfg(feature = "std")] -impl ::std::fmt::Debug for AuthorityId { +impl ::std::fmt::Debug for Ed25519AuthorityId { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { let h = format!("{}", ::hexdisplay::HexDisplay::from(&self.0)); write!(f, "{} ({}…{})", ::ed25519::Public(self.0).to_ss58check(), &h[0..8], &h[60..]) @@ -38,57 +38,57 @@ impl ::std::fmt::Debug for AuthorityId { } #[cfg(feature = "std")] -impl ::std::hash::Hash for AuthorityId { +impl ::std::hash::Hash for Ed25519AuthorityId { fn hash(&self, state: &mut H) { self.0.hash(state); } } -impl AsRef<[u8; 32]> for AuthorityId { +impl AsRef<[u8; 32]> for Ed25519AuthorityId { fn as_ref(&self) -> &[u8; 32] { &self.0 } } -impl AsRef<[u8]> for AuthorityId { +impl AsRef<[u8]> for Ed25519AuthorityId { fn as_ref(&self) -> &[u8] { &self.0[..] } } -impl Into<[u8; 32]> for AuthorityId { +impl Into<[u8; 32]> for Ed25519AuthorityId { fn into(self) -> [u8; 32] { self.0 } } -impl From<[u8; 32]> for AuthorityId { +impl From<[u8; 32]> for Ed25519AuthorityId { fn from(a: [u8; 32]) -> Self { - AuthorityId(a) + Ed25519AuthorityId(a) } } -impl AsRef for AuthorityId { - fn as_ref(&self) -> &AuthorityId { +impl AsRef for Ed25519AuthorityId { + fn as_ref(&self) -> &Ed25519AuthorityId { &self } } -impl Into for AuthorityId { +impl Into for Ed25519AuthorityId { fn into(self) -> H256 { self.0.into() } } #[cfg(feature = "std")] -impl Serialize for AuthorityId { +impl Serialize for Ed25519AuthorityId { fn serialize(&self, serializer: S) -> Result where S: Serializer { ::ed25519::serialize(&self, serializer) } } #[cfg(feature = "std")] -impl<'de> Deserialize<'de> for AuthorityId { +impl<'de> Deserialize<'de> for Ed25519AuthorityId { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de> { ::ed25519::deserialize(deserializer) } diff --git a/substrate/core/primitives/src/ed25519.rs b/substrate/core/primitives/src/ed25519.rs index c6f28c64c1..05077fbd37 100644 --- a/substrate/core/primitives/src/ed25519.rs +++ b/substrate/core/primitives/src/ed25519.rs @@ -21,7 +21,7 @@ use untrusted; use blake2_rfc; use ring::{rand, signature}; -use {hash::H512, AuthorityId}; +use {hash::H512, Ed25519AuthorityId}; use base58::{ToBase58, FromBase58}; #[cfg(feature = "std")] @@ -169,14 +169,14 @@ impl AsRef for Pair { } } -impl Into for Public { - fn into(self) -> AuthorityId { - AuthorityId(self.0) +impl Into for Public { + fn into(self) -> Ed25519AuthorityId { + Ed25519AuthorityId(self.0) } } -impl From for Public { - fn from(id: AuthorityId) -> Self { +impl From for Public { + fn from(id: Ed25519AuthorityId) -> Self { Public(id.0) } } diff --git a/substrate/core/primitives/src/lib.rs b/substrate/core/primitives/src/lib.rs index 83f6a8d0bc..98289ddc18 100644 --- a/substrate/core/primitives/src/lib.rs +++ b/substrate/core/primitives/src/lib.rs @@ -109,7 +109,7 @@ mod tests; pub use self::hash::{H160, H256, H512, convert_hash}; pub use self::uint::U256; -pub use authority_id::AuthorityId; +pub use authority_id::Ed25519AuthorityId; pub use changes_trie::ChangesTrieConfiguration; pub use hash_db::Hasher; diff --git a/substrate/core/sr-api-macros/tests/decl_and_impl.rs b/substrate/core/sr-api-macros/tests/decl_and_impl.rs index 47822e538b..699c8c01cf 100644 --- a/substrate/core/sr-api-macros/tests/decl_and_impl.rs +++ b/substrate/core/sr-api-macros/tests/decl_and_impl.rs @@ -4,9 +4,8 @@ extern crate sr_primitives as runtime_primitives; extern crate substrate_primitives as primitives; extern crate substrate_test_client as test_client; -use runtime_primitives::traits::{GetNodeBlockType, Block as BlockT}; +use runtime_primitives::traits::{GetNodeBlockType, Block as BlockT, AuthorityIdFor}; use runtime_primitives::generic::BlockId; -use primitives::AuthorityId; use substrate_client::runtime_api::{self, RuntimeApiInfo}; use substrate_client::error::Result; use test_client::runtime::Block; @@ -57,7 +56,7 @@ impl_runtime_apis! { fn version() -> runtime_api::RuntimeVersion { unimplemented!() } - fn authorities() -> Vec { + fn authorities() -> Vec> { unimplemented!() } fn execute_block(_: Block) { diff --git a/substrate/core/sr-primitives/src/generic/digest.rs b/substrate/core/sr-primitives/src/generic/digest.rs index 1bf53a9c01..f2185c23db 100644 --- a/substrate/core/sr-primitives/src/generic/digest.rs +++ b/substrate/core/sr-primitives/src/generic/digest.rs @@ -19,7 +19,7 @@ use rstd::prelude::*; use codec::{Decode, Encode, Codec, Input}; -use traits::{self, Member, DigestItem as DigestItemT, MaybeSerializeDebug}; +use traits::{self, Member, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeHash}; use substrate_primitives::hash::H512 as Signature; @@ -124,7 +124,7 @@ impl DigestItem { impl< Hash: Codec + Member + MaybeSerializeDebug, - AuthorityId: Codec + Member + MaybeSerializeDebug + AuthorityId: Codec + Member + MaybeSerializeDebug + MaybeHash > traits::DigestItem for DigestItem { type Hash = Hash; type AuthorityId = AuthorityId; diff --git a/substrate/core/sr-primitives/src/testing.rs b/substrate/core/sr-primitives/src/testing.rs index acbcd9241d..f552600de9 100644 --- a/substrate/core/sr-primitives/src/testing.rs +++ b/substrate/core/sr-primitives/src/testing.rs @@ -19,12 +19,30 @@ use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer}; use std::{fmt::Debug, ops::Deref, fmt}; use codec::{Codec, Encode, Decode}; -use traits::{self, Checkable, Applyable, BlakeTwo256}; +use traits::{self, Checkable, Applyable, BlakeTwo256, Convert}; use generic::DigestItem as GenDigestItem; -pub use substrate_primitives::{H256, AuthorityId}; +pub use substrate_primitives::{H256, Ed25519AuthorityId}; +use substrate_primitives::U256; -pub type DigestItem = GenDigestItem; +#[derive(Default, PartialEq, Eq, Clone, Decode, Encode, Debug)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +pub struct UintAuthorityId(pub u64); +impl Into for UintAuthorityId { + fn into(self) -> Ed25519AuthorityId { + let bytes: [u8; 32] = U256::from(self.0).into(); + Ed25519AuthorityId(bytes) + } +} + +pub struct ConvertUintAuthorityId; +impl Convert for ConvertUintAuthorityId { + fn convert(a: u64) -> UintAuthorityId { + UintAuthorityId(a) + } +} + +pub type DigestItem = GenDigestItem; #[derive(Default, PartialEq, Eq, Clone, Serialize, Debug, Encode, Decode)] pub struct Digest { diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 8bdfd7eda6..0354953bfb 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -413,6 +413,16 @@ pub trait MaybeDisplay {} #[cfg(not(feature = "std"))] impl MaybeDisplay for T {} +#[cfg(feature = "std")] +pub trait MaybeHash: ::rstd::hash::Hash {} +#[cfg(feature = "std")] +impl MaybeHash for T {} + +#[cfg(not(feature = "std"))] +pub trait MaybeHash {} +#[cfg(not(feature = "std"))] +impl MaybeHash for T {} + #[cfg(feature = "std")] pub trait MaybeDecode: ::codec::Decode {} #[cfg(feature = "std")] @@ -500,6 +510,8 @@ pub type NumberFor = <::Header as Header>::Number; pub type DigestFor = <::Header as Header>::Digest; /// Extract the digest item type for a block. pub type DigestItemFor = as Digest>::Item; +/// Extract the authority ID type for a block. +pub type AuthorityIdFor = as DigestItem>::AuthorityId; /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. @@ -575,7 +587,7 @@ pub trait Digest: Member + MaybeSerializeDebugButNotDeserialize + Default { /// If the runtime does not supports some 'system' items, use `()` as a stub. pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize { type Hash: Member + MaybeSerializeDebugButNotDeserialize; - type AuthorityId: Member + MaybeSerializeDebugButNotDeserialize; + type AuthorityId: Member + MaybeSerializeDebugButNotDeserialize + MaybeHash + codec::Encode + codec::Decode; /// Returns Some if the entry is the `AuthoritiesChange` entry. fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]>; diff --git a/substrate/core/test-runtime/src/genesismap.rs b/substrate/core/test-runtime/src/genesismap.rs index 5e6adec86a..82e9423f05 100644 --- a/substrate/core/test-runtime/src/genesismap.rs +++ b/substrate/core/test-runtime/src/genesismap.rs @@ -19,23 +19,23 @@ use std::collections::HashMap; use runtime_io::twox_128; use codec::{Encode, KeyedVec, Joiner}; -use primitives::{AuthorityId, ChangesTrieConfiguration}; +use primitives::{Ed25519AuthorityId, ChangesTrieConfiguration}; use primitives::storage::well_known_keys; use runtime_primitives::traits::Block; /// Configuration of a general Substrate test genesis block. pub struct GenesisConfig { pub changes_trie_config: Option, - pub authorities: Vec, - pub balances: Vec<(AuthorityId, u64)>, + pub authorities: Vec, + pub balances: Vec<(Ed25519AuthorityId, u64)>, } impl GenesisConfig { - pub fn new_simple(authorities: Vec, balance: u64) -> Self { + pub fn new_simple(authorities: Vec, balance: u64) -> Self { Self::new(false, authorities, balance) } - pub fn new(support_changes_trie: bool, authorities: Vec, balance: u64) -> Self { + pub fn new(support_changes_trie: bool, authorities: Vec, balance: u64) -> Self { GenesisConfig { changes_trie_config: match support_changes_trie { true => Some(super::changes_trie_config()), diff --git a/substrate/core/test-runtime/src/lib.rs b/substrate/core/test-runtime/src/lib.rs index cceeee74d1..8aafd99791 100644 --- a/substrate/core/test-runtime/src/lib.rs +++ b/substrate/core/test-runtime/src/lib.rs @@ -61,8 +61,7 @@ use runtime_primitives::{ }; use runtime_version::RuntimeVersion; pub use primitives::hash::H256; -use primitives::AuthorityId; -use primitives::OpaqueMetadata; +use primitives::{Ed25519AuthorityId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] use runtime_version::NativeVersion; use consensus_aura::api as aura_api; @@ -143,7 +142,7 @@ pub type BlockNumber = u64; /// Index of a transaction. pub type Index = u64; /// The item of a block digest. -pub type DigestItem = runtime_primitives::generic::DigestItem; +pub type DigestItem = runtime_primitives::generic::DigestItem; /// The digest of a block. pub type Digest = runtime_primitives::generic::Digest; /// A test block. @@ -197,7 +196,7 @@ impl_runtime_apis! { version() } - fn authorities() -> Vec { + fn authorities() -> Vec { system::authorities() } diff --git a/substrate/core/test-runtime/src/system.rs b/substrate/core/test-runtime/src/system.rs index 3703fb553e..81cbabe906 100644 --- a/substrate/core/test-runtime/src/system.rs +++ b/substrate/core/test-runtime/src/system.rs @@ -25,7 +25,7 @@ use runtime_primitives::generic; use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult, transaction_validity::TransactionValidity}; use codec::{KeyedVec, Encode}; use super::{AccountId, BlockNumber, Extrinsic, H256 as Hash, Block, Header, Digest}; -use primitives::{Blake2Hasher}; +use primitives::{Ed25519AuthorityId, Blake2Hasher}; use primitives::storage::well_known_keys; const NONCE_OF: &[u8] = b"nonce:"; @@ -51,7 +51,7 @@ pub fn nonce_of(who: AccountId) -> u64 { } /// Get authorities ar given block. -pub fn authorities() -> Vec<::primitives::AuthorityId> { +pub fn authorities() -> Vec { let len: u32 = storage::unhashed::get(well_known_keys::AUTHORITY_COUNT) .expect("There are always authorities in test-runtime"); (0..len) @@ -94,7 +94,7 @@ pub fn execute_block(block: Block) { // check digest let mut digest = Digest::default(); if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into(), header.number - 1) { - digest.push(generic::DigestItem::ChangesTrieRoot::(storage_changes_root.into())); + digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root.into())); } assert!(digest == header.digest, "Header digest items must match that calculated."); } @@ -164,7 +164,7 @@ pub fn finalise_block() -> Header { let mut digest = Digest::default(); if let Some(storage_changes_root) = storage_changes_root { - digest.push(generic::DigestItem::ChangesTrieRoot::(storage_changes_root)); + digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root)); } Header { diff --git a/substrate/node/cli/src/chain_spec.rs b/substrate/node/cli/src/chain_spec.rs index 26e86f596b..b2d4b2ed4a 100644 --- a/substrate/node/cli/src/chain_spec.rs +++ b/substrate/node/cli/src/chain_spec.rs @@ -16,7 +16,7 @@ //! Substrate chain configurations. -use primitives::{AuthorityId, ed25519}; +use primitives::{Ed25519AuthorityId, ed25519}; use node_primitives::AccountId; use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig, SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig, @@ -158,7 +158,7 @@ pub fn staging_testnet_config() -> ChainSpec { } /// Helper function to generate AuthorityID from seed -pub fn get_authority_id_from_seed(seed: &str) -> AuthorityId { +pub fn get_authority_id_from_seed(seed: &str) -> Ed25519AuthorityId { let padded_seed = pad_seed(seed); // NOTE from ed25519 impl: // prefer pkcs#8 unless security doesn't matter -- this is used primarily for tests. @@ -167,9 +167,9 @@ pub fn get_authority_id_from_seed(seed: &str) -> AuthorityId { /// Helper function to create GenesisConfig for testing pub fn testnet_genesis( - initial_authorities: Vec, + initial_authorities: Vec, upgrade_key: AccountId, - endowed_accounts: Option>, + endowed_accounts: Option>, ) -> GenesisConfig { let endowed_accounts = endowed_accounts.unwrap_or_else(|| { vec![ diff --git a/substrate/node/primitives/src/lib.rs b/substrate/node/primitives/src/lib.rs index e2336acafd..967b0d775c 100644 --- a/substrate/node/primitives/src/lib.rs +++ b/substrate/node/primitives/src/lib.rs @@ -56,7 +56,7 @@ pub type Balance = u128; /// The Ed25519 pub key of an session that belongs to an authority of the chain. This is /// exactly equivalent to what the substrate calls an "authority". -pub type SessionKey = primitives::AuthorityId; +pub type SessionKey = primitives::Ed25519AuthorityId; /// Index of a transaction in the chain. pub type Index = u64; diff --git a/substrate/srml/aura/src/mock.rs b/substrate/srml/aura/src/mock.rs index 125466c9c0..eb1fc9756b 100644 --- a/substrate/srml/aura/src/mock.rs +++ b/substrate/srml/aura/src/mock.rs @@ -18,7 +18,7 @@ #![cfg(test)] -use primitives::{BuildStorage, testing::{Digest, DigestItem, Header}}; +use primitives::{BuildStorage, testing::{Digest, DigestItem, Header, UintAuthorityId}}; use runtime_io; use substrate_primitives::{H256, Blake2Hasher}; use {Trait, Module, consensus, system, timestamp}; @@ -34,7 +34,7 @@ pub struct Test; impl consensus::Trait for Test { const NOTE_OFFLINE_POSITION: u32 = 1; type Log = DigestItem; - type SessionKey = u64; + type SessionKey = UintAuthorityId; type InherentOfflineReport = (); } @@ -66,7 +66,7 @@ pub fn new_test_ext(authorities: Vec) -> runtime_io::TestExternalities::default().build_storage().unwrap().0; t.extend(consensus::GenesisConfig::{ code: vec![], - authorities, + authorities: authorities.into_iter().map(|a| UintAuthorityId(a)).collect(), }.build_storage().unwrap().0); t.extend(timestamp::GenesisConfig::{ period: 1, diff --git a/substrate/srml/consensus/src/lib.rs b/substrate/srml/consensus/src/lib.rs index 2c72642cf6..2a55ac9e19 100644 --- a/substrate/srml/consensus/src/lib.rs +++ b/substrate/srml/consensus/src/lib.rs @@ -143,12 +143,12 @@ impl RawLog { // Implementation for tests outside of this crate. #[cfg(any(feature = "std", test))] -impl From> for primitives::testing::DigestItem where N: Into { +impl From> for primitives::testing::DigestItem where N: Into { fn from(log: RawLog) -> primitives::testing::DigestItem { match log { RawLog::AuthoritiesChange(authorities) => - primitives::generic::DigestItem::AuthoritiesChange - ::(authorities.into_iter() + primitives::generic::DigestItem::AuthoritiesChange( + authorities.into_iter() .map(Into::into).collect()), } } diff --git a/substrate/srml/consensus/src/mock.rs b/substrate/srml/consensus/src/mock.rs index 5945a89018..78351309ac 100644 --- a/substrate/srml/consensus/src/mock.rs +++ b/substrate/srml/consensus/src/mock.rs @@ -18,7 +18,7 @@ #![cfg(test)] -use primitives::{BuildStorage, testing::{Digest, DigestItem, Header}}; +use primitives::{BuildStorage, testing::{Digest, DigestItem, Header, UintAuthorityId}}; use runtime_io; use substrate_primitives::{H256, Blake2Hasher}; use {GenesisConfig, Trait, Module, system}; @@ -33,7 +33,7 @@ pub struct Test; impl Trait for Test { const NOTE_OFFLINE_POSITION: u32 = 1; type Log = DigestItem; - type SessionKey = u64; + type SessionKey = UintAuthorityId; type InherentOfflineReport = ::InstantFinalityReportVec<()>; } impl system::Trait for Test { @@ -53,7 +53,7 @@ pub fn new_test_ext(authorities: Vec) -> runtime_io::TestExternalities::default().build_storage().unwrap().0; t.extend(GenesisConfig::{ code: vec![], - authorities, + authorities: authorities.into_iter().map(|a| UintAuthorityId(a)).collect(), }.build_storage().unwrap().0); t.into() } diff --git a/substrate/srml/consensus/src/tests.rs b/substrate/srml/consensus/src/tests.rs index 9c57739fbc..9dc65136fb 100644 --- a/substrate/srml/consensus/src/tests.rs +++ b/substrate/srml/consensus/src/tests.rs @@ -18,21 +18,20 @@ #![cfg(test)] -use primitives::{generic, testing, traits::{OnFinalise, ProvideInherent}}; +use primitives::{generic, testing::{self, UintAuthorityId}, traits::{OnFinalise, ProvideInherent}}; use runtime_io::with_externalities; -use substrate_primitives::H256; use mock::{Consensus, System, new_test_ext}; #[test] fn authorities_change_logged() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { System::initialise(&1, &Default::default(), &Default::default()); - Consensus::set_authorities(&[4, 5, 6]); + Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]); Consensus::on_finalise(1); let header = System::finalise(); assert_eq!(header.digest, testing::Digest { logs: vec![ - generic::DigestItem::AuthoritiesChange::(vec![4, 5, 6]), + generic::DigestItem::AuthoritiesChange(vec![UintAuthorityId(4).into(), UintAuthorityId(5).into(), UintAuthorityId(6).into()]), ], }); }); @@ -54,8 +53,8 @@ fn authorities_change_is_not_logged_when_not_changed() { fn authorities_change_is_not_logged_when_changed_back_to_original() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { System::initialise(&1, &Default::default(), &Default::default()); - Consensus::set_authorities(&[4, 5, 6]); - Consensus::set_authorities(&[1, 2, 3]); + Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]); + Consensus::set_authorities(&[UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); Consensus::on_finalise(1); let header = System::finalise(); assert_eq!(header.digest, testing::Digest { diff --git a/substrate/srml/grandpa/src/lib.rs b/substrate/srml/grandpa/src/lib.rs index 50ab852891..1a0d0f7c31 100644 --- a/substrate/srml/grandpa/src/lib.rs +++ b/substrate/srml/grandpa/src/lib.rs @@ -61,7 +61,7 @@ use runtime_support::dispatch::Result; use runtime_support::storage::StorageValue; use runtime_support::storage::unhashed::StorageVec; use primitives::traits::{CurrentHeight, Convert}; -use substrate_primitives::AuthorityId; +use substrate_primitives::Ed25519AuthorityId; use system::ensure_signed; use primitives::traits::MaybeSerializeDebug; @@ -105,7 +105,7 @@ impl RawLog { } impl GrandpaChangeSignal for RawLog - where N: Clone, SessionKey: Clone + Into, + where N: Clone, SessionKey: Clone + Into, { fn as_signal(&self) -> Option> { RawLog::as_signal(self).map(|(delay, next_authorities)| ScheduledChange { @@ -243,7 +243,7 @@ impl Module { } } -impl Module where AuthorityId: core::convert::From<::SessionKey> { +impl Module where Ed25519AuthorityId: core::convert::From<::SessionKey> { /// See if the digest contains any scheduled change. pub fn scrape_digest_change(log: &Log) -> Option> diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index 6992a5311f..05381e6df9 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -248,8 +248,8 @@ mod tests { use runtime_io::with_externalities; use substrate_primitives::{H256, Blake2Hasher}; use primitives::BuildStorage; - use primitives::traits::{Identity, BlakeTwo256}; - use primitives::testing::{Digest, DigestItem, Header}; + use primitives::traits::BlakeTwo256; + use primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, ConvertUintAuthorityId}; impl_outer_origin!{ pub enum Origin for Test {} @@ -260,7 +260,7 @@ mod tests { impl consensus::Trait for Test { const NOTE_OFFLINE_POSITION: u32 = 1; type Log = DigestItem; - type SessionKey = u64; + type SessionKey = UintAuthorityId; type InherentOfflineReport = (); } impl system::Trait for Test { @@ -281,7 +281,7 @@ mod tests { type OnTimestampSet = (); } impl Trait for Test { - type ConvertAccountIdToSessionKey = Identity; + type ConvertAccountIdToSessionKey = ConvertUintAuthorityId; type OnSessionChange = (); type Event = (); } @@ -294,7 +294,7 @@ mod tests { let mut t = system::GenesisConfig::::default().build_storage().unwrap().0; t.extend(consensus::GenesisConfig::{ code: vec![], - authorities: vec![1, 2, 3], + authorities: vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)], }.build_storage().unwrap().0); t.extend(timestamp::GenesisConfig::{ period: 5, @@ -309,7 +309,7 @@ mod tests { #[test] fn simple_setup_should_work() { with_externalities(&mut new_test_ext(), || { - assert_eq!(Consensus::authorities(), vec![1, 2, 3]); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1).into(), UintAuthorityId(2).into(), UintAuthorityId(3).into()]); assert_eq!(Session::length(), 2); assert_eq!(Session::validators(), vec![1, 2, 3]); }); @@ -405,25 +405,25 @@ mod tests { // Block 1: No change System::set_block_number(1); Session::check_rotate_session(1); - assert_eq!(Consensus::authorities(), vec![1, 2, 3]); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); // Block 2: Session rollover, but no change. System::set_block_number(2); Session::check_rotate_session(2); - assert_eq!(Consensus::authorities(), vec![1, 2, 3]); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); // Block 3: Set new key for validator 2; no visible change. System::set_block_number(3); - assert_ok!(Session::set_key(Origin::signed(2), 5)); - assert_eq!(Consensus::authorities(), vec![1, 2, 3]); + assert_ok!(Session::set_key(Origin::signed(2), UintAuthorityId(5))); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); Session::check_rotate_session(3); - assert_eq!(Consensus::authorities(), vec![1, 2, 3]); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); // Block 4: Session rollover, authority 2 changes. System::set_block_number(4); Session::check_rotate_session(4); - assert_eq!(Consensus::authorities(), vec![1, 5, 3]); + assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(5), UintAuthorityId(3)]); }); } } diff --git a/substrate/srml/staking/src/mock.rs b/substrate/srml/staking/src/mock.rs index cf5976f88a..b6efce154d 100644 --- a/substrate/srml/staking/src/mock.rs +++ b/substrate/srml/staking/src/mock.rs @@ -19,8 +19,8 @@ #![cfg(test)] use primitives::BuildStorage; -use primitives::{Perbill, traits::Identity}; -use primitives::testing::{Digest, DigestItem, Header}; +use primitives::Perbill; +use primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, ConvertUintAuthorityId}; use substrate_primitives::{H256, Blake2Hasher}; use runtime_io; use {GenesisConfig, Module, Trait, consensus, session, system, timestamp, balances}; @@ -35,7 +35,7 @@ pub struct Test; impl consensus::Trait for Test { const NOTE_OFFLINE_POSITION: u32 = 1; type Log = DigestItem; - type SessionKey = u64; + type SessionKey = UintAuthorityId; type InherentOfflineReport = (); } impl system::Trait for Test { @@ -58,7 +58,7 @@ impl balances::Trait for Test { type Event = (); } impl session::Trait for Test { - type ConvertAccountIdToSessionKey = Identity; + type ConvertAccountIdToSessionKey = ConvertUintAuthorityId; type OnSessionChange = Staking; type Event = (); } diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index bd349982e4..67b10e2639 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -176,8 +176,7 @@ impl RawLog { impl From> for primitives::testing::DigestItem { fn from(log: RawLog) -> primitives::testing::DigestItem { match log { - RawLog::ChangesTrieRoot(root) => primitives::generic::DigestItem::ChangesTrieRoot - ::(root), + RawLog::ChangesTrieRoot(root) => primitives::generic::DigestItem::ChangesTrieRoot(root), } } } diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index d89bb50a64..0d9360b747 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -190,7 +190,7 @@ mod tests { use substrate_primitives::H256; use runtime_primitives::BuildStorage; use runtime_primitives::traits::BlakeTwo256; - use runtime_primitives::testing::{Digest, DigestItem, Header}; + use runtime_primitives::testing::{Digest, DigestItem, Header, UintAuthorityId}; impl_outer_origin! { pub enum Origin for Test {} @@ -213,7 +213,7 @@ mod tests { impl consensus::Trait for Test { const NOTE_OFFLINE_POSITION: u32 = 1; type Log = DigestItem; - type SessionKey = u64; + type SessionKey = UintAuthorityId; type InherentOfflineReport = (); } impl Trait for Test {