diff --git a/substrate/bin/node/inspect/src/lib.rs b/substrate/bin/node/inspect/src/lib.rs index 5764e0f05c..65dfecdf77 100644 --- a/substrate/bin/node/inspect/src/lib.rs +++ b/substrate/bin/node/inspect/src/lib.rs @@ -33,13 +33,13 @@ use sp_blockchain::HeaderBackend; use sp_core::hexdisplay::HexDisplay; use sp_runtime::{ generic::BlockId, - traits::{Block, Hash, HashFor, NumberFor}, + traits::{Block, Hash, HashingFor, NumberFor}, }; use std::{fmt, fmt::Debug, marker::PhantomData, str::FromStr}; /// A helper type for a generic block input. pub type BlockAddressFor = - BlockAddress< as Hash>::Output, NumberFor>; + BlockAddress< as Hash>::Output, NumberFor>; /// A Pretty formatter implementation. pub trait PrettyPrinter { @@ -166,7 +166,7 @@ impl> Inspector /// Get a pretty-printed extrinsic. pub fn extrinsic( &self, - input: ExtrinsicAddress< as Hash>::Output, NumberFor>, + input: ExtrinsicAddress< as Hash>::Output, NumberFor>, ) -> Result { struct ExtrinsicPrinter<'a, A: Block, B>(A::Extrinsic, &'a B); impl<'a, A: Block, B: PrettyPrinter> fmt::Display for ExtrinsicPrinter<'a, A, B> { diff --git a/substrate/bin/node/rpc/src/lib.rs b/substrate/bin/node/rpc/src/lib.rs index a2ae46904d..6d8aa5ff0a 100644 --- a/substrate/bin/node/rpc/src/lib.rs +++ b/substrate/bin/node/rpc/src/lib.rs @@ -125,7 +125,7 @@ where P: TransactionPool + 'static, SC: SelectChain + 'static, B: sc_client_api::Backend + Send + Sync + 'static, - B::State: sc_client_api::backend::StateBackend>, + B::State: sc_client_api::backend::StateBackend>, { use mmr_rpc::{Mmr, MmrApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; diff --git a/substrate/client/api/src/backend.rs b/substrate/client/api/src/backend.rs index b88feafb6c..465e198847 100644 --- a/substrate/client/api/src/backend.rs +++ b/substrate/client/api/src/backend.rs @@ -25,7 +25,7 @@ use parking_lot::RwLock; use sp_consensus::BlockOrigin; use sp_core::offchain::OffchainStorage; use sp_runtime::{ - traits::{Block as BlockT, HashFor, NumberFor}, + traits::{Block as BlockT, HashingFor, NumberFor}, Justification, Justifications, StateVersion, Storage, }; use sp_state_machine::{ @@ -42,7 +42,7 @@ pub use sp_state_machine::{Backend as StateBackend, KeyValueStates}; pub type StateBackendFor = >::State; /// Extracts the transaction for the given state backend. -pub type TransactionForSB = >>::Transaction; +pub type TransactionForSB = >>::Transaction; /// Extracts the transaction for the given backend. pub type TransactionFor = TransactionForSB, Block>; @@ -161,7 +161,7 @@ impl NewBlockState { /// Keeps hold if the inserted block state and data. pub trait BlockImportOperation { /// Associated state backend type. - type State: StateBackend>; + type State: StateBackend>; /// Returns pending state. /// @@ -315,16 +315,16 @@ pub trait AuxStore { /// An `Iterator` that iterates keys in a given block under a prefix. pub struct KeysIter where - State: StateBackend>, + State: StateBackend>, Block: BlockT, { - inner: >>::RawIter, + inner: >>::RawIter, state: State, } impl KeysIter where - State: StateBackend>, + State: StateBackend>, Block: BlockT, { /// Create a new iterator over storage keys. @@ -361,7 +361,7 @@ where impl Iterator for KeysIter where Block: BlockT, - State: StateBackend>, + State: StateBackend>, { type Item = StorageKey; @@ -373,17 +373,17 @@ where /// An `Iterator` that iterates keys and values in a given block under a prefix. pub struct PairsIter where - State: StateBackend>, + State: StateBackend>, Block: BlockT, { - inner: >>::RawIter, + inner: >>::RawIter, state: State, } impl Iterator for PairsIter where Block: BlockT, - State: StateBackend>, + State: StateBackend>, { type Item = (StorageKey, StorageData); @@ -397,7 +397,7 @@ where impl PairsIter where - State: StateBackend>, + State: StateBackend>, Block: BlockT, { /// Create a new iterator over storage key and value pairs. @@ -506,11 +506,11 @@ pub trait Backend: AuxStore + Send + Sync { /// Associated blockchain backend type. type Blockchain: BlockchainBackend; /// Associated state backend type. - type State: StateBackend> + type State: StateBackend> + Send + AsTrieBackend< - HashFor, - TrieBackendStorage = >>::TrieBackendStorage, + HashingFor, + TrieBackendStorage = >>::TrieBackendStorage, >; /// Offchain workers local storage. type OffchainStorage: OffchainStorage; diff --git a/substrate/client/api/src/in_mem.rs b/substrate/client/api/src/in_mem.rs index 9ea5169d78..711d739c16 100644 --- a/substrate/client/api/src/in_mem.rs +++ b/substrate/client/api/src/in_mem.rs @@ -25,7 +25,7 @@ use sp_core::{ }; use sp_runtime::{ generic::BlockId, - traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor, Zero}, + traits::{Block as BlockT, HashingFor, Header as HeaderT, NumberFor, Zero}, Justification, Justifications, StateVersion, Storage, }; use sp_state_machine::{ @@ -479,9 +479,10 @@ impl backend::AuxStore for Blockchain { /// In-memory operation. pub struct BlockImportOperation { pending_block: Option>, - old_state: InMemoryBackend>, - new_state: - Option<> as StateBackend>>::Transaction>, + old_state: InMemoryBackend>, + new_state: Option< + > as StateBackend>>::Transaction, + >, aux: Vec<(Vec, Option>)>, finalized_blocks: Vec<(Block::Hash, Option)>, set_head: Option, @@ -517,7 +518,7 @@ impl BlockImportOperation { } impl backend::BlockImportOperation for BlockImportOperation { - type State = InMemoryBackend>; + type State = InMemoryBackend>; fn state(&self) -> sp_blockchain::Result> { Ok(Some(&self.old_state)) @@ -539,7 +540,7 @@ impl backend::BlockImportOperation for BlockImportOperatio fn update_db_storage( &mut self, - update: > as StateBackend>>::Transaction, + update: > as StateBackend>>::Transaction, ) -> sp_blockchain::Result<()> { self.new_state = Some(update); Ok(()) @@ -606,7 +607,7 @@ impl backend::BlockImportOperation for BlockImportOperatio /// > **Warning**: Doesn't support all the features necessary for a proper database. Only use this /// > struct for testing purposes. Do **NOT** use in production. pub struct Backend { - states: RwLock>>>, + states: RwLock>>>, blockchain: Blockchain, import_lock: RwLock<()>, pinned_blocks: RwLock>, @@ -661,7 +662,7 @@ impl backend::AuxStore for Backend { impl backend::Backend for Backend { type BlockImportOperation = BlockImportOperation; type Blockchain = Blockchain; - type State = InMemoryBackend>; + type State = InMemoryBackend>; type OffchainStorage = OffchainStorage; fn begin_operation(&self) -> sp_blockchain::Result { diff --git a/substrate/client/basic-authorship/src/basic_authorship.rs b/substrate/client/basic-authorship/src/basic_authorship.rs index d1921b3413..55aadb07e6 100644 --- a/substrate/client/basic-authorship/src/basic_authorship.rs +++ b/substrate/client/basic-authorship/src/basic_authorship.rs @@ -304,7 +304,10 @@ where .propose_with(inherent_data, inherent_digests, deadline, block_size_limit) .await; if tx.send(res).is_err() { - trace!(target: LOG_TARGET, "Could not send block production result to proposer!"); + trace!( + target: LOG_TARGET, + "Could not send block production result to proposer!" + ); } }), ); @@ -384,7 +387,10 @@ where for inherent in inherents { match block_builder.push(inherent) { Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => { - warn!(target: LOG_TARGET, "⚠️ Dropping non-mandatory inherent from overweight block.") + warn!( + target: LOG_TARGET, + "⚠️ Dropping non-mandatory inherent from overweight block." + ) }, Err(ApplyExtrinsicFailed(Validity(e))) if e.was_mandatory() => { error!( @@ -393,7 +399,10 @@ where return Err(ApplyExtrinsicFailed(Validity(e))) }, Err(e) => { - warn!(target: LOG_TARGET, "❗️ Inherent extrinsic returned unexpected error: {}. Dropping.", e); + warn!( + target: LOG_TARGET, + "❗️ Inherent extrinsic returned unexpected error: {}. Dropping.", e + ); }, Ok(_) => {}, } @@ -449,9 +458,10 @@ where let now = (self.now)(); if now > deadline { - debug!(target: LOG_TARGET, + debug!( + target: LOG_TARGET, "Consensus deadline reached when pushing block transactions, \ - proceeding with proposing." + proceeding with proposing." ); break EndProposingReason::HitDeadline } @@ -465,21 +475,26 @@ where pending_iterator.report_invalid(&pending_tx); if skipped < MAX_SKIPPED_TRANSACTIONS { skipped += 1; - debug!(target: LOG_TARGET, + debug!( + target: LOG_TARGET, "Transaction would overflow the block size limit, \ - but will try {} more transactions before quitting.", + but will try {} more transactions before quitting.", MAX_SKIPPED_TRANSACTIONS - skipped, ); continue } else if now < soft_deadline { - debug!(target: LOG_TARGET, + debug!( + target: LOG_TARGET, "Transaction would overflow the block size limit, \ - but we still have time before the soft deadline, so \ - we will try a bit more." + but we still have time before the soft deadline, so \ + we will try a bit more." ); continue } else { - debug!(target: LOG_TARGET, "Reached block size limit, proceeding with proposing."); + debug!( + target: LOG_TARGET, + "Reached block size limit, proceeding with proposing." + ); break EndProposingReason::HitBlockSizeLimit } } @@ -504,22 +519,28 @@ where so we will try a bit more before quitting." ); } else { - debug!(target: LOG_TARGET, "Reached block weight limit, proceeding with proposing."); + debug!( + target: LOG_TARGET, + "Reached block weight limit, proceeding with proposing." + ); break EndProposingReason::HitBlockWeightLimit } }, Err(e) => { pending_iterator.report_invalid(&pending_tx); - debug!(target: LOG_TARGET, "[{:?}] Invalid transaction: {}", pending_tx_hash, e); + debug!( + target: LOG_TARGET, + "[{:?}] Invalid transaction: {}", pending_tx_hash, e + ); unqueue_invalid.push(pending_tx_hash); }, } }; if matches!(end_reason, EndProposingReason::HitBlockSizeLimit) && !transaction_pushed { - warn!(target: LOG_TARGET, - "Hit block size limit of `{}` without including any transaction!", - block_size_limit, + warn!( + target: LOG_TARGET, + "Hit block size limit of `{}` without including any transaction!", block_size_limit, ); } diff --git a/substrate/client/block-builder/src/lib.rs b/substrate/client/block-builder/src/lib.rs index 7c57c77f3d..5d692c4bda 100644 --- a/substrate/client/block-builder/src/lib.rs +++ b/substrate/client/block-builder/src/lib.rs @@ -35,7 +35,7 @@ use sp_blockchain::{ApplyExtrinsicFailed, Error}; use sp_core::traits::CallContext; use sp_runtime::{ legacy, - traits::{Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One}, + traits::{Block as BlockT, Hash, HashingFor, Header as HeaderT, NumberFor, One}, Digest, }; @@ -85,7 +85,7 @@ impl From for RecordProof { /// backend to get the state of the block. Furthermore an optional `proof` is included which /// can be used to proof that the build block contains the expected data. The `proof` will /// only be set when proof recording was activated. -pub struct BuiltBlock>> { +pub struct BuiltBlock>> { /// The actual block that was build. pub block: Block, /// The changes that need to be applied to the backend to get the state of the build block. @@ -94,7 +94,7 @@ pub struct BuiltBlock, } -impl>> +impl>> BuiltBlock { /// Convert into the inner values. @@ -236,7 +236,7 @@ where debug_assert_eq!( header.extrinsics_root().clone(), - HashFor::::ordered_trie_root( + HashingFor::::ordered_trie_root( self.extrinsics.iter().map(Encode::encode).collect(), sp_runtime::StateVersion::V0, ), diff --git a/substrate/client/consensus/common/src/block_import.rs b/substrate/client/consensus/common/src/block_import.rs index 70bf0283af..b84a45d533 100644 --- a/substrate/client/consensus/common/src/block_import.rs +++ b/substrate/client/consensus/common/src/block_import.rs @@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize}; use sp_runtime::{ - traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor}, + traits::{Block as BlockT, HashingFor, Header as HeaderT, NumberFor}, DigestItem, Justification, Justifications, }; use std::{any::Any, borrow::Cow, collections::HashMap, sync::Arc}; @@ -121,7 +121,7 @@ pub struct BlockCheckParams { /// Precomputed storage. pub enum StorageChanges { /// Changes coming from block execution. - Changes(sp_state_machine::StorageChanges>), + Changes(sp_state_machine::StorageChanges>), /// Whole new state. Import(ImportedState), } diff --git a/substrate/client/consensus/slots/src/lib.rs b/substrate/client/consensus/slots/src/lib.rs index 5057e7858a..533ddb54e8 100644 --- a/substrate/client/consensus/slots/src/lib.rs +++ b/substrate/client/consensus/slots/src/lib.rs @@ -41,7 +41,7 @@ use sp_arithmetic::traits::BaseArithmetic; use sp_consensus::{Proposal, Proposer, SelectChain, SyncOracle}; use sp_consensus_slots::{Slot, SlotDuration}; use sp_inherents::CreateInherentDataProviders; -use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT}; +use sp_runtime::traits::{Block as BlockT, HashingFor, Header as HeaderT}; use std::{ fmt::Debug, ops::Deref, @@ -54,7 +54,7 @@ const LOG_TARGET: &str = "slots"; /// /// See [`sp_state_machine::StorageChanges`] for more information. pub type StorageChanges = - sp_state_machine::StorageChanges>; + sp_state_machine::StorageChanges>; /// The result of [`SlotWorker::on_slot`]. #[derive(Debug, Clone)] diff --git a/substrate/client/db/src/bench.rs b/substrate/client/db/src/bench.rs index 5bec03cb10..9307a63ad4 100644 --- a/substrate/client/db/src/bench.rs +++ b/substrate/client/db/src/bench.rs @@ -28,7 +28,7 @@ use sp_core::{ storage::{ChildInfo, TrackedStorageKey}, }; use sp_runtime::{ - traits::{Block as BlockT, HashFor}, + traits::{Block as BlockT, HashingFor}, StateVersion, Storage, }; use sp_state_machine::{ @@ -52,9 +52,9 @@ struct StorageDb { _block: std::marker::PhantomData, } -impl sp_state_machine::Storage> for StorageDb { +impl sp_state_machine::Storage> for StorageDb { fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result, String> { - let prefixed_key = prefixed_key::>(key, prefix); + let prefixed_key = prefixed_key::>(key, prefix); self.db .get(0, &prefixed_key) .map_err(|e| format!("Database backend error: {:?}", e)) @@ -84,19 +84,19 @@ pub struct BenchmarkingState { record: Cell>>, key_tracker: Arc>, whitelist: RefCell>, - proof_recorder: Option>>, + proof_recorder: Option>>, proof_recorder_root: Cell, - shared_trie_cache: SharedTrieCache>, + shared_trie_cache: SharedTrieCache>, } /// A raw iterator over the `BenchmarkingState`. pub struct RawIter { - inner: as StateBackend>>::RawIter, + inner: as StateBackend>>::RawIter, child_trie: Option>, key_tracker: Arc>, } -impl StorageIterator> for RawIter { +impl StorageIterator> for RawIter { type Backend = BenchmarkingState; type Error = String; @@ -138,8 +138,8 @@ impl BenchmarkingState { ) -> Result { let state_version = sp_runtime::StateVersion::default(); let mut root = B::Hash::default(); - let mut mdb = MemoryDB::>::default(); - sp_trie::trie_types::TrieDBMutBuilderV1::>::new(&mut mdb, &mut root).build(); + let mut mdb = MemoryDB::>::default(); + sp_trie::trie_types::TrieDBMutBuilderV1::>::new(&mut mdb, &mut root).build(); let mut state = BenchmarkingState { state: RefCell::new(None), @@ -341,10 +341,10 @@ fn state_err() -> String { "State is not open".into() } -impl StateBackend> for BenchmarkingState { - type Error = as StateBackend>>::Error; - type Transaction = as StateBackend>>::Transaction; - type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; +impl StateBackend> for BenchmarkingState { + type Error = as StateBackend>>::Error; + type Transaction = as StateBackend>>::Transaction; + type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; type RawIter = RawIter; fn storage(&self, key: &[u8]) -> Result>, Self::Error> { @@ -459,7 +459,7 @@ impl StateBackend> for BenchmarkingState { fn commit( &self, - storage_root: as Hasher>::Out, + storage_root: as Hasher>::Out, mut transaction: Self::Transaction, main_storage_changes: StorageCollection, child_storage_changes: ChildStorageCollection, @@ -614,7 +614,8 @@ impl StateBackend> for BenchmarkingState { log::debug!(target: "benchmark", "Some proof size: {}", &proof_size); proof_size } else { - if let Some(size) = proof.encoded_compact_size::>(proof_recorder_root) { + if let Some(size) = proof.encoded_compact_size::>(proof_recorder_root) + { size as u32 } else if proof_recorder_root == self.root.get() { log::debug!(target: "benchmark", "No changes - no proof"); diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index 21a03582ca..aba5b0829b 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -79,7 +79,7 @@ use sp_database::Transaction; use sp_runtime::{ generic::BlockId, traits::{ - Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One, SaturatedConversion, + Block as BlockT, Hash, HashingFor, Header as HeaderT, NumberFor, One, SaturatedConversion, Zero, }, Justification, Justifications, StateVersion, Storage, @@ -102,12 +102,12 @@ const CACHE_HEADERS: usize = 8; /// DB-backed patricia trie state, transaction type is an overlay of changes to commit. pub type DbState = - sp_state_machine::TrieBackend>>, HashFor>; + sp_state_machine::TrieBackend>>, HashingFor>; /// Builder for [`DbState`]. pub type DbStateBuilder = sp_state_machine::TrieBackendBuilder< - Arc>>, - HashFor, + Arc>>, + HashingFor, >; /// Length of a [`DbHash`]. @@ -162,12 +162,12 @@ impl std::fmt::Debug for RefTrackingState { /// A raw iterator over the `RefTrackingState`. pub struct RawIter { - inner: as StateBackend>>::RawIter, + inner: as StateBackend>>::RawIter, } -impl StorageIterator> for RawIter { +impl StorageIterator> for RawIter { type Backend = RefTrackingState; - type Error = as StateBackend>>::Error; + type Error = as StateBackend>>::Error; fn next_key(&mut self, backend: &Self::Backend) -> Option> { self.inner.next_key(&backend.state) @@ -185,10 +185,10 @@ impl StorageIterator> for RawIter { } } -impl StateBackend> for RefTrackingState { - type Error = as StateBackend>>::Error; - type Transaction = as StateBackend>>::Transaction; - type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; +impl StateBackend> for RefTrackingState { + type Error = as StateBackend>>::Error; + type Transaction = as StateBackend>>::Transaction; + type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; type RawIter = RawIter; fn storage(&self, key: &[u8]) -> Result>, Self::Error> { @@ -269,12 +269,12 @@ impl StateBackend> for RefTrackingState { } } -impl AsTrieBackend> for RefTrackingState { - type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; +impl AsTrieBackend> for RefTrackingState { + type TrieBackendStorage = as StateBackend>>::TrieBackendStorage; fn as_trie_backend( &self, - ) -> &sp_state_machine::TrieBackend> { + ) -> &sp_state_machine::TrieBackend> { &self.state.as_trie_backend() } } @@ -818,7 +818,7 @@ impl HeaderMetadata for BlockchainDb { /// Database transaction pub struct BlockImportOperation { old_state: RecordStatsState, Block>, - db_updates: PrefixedMemoryDB>, + db_updates: PrefixedMemoryDB>, storage_updates: StorageCollection, child_storage_updates: ChildStorageCollection, offchain_storage_updates: OffchainChangesCollection, @@ -907,7 +907,10 @@ impl sc_client_api::backend::BlockImportOperation Ok(()) } - fn update_db_storage(&mut self, update: PrefixedMemoryDB>) -> ClientResult<()> { + fn update_db_storage( + &mut self, + update: PrefixedMemoryDB>, + ) -> ClientResult<()> { self.db_updates = update; Ok(()) } @@ -986,10 +989,10 @@ struct StorageDb { prefix_keys: bool, } -impl sp_state_machine::Storage> for StorageDb { +impl sp_state_machine::Storage> for StorageDb { fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result, String> { if self.prefix_keys { - let key = prefixed_key::>(key, prefix); + let key = prefixed_key::>(key, prefix); self.state_db.get(&key, self) } else { self.state_db.get(key.as_ref(), self) @@ -1009,16 +1012,16 @@ impl sc_state_db::NodeDb for StorageDb { struct DbGenesisStorage { root: Block::Hash, - storage: PrefixedMemoryDB>, + storage: PrefixedMemoryDB>, } impl DbGenesisStorage { - pub fn new(root: Block::Hash, storage: PrefixedMemoryDB>) -> Self { + pub fn new(root: Block::Hash, storage: PrefixedMemoryDB>) -> Self { DbGenesisStorage { root, storage } } } -impl sp_state_machine::Storage> for DbGenesisStorage { +impl sp_state_machine::Storage> for DbGenesisStorage { fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result, String> { use hash_db::HashDB; Ok(self.storage.get(key, prefix)) @@ -1030,14 +1033,15 @@ struct EmptyStorage(pub Block::Hash); impl EmptyStorage { pub fn new() -> Self { let mut root = Block::Hash::default(); - let mut mdb = MemoryDB::>::default(); + let mut mdb = MemoryDB::>::default(); // both triedbmut are the same on empty storage. - sp_trie::trie_types::TrieDBMutBuilderV1::>::new(&mut mdb, &mut root).build(); + sp_trie::trie_types::TrieDBMutBuilderV1::>::new(&mut mdb, &mut root) + .build(); EmptyStorage(root) } } -impl sp_state_machine::Storage> for EmptyStorage { +impl sp_state_machine::Storage> for EmptyStorage { fn get(&self, _key: &Block::Hash, _prefix: Prefix) -> Result, String> { Ok(None) } @@ -1098,7 +1102,7 @@ pub struct Backend { io_stats: FrozenForDuration<(kvdb::IoStats, StateUsageInfo)>, state_usage: Arc, genesis_state: RwLock>>>, - shared_trie_cache: Option>>, + shared_trie_cache: Option>>, } impl Backend { @@ -1173,7 +1177,7 @@ impl Backend { /// /// Should only be needed for benchmarking. #[cfg(any(feature = "runtime-benchmarks"))] - pub fn expose_storage(&self) -> Arc>> { + pub fn expose_storage(&self) -> Arc>> { self.storage.clone() } @@ -3542,8 +3546,8 @@ pub(crate) mod tests { let x0 = ExtrinsicWrapper::from(0u64).encode(); let x1 = ExtrinsicWrapper::from(1u64).encode(); - let x0_hash = as sp_core::Hasher>::hash(&x0[1..]); - let x1_hash = as sp_core::Hasher>::hash(&x1[1..]); + let x0_hash = as sp_core::Hasher>::hash(&x0[1..]); + let x1_hash = as sp_core::Hasher>::hash(&x1[1..]); let index = vec![ IndexOperation::Insert { extrinsic: 0, @@ -3586,8 +3590,8 @@ pub(crate) mod tests { let x0 = ExtrinsicWrapper::from(0u64).encode(); let x1 = ExtrinsicWrapper::from(1u64).encode(); - let x0_hash = as sp_core::Hasher>::hash(&x0[..]); - let x1_hash = as sp_core::Hasher>::hash(&x1[..]); + let x0_hash = as sp_core::Hasher>::hash(&x0[..]); + let x1_hash = as sp_core::Hasher>::hash(&x1[..]); let index = vec![ IndexOperation::Insert { extrinsic: 0, @@ -3621,7 +3625,7 @@ pub(crate) mod tests { let mut blocks = Vec::new(); let mut prev_hash = Default::default(); let x1 = ExtrinsicWrapper::from(0u64).encode(); - let x1_hash = as sp_core::Hasher>::hash(&x1[1..]); + let x1_hash = as sp_core::Hasher>::hash(&x1[1..]); for i in 0..10 { let mut index = Vec::new(); if i == 0 { diff --git a/substrate/client/db/src/record_stats_state.rs b/substrate/client/db/src/record_stats_state.rs index f794717902..005315ce9f 100644 --- a/substrate/client/db/src/record_stats_state.rs +++ b/substrate/client/db/src/record_stats_state.rs @@ -21,7 +21,7 @@ use crate::stats::StateUsageStats; use sp_core::storage::ChildInfo; use sp_runtime::{ - traits::{Block as BlockT, HashFor}, + traits::{Block as BlockT, HashingFor}, StateVersion, }; use sp_state_machine::{ @@ -56,7 +56,7 @@ impl Drop for RecordStatsState { } } -impl>, B: BlockT> RecordStatsState { +impl>, B: BlockT> RecordStatsState { /// Create a new instance wrapping generic State and shared cache. pub(crate) fn new( state: S, @@ -75,15 +75,15 @@ impl>, B: BlockT> RecordStatsState { pub struct RawIter where - S: StateBackend>, + S: StateBackend>, B: BlockT, { - inner: >>::RawIter, + inner: >>::RawIter, } -impl StorageIterator> for RawIter +impl StorageIterator> for RawIter where - S: StateBackend>, + S: StateBackend>, B: BlockT, { type Backend = RecordStatsState; @@ -105,7 +105,9 @@ where } } -impl>, B: BlockT> StateBackend> for RecordStatsState { +impl>, B: BlockT> StateBackend> + for RecordStatsState +{ type Error = S::Error; type Transaction = S::Transaction; type TrieBackendStorage = S::TrieBackendStorage; @@ -199,12 +201,12 @@ impl>, B: BlockT> StateBackend> for Record } } -impl> + AsTrieBackend>, B: BlockT> AsTrieBackend> - for RecordStatsState +impl> + AsTrieBackend>, B: BlockT> + AsTrieBackend> for RecordStatsState { - type TrieBackendStorage = >>::TrieBackendStorage; + type TrieBackendStorage = >>::TrieBackendStorage; - fn as_trie_backend(&self) -> &TrieBackend> { + fn as_trie_backend(&self) -> &TrieBackend> { self.state.as_trie_backend() } } diff --git a/substrate/client/network-gossip/src/state_machine.rs b/substrate/client/network-gossip/src/state_machine.rs index 4b474baab7..3eb7cf6844 100644 --- a/substrate/client/network-gossip/src/state_machine.rs +++ b/substrate/client/network-gossip/src/state_machine.rs @@ -25,7 +25,7 @@ use schnellru::{ByLength, LruMap}; use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64}; use sc_network::types::ProtocolName; use sc_network_common::role::ObservedRole; -use sp_runtime::traits::{Block as BlockT, Hash, HashFor}; +use sp_runtime::traits::{Block as BlockT, Hash, HashingFor}; use std::{collections::HashMap, iter, sync::Arc, time, time::Instant}; // FIXME: Add additional spam/DoS attack protection: https://github.com/paritytech/substrate/issues/1115 @@ -228,7 +228,7 @@ impl ConsensusGossip { /// message is already expired it should be dropped on the next garbage /// collection. pub fn register_message(&mut self, topic: B::Hash, message: Vec) { - let message_hash = HashFor::::hash(&message[..]); + let message_hash = HashingFor::::hash(&message[..]); self.register_message_hashed(message_hash, topic, message, None); } @@ -343,7 +343,7 @@ impl ConsensusGossip { } for message in messages { - let message_hash = HashFor::::hash(&message[..]); + let message_hash = HashingFor::::hash(&message[..]); if self.known_messages.get(&message_hash).is_some() { tracing::trace!( @@ -456,7 +456,7 @@ impl ConsensusGossip { message: Vec, force: bool, ) { - let message_hash = HashFor::::hash(&message); + let message_hash = HashingFor::::hash(&message); self.register_message_hashed(message_hash, topic, message.clone(), None); let intent = if force { MessageIntent::ForcedBroadcast } else { MessageIntent::Broadcast }; propagate( @@ -477,7 +477,7 @@ impl ConsensusGossip { Some(peer) => peer, }; - let message_hash = HashFor::::hash(&message); + let message_hash = HashingFor::::hash(&message); tracing::trace!( target: "gossip", @@ -740,7 +740,7 @@ mod tests { // Register message. let message = vec![4, 5, 6]; - let topic = HashFor::::hash(&[1, 2, 3]); + let topic = HashingFor::::hash(&[1, 2, 3]); consensus.register_message(topic, message.clone()); assert_eq!( diff --git a/substrate/client/network/src/protocol_controller.rs b/substrate/client/network/src/protocol_controller.rs index 5b421e1485..a7190cc639 100644 --- a/substrate/client/network/src/protocol_controller.rs +++ b/substrate/client/network/src/protocol_controller.rs @@ -399,11 +399,7 @@ impl ProtocolController { PeerState::Connected(direction) }, None => { - trace!( - target: LOG_TARGET, - "Adding reserved node {peer_id} on {:?}.", - self.set_id, - ); + trace!(target: LOG_TARGET, "Adding reserved node {peer_id} on {:?}.", self.set_id,); PeerState::NotConnected }, }; @@ -426,8 +422,7 @@ impl ProtocolController { None => { warn!( target: LOG_TARGET, - "Trying to remove unknown reserved node {peer_id} from {:?}.", - self.set_id, + "Trying to remove unknown reserved node {peer_id} from {:?}.", self.set_id, ); return }, @@ -524,8 +519,7 @@ impl ProtocolController { if self.reserved_nodes.contains_key(&peer_id) { debug!( target: LOG_TARGET, - "Ignoring request to disconnect reserved peer {peer_id} from {:?}.", - self.set_id, + "Ignoring request to disconnect reserved peer {peer_id} from {:?}.", self.set_id, ); return } @@ -546,8 +540,7 @@ impl ProtocolController { None => { debug!( target: LOG_TARGET, - "Trying to disconnect unknown peer {peer_id} from {:?}.", - self.set_id, + "Trying to disconnect unknown peer {peer_id} from {:?}.", self.set_id, ); }, } diff --git a/substrate/client/network/sync/src/lib.rs b/substrate/client/network/sync/src/lib.rs index 03a22995bb..175c1c43f4 100644 --- a/substrate/client/network/sync/src/lib.rs +++ b/substrate/client/network/sync/src/lib.rs @@ -78,7 +78,7 @@ use sp_consensus::{ }; use sp_runtime::{ traits::{ - Block as BlockT, CheckedSub, Hash, HashFor, Header as HeaderT, NumberFor, One, + Block as BlockT, CheckedSub, Hash, HashingFor, Header as HeaderT, NumberFor, One, SaturatedConversion, Zero, }, EncodedJustification, Justifications, @@ -3137,7 +3137,7 @@ fn validate_blocks( } if let (Some(header), Some(body)) = (&b.header, &b.body) { let expected = *header.extrinsics_root(); - let got = HashFor::::ordered_trie_root( + let got = HashingFor::::ordered_trie_root( body.iter().map(Encode::encode).collect(), sp_runtime::StateVersion::V0, ); diff --git a/substrate/client/service/src/client/client.rs b/substrate/client/service/src/client/client.rs index 8c4b14fbdd..d0a46ab2c0 100644 --- a/substrate/client/service/src/client/client.rs +++ b/substrate/client/service/src/client/client.rs @@ -67,7 +67,7 @@ use sp_core::{ use sp_runtime::{ generic::{BlockId, SignedBlock}, traits::{ - Block as BlockT, BlockIdTo, HashFor, Header as HeaderT, NumberFor, One, + Block as BlockT, BlockIdTo, HashingFor, Header as HeaderT, NumberFor, One, SaturatedConversion, Zero, }, Digest, Justification, Justifications, StateVersion, @@ -1267,11 +1267,11 @@ where // this is a read proof, using version V0 or V1 is equivalent. let root = state.storage_root(std::iter::empty(), StateVersion::V0).0; - let (proof, count) = prove_range_read_with_child_with_size::<_, HashFor>( + let (proof, count) = prove_range_read_with_child_with_size::<_, HashingFor>( state, size_limit, start_key, )?; let proof = proof - .into_compact_proof::>(root) + .into_compact_proof::>(root) .map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?; Ok((proof, count)) } @@ -1394,16 +1394,16 @@ where proof: CompactProof, start_key: &[Vec], ) -> sp_blockchain::Result<(KeyValueStates, usize)> { - let mut db = sp_state_machine::MemoryDB::>::new(&[]); + let mut db = sp_state_machine::MemoryDB::>::new(&[]); // Compact encoding - let _ = sp_trie::decode_compact::>, _, _>( + let _ = sp_trie::decode_compact::>, _, _>( &mut db, proof.iter_compact_encoded_nodes(), Some(&root), ) .map_err(|e| sp_blockchain::Error::from_state(Box::new(e)))?; let proving_backend = sp_state_machine::TrieBackendBuilder::new(db, root).build(); - let state = read_range_proof_check_with_child_on_proving_backend::>( + let state = read_range_proof_check_with_child_on_proving_backend::>( &proving_backend, start_key, )?; diff --git a/substrate/client/transaction-pool/src/api.rs b/substrate/client/transaction-pool/src/api.rs index f9d79ee429..871d8e9c81 100644 --- a/substrate/client/transaction-pool/src/api.rs +++ b/substrate/client/transaction-pool/src/api.rs @@ -186,7 +186,7 @@ where &self, ex: &graph::ExtrinsicFor, ) -> (graph::ExtrinsicHash, usize) { - ex.using_encoded(|x| ( as traits::Hash>::hash(x), x.len())) + ex.using_encoded(|x| ( as traits::Hash>::hash(x), x.len())) } fn block_header( diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 4bbabef1dd..c5b41cd9a4 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1618,7 +1618,7 @@ pub(crate) mod remote_tests { use remote_externalities::Mode; use sp_core::H256; use sp_runtime::{ - traits::{Block as BlockT, HashFor, Header as _, One, Zero}, + traits::{Block as BlockT, HashingFor, Header as _, One, Zero}, DeserializeOwned, }; use thousands::Separable; @@ -1698,7 +1698,7 @@ pub(crate) mod remote_tests { }); let compact_proof = - proof.clone().into_compact_proof::>(last_state_root).unwrap(); + proof.clone().into_compact_proof::>(last_state_root).unwrap(); log::info!( target: LOG_TARGET, "proceeded to #{}, weight: [{} / {}], proof: [{} / {} / {}]", diff --git a/substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs b/substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs index e45f05029d..cb683b6644 100644 --- a/substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs +++ b/substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs @@ -592,7 +592,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> { where_clause.predicates.push(parse_quote! { RuntimeApiImplCall::StateBackend: - #crate_::StateBackend<#crate_::HashFor<__SrApiBlock__>> + #crate_::StateBackend<#crate_::HashingFor<__SrApiBlock__>> }); where_clause.predicates.push(parse_quote! { &'static RuntimeApiImplCall: Send }); diff --git a/substrate/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs b/substrate/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs index f85be81cc7..0a1a89c6da 100644 --- a/substrate/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs +++ b/substrate/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs @@ -66,7 +66,7 @@ fn implement_common_api_traits(block_type: TypePath, self_ty: Type) -> Result for #self_ty { - type StateBackend = #crate_::InMemoryBackend<#crate_::HashFor<#block_type>>; + type StateBackend = #crate_::InMemoryBackend<#crate_::HashingFor<#block_type>>; fn execute_in_transaction #crate_::TransactionOutcome, R>( &self, diff --git a/substrate/primitives/api/src/lib.rs b/substrate/primitives/api/src/lib.rs index e683d7aa63..2cc20dcb35 100644 --- a/substrate/primitives/api/src/lib.rs +++ b/substrate/primitives/api/src/lib.rs @@ -98,7 +98,7 @@ pub use sp_runtime::StateVersion; #[doc(hidden)] pub use sp_runtime::{ generic::BlockId, - traits::{Block as BlockT, Hash as HashT, HashFor, Header as HeaderT, NumberFor}, + traits::{Block as BlockT, Hash as HashT, HashingFor, Header as HeaderT, NumberFor}, transaction_validity::TransactionValidity, RuntimeString, TransactionOutcome, }; @@ -454,19 +454,19 @@ pub use sp_api_proc_macro::mock_impl_runtime_apis; /// A type that records all accessed trie nodes and generates a proof out of it. #[cfg(feature = "std")] -pub type ProofRecorder = sp_trie::recorder::Recorder>; +pub type ProofRecorder = sp_trie::recorder::Recorder>; /// A type that is used as cache for the storage transactions. #[cfg(feature = "std")] pub type StorageTransactionCache = sp_state_machine::StorageTransactionCache< - >>::Transaction, - HashFor, + >>::Transaction, + HashingFor, >; #[cfg(feature = "std")] pub type StorageChanges = sp_state_machine::StorageChanges< - >>::Transaction, - HashFor, + >>::Transaction, + HashingFor, >; /// Extract the state backend type for a type that implements `ProvideRuntimeApi`. @@ -477,7 +477,7 @@ pub type StateBackendFor = /// Extract the state backend transaction type for a type that implements `ProvideRuntimeApi`. #[cfg(feature = "std")] pub type TransactionFor = - as StateBackend>>::Transaction; + as StateBackend>>::Transaction; /// Something that can be constructed to a runtime api. #[cfg(feature = "std")] @@ -532,7 +532,7 @@ pub enum ApiError { #[cfg(feature = "std")] pub trait ApiExt { /// The state backend that is used to store the block states. - type StateBackend: StateBackend>; + type StateBackend: StateBackend>; /// Execute the given closure inside a new transaction. /// @@ -599,7 +599,7 @@ pub trait ApiExt { /// Parameters for [`CallApiAt::call_api_at`]. #[cfg(feature = "std")] -pub struct CallApiAtParams<'a, Block: BlockT, Backend: StateBackend>> { +pub struct CallApiAtParams<'a, Block: BlockT, Backend: StateBackend>> { /// The block id that determines the state that should be setup when calling the function. pub at: Block::Hash, /// The name of the function that should be called. @@ -622,7 +622,7 @@ pub struct CallApiAtParams<'a, Block: BlockT, Backend: StateBackend { /// The state backend that is used to store the block states. - type StateBackend: StateBackend> + AsTrieBackend>; + type StateBackend: StateBackend> + AsTrieBackend>; /// Calls the given api function with the given encoded arguments at the given block and returns /// the encoded result. diff --git a/substrate/primitives/api/test/tests/runtime_calls.rs b/substrate/primitives/api/test/tests/runtime_calls.rs index 92118c16cd..353be73dcc 100644 --- a/substrate/primitives/api/test/tests/runtime_calls.rs +++ b/substrate/primitives/api/test/tests/runtime_calls.rs @@ -19,7 +19,7 @@ use std::panic::UnwindSafe; use sp_api::{ApiExt, Core, ProvideRuntimeApi}; use sp_runtime::{ - traits::{HashFor, Header as HeaderT}, + traits::{HashingFor, Header as HeaderT}, TransactionOutcome, }; use sp_state_machine::{create_proof_check_backend, execution_proof_check_on_trie_backend}; @@ -111,7 +111,7 @@ fn record_proof_works() { builder.push(transaction.clone()).unwrap(); let (block, _, proof) = builder.build().expect("Bake block").into_inner(); - let backend = create_proof_check_backend::>( + let backend = create_proof_check_backend::>( storage_root, proof.expect("Proof was generated"), ) diff --git a/substrate/primitives/consensus/common/src/lib.rs b/substrate/primitives/consensus/common/src/lib.rs index d47f3bafc4..2203110437 100644 --- a/substrate/primitives/consensus/common/src/lib.rs +++ b/substrate/primitives/consensus/common/src/lib.rs @@ -25,7 +25,7 @@ use std::{sync::Arc, time::Duration}; use futures::prelude::*; use sp_runtime::{ - traits::{Block as BlockT, HashFor}, + traits::{Block as BlockT, HashingFor}, Digest, }; use sp_state_machine::StorageProof; @@ -97,7 +97,7 @@ pub struct Proposal { /// Proof that was recorded while building the block. pub proof: Proof, /// The storage changes while building this block. - pub storage_changes: sp_state_machine::StorageChanges>, + pub storage_changes: sp_state_machine::StorageChanges>, } /// Error that is returned when [`ProofRecording`] requested to record a proof, diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index 51d91958ab..1ff2712381 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -1345,7 +1345,7 @@ pub trait ExtrinsicMetadata { } /// Extract the hashing type for a block. -pub type HashFor = <::Header as Header>::Hashing; +pub type HashingFor = <::Header as Header>::Hashing; /// Extract the number type for a block. pub type NumberFor = <::Header as Header>::Number; /// Extract the digest type for a block. diff --git a/substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs b/substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs index 99cadbe8ec..307c9207fd 100644 --- a/substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs +++ b/substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs @@ -21,7 +21,7 @@ use sc_client_db::DbHash; use sc_service::Configuration; use sp_blockchain::HeaderBackend; use sp_database::{ColumnId, Database}; -use sp_runtime::traits::{Block as BlockT, HashFor}; +use sp_runtime::traits::{Block as BlockT, HashingFor}; use sp_state_machine::Storage; use sp_storage::{ChildInfo, ChildType, PrefixedStorageKey, StateVersion}; @@ -126,7 +126,7 @@ impl StorageCmd { cfg: Configuration, client: Arc, db: (Arc>, ColumnId), - storage: Arc>>, + storage: Arc>>, ) -> Result<()> where BA: ClientBackend, diff --git a/substrate/utils/frame/benchmarking-cli/src/storage/write.rs b/substrate/utils/frame/benchmarking-cli/src/storage/write.rs index faca3b536b..4def1909ea 100644 --- a/substrate/utils/frame/benchmarking-cli/src/storage/write.rs +++ b/substrate/utils/frame/benchmarking-cli/src/storage/write.rs @@ -21,7 +21,7 @@ use sc_client_db::{DbHash, DbState, DbStateBuilder}; use sp_api::StateBackend; use sp_blockchain::HeaderBackend; use sp_database::{ColumnId, Transaction}; -use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT}; +use sp_runtime::traits::{Block as BlockT, HashingFor, Header as HeaderT}; use sp_trie::PrefixedMemoryDB; use log::{info, trace}; @@ -43,7 +43,7 @@ impl StorageCmd { &self, client: Arc, (db, state_col): (Arc>, ColumnId), - storage: Arc>>, + storage: Arc>>, ) -> Result where Block: BlockT
+ Debug, @@ -164,7 +164,7 @@ impl StorageCmd { /// `invert_inserts` replaces all inserts with removals. fn convert_tx( db: Arc>, - mut tx: PrefixedMemoryDB>, + mut tx: PrefixedMemoryDB>, invert_inserts: bool, col: ColumnId, ) -> Transaction { diff --git a/substrate/utils/frame/remote-externalities/src/lib.rs b/substrate/utils/frame/remote-externalities/src/lib.rs index 7cd3d3750a..761f3c8859 100644 --- a/substrate/utils/frame/remote-externalities/src/lib.rs +++ b/substrate/utils/frame/remote-externalities/src/lib.rs @@ -776,10 +776,7 @@ where .collect::>(); if child_roots.is_empty() { - info!( - target: LOG_TARGET, - "👩‍👦 no child roots found to scrape", - ); + info!(target: LOG_TARGET, "👩‍👦 no child roots found to scrape",); return Ok(Default::default()) }