diff --git a/substrate/core/client/db/src/storage_cache.rs b/substrate/core/client/db/src/storage_cache.rs index 53e4594856..7df1472ece 100644 --- a/substrate/core/client/db/src/storage_cache.rs +++ b/substrate/core/client/db/src/storage_cache.rs @@ -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, Header}; +use runtime_primitives::traits::{Block as BlockT, Header}; use state_machine::{backend::Backend as StateBackend, TrieBackend}; use log::trace; use super::{StorageCollection, ChildStorageCollection}; @@ -33,7 +33,7 @@ type ChildStorageKey = (Vec, Vec); type StorageValue = Vec; /// Shared canonical state cache. -pub struct Cache { +pub struct Cache { /// Storage cache. `None` indicates that key is known to be missing. lru_storage: LRUMap>, /// Storage hashes cache. `None` indicates that key is known to be missing. @@ -144,7 +144,7 @@ impl LRUMap { } -impl Cache { +impl Cache { /// Returns the used memory size of the storage cache in bytes. pub fn used_storage_cache_size(&self) -> usize { self.lru_storage.used_size() @@ -159,7 +159,7 @@ pub type SharedCache = Arc>>; const FIX_LRU_HASH_SIZE: usize = 65_536; /// Create a new shared cache instance with given max memory usage. -pub fn new_shared_cache( +pub fn new_shared_cache( shared_cache_size: usize, child_ratio: (usize, usize), ) -> SharedCache { @@ -202,7 +202,7 @@ struct LocalCache { } /// Cache changes. -pub struct CacheChanges { +pub struct CacheChanges { /// Shared canonical state cache. shared_cache: SharedCache, /// Local cache of values for this state. @@ -219,14 +219,14 @@ pub struct CacheChanges { /// For canonical instances local cache is accumulated and applied /// in `sync_cache` along with the change overlay. /// For non-canonical clones local cache and changes are dropped. -pub struct CachingState, B: Block> { +pub struct CachingState, B: BlockT> { /// Backing state. state: S, /// Cache data. pub cache: CacheChanges } -impl CacheChanges { +impl CacheChanges { /// Propagate local cache into the shared cache and synchronize /// the shared cache with the best block state. /// This function updates the shared cache by removing entries @@ -374,7 +374,7 @@ impl CacheChanges { } -impl, B: Block> CachingState { +impl, B: BlockT> CachingState { /// Create a new instance wrapping generic State and shared cache. pub fn new(state: S, shared_cache: SharedCache, parent_hash: Option) -> CachingState { CachingState { @@ -447,7 +447,7 @@ impl, B: Block> CachingState { } } -impl, B:Block> StateBackend for CachingState { +impl, B: BlockT> StateBackend for CachingState { type Error = S::Error; type Transaction = S::Transaction; type TrieBackendStorage = S::TrieBackendStorage; diff --git a/substrate/core/consensus/aura/src/lib.rs b/substrate/core/consensus/aura/src/lib.rs index 94b5f97ffc..b4dbd79308 100644 --- a/substrate/core/consensus/aura/src/lib.rs +++ b/substrate/core/consensus/aura/src/lib.rs @@ -47,7 +47,7 @@ use client::{ }; use runtime_primitives::{generic::{self, BlockId, OpaqueDigestItemId}, Justification}; -use runtime_primitives::traits::{Block, Header, DigestItemFor, ProvideRuntimeApi, Zero, Member}; +use runtime_primitives::traits::{Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, Zero, Member}; use primitives::Pair; use inherents::{InherentDataProviders, InherentData}; @@ -84,7 +84,7 @@ impl SlotDuration { pub fn get_or_compute(client: &C) -> CResult where A: Codec, - B: Block, + B: BlockT, C: AuxStore + ProvideRuntimeApi, C::Api: AuraApi, { @@ -140,7 +140,7 @@ pub fn start_aura( inherent_data_providers: InherentDataProviders, force_authoring: bool, ) -> Result, consensus_common::Error> where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache + AuxStore + Send + Sync, C::Api: AuraApi>, SC: SelectChain, @@ -187,7 +187,7 @@ struct AuraWorker { } impl SlotWorker for AuraWorker where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache + Sync, C::Api: AuraApi>, E: Environment, @@ -358,7 +358,7 @@ macro_rules! aura_err { }; } -fn find_pre_digest(header: &B::Header) -> Result +fn find_pre_digest(header: &B::Header) -> Result where DigestItemFor: CompatibleDigestItem

, P::Signature: Decode, P::Public: Encode + Decode + PartialEq + Clone, @@ -382,7 +382,7 @@ fn find_pre_digest(header: &B::Header) -> Result /// This digest item will always return `Some` when used with `as_aura_seal`. // // FIXME #1018 needs misbehavior types -fn check_header( +fn check_header( client: &C, slot_now: u64, mut header: B::Header, @@ -451,7 +451,7 @@ pub struct AuraVerifier { impl AuraVerifier where P: Send + Sync + 'static { - fn check_inherents( + fn check_inherents( &self, block: B, block_id: BlockId, @@ -501,7 +501,7 @@ impl AuraVerifier } #[forbid(deprecated)] -impl Verifier for AuraVerifier where +impl Verifier for AuraVerifier where C: ProvideRuntimeApi + Send + Sync + client::backend::AuxStore + ProvideCache, C::Api: BlockBuilderApi + AuraApi>, DigestItemFor: CompatibleDigestItem

, @@ -604,7 +604,7 @@ impl Verifier for AuraVerifier where fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusError> where A: Codec, - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: AuraApi, { @@ -638,7 +638,7 @@ fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusErro #[allow(deprecated)] fn authorities(client: &C, at: &BlockId) -> Result, ConsensusError> where A: Codec, - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: AuraApi, { @@ -679,7 +679,7 @@ pub fn import_queue( client: Arc, inherent_data_providers: InherentDataProviders, ) -> Result, consensus_common::Error> where - B: Block, + B: BlockT, C: 'static + ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore, C::Api: BlockBuilderApi + AuraApi>, DigestItemFor: CompatibleDigestItem

, diff --git a/substrate/core/consensus/babe/src/lib.rs b/substrate/core/consensus/babe/src/lib.rs index 454b356f7c..e1279479d9 100644 --- a/substrate/core/consensus/babe/src/lib.rs +++ b/substrate/core/consensus/babe/src/lib.rs @@ -37,7 +37,7 @@ use consensus_common::import_queue::{ use consensus_common::well_known_cache_keys::Id as CacheKeyId; use runtime_primitives::{generic, generic::{BlockId, OpaqueDigestItemId}, Justification}; use runtime_primitives::traits::{ - Block, Header, DigestItemFor, ProvideRuntimeApi, + Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, SimpleBitOps, Zero, }; use std::{sync::Arc, u64, fmt::{Debug, Display}, time::{Instant, Duration}}; @@ -95,7 +95,7 @@ pub struct Config(slots::SlotDuration); impl Config { /// Either fetch the slot duration from disk or compute it from the genesis /// state. - pub fn get_or_compute(client: &C) -> CResult + pub fn get_or_compute(client: &C) -> CResult where C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi, { @@ -185,7 +185,7 @@ pub fn start_babe(BabeParams { impl Future, consensus_common::Error, > where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: BabeApi, SC: SelectChain, @@ -228,7 +228,7 @@ struct BabeWorker { } impl SlotWorker for BabeWorker where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: BabeApi, E: Environment, @@ -418,7 +418,7 @@ macro_rules! babe_err { }; } -fn find_pre_digest(header: &B::Header) -> Result +fn find_pre_digest(header: &B::Header) -> Result where DigestItemFor: CompatibleDigestItem, { let mut pre_digest: Option<_> = None; @@ -443,7 +443,7 @@ fn find_pre_digest(header: &B::Header) -> Result( +fn check_header( client: &C, slot_now: u64, mut header: B::Header, @@ -531,7 +531,7 @@ pub struct BabeVerifier { } impl BabeVerifier { - fn check_inherents( + fn check_inherents( &self, block: B, block_id: BlockId, @@ -587,7 +587,7 @@ fn median_algorithm( } } -impl Verifier for BabeVerifier where +impl Verifier for BabeVerifier where C: ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache, C::Api: BlockBuilderApi + BabeApi, DigestItemFor: CompatibleDigestItem, @@ -701,7 +701,7 @@ fn authorities(client: &C, at: &BlockId) -> Result< Vec, ConsensusError, > where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: BabeApi, { @@ -796,7 +796,7 @@ fn claim_slot( } fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusError> where - B: Block, + B: BlockT, C: ProvideRuntimeApi + ProvideCache, C::Api: BabeApi, { @@ -834,7 +834,7 @@ pub fn import_queue( client: Arc, inherent_data_providers: InherentDataProviders, ) -> Result<(BabeImportQueue, BabeLink), consensus_common::Error> where - B: Block, + B: BlockT, C: 'static + ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore, C::Api: BlockBuilderApi + BabeApi, DigestItemFor: CompatibleDigestItem, diff --git a/substrate/core/consensus/common/src/lib.rs b/substrate/core/consensus/common/src/lib.rs index e445d974d8..1b9f31bbbc 100644 --- a/substrate/core/consensus/common/src/lib.rs +++ b/substrate/core/consensus/common/src/lib.rs @@ -31,7 +31,7 @@ use std::sync::Arc; use std::time::Duration; -use runtime_primitives::traits::{Block, DigestFor}; +use runtime_primitives::traits::{Block as BlockT, DigestFor}; use futures::prelude::*; pub use inherents::InherentData; @@ -53,7 +53,7 @@ pub use block_import::{ pub use select_chain::SelectChain; /// Environment producer for a Consensus instance. Creates proposer instance and communication streams. -pub trait Environment { +pub trait Environment { /// The proposer type this creates. type Proposer: Proposer; /// Error which can occur upon creation. @@ -71,7 +71,7 @@ pub trait Environment { /// block. /// /// Proposers are generic over bits of "consensus data" which are engine-specific. -pub trait Proposer { +pub trait Proposer { /// Error type which can occur when proposing or evaluating. type Error: From + ::std::fmt::Debug + 'static; /// Future that resolves to a committed proposal. diff --git a/substrate/core/consensus/rhd/src/lib.rs b/substrate/core/consensus/rhd/src/lib.rs index 4a3e03759b..1f6582d077 100644 --- a/substrate/core/consensus/rhd/src/lib.rs +++ b/substrate/core/consensus/rhd/src/lib.rs @@ -150,7 +150,7 @@ pub type Misbehavior = rhododendron::Misbehavior; pub type SharedOfflineTracker = Arc>; /// A proposer for a rhododendron instance. This must implement the base proposer logic. -pub trait LocalProposer: BaseProposer { +pub trait LocalProposer: BaseProposer { /// Import witnessed rhododendron misbehavior. fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, Misbehavior)>); @@ -224,7 +224,7 @@ struct RoundCache { } /// Instance of BFT agreement. -struct BftInstance { +struct BftInstance { key: Arc, authorities: Vec, parent_hash: B::Hash, @@ -233,7 +233,7 @@ struct BftInstance { proposer: P, } -impl> BftInstance +impl> BftInstance where B: Clone + Eq, B::Hash: ::std::hash::Hash @@ -262,7 +262,7 @@ impl> BftInstance } } -impl> rhododendron::Context for BftInstance +impl> rhododendron::Context for BftInstance where B: Clone + Eq, B::Hash: ::std::hash::Hash, @@ -465,7 +465,7 @@ impl Drop for AgreementHandle { /// is notified of. /// /// This assumes that it is being run in the context of a tokio runtime. -pub struct BftService { +pub struct BftService { client: Arc, live_agreement: Mutex>, round_cache: Arc>>, @@ -638,14 +638,14 @@ impl BftService /// This stream is localized to a specific parent block-hash, as all messages /// will be signed in a way that accounts for it. When using this with /// `BftService::build_upon`, the user should take care to use the same hash as for that. -pub struct CheckedStream { +pub struct CheckedStream { inner: S, local_id: AuthorityId, authorities: Vec, parent_hash: B::Hash, } -impl CheckedStream { +impl CheckedStream { /// Construct a new checked stream. pub fn new( inner: S, @@ -662,7 +662,7 @@ impl CheckedStream { } } -impl>> Stream for CheckedStream +impl>> Stream for CheckedStream where S::Error: From, { type Item = Communication; @@ -780,7 +780,7 @@ fn check_justification_signed_message( /// Provide all valid authorities. /// /// On failure, returns the justification back. -pub fn check_justification( +pub fn check_justification( authorities: &[AuthorityId], parent: B::Hash, just: UncheckedJustification @@ -795,9 +795,11 @@ pub fn check_justification( /// Provide all valid authorities. /// /// On failure, returns the justification back. -pub fn check_prepare_justification(authorities: &[AuthorityId], parent: B::Hash, just: UncheckedJustification) - -> Result, UncheckedJustification> -{ +pub fn check_prepare_justification( + authorities: &[AuthorityId], + parent: B::Hash, + just: UncheckedJustification +) -> Result, UncheckedJustification> { let vote: Action = Action::Prepare(just.0.round_number as u32, just.0.digest.clone()); let message = localized_encode(parent, vote); @@ -824,7 +826,7 @@ pub fn check_proposal( /// Check vote message signatures and authority. /// Provide all valid authorities. -pub fn check_vote( +pub fn check_vote( authorities: &[AuthorityId], parent_hash: &B::Hash, vote: &rhododendron::LocalizedVote) @@ -842,7 +844,11 @@ pub fn check_vote( check_action::(action, parent_hash, &vote.signature) } -fn check_action(action: Action, parent_hash: &B::Hash, sig: &LocalizedSignature) -> Result<(), Error> { +fn check_action( + action: Action, + parent_hash: &B::Hash, + sig: &LocalizedSignature +) -> Result<(), Error> { let message = localized_encode(*parent_hash, action); if ed25519::Pair::verify(&sig.signature, &message, &sig.signer) { Ok(()) @@ -981,7 +987,8 @@ impl consensus::Environment<::Block> for ProposerFac let id = BlockId::hash(parent_hash); let random_seed = self.client.random_seed(&id)?; - let random_seed = <<::Block as BlockT>::Header as HeaderT>::Hashing::hash(random_seed.as_ref()); + let random_seed = <<::Block as BlockT>::Header as HeaderT> + ::Hashing::hash(random_seed.as_ref()); let validators = self.client.validators(&id)?; self.offline.write().note_new_block(&validators[..]); @@ -1225,7 +1232,10 @@ impl LocalProposer<::Block> for Proposer where proposer } - fn import_misbehavior(&self, _misbehavior: Vec<(AuthorityId, Misbehavior<<::Block as BlockT>::Hash>)>) { + fn import_misbehavior( + &self, + _misbehavior: Vec<(AuthorityId, Misbehavior<<::Block as BlockT>::Hash>)> + ) { use rhododendron::Misbehavior as GenericMisbehavior; use runtime_primitives::bft::{MisbehaviorKind, MisbehaviorReport}; use node_runtime::{Call, UncheckedExtrinsic, ConsensusCall}; diff --git a/substrate/core/consensus/slots/src/lib.rs b/substrate/core/consensus/slots/src/lib.rs index b265161923..dd6d55345b 100644 --- a/substrate/core/consensus/slots/src/lib.rs +++ b/substrate/core/consensus/slots/src/lib.rs @@ -38,12 +38,12 @@ use futures::{ use inherents::{InherentData, InherentDataProviders}; use log::{debug, error, info, warn}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{ApiRef, Block, ProvideRuntimeApi}; +use runtime_primitives::traits::{ApiRef, Block as BlockT, ProvideRuntimeApi}; use std::fmt::Debug; use std::ops::Deref; /// A worker that should be invoked at every new slot. -pub trait SlotWorker { +pub trait SlotWorker { /// The type of the future that will be returned when a new slot is /// triggered. type OnSlot: IntoFuture; @@ -78,7 +78,7 @@ pub fn start_slot_worker( timestamp_extractor: SC, ) -> impl Future where - B: Block, + B: BlockT, C: SelectChain + Clone, W: SlotWorker, SO: SyncOracle + Send + Clone, @@ -193,7 +193,7 @@ impl SlotDuration { /// /// `slot_key` is marked as `'static`, as it should really be a /// compile-time constant. - pub fn get_or_compute(client: &C, cb: CB) -> ::client::error::Result where + pub fn get_or_compute(client: &C, cb: CB) -> ::client::error::Result where C: client::backend::AuxStore, C: ProvideRuntimeApi, CB: FnOnce(ApiRef, &BlockId) -> ::client::error::Result, diff --git a/substrate/core/network/src/protocol/sync.rs b/substrate/core/network/src/protocol/sync.rs index 5405073a0e..3cc4b8243c 100644 --- a/substrate/core/network/src/protocol/sync.rs +++ b/substrate/core/network/src/protocol/sync.rs @@ -42,7 +42,7 @@ use log::{debug, trace, warn, info, error}; use runtime_primitives::{ Justification, generic::BlockId, - traits::{Block, Header, NumberFor, Zero, One, CheckedSub, SaturatedConversion} + traits::{Block as BlockT, Header, NumberFor, Zero, One, CheckedSub, SaturatedConversion} }; use std::{fmt, ops::Range, collections::{HashMap, HashSet, VecDeque}, sync::Arc}; @@ -94,7 +94,7 @@ const BAD_JUSTIFICATION_REPUTATION_CHANGE: i32 = -(1 << 16); /// The main data structure which contains all the state for a chains /// active syncing strategy. -pub struct ChainSync { +pub struct ChainSync { /// Chain client. client: Arc>, /// The active peers that we are using to sync and their PeerSync status @@ -124,7 +124,7 @@ pub struct ChainSync { /// All the data we have about a Peer that we are trying to sync with #[derive(Debug, Clone)] -pub struct PeerSync { +pub struct PeerSync { /// The common number is the block number that is a common point of /// ancestry for both our chains (as far as we know). pub common_number: NumberFor, @@ -142,7 +142,7 @@ pub struct PeerSync { /// The sync status of a peer we are trying to sync with #[derive(Debug)] -pub struct PeerInfo { +pub struct PeerInfo { /// Their best block hash. pub best_hash: B::Hash, /// Their best block number. @@ -154,7 +154,7 @@ pub struct PeerInfo { /// Generally two categories, "busy" or `Available`. If busy, the enum /// defines what we are busy with. #[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum PeerSyncState { +pub enum PeerSyncState { /// Available for sync requests. Available, /// Searching for ancestors the Peer has in common with us. @@ -171,7 +171,7 @@ pub enum PeerSyncState { DownloadingFinalityProof(B::Hash) } -impl PeerSyncState { +impl PeerSyncState { pub fn is_available(&self) -> bool { if let PeerSyncState::Available = self { true @@ -192,7 +192,7 @@ pub enum SyncState { /// Syncing status and statistics. #[derive(Clone)] -pub struct Status { +pub struct Status { /// Current global sync state. pub state: SyncState, /// Target sync block number. @@ -215,7 +215,7 @@ impl std::error::Error for BadPeer {} /// Result of [`ChainSync::on_block_data`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum OnBlockData { +pub enum OnBlockData { /// The block should be imported. Import(BlockOrigin, Vec>), /// A new block request needs to be made to the given peer. @@ -224,7 +224,7 @@ pub enum OnBlockData { /// Result of [`ChainSync::on_block_announce`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum OnBlockAnnounce { +pub enum OnBlockAnnounce { /// The announcement does not require further handling. Nothing, /// The announcement header should be imported. @@ -235,7 +235,7 @@ pub enum OnBlockAnnounce { /// Result of [`ChainSync::on_block_justification`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum OnBlockJustification { +pub enum OnBlockJustification { /// The justification needs no further handling. Nothing, /// The justification should be imported. @@ -249,7 +249,7 @@ pub enum OnBlockJustification { /// Result of [`ChainSync::on_block_finality_proof`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum OnBlockFinalityProof { +pub enum OnBlockFinalityProof { /// The proof needs no further handling. Nothing, /// The proof should be imported. @@ -261,7 +261,7 @@ pub enum OnBlockFinalityProof { } } -impl ChainSync { +impl ChainSync { /// Create a new instance. pub fn new( role: Roles, @@ -1097,7 +1097,7 @@ impl ChainSync { /// Request the ancestry for a block. Sends a request for header and justification for the given /// block number. Used during ancestry search. -fn ancestry_request(block: NumberFor) -> BlockRequest { +fn ancestry_request(block: NumberFor) -> BlockRequest { message::generic::BlockRequest { id: 0, fields: BlockAttributes::HEADER | BlockAttributes::JUSTIFICATION, @@ -1111,7 +1111,7 @@ fn ancestry_request(block: NumberFor) -> BlockRequest { /// The ancestor search state expresses which algorithm, and its stateful parameters, we are using to /// try to find an ancestor block #[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum AncestorSearchState { +pub enum AncestorSearchState { /// Use exponential backoff to find an ancestor, then switch to binary search. /// We keep track of the exponent. ExponentialBackoff(NumberFor), @@ -1127,7 +1127,7 @@ pub enum AncestorSearchState { /// /// When we've found a block hash mismatch we then fall back to a binary search between the two /// last known points to find the common block closest to the tip. -fn handle_ancestor_search_state( +fn handle_ancestor_search_state( state: &AncestorSearchState, curr_block_num: NumberFor, block_hash_match: bool @@ -1169,7 +1169,7 @@ fn handle_ancestor_search_state( } /// Get a new block request for the peer if any. -fn peer_block_request( +fn peer_block_request( id: &PeerId, peer: &PeerSync, blocks: &mut BlockCollection,