Apply some clippy lints (#11154)

* Apply some clippy hints

* Revert clippy ci changes

* Update client/cli/src/commands/generate.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/cli/src/commands/inspect_key.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Revert due to missing `or_default` function.

* Fix compilation and simplify code

* Undo change that corrupts benchmark.

* fix clippy

* Update client/service/test/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

remove leftovers!

* Update client/tracing/src/logging/directives.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/fork-tree/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* added needed ref

* Update frame/referenda/src/benchmarking.rs

* Simplify byte-vec creation

* let's just not overlap the ranges

* Correction

* cargo fmt

* Update utils/frame/benchmarking-cli/src/shared/stats.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Falco Hirschenberger
2022-04-30 23:28:27 +02:00
committed by GitHub
parent a990473cf9
commit b581604aa7
368 changed files with 1927 additions and 2236 deletions
+1 -1
View File
@@ -499,7 +499,7 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
/// Returns true if state for given block is available.
fn have_state_at(&self, hash: &Block::Hash, _number: NumberFor<Block>) -> bool {
self.state_at(BlockId::Hash(hash.clone())).is_ok()
self.state_at(BlockId::Hash(*hash)).is_ok()
}
/// Returns state backend with post-state of given block.
@@ -151,7 +151,7 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
where
T: OffchainSubmitTransaction<Block> + 'static,
{
*self.transaction_pool.write() = Some(Arc::downgrade(&pool) as _);
*self.transaction_pool.write() = Some(Arc::downgrade(pool) as _);
}
/// Based on the execution context and capabilities it produces
+13 -21
View File
@@ -166,23 +166,19 @@ impl<Block: BlockT> Blockchain<Block> {
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState,
) -> sp_blockchain::Result<()> {
let number = header.number().clone();
let number = *header.number();
if new_state.is_best() {
self.apply_head(&header)?;
}
{
let mut storage = self.storage.write();
storage
.leaves
.import(hash.clone(), number.clone(), header.parent_hash().clone());
storage
.blocks
.insert(hash.clone(), StoredBlock::new(header, body, justifications));
storage.leaves.import(hash, number, header.parent_hash().clone());
storage.blocks.insert(hash, StoredBlock::new(header, body, justifications));
if let NewBlockState::Final = new_state {
storage.finalized_hash = hash;
storage.finalized_number = number.clone();
storage.finalized_number = number;
}
if number == Zero::zero() {
@@ -266,9 +262,9 @@ impl<Block: BlockT> Blockchain<Block> {
}
}
storage.best_hash = hash.clone();
storage.best_number = number.clone();
storage.hashes.insert(number.clone(), hash.clone());
storage.best_hash = hash;
storage.best_number = *number;
storage.hashes.insert(*number, hash);
Ok(())
}
@@ -362,7 +358,7 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
finalized_hash: storage.finalized_hash,
finalized_number: storage.finalized_number,
finalized_state: if storage.finalized_hash != Default::default() {
Some((storage.finalized_hash.clone(), storage.finalized_number))
Some((storage.finalized_hash, storage.finalized_number))
} else {
None
},
@@ -428,16 +424,12 @@ impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
fn justifications(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Justifications>> {
Ok(self.id(id).and_then(|hash| {
self.storage
.read()
.blocks
.get(&hash)
.and_then(|b| b.justifications().map(|x| x.clone()))
self.storage.read().blocks.get(&hash).and_then(|b| b.justifications().cloned())
}))
}
fn last_finalized(&self) -> sp_blockchain::Result<Block::Hash> {
Ok(self.storage.read().finalized_hash.clone())
Ok(self.storage.read().finalized_hash)
}
fn leaves(&self) -> sp_blockchain::Result<Vec<Block::Hash>> {
@@ -810,15 +802,15 @@ impl<Block: BlockT> backend::LocalBackend<Block> for Backend<Block> where Block:
/// Check that genesis storage is valid.
pub fn check_genesis_storage(storage: &Storage) -> sp_blockchain::Result<()> {
if storage.top.iter().any(|(k, _)| well_known_keys::is_child_storage_key(k)) {
return Err(sp_blockchain::Error::InvalidState.into())
return Err(sp_blockchain::Error::InvalidState)
}
if storage
.children_default
.keys()
.any(|child_key| !well_known_keys::is_child_storage_key(&child_key))
.any(|child_key| !well_known_keys::is_child_storage_key(child_key))
{
return Err(sp_blockchain::Error::InvalidState.into())
return Err(sp_blockchain::Error::InvalidState)
}
Ok(())
+3 -3
View File
@@ -57,10 +57,10 @@ pub mod utils {
/// represent the current block `hash` and its `parent hash`, if given the
/// function that's returned will assume that `hash` isn't part of the local DB
/// yet, and all searches in the DB will instead reference the parent.
pub fn is_descendent_of<'a, Block: BlockT, T>(
client: &'a T,
pub fn is_descendent_of<Block: BlockT, T>(
client: &T,
current: Option<(Block::Hash, Block::Hash)>,
) -> impl Fn(&Block::Hash, &Block::Hash) -> Result<bool, Error> + 'a
) -> impl Fn(&Block::Hash, &Block::Hash) -> Result<bool, Error> + '_
where
T: HeaderBackend<Block> + HeaderMetadata<Block, Error = Error>,
{
+3 -4
View File
@@ -71,10 +71,9 @@ type ChildKeys = Option<HashMap<StorageKey, Option<HashSet<StorageKey>>>>;
impl StorageChangeSet {
/// Convert the change set into iterator over storage items.
pub fn iter<'a>(
&'a self,
) -> impl Iterator<Item = (Option<&'a StorageKey>, &'a StorageKey, Option<&'a StorageData>)> + 'a
{
pub fn iter(
&self,
) -> impl Iterator<Item = (Option<&StorageKey>, &StorageKey, Option<&StorageData>)> + '_ {
let top = self
.changes
.iter()
@@ -134,7 +134,7 @@ impl<'a> Subscribe<SubscribeOp<'a>> for Registry {
});
if let Some(m) = self.metrics.as_ref() {
m.with_label_values(&[&"added"]).inc();
m.with_label_values(&["added"]).inc();
}
if self
@@ -195,7 +195,7 @@ impl Registry {
let k = StorageKey(k);
let listeners = self.listeners.get(&k);
if let Some(ref listeners) = listeners {
if let Some(listeners) = listeners {
subscribers.extend(listeners.iter());
}
@@ -211,7 +211,7 @@ impl Registry {
let k = StorageKey(k);
let listeners = cl.get(&k);
if let Some(ref listeners) = listeners {
if let Some(listeners) = listeners {
subscribers.extend(listeners.iter());
}
@@ -268,22 +268,22 @@ impl Registry {
);
if let Some(child_filters) = &sink.child_keys {
for (c_key, filters) in child_filters {
if let Some((listeners, wildcards)) = self.child_listeners.get_mut(&c_key) {
if let Some((listeners, wildcards)) = self.child_listeners.get_mut(c_key) {
Self::remove_subscriber_from(
subscriber,
&filters,
filters,
&mut *listeners,
&mut *wildcards,
);
if listeners.is_empty() && wildcards.is_empty() {
self.child_listeners.remove(&c_key);
self.child_listeners.remove(c_key);
}
}
}
}
if let Some(m) = self.metrics.as_ref() {
m.with_label_values(&[&"removed"]).inc();
m.with_label_values(&["removed"]).inc();
}
Some((sink.keys.clone(), sink.child_keys.clone()))