From 36e04f8e4ca7c048f0cafcc16deba5e1d939c1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 14 Jan 2020 10:13:03 +0100 Subject: [PATCH] Take `genesis_storage` by ref Instead of having these weird implementation of `BuildStorage for &ChainSpec` we should just take the `genesis_storage` by ref. The `BuildStorage` trait changed some time ago to take a self ref anyway, instead of a self value. Also fixes warnings in frame-staking --- client/chain-spec/src/chain_spec.rs | 2 +- client/db/src/lib.rs | 2 +- client/src/client.rs | 6 +++--- client/src/lib.rs | 2 +- client/src/light/mod.rs | 2 +- frame/staking/src/lib.rs | 6 ++---- test-utils/client/src/lib.rs | 2 +- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/client/chain-spec/src/chain_spec.rs b/client/chain-spec/src/chain_spec.rs index 6e58083e8cc2e..81cbce5ea731c 100644 --- a/client/chain-spec/src/chain_spec.rs +++ b/client/chain-spec/src/chain_spec.rs @@ -70,7 +70,7 @@ impl GenesisSource { } } -impl<'a, G: RuntimeGenesis, E> BuildStorage for &'a ChainSpec { +impl BuildStorage for ChainSpec { fn build_storage(&self) -> Result { match self.genesis.resolve()? { Genesis::Runtime(gc) => gc.build_storage(), diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index 06d0dc18ffa36..b4eae2db2b49f 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -274,7 +274,7 @@ pub enum DatabaseSettingsSrc { pub fn new_client( settings: DatabaseSettings, executor: E, - genesis_storage: S, + genesis_storage: &S, fork_blocks: ForkBlocks, bad_blocks: BadBlocks, execution_extensions: ExecutionExtensions, diff --git a/client/src/client.rs b/client/src/client.rs index 2babf6f3e900e..aeca4331844c0 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -129,7 +129,7 @@ impl PrePostHeader { /// Create an instance of in-memory client. pub fn new_in_mem( executor: E, - genesis_storage: S, + genesis_storage: &S, keystore: Option, ) -> sp_blockchain::Result, @@ -149,7 +149,7 @@ pub fn new_in_mem( pub fn new_with_backend( backend: Arc, executor: E, - build_genesis_storage: S, + build_genesis_storage: &S, keystore: Option, ) -> sp_blockchain::Result, Block, RA>> where @@ -187,7 +187,7 @@ impl Client where pub fn new( backend: Arc, executor: E, - build_genesis_storage: S, + build_genesis_storage: &S, fork_blocks: ForkBlocks, bad_blocks: BadBlocks, execution_extensions: ExecutionExtensions, diff --git a/client/src/lib.rs b/client/src/lib.rs index cfaf08ca7ef6e..db2d4785a2c98 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -65,7 +65,7 @@ //! NativeExecutor::::new(WasmExecutionMethod::Interpreted, None), //! ), //! // This parameter provides the storage for the chain genesis. -//! ::default(), +//! &::default(), //! Default::default(), //! Default::default(), //! Default::default(), diff --git a/client/src/light/mod.rs b/client/src/light/mod.rs index 5052b36d7f3e1..c067fc9caaa53 100644 --- a/client/src/light/mod.rs +++ b/client/src/light/mod.rs @@ -56,7 +56,7 @@ pub fn new_light_backend(blockchain: Arc>) -> Arc( backend: Arc>>, - genesis_storage: GS, + genesis_storage: &GS, code_executor: E, ) -> ClientResult< Client< diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 94618c9349815..326a01599034c 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -283,7 +283,7 @@ use sp_staking::{ use sp_runtime::{Serialize, Deserialize}; use frame_system::{self as system, ensure_signed, ensure_root}; -use sp_phragmen::{ExtendedBalance, PhragmenStakedAssignment}; +use sp_phragmen::ExtendedBalance; const DEFAULT_MINIMUM_VALIDATOR_COUNT: u32 = 4; const MAX_NOMINATIONS: usize = 16; @@ -1508,12 +1508,10 @@ impl Module { .collect::>(); let assignments = phragmen_result.assignments; - let to_votes = |b: BalanceOf| - , u64>>::convert(b) as ExtendedBalance; let to_balance = |e: ExtendedBalance| >>::convert(e); - let mut supports = sp_phragmen::build_support_map::<_, _, _, T::CurrencyToVote>( + let supports = sp_phragmen::build_support_map::<_, _, _, T::CurrencyToVote>( &elected_stashes, &assignments, Self::slashable_balance_of, diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index ac1cfe4d6b6a5..c8d3a809a7d0d 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -190,7 +190,7 @@ impl TestClientBuilder let client = sc_client::Client::new( self.backend.clone(), executor, - storage, + &storage, Default::default(), Default::default(), ExecutionExtensions::new(