From 25b5277e469a9eb37e43ae6bf264d240e74dff1e Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Tue, 13 Jun 2023 14:10:41 +0200
Subject: [PATCH] fix clippy warnings and optimization

---
 Cargo.lock                                   |  1 +
 node/src/cli.rs                              |  2 +-
 node/src/command.rs                          |  4 ++--
 node/src/rpc.rs                              |  4 ++--
 node/src/service.rs                          | 21 +++++++++-----------
 pallets/offences/src/mock.rs                 |  2 +-
 runtime/common/src/pallets_config.rs         |  4 ++--
 runtime/common/src/weights/pallet_grandpa.rs |  2 +-
 runtime/g1/src/lib.rs                        |  2 +-
 runtime/gdev/Cargo.toml                      |  1 +
 runtime/gdev/tests/common/mod.rs             |  4 ++--
 runtime/gdev/tests/integration_tests.rs      |  2 +-
 runtime/gtest/src/lib.rs                     |  2 +-
 13 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 2d222269d..8bfee8474 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3025,6 +3025,7 @@ dependencies = [
  "sp-authority-discovery",
  "sp-block-builder",
  "sp-consensus-babe",
+ "sp-consensus-grandpa",
  "sp-core",
  "sp-inherents",
  "sp-io",
diff --git a/node/src/cli.rs b/node/src/cli.rs
index 3cfdc73c3..e1f62481f 100644
--- a/node/src/cli.rs
+++ b/node/src/cli.rs
@@ -75,7 +75,7 @@ pub enum Subcommand {
     /// Sub-commands concerned with benchmarking.
     /// The pallet benchmarking moved to the `pallet` sub-command.
     #[clap(subcommand)]
-    Benchmark(frame_benchmarking_cli::BenchmarkCmd),
+    Benchmark(Box<frame_benchmarking_cli::BenchmarkCmd>),
 
     /// Try some command against runtime state.
     #[cfg(feature = "try-runtime")]
diff --git a/node/src/command.rs b/node/src/command.rs
index d151a7fb6..90bf1bd5d 100644
--- a/node/src/command.rs
+++ b/node/src/command.rs
@@ -311,11 +311,11 @@ pub fn run() -> sc_cli::Result<()> {
         }
         #[cfg(feature = "runtime-benchmarks")]
         Some(Subcommand::Benchmark(cmd)) => {
-            let runner = cli.create_runner(cmd)?;
+            let runner = cli.create_runner(&**cmd)?;
             let chain_spec = &runner.config().chain_spec;
             ensure_dev(chain_spec)?;
 
-            match cmd {
+            match &**cmd {
                 BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| {
                     let (client, backend, _, _) = service::new_chain_ops(&mut config, false)?;
                     let db = backend.expose_db();
diff --git a/node/src/rpc.rs b/node/src/rpc.rs
index 036f63eb8..301d4ce9f 100644
--- a/node/src/rpc.rs
+++ b/node/src/rpc.rs
@@ -104,7 +104,7 @@ where
         module.merge(
             Babe::new(
                 client.clone(),
-                babe_worker_handle.clone(),
+                babe_worker_handle,
                 keystore,
                 select_chain,
                 deny_unsafe,
@@ -113,7 +113,7 @@ where
         )?;
     }
     module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
-    module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
+    module.merge(TransactionPayment::new(client).into_rpc())?;
     if let Some(command_sink) = command_sink_opt {
         // We provide the rpc handler with the sending end of the channel to allow the rpc
         // send EngineCommands to the background block authorship task.
diff --git a/node/src/service.rs b/node/src/service.rs
index 18162b7db..49b51a387 100644
--- a/node/src/service.rs
+++ b/node/src/service.rs
@@ -276,9 +276,10 @@ where
         client.clone(),
     );
 
+    let client_ = client.clone();
     let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import(
         client.clone(),
-        &(client.clone() as Arc<_>),
+        &(client_ as Arc<_>),
         select_chain.clone(),
         telemetry.as_ref().map(|x| x.handle()),
     )?;
@@ -555,17 +556,13 @@ where
     let rpc_extensions_builder = {
         let client = client.clone();
         let pool = transaction_pool.clone();
-        let select_chain = select_chain.clone();
+        let select_chain = select_chain;
         let chain_spec = config.chain_spec.cloned_box();
         let keystore = keystore_container.keystore().clone();
-        let babe_deps = if let Some(babe_worker_handle) = babe_worker_handle {
-            Some(crate::rpc::BabeDeps {
-                babe_worker_handle: babe_worker_handle.clone(),
-                keystore: keystore.clone(),
-            })
-        } else {
-            None
-        };
+        let babe_deps = babe_worker_handle.map(|babe_worker_handle| crate::rpc::BabeDeps {
+            babe_worker_handle,
+            keystore: keystore.clone(),
+        });
 
         Box::new(move |deny_unsafe, _| {
             let deps = crate::rpc::FullDeps {
@@ -627,8 +624,8 @@ where
         let grandpa_config = sc_consensus_grandpa::GrandpaParams {
             config: grandpa_config,
             link: grandpa_link,
-            sync: sync_service.clone(),
-            network: network.clone(),
+            sync: sync_service,
+            network,
             voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(),
             prometheus_registry,
             shared_voter_state: SharedVoterState::empty(),
diff --git a/pallets/offences/src/mock.rs b/pallets/offences/src/mock.rs
index 1229f7559..57f8e7399 100644
--- a/pallets/offences/src/mock.rs
+++ b/pallets/offences/src/mock.rs
@@ -114,7 +114,7 @@ pub const KIND: [u8; 16] = *b"test_report_1234";
 
 /// Returns all offence details for the specific `kind` happened at the specific time slot.
 pub fn offence_reports(kind: Kind, time_slot: u128) -> Vec<OffenceDetails<u64, u64>> {
-    <crate::ConcurrentReportsIndex<Runtime>>::get(kind, &time_slot.encode())
+    <crate::ConcurrentReportsIndex<Runtime>>::get(kind, time_slot.encode())
         .into_iter()
         .map(|report_id| {
             <crate::Reports<Runtime>>::get(report_id)
diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index 043b8c675..fe2e8c240 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -160,12 +160,12 @@ macro_rules! pallets_config {
         }
 
         // Take Dust from Balances and put it in the Treasury pot
-        use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
-        use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Imbalance;
         pub struct HandleDust;
         type CreditOf = frame_support::traits::tokens::fungible::Credit<AccountId, Balances>;
         impl frame_support::traits::OnUnbalanced<CreditOf> for HandleDust {
             fn on_nonzero_unbalanced(amount: CreditOf) {
+                use frame_support::traits::Currency as _;
+                use frame_support::traits::Imbalance as _;
                 let imbalance = NegativeImbalance::new(amount.peek());
                 Balances::resolve_creating(&Treasury::account_id(), imbalance);
             }
diff --git a/runtime/common/src/weights/pallet_grandpa.rs b/runtime/common/src/weights/pallet_grandpa.rs
index b824f4c9d..c30daf261 100644
--- a/runtime/common/src/weights/pallet_grandpa.rs
+++ b/runtime/common/src/weights/pallet_grandpa.rs
@@ -36,7 +36,7 @@ impl<T: frame_system::Config> pallet_grandpa::WeightInfo for WeightInfo<T> {
 
         // checking membership proof
         (Weight::from_parts(WEIGHT_REF_TIME_PER_MICROS, 0) * 35)
-            .saturating_add((Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS, 0) * 175))
+            .saturating_add(Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS, 0) * 175)
             .saturating_mul(validator_count)
             .saturating_add(T::DbWeight::get().reads(5))
             // check equivocation proof
diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs
index 3d34f0ef0..e4c2435cc 100644
--- a/runtime/g1/src/lib.rs
+++ b/runtime/g1/src/lib.rs
@@ -257,7 +257,7 @@ construct_runtime!(
 
         // Consensus support.
         AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
-        Authorship: pallet_authorship::{Pallet, Call, Storage} = 11,
+        Authorship: pallet_authorship::{Pallet, Storage} = 11,
         Offences: pallet_offences::{Pallet, Storage, Event} = 12,
         Historical: session_historical::{Pallet} = 13,
         Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 14,
diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml
index 8f51cf101..76d647fbe 100644
--- a/runtime/gdev/Cargo.toml
+++ b/runtime/gdev/Cargo.toml
@@ -187,6 +187,7 @@ sp-arithmetic = { git = 'https://github.com/duniter/substrate', branch = 'dunite
 sp-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
 sp-block-builder = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
 sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
+sp-consensus-grandpa = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
 sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
 sp-inherents = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
 sp-offchain = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
diff --git a/runtime/gdev/tests/common/mod.rs b/runtime/gdev/tests/common/mod.rs
index 12e708e65..8f630fdd0 100644
--- a/runtime/gdev/tests/common/mod.rs
+++ b/runtime/gdev/tests/common/mod.rs
@@ -22,10 +22,10 @@ use frame_support::instances::{Instance1, Instance2};
 use frame_support::traits::{GenesisBuild, OnFinalize, OnInitialize};
 use gdev_runtime::opaque::SessionKeys;
 use gdev_runtime::*;
-use sc_consensus_grandpa::AuthorityId as GrandpaId;
 use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
 use sp_consensus_babe::{AuthorityId as BabeId, Slot};
-use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
+use sp_consensus_babe::{VrfOutput, VrfProof};
+use sp_consensus_grandpa::AuthorityId as GrandpaId;
 use sp_core::crypto::IsWrappedBy;
 use sp_core::sr25519;
 use sp_core::{Encode, Pair, Public, H256};
diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs
index 22d1fb056..282180349 100644
--- a/runtime/gdev/tests/integration_tests.rs
+++ b/runtime/gdev/tests/integration_tests.rs
@@ -479,7 +479,7 @@ fn test_create_new_account() {
                     MultiAddress::Id(AccountKeyring::Alice.to_account_id()),
                     200
                 ),
-                pallet_balances::Error::<Runtime>::KeepAlive,
+                pallet_balances::Error::<Runtime>::Expendability,
             );
             assert_eq!(
                 Balances::free_balance(AccountKeyring::Eve.to_account_id()),
diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs
index ea65433a5..0e1ca05c2 100644
--- a/runtime/gtest/src/lib.rs
+++ b/runtime/gtest/src/lib.rs
@@ -273,7 +273,7 @@ construct_runtime!(
 
         // Consensus support
         AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
-        Authorship: pallet_authorship::{Pallet, Call, Storage} = 11,
+        Authorship: pallet_authorship::{Pallet, Storage} = 11,
         Offences: pallet_offences::{Pallet, Storage, Event} = 12,
         Historical: session_historical::{Pallet} = 13,
         Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 14,
-- 
GitLab