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
+47 -55
View File
@@ -352,8 +352,8 @@ impl DatabaseSource {
//
// IIUC this is needed for polkadot to create its own dbs, so until it can use parity db
// I would think rocksdb, but later parity-db.
DatabaseSource::Auto { paritydb_path, .. } => Some(&paritydb_path),
DatabaseSource::RocksDb { path, .. } | DatabaseSource::ParityDb { path } => Some(&path),
DatabaseSource::Auto { paritydb_path, .. } => Some(paritydb_path),
DatabaseSource::RocksDb { path, .. } | DatabaseSource::ParityDb { path } => Some(path),
DatabaseSource::Custom(..) => None,
}
}
@@ -478,7 +478,7 @@ impl<Block: BlockT> BlockchainDb<Block> {
if is_finalized {
if with_state {
meta.finalized_state = Some((hash.clone(), number));
meta.finalized_state = Some((hash, number));
}
meta.finalized_number = number;
meta.finalized_hash = hash;
@@ -501,7 +501,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
}
let header =
utils::read_header(&*self.db, columns::KEY_LOOKUP, columns::HEADER, id)?;
cache_header(&mut cache, h.clone(), header.clone());
cache_header(&mut cache, *h, header.clone());
Ok(header)
},
BlockId::Number(_) =>
@@ -517,7 +517,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
genesis_hash: meta.genesis_hash,
finalized_hash: meta.finalized_hash,
finalized_number: meta.finalized_number,
finalized_state: meta.finalized_state.clone(),
finalized_state: meta.finalized_state,
number_leaves: self.leaves.read().count(),
block_gap: meta.block_gap,
}
@@ -540,10 +540,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
fn hash(&self, number: NumberFor<Block>) -> ClientResult<Option<Block::Hash>> {
self.header(BlockId::Number(number))
.and_then(|maybe_header| match maybe_header {
Some(header) => Ok(Some(header.hash().clone())),
None => Ok(None),
})
.map(|maybe_header| maybe_header.map(|header| header.hash()))
}
}
@@ -621,7 +618,7 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B
}
fn last_finalized(&self) -> ClientResult<Block::Hash> {
Ok(self.meta.read().finalized_hash.clone())
Ok(self.meta.read().finalized_hash)
}
fn leaves(&self) -> ClientResult<Vec<Block::Hash>> {
@@ -765,8 +762,8 @@ impl<Block: BlockT> BlockImportOperation<Block> {
storage: Storage,
state_version: StateVersion,
) -> ClientResult<Block::Hash> {
if storage.top.keys().any(|k| well_known_keys::is_child_storage_key(&k)) {
return Err(sp_blockchain::Error::InvalidState.into())
if storage.top.keys().any(|k| well_known_keys::is_child_storage_key(k)) {
return Err(sp_blockchain::Error::InvalidState)
}
let child_delta = storage.children_default.iter().map(|(_storage_key, child_content)| {
@@ -1063,7 +1060,7 @@ impl<Block: BlockT> Backend<Block> {
) -> ClientResult<Self> {
let is_archive_pruning = config.state_pruning.is_archive();
let blockchain = BlockchainDb::new(db.clone())?;
let map_e = |e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e);
let map_e = sp_blockchain::Error::from_state_db;
let state_db: StateDb<_, _> = StateDb::new(
config.state_pruning.clone(),
!db.supports_ref_counting(),
@@ -1087,7 +1084,7 @@ impl<Block: BlockT> Backend<Block> {
is_archive: is_archive_pruning,
io_stats: FrozenForDuration::new(std::time::Duration::from_secs(1)),
state_usage: Arc::new(StateUsageStats::new()),
keep_blocks: config.keep_blocks.clone(),
keep_blocks: config.keep_blocks,
genesis_state: RwLock::new(None),
};
@@ -1135,7 +1132,7 @@ impl<Block: BlockT> Backend<Block> {
(meta.best_number - best_number).saturated_into::<u64>() >
self.canonicalization_delay
{
return Err(sp_blockchain::Error::SetHeadTooOld.into())
return Err(sp_blockchain::Error::SetHeadTooOld)
}
let parent_exists =
@@ -1154,16 +1151,16 @@ impl<Block: BlockT> Backend<Block> {
(&r.number, &r.hash)
);
return Err(::sp_blockchain::Error::NotInFinalizedChain.into())
return Err(::sp_blockchain::Error::NotInFinalizedChain)
}
retracted.push(r.hash.clone());
retracted.push(r.hash);
utils::remove_number_to_key_mapping(transaction, columns::KEY_LOOKUP, r.number)?;
}
// canonicalize: set the number lookup to map to this block's hash.
for e in tree_route.enacted() {
enacted.push(e.hash.clone());
enacted.push(e.hash);
utils::insert_number_to_key_mapping(
transaction,
columns::KEY_LOOKUP,
@@ -1199,8 +1196,7 @@ impl<Block: BlockT> Backend<Block> {
"Last finalized {:?} not parent of {:?}",
last_finalized,
header.hash()
))
.into())
)))
}
Ok(())
}
@@ -1217,7 +1213,7 @@ impl<Block: BlockT> Backend<Block> {
// TODO: ensure best chain contains this block.
let number = *header.number();
self.ensure_sequential_finalization(header, last_finalized)?;
let with_state = sc_client_api::Backend::have_state_at(self, &hash, number);
let with_state = sc_client_api::Backend::have_state_at(self, hash, number);
self.note_finalized(transaction, header, *hash, finalization_displaced, with_state)?;
@@ -1264,9 +1260,10 @@ impl<Block: BlockT> Backend<Block> {
}
trace!(target: "db", "Canonicalize block #{} ({:?})", new_canonical, hash);
let commit = self.storage.state_db.canonicalize_block(&hash).map_err(
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
)?;
let commit =
self.storage.state_db.canonicalize_block(&hash).map_err(
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
)?;
apply_state_commit(transaction, commit);
}
Ok(())
@@ -1282,7 +1279,7 @@ impl<Block: BlockT> Backend<Block> {
let mut meta_updates = Vec::with_capacity(operation.finalized_blocks.len());
let (best_num, mut last_finalized_hash, mut last_finalized_num, mut block_gap) = {
let meta = self.blockchain.meta.read();
(meta.best_number, meta.finalized_hash, meta.finalized_number, meta.block_gap.clone())
(meta.best_number, meta.finalized_hash, meta.finalized_number, meta.block_gap)
};
for (block, justification) in operation.finalized_blocks {
@@ -1297,14 +1294,14 @@ impl<Block: BlockT> Backend<Block> {
&mut finalization_displaced_leaves,
)?);
last_finalized_hash = block_hash;
last_finalized_num = block_header.number().clone();
last_finalized_num = *block_header.number();
}
let imported = if let Some(pending_block) = operation.pending_block {
let hash = pending_block.header.hash();
let parent_hash = *pending_block.header.parent_hash();
let number = pending_block.header.number().clone();
let number = *pending_block.header.number();
let existing_header =
number <= best_num && self.blockchain.header(BlockId::hash(hash))?.is_some();
@@ -1352,7 +1349,7 @@ impl<Block: BlockT> Backend<Block> {
// memory to bootstrap consensus. It is queried for an initial list of
// authorities, etc.
*self.genesis_state.write() = Some(Arc::new(DbGenesisStorage::new(
pending_block.header.state_root().clone(),
*pending_block.header.state_root(),
operation.db_updates.clone(),
)));
}
@@ -1411,7 +1408,7 @@ impl<Block: BlockT> Backend<Block> {
let commit = self
.storage
.state_db
.insert_block(&hash, number_u64, &pending_block.header.parent_hash(), changeset)
.insert_block(&hash, number_u64, pending_block.header.parent_hash(), changeset)
.map_err(|e: sc_state_db::Error<io::Error>| {
sp_blockchain::Error::from_state_db(e)
})?;
@@ -1419,7 +1416,7 @@ impl<Block: BlockT> Backend<Block> {
if number <= last_finalized_num {
// Canonicalize in the db when re-importing existing blocks with state.
let commit = self.storage.state_db.canonicalize_block(&hash).map_err(
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
)?;
apply_state_commit(&mut transaction, commit);
meta_updates.push(MetaUpdate {
@@ -1549,11 +1546,8 @@ impl<Block: BlockT> Backend<Block> {
let number = header.number();
let hash = header.hash();
let (enacted, retracted) = self.set_head_with_transaction(
&mut transaction,
hash.clone(),
(number.clone(), hash.clone()),
)?;
let (enacted, retracted) =
self.set_head_with_transaction(&mut transaction, hash, (*number, hash))?;
meta_updates.push(MetaUpdate {
hash,
number: *number,
@@ -1616,9 +1610,9 @@ impl<Block: BlockT> Backend<Block> {
displaced: &mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>,
with_state: bool,
) -> ClientResult<()> {
let f_num = f_header.number().clone();
let f_num = *f_header.number();
let lookup_key = utils::number_and_hash_to_lookup_key(f_num, f_hash.clone())?;
let lookup_key = utils::number_and_hash_to_lookup_key(f_num, f_hash)?;
if with_state {
transaction.set_from_vec(columns::META, meta_keys::FINALIZED_STATE, lookup_key.clone());
}
@@ -1631,9 +1625,10 @@ impl<Block: BlockT> Backend<Block> {
.map(|c| f_num.saturated_into::<u64>() > c)
.unwrap_or(true)
{
let commit = self.storage.state_db.canonicalize_block(&f_hash).map_err(
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
)?;
let commit =
self.storage.state_db.canonicalize_block(&f_hash).map_err(
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
)?;
apply_state_commit(transaction, commit);
}
@@ -1664,18 +1659,18 @@ impl<Block: BlockT> Backend<Block> {
// Also discard all blocks from displaced branches
for h in displaced.leaves() {
let mut number = finalized;
let mut hash = h.clone();
let mut hash = *h;
// Follow displaced chains back until we reach a finalized block.
// Since leaves are discarded due to finality, they can't have parents
// that are canonical, but not yet finalized. So we stop deleting as soon as
// we reach canonical chain.
while self.blockchain.hash(number)? != Some(hash.clone()) {
let id = BlockId::<Block>::hash(hash.clone());
while self.blockchain.hash(number)? != Some(hash) {
let id = BlockId::<Block>::hash(hash);
match self.blockchain.header(id)? {
Some(header) => {
self.prune_block(transaction, id)?;
number = header.number().saturating_sub(One::one());
hash = header.parent_hash().clone();
hash = *header.parent_hash();
},
None => break,
}
@@ -1780,7 +1775,7 @@ fn apply_index_ops<Block: BlockT>(
// Bump ref counter
let extrinsic = extrinsic.encode();
transaction.reference(columns::TRANSACTION, DbHash::from_slice(hash.as_ref()));
DbExtrinsic::Indexed { hash: hash.clone(), header: extrinsic }
DbExtrinsic::Indexed { hash: *hash, header: extrinsic }
} else {
match index_map.get(&(index as u32)) {
Some((hash, size)) => {
@@ -2063,8 +2058,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
let update_finalized = best_number < finalized;
let key =
utils::number_and_hash_to_lookup_key(best_number.clone(), &best_hash)?;
let key = utils::number_and_hash_to_lookup_key(best_number, &best_hash)?;
if update_finalized {
transaction.set_from_vec(
columns::META,
@@ -2143,8 +2137,8 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
return Err(sp_blockchain::Error::Backend(format!("Can't remove best block {:?}", hash)))
}
let hdr = self.blockchain.header_metadata(hash.clone())?;
if !self.have_state_at(&hash, hdr.number) {
let hdr = self.blockchain.header_metadata(*hash)?;
if !self.have_state_at(hash, hdr.number) {
return Err(sp_blockchain::Error::UnknownBlock(format!(
"State already discarded for {:?}",
hash
@@ -2164,7 +2158,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
apply_state_commit(&mut transaction, commit);
}
transaction.remove(columns::KEY_LOOKUP, hash.as_ref());
leaves.revert(hash.clone(), hdr.number);
leaves.revert(*hash, hdr.number);
leaves.prepare_transaction(&mut transaction, columns::META, meta_keys::LEAF_PREFIX);
self.storage.db.commit(transaction)?;
self.blockchain().remove_header_metadata(*hash);
@@ -2185,8 +2179,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
};
if is_genesis {
if let Some(genesis_state) = &*self.genesis_state.read() {
let root = genesis_state.root.clone();
let db_state = DbState::<Block>::new(genesis_state.clone(), root);
let db_state = DbState::<Block>::new(genesis_state.clone(), genesis_state.root);
let state = RefTrackingState::new(db_state, self.storage.clone(), None);
let caching_state = CachingState::new(state, self.shared_cache.clone(), None);
let mut state = SyncingCachingState::new(
@@ -2218,8 +2211,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
if let Ok(()) = self.storage.state_db.pin(&hash) {
let root = hdr.state_root;
let db_state = DbState::<Block>::new(self.storage.clone(), root);
let state =
RefTrackingState::new(db_state, self.storage.clone(), Some(hash.clone()));
let state = RefTrackingState::new(db_state, self.storage.clone(), Some(hash));
let caching_state =
CachingState::new(state, self.shared_cache.clone(), Some(hash));
Ok(SyncingCachingState::new(
@@ -2241,7 +2233,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
fn have_state_at(&self, hash: &Block::Hash, number: NumberFor<Block>) -> bool {
if self.is_archive {
match self.blockchain.header_metadata(hash.clone()) {
match self.blockchain.header_metadata(*hash) {
Ok(header) => sp_state_machine::Storage::get(
self.storage.as_ref(),
&header.state_root,