From 6f2a83400407a823bfdfe9039c240525ac007fe5 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Fri, 30 Jun 2023 08:14:42 +0200 Subject: [PATCH 1/3] change HashFor to HashingFor --- bin/node/inspect/src/lib.rs | 6 +- bin/node/rpc/src/lib.rs | 2 +- client/api/src/backend.rs | 28 ++++----- client/api/src/in_mem.rs | 14 ++--- client/block-builder/src/lib.rs | 8 +-- client/consensus/common/src/block_import.rs | 4 +- client/consensus/slots/src/lib.rs | 4 +- client/db/src/bench.rs | 30 ++++----- client/db/src/lib.rs | 62 +++++++++---------- client/db/src/record_stats_state.rs | 20 +++--- client/network-gossip/src/state_machine.rs | 12 ++-- client/network/sync/src/lib.rs | 4 +- client/service/src/client/client.rs | 12 ++-- client/transaction-pool/src/api.rs | 2 +- frame/state-trie-migration/src/lib.rs | 4 +- .../api/proc-macro/src/impl_runtime_apis.rs | 2 +- .../proc-macro/src/mock_impl_runtime_apis.rs | 2 +- primitives/api/src/lib.rs | 20 +++--- primitives/api/test/tests/runtime_calls.rs | 4 +- primitives/consensus/common/src/lib.rs | 4 +- primitives/runtime/src/traits.rs | 2 +- .../frame/benchmarking-cli/src/storage/cmd.rs | 4 +- .../benchmarking-cli/src/storage/write.rs | 6 +- 23 files changed, 128 insertions(+), 128 deletions(-) diff --git a/bin/node/inspect/src/lib.rs b/bin/node/inspect/src/lib.rs index 5764e0f05c172..65dfecdf77a2d 100644 --- a/bin/node/inspect/src/lib.rs +++ b/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/bin/node/rpc/src/lib.rs b/bin/node/rpc/src/lib.rs index 5ab96bf1c7064..651ad1a984eed 100644 --- a/bin/node/rpc/src/lib.rs +++ b/bin/node/rpc/src/lib.rs @@ -114,7 +114,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/client/api/src/backend.rs b/client/api/src/backend.rs index b88feafb6ca3a..465e1988478d7 100644 --- a/client/api/src/backend.rs +++ b/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/client/api/src/in_mem.rs b/client/api/src/in_mem.rs index 9ea5169d78832..0cad3813deead 100644 --- a/client/api/src/in_mem.rs +++ b/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,9 @@ impl backend::AuxStore for Blockchain { /// In-memory operation. pub struct BlockImportOperation { pending_block: Option>, - old_state: InMemoryBackend>, + old_state: InMemoryBackend>, new_state: - Option<> as StateBackend>>::Transaction>, + Option<> as StateBackend>>::Transaction>, aux: Vec<(Vec, Option>)>, finalized_blocks: Vec<(Block::Hash, Option)>, set_head: Option, @@ -517,7 +517,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 +539,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 +606,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 +661,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/client/block-builder/src/lib.rs b/client/block-builder/src/lib.rs index f055d4688822a..4114a856c083e 100644 --- a/client/block-builder/src/lib.rs +++ b/client/block-builder/src/lib.rs @@ -35,7 +35,7 @@ use sp_blockchain::{ApplyExtrinsicFailed, Error}; use sp_core::ExecutionContext; 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. @@ -248,7 +248,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/client/consensus/common/src/block_import.rs b/client/consensus/common/src/block_import.rs index 70bf0283af2d9..b84a45d533d46 100644 --- a/client/consensus/common/src/block_import.rs +++ b/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/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index 5057e7858a0bc..533ddb54e899d 100644 --- a/client/consensus/slots/src/lib.rs +++ b/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/client/db/src/bench.rs b/client/db/src/bench.rs index 5bec03cb1088d..f251da62ebf73 100644 --- a/client/db/src/bench.rs +++ b/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,7 @@ 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/client/db/src/lib.rs b/client/db/src/lib.rs index 69d8d8cfc3229..54eb11e5a2c09 100644 --- a/client/db/src/lib.rs +++ b/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,7 @@ 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 +986,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 +1009,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 +1030,14 @@ 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 +1098,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 { @@ -1166,7 +1166,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() } @@ -3535,8 +3535,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, @@ -3579,8 +3579,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, @@ -3614,7 +3614,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/client/db/src/record_stats_state.rs b/client/db/src/record_stats_state.rs index f794717902d55..0c5e21c7947e2 100644 --- a/client/db/src/record_stats_state.rs +++ b/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,7 @@ 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 +199,12 @@ impl>, B: BlockT> StateBackend> for Record } } -impl> + AsTrieBackend>, B: BlockT> AsTrieBackend> +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/client/network-gossip/src/state_machine.rs b/client/network-gossip/src/state_machine.rs index 24373cd402513..2bb0444c48b35 100644 --- a/client/network-gossip/src/state_machine.rs +++ b/client/network-gossip/src/state_machine.rs @@ -24,7 +24,7 @@ use lru::LruCache; 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, num::NonZeroUsize, sync::Arc, time, time::Instant}; // FIXME: Add additional spam/DoS attack protection: https://github.com/paritytech/substrate/issues/1115 @@ -231,7 +231,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); } @@ -346,7 +346,7 @@ impl ConsensusGossip { } for message in messages { - let message_hash = HashFor::::hash(&message[..]); + let message_hash = HashingFor::::hash(&message[..]); if self.known_messages.contains(&message_hash) { tracing::trace!( @@ -459,7 +459,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( @@ -480,7 +480,7 @@ impl ConsensusGossip { Some(peer) => peer, }; - let message_hash = HashFor::::hash(&message); + let message_hash = HashingFor::::hash(&message); tracing::trace!( target: "gossip", @@ -743,7 +743,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/client/network/sync/src/lib.rs b/client/network/sync/src/lib.rs index 03a22995bb924..175c1c43f46f7 100644 --- a/client/network/sync/src/lib.rs +++ b/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/client/service/src/client/client.rs b/client/service/src/client/client.rs index 3b1a526154d74..86506a3319573 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -69,7 +69,7 @@ use sp_keystore::KeystorePtr; 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, @@ -1277,11 +1277,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)) } @@ -1404,16 +1404,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/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index f9d79ee429e6c..871d8e9c81707 100644 --- a/client/transaction-pool/src/api.rs +++ b/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/frame/state-trie-migration/src/lib.rs b/frame/state-trie-migration/src/lib.rs index 05ca21c1de752..ddd91b8518272 100644 --- a/frame/state-trie-migration/src/lib.rs +++ b/frame/state-trie-migration/src/lib.rs @@ -1623,7 +1623,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; @@ -1703,7 +1703,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/primitives/api/proc-macro/src/impl_runtime_apis.rs b/primitives/api/proc-macro/src/impl_runtime_apis.rs index 028cc6a675ee5..2dfda92a1d6b4 100644 --- a/primitives/api/proc-macro/src/impl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/impl_runtime_apis.rs @@ -559,7 +559,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/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs b/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs index be8c8ca0f8527..27ed194100a4c 100644 --- a/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs +++ b/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/primitives/api/src/lib.rs b/primitives/api/src/lib.rs index 78c4cd73a18ae..33291dae624f2 100644 --- a/primitives/api/src/lib.rs +++ b/primitives/api/src/lib.rs @@ -92,7 +92,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, }; @@ -448,19 +448,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`. @@ -471,7 +471,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")] @@ -524,7 +524,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. /// @@ -585,7 +585,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. @@ -606,7 +606,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/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 344c2d31eb0a6..face9933bdb1f 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/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::{ @@ -127,7 +127,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/primitives/consensus/common/src/lib.rs b/primitives/consensus/common/src/lib.rs index 215b4448b4a8e..13a3d17dceacf 100644 --- a/primitives/consensus/common/src/lib.rs +++ b/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; @@ -107,7 +107,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/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 3aa27234fbce2..ab109b884668a 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -1305,7 +1305,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/utils/frame/benchmarking-cli/src/storage/cmd.rs b/utils/frame/benchmarking-cli/src/storage/cmd.rs index 99cadbe8ec34e..307c9207fdaf9 100644 --- a/utils/frame/benchmarking-cli/src/storage/cmd.rs +++ b/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/utils/frame/benchmarking-cli/src/storage/write.rs b/utils/frame/benchmarking-cli/src/storage/write.rs index faca3b536b22e..4def1909ead5e 100644 --- a/utils/frame/benchmarking-cli/src/storage/write.rs +++ b/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 { From f35ab64af0bfe8d64ab89dc5f28196733d97d9a3 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 13 Jul 2023 09:22:17 +0200 Subject: [PATCH 2/3] fmt --- client/api/src/in_mem.rs | 5 +- .../basic-authorship/src/basic_authorship.rs | 156 ++++++++++-------- client/db/src/bench.rs | 3 +- client/db/src/lib.rs | 8 +- client/db/src/record_stats_state.rs | 8 +- client/network/src/protocol_controller.rs | 15 +- utils/frame/remote-externalities/src/lib.rs | 5 +- 7 files changed, 110 insertions(+), 90 deletions(-) diff --git a/client/api/src/in_mem.rs b/client/api/src/in_mem.rs index 0cad3813deead..711d739c16711 100644 --- a/client/api/src/in_mem.rs +++ b/client/api/src/in_mem.rs @@ -480,8 +480,9 @@ impl backend::AuxStore for Blockchain { pub struct BlockImportOperation { pending_block: Option>, old_state: InMemoryBackend>, - new_state: - Option<> as StateBackend>>::Transaction>, + new_state: Option< + > as StateBackend>>::Transaction, + >, aux: Vec<(Vec, Option>)>, finalized_blocks: Vec<(Block::Hash, Option)>, set_head: Option, diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index d1921b3413cbc..d9df4aa30da19 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/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(_) => {}, } @@ -440,86 +449,99 @@ where debug!(target: LOG_TARGET, "Pool status: {:?}", self.transaction_pool.status()); let mut transaction_pushed = false; - let end_reason = loop { - let pending_tx = if let Some(pending_tx) = pending_iterator.next() { - pending_tx - } else { - break EndProposingReason::NoMoreTransactions - }; + let end_reason = + loop { + let pending_tx = if let Some(pending_tx) = pending_iterator.next() { + pending_tx + } else { + break EndProposingReason::NoMoreTransactions + }; - let now = (self.now)(); - if now > deadline { - debug!(target: LOG_TARGET, - "Consensus deadline reached when pushing block transactions, \ + let now = (self.now)(); + if now > deadline { + debug!( + target: LOG_TARGET, + "Consensus deadline reached when pushing block transactions, \ proceeding with proposing." - ); - break EndProposingReason::HitDeadline - } - - let pending_tx_data = pending_tx.data().clone(); - let pending_tx_hash = pending_tx.hash().clone(); - - let block_size = - block_builder.estimate_block_size(self.include_proof_in_block_size_estimation); - if block_size + pending_tx_data.encoded_size() > block_size_limit { - pending_iterator.report_invalid(&pending_tx); - if skipped < MAX_SKIPPED_TRANSACTIONS { - skipped += 1; - debug!(target: LOG_TARGET, - "Transaction would overflow the block size limit, \ - but will try {} more transactions before quitting.", - MAX_SKIPPED_TRANSACTIONS - skipped, ); - continue - } else if now < soft_deadline { - 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." - ); - continue - } else { - debug!(target: LOG_TARGET, "Reached block size limit, proceeding with proposing."); - break EndProposingReason::HitBlockSizeLimit + break EndProposingReason::HitDeadline } - } - trace!(target: LOG_TARGET, "[{:?}] Pushing to the block.", pending_tx_hash); - match sc_block_builder::BlockBuilder::push(block_builder, pending_tx_data) { - Ok(()) => { - transaction_pushed = true; - debug!(target: LOG_TARGET, "[{:?}] Pushed to the block.", pending_tx_hash); - }, - Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => { + let pending_tx_data = pending_tx.data().clone(); + let pending_tx_hash = pending_tx.hash().clone(); + + let block_size = + block_builder.estimate_block_size(self.include_proof_in_block_size_estimation); + if block_size + pending_tx_data.encoded_size() > block_size_limit { 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.", + MAX_SKIPPED_TRANSACTIONS - skipped, + ); + continue + } else if now < soft_deadline { + 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." + ); + continue + } else { + debug!( + target: LOG_TARGET, + "Reached block size limit, proceeding with proposing." + ); + break EndProposingReason::HitBlockSizeLimit + } + } + + trace!(target: LOG_TARGET, "[{:?}] Pushing to the block.", pending_tx_hash); + match sc_block_builder::BlockBuilder::push(block_builder, pending_tx_data) { + Ok(()) => { + transaction_pushed = true; + debug!(target: LOG_TARGET, "[{:?}] Pushed to the block.", pending_tx_hash); + }, + Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => { + pending_iterator.report_invalid(&pending_tx); + if skipped < MAX_SKIPPED_TRANSACTIONS { + skipped += 1; + debug!(target: LOG_TARGET, "Block seems full, but will try {} more transactions before quitting.", MAX_SKIPPED_TRANSACTIONS - skipped, ); - } else if (self.now)() < soft_deadline { - debug!(target: LOG_TARGET, + } else if (self.now)() < soft_deadline { + debug!(target: LOG_TARGET, "Block seems full, but we still have time before the soft deadline, \ so we will try a bit more before quitting." ); - } else { - 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); - unqueue_invalid.push(pending_tx_hash); - }, - } - }; + } else { + 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 + ); + 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/client/db/src/bench.rs b/client/db/src/bench.rs index f251da62ebf73..9307a63ad444e 100644 --- a/client/db/src/bench.rs +++ b/client/db/src/bench.rs @@ -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/client/db/src/lib.rs b/client/db/src/lib.rs index 54eb11e5a2c09..6714ccaa7eaef 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -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(()) } @@ -1032,7 +1035,8 @@ impl EmptyStorage { let mut root = Block::Hash::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) } } diff --git a/client/db/src/record_stats_state.rs b/client/db/src/record_stats_state.rs index 0c5e21c7947e2..005315ce9f458 100644 --- a/client/db/src/record_stats_state.rs +++ b/client/db/src/record_stats_state.rs @@ -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,8 +201,8 @@ impl>, B: BlockT> StateBackend> for } } -impl> + AsTrieBackend>, B: BlockT> AsTrieBackend> - for RecordStatsState +impl> + AsTrieBackend>, B: BlockT> + AsTrieBackend> for RecordStatsState { type TrieBackendStorage = >>::TrieBackendStorage; diff --git a/client/network/src/protocol_controller.rs b/client/network/src/protocol_controller.rs index 9a77881c63320..1866ca684cfe1 100644 --- a/client/network/src/protocol_controller.rs +++ b/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/utils/frame/remote-externalities/src/lib.rs b/utils/frame/remote-externalities/src/lib.rs index 7cd3d3750aebc..761f3c8859046 100644 --- a/utils/frame/remote-externalities/src/lib.rs +++ b/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()) } From 7d5ac104bb74cc30a504adcb0fb0f1e00224335e Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 13 Jul 2023 11:47:31 +0000 Subject: [PATCH 3/3] ".git/.scripts/commands/fmt/fmt.sh" --- .../basic-authorship/src/basic_authorship.rs | 139 +++++++++--------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index d9df4aa30da19..55aadb07e6756 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/client/basic-authorship/src/basic_authorship.rs @@ -449,94 +449,93 @@ where debug!(target: LOG_TARGET, "Pool status: {:?}", self.transaction_pool.status()); let mut transaction_pushed = false; - let end_reason = - loop { - let pending_tx = if let Some(pending_tx) = pending_iterator.next() { - pending_tx - } else { - break EndProposingReason::NoMoreTransactions - }; + let end_reason = loop { + let pending_tx = if let Some(pending_tx) = pending_iterator.next() { + pending_tx + } else { + break EndProposingReason::NoMoreTransactions + }; + + let now = (self.now)(); + if now > deadline { + debug!( + target: LOG_TARGET, + "Consensus deadline reached when pushing block transactions, \ + proceeding with proposing." + ); + break EndProposingReason::HitDeadline + } + + let pending_tx_data = pending_tx.data().clone(); + let pending_tx_hash = pending_tx.hash().clone(); - let now = (self.now)(); - if now > deadline { + let block_size = + block_builder.estimate_block_size(self.include_proof_in_block_size_estimation); + if block_size + pending_tx_data.encoded_size() > block_size_limit { + pending_iterator.report_invalid(&pending_tx); + if skipped < MAX_SKIPPED_TRANSACTIONS { + skipped += 1; + debug!( + target: LOG_TARGET, + "Transaction would overflow the block size limit, \ + but will try {} more transactions before quitting.", + MAX_SKIPPED_TRANSACTIONS - skipped, + ); + continue + } else if now < soft_deadline { debug!( target: LOG_TARGET, - "Consensus deadline reached when pushing block transactions, \ - proceeding with proposing." + "Transaction would overflow the block size limit, \ + but we still have time before the soft deadline, so \ + we will try a bit more." ); - break EndProposingReason::HitDeadline + continue + } else { + debug!( + target: LOG_TARGET, + "Reached block size limit, proceeding with proposing." + ); + break EndProposingReason::HitBlockSizeLimit } + } - let pending_tx_data = pending_tx.data().clone(); - let pending_tx_hash = pending_tx.hash().clone(); - - let block_size = - block_builder.estimate_block_size(self.include_proof_in_block_size_estimation); - if block_size + pending_tx_data.encoded_size() > block_size_limit { + trace!(target: LOG_TARGET, "[{:?}] Pushing to the block.", pending_tx_hash); + match sc_block_builder::BlockBuilder::push(block_builder, pending_tx_data) { + Ok(()) => { + transaction_pushed = true; + debug!(target: LOG_TARGET, "[{:?}] Pushed to the block.", pending_tx_hash); + }, + Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => { pending_iterator.report_invalid(&pending_tx); if skipped < MAX_SKIPPED_TRANSACTIONS { skipped += 1; - debug!( - target: LOG_TARGET, - "Transaction would overflow the block size limit, \ - but will try {} more transactions before quitting.", - MAX_SKIPPED_TRANSACTIONS - skipped, - ); - continue - } else if now < soft_deadline { - 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." - ); - continue - } else { - debug!( - target: LOG_TARGET, - "Reached block size limit, proceeding with proposing." - ); - break EndProposingReason::HitBlockSizeLimit - } - } - - trace!(target: LOG_TARGET, "[{:?}] Pushing to the block.", pending_tx_hash); - match sc_block_builder::BlockBuilder::push(block_builder, pending_tx_data) { - Ok(()) => { - transaction_pushed = true; - debug!(target: LOG_TARGET, "[{:?}] Pushed to the block.", pending_tx_hash); - }, - Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => { - pending_iterator.report_invalid(&pending_tx); - if skipped < MAX_SKIPPED_TRANSACTIONS { - skipped += 1; - debug!(target: LOG_TARGET, + debug!(target: LOG_TARGET, "Block seems full, but will try {} more transactions before quitting.", MAX_SKIPPED_TRANSACTIONS - skipped, ); - } else if (self.now)() < soft_deadline { - debug!(target: LOG_TARGET, + } else if (self.now)() < soft_deadline { + debug!(target: LOG_TARGET, "Block seems full, but we still have time before the soft deadline, \ so we will try a bit more before quitting." ); - } else { - debug!( - target: LOG_TARGET, - "Reached block weight limit, proceeding with proposing." - ); - break EndProposingReason::HitBlockWeightLimit - } - }, - Err(e) => { - pending_iterator.report_invalid(&pending_tx); + } else { debug!( target: LOG_TARGET, - "[{:?}] Invalid transaction: {}", pending_tx_hash, e + "Reached block weight limit, proceeding with proposing." ); - unqueue_invalid.push(pending_tx_hash); - }, - } - }; + break EndProposingReason::HitBlockWeightLimit + } + }, + Err(e) => { + pending_iterator.report_invalid(&pending_tx); + 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!(