From 1b18c63a53d425266bdc3e93935e00996dd98c76 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 30 Nov 2020 16:14:07 +0300 Subject: [PATCH] Fixed clippy warnings (#537) * fixed clippy warnings * Revert "Actually use pinned nightly version when building runtimes (#465)" This reverts commit dedddb6b0f22260e00053c28873a0cb1fbea22e2. * Revert "Pin Rust Nightly Version (#420)" This reverts commit 8902ac2030cf7ef48ec512463424f134a3b38804. * fix after revert * another fix after revert * more clippy fixes --- bridges/bin/millau/node/src/chain_spec.rs | 6 +-- bridges/bin/millau/node/src/command.rs | 2 +- bridges/bin/rialto/node/src/chain_spec.rs | 22 +++++----- bridges/bin/rialto/node/src/command.rs | 2 +- bridges/modules/ethereum/src/lib.rs | 41 ++++++++++--------- bridges/modules/ethereum/src/validators.rs | 12 ++++-- bridges/modules/substrate/src/lib.rs | 1 + .../headers-relay/src/sync_loop_tests.rs | 7 ++-- bridges/relays/utils/src/lib.rs | 11 ++--- 9 files changed, 57 insertions(+), 47 deletions(-) diff --git a/bridges/bin/millau/node/src/chain_spec.rs b/bridges/bin/millau/node/src/chain_spec.rs index f1b6323763c4f..8c7c40472751b 100644 --- a/bridges/bin/millau/node/src/chain_spec.rs +++ b/bridges/bin/millau/node/src/chain_spec.rs @@ -65,8 +65,8 @@ pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) { impl Alternative { /// Get an actual chain config from one of the alternatives. - pub(crate) fn load(self) -> Result { - Ok(match self { + pub(crate) fn load(self) -> ChainSpec { + match self { Alternative::Development => ChainSpec::from_genesis( "Development", "dev", @@ -131,7 +131,7 @@ impl Alternative { None, None, ), - }) + } } } diff --git a/bridges/bin/millau/node/src/command.rs b/bridges/bin/millau/node/src/command.rs index 651080bbf200e..c007d5d848532 100644 --- a/bridges/bin/millau/node/src/command.rs +++ b/bridges/bin/millau/node/src/command.rs @@ -61,7 +61,7 @@ impl SubstrateCli for Cli { "local" => crate::chain_spec::Alternative::LocalTestnet, _ => return Err(format!("Unsupported chain specification: {}", id)), } - .load()?, + .load(), )) } } diff --git a/bridges/bin/rialto/node/src/chain_spec.rs b/bridges/bin/rialto/node/src/chain_spec.rs index ed226334e5302..939dcc5e3fe6b 100644 --- a/bridges/bin/rialto/node/src/chain_spec.rs +++ b/bridges/bin/rialto/node/src/chain_spec.rs @@ -65,8 +65,8 @@ pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) { impl Alternative { /// Get an actual chain config from one of the alternatives. - pub(crate) fn load(self) -> Result { - Ok(match self { + pub(crate) fn load(self) -> ChainSpec { + match self { Alternative::Development => ChainSpec::from_genesis( "Development", "dev", @@ -131,7 +131,7 @@ impl Alternative { None, None, ), - }) + } } } @@ -156,8 +156,8 @@ fn testnet_genesis( pallet_aura: Some(AuraConfig { authorities: Vec::new(), }), - pallet_bridge_eth_poa_Instance1: load_rialto_poa_bridge_config(), - pallet_bridge_eth_poa_Instance2: load_kovan_bridge_config(), + pallet_bridge_eth_poa_Instance1: Some(load_rialto_poa_bridge_config()), + pallet_bridge_eth_poa_Instance2: Some(load_kovan_bridge_config()), pallet_grandpa: Some(GrandpaConfig { authorities: Vec::new(), }), @@ -176,18 +176,18 @@ fn testnet_genesis( } } -fn load_rialto_poa_bridge_config() -> Option { - Some(BridgeRialtoPoAConfig { +fn load_rialto_poa_bridge_config() -> BridgeRialtoPoAConfig { + BridgeRialtoPoAConfig { initial_header: rialto_runtime::rialto_poa::genesis_header(), initial_difficulty: 0.into(), initial_validators: rialto_runtime::rialto_poa::genesis_validators(), - }) + } } -fn load_kovan_bridge_config() -> Option { - Some(BridgeKovanConfig { +fn load_kovan_bridge_config() -> BridgeKovanConfig { + BridgeKovanConfig { initial_header: rialto_runtime::kovan::genesis_header(), initial_difficulty: 0.into(), initial_validators: rialto_runtime::kovan::genesis_validators(), - }) + } } diff --git a/bridges/bin/rialto/node/src/command.rs b/bridges/bin/rialto/node/src/command.rs index fe423f8803d97..52ff1d5a254d3 100644 --- a/bridges/bin/rialto/node/src/command.rs +++ b/bridges/bin/rialto/node/src/command.rs @@ -61,7 +61,7 @@ impl SubstrateCli for Cli { "local" => crate::chain_spec::Alternative::LocalTestnet, _ => return Err(format!("Unsupported chain specification: {}", id)), } - .load()?, + .load(), )) } } diff --git a/bridges/modules/ethereum/src/lib.rs b/bridges/modules/ethereum/src/lib.rs index ace34f38edb81..75062f763952a 100644 --- a/bridges/modules/ethereum/src/lib.rs +++ b/bridges/modules/ethereum/src/lib.rs @@ -1028,7 +1028,7 @@ fn pool_configuration() -> PoolConfiguration { } /// Return iterator of given header ancestors. -fn ancestry<'a, S: Storage>(storage: &'a S, mut parent_hash: H256) -> impl Iterator + 'a { +fn ancestry(storage: &'_ S, mut parent_hash: H256) -> impl Iterator + '_ { sp_std::iter::from_fn(move || { let (header, _) = storage.header(&parent_hash)?; if header.number == 0 { @@ -1069,30 +1069,33 @@ pub(crate) mod tests { } fn example_header_with_failed_receipt() -> AuraHeader { - let mut header = AuraHeader::default(); - header.number = 3; - header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter()); - header.receipts_root = compute_merkle_root(vec![example_tx_receipt(false)].into_iter()); - header.parent_hash = example_header().compute_hash(); - header + AuraHeader { + number: 3, + transactions_root: compute_merkle_root(vec![example_tx()].into_iter()), + receipts_root: compute_merkle_root(vec![example_tx_receipt(false)].into_iter()), + parent_hash: example_header().compute_hash(), + ..Default::default() + } } fn example_header() -> AuraHeader { - let mut header = AuraHeader::default(); - header.number = 2; - header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter()); - header.receipts_root = compute_merkle_root(vec![example_tx_receipt(true)].into_iter()); - header.parent_hash = example_header_parent().compute_hash(); - header + AuraHeader { + number: 2, + transactions_root: compute_merkle_root(vec![example_tx()].into_iter()), + receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()), + parent_hash: example_header_parent().compute_hash(), + ..Default::default() + } } fn example_header_parent() -> AuraHeader { - let mut header = AuraHeader::default(); - header.number = 1; - header.transactions_root = compute_merkle_root(vec![example_tx()].into_iter()); - header.receipts_root = compute_merkle_root(vec![example_tx_receipt(true)].into_iter()); - header.parent_hash = genesis().compute_hash(); - header + AuraHeader { + number: 1, + transactions_root: compute_merkle_root(vec![example_tx()].into_iter()), + receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()), + parent_hash: genesis().compute_hash(), + ..Default::default() + } } fn with_headers_to_prune(f: impl Fn(BridgeStorage) -> T) -> T { diff --git a/bridges/modules/ethereum/src/validators.rs b/bridges/modules/ethereum/src/validators.rs index dc09b48d55062..d4ddac66b7df0 100644 --- a/bridges/modules/ethereum/src/validators.rs +++ b/bridges/modules/ethereum/src/validators.rs @@ -325,8 +325,10 @@ pub(crate) mod tests { // when contract is active, but bloom has no required bits set let config = ValidatorsConfiguration::Single(ValidatorsSource::Contract(Default::default(), Vec::new())); let validators = Validators::new(&config); - let mut header = AuraHeader::default(); - header.number = u64::max_value(); + let mut header = AuraHeader { + number: u64::max_value(), + ..Default::default() + }; assert!(!validators.maybe_signals_validators_change(&header)); // when contract is active and bloom has required bits set @@ -347,10 +349,12 @@ pub(crate) mod tests { (200, ValidatorsSource::Contract([3; 20].into(), vec![[3; 20].into()])), ]); let validators = Validators::new(&config); - let mut header = AuraHeader::default(); + let mut header = AuraHeader { + number: 100, + ..Default::default() + }; // when we're at the block that switches to list source - header.number = 100; assert_eq!( validators.extract_validators_change(&header, None), Ok((None, Some(vec![[2; 20].into()]))), diff --git a/bridges/modules/substrate/src/lib.rs b/bridges/modules/substrate/src/lib.rs index 4e62841af7b56..eb77b5af750fb 100644 --- a/bridges/modules/substrate/src/lib.rs +++ b/bridges/modules/substrate/src/lib.rs @@ -459,6 +459,7 @@ pub trait BridgeStorage { /// Replace the current authority set with the next scheduled set. /// /// Returns an error if there is no scheduled authority set to enact. + #[allow(clippy::result_unit_err)] fn enact_authority_set(&mut self, signal_hash: ::Hash) -> Result<(), ()>; /// Get the next scheduled Grandpa authority set change. diff --git a/bridges/relays/headers-relay/src/sync_loop_tests.rs b/bridges/relays/headers-relay/src/sync_loop_tests.rs index f41d9708cd61c..27e5daa7da4f4 100644 --- a/bridges/relays/headers-relay/src/sync_loop_tests.rs +++ b/bridges/relays/headers-relay/src/sync_loop_tests.rs @@ -357,9 +357,10 @@ fn target_accept_all_headers(method: &TargetMethod, data: &mut TargetData, requi if let TargetMethod::SubmitHeaders(ref submitted) = method { assert_eq!(submitted.iter().all(|header| header.extra().is_some()), requires_extra,); - let mut submitted_headers = SubmittedHeaders::default(); - submitted_headers.submitted = submitted.iter().map(|header| header.id()).collect(); - data.submit_headers_result = Some(submitted_headers); + data.submit_headers_result = Some(SubmittedHeaders { + submitted: submitted.iter().map(|header| header.id()).collect(), + ..Default::default() + }); } } diff --git a/bridges/relays/utils/src/lib.rs b/bridges/relays/utils/src/lib.rs index e81660299becb..2968320ff5c87 100644 --- a/bridges/relays/utils/src/lib.rs +++ b/bridges/relays/utils/src/lib.rs @@ -147,11 +147,12 @@ impl ToString for StringifiedMaybeConnectionError { /// Exponential backoff for connection-unrelated errors retries. pub fn retry_backoff() -> ExponentialBackoff { - let mut backoff = ExponentialBackoff::default(); - // we do not want relayer to stop - backoff.max_elapsed_time = None; - backoff.max_interval = MAX_BACKOFF_INTERVAL; - backoff + ExponentialBackoff { + // we do not want relayer to stop + max_elapsed_time: None, + max_interval: MAX_BACKOFF_INTERVAL, + ..Default::default() + } } /// Compact format of IDs vector.