From f27e1a51a39b57e16053ef2a5ba813aef9557056 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 18 Oct 2022 13:32:13 +0300 Subject: [PATCH 1/2] clipy --- bin/millau/runtime/src/lib.rs | 2 +- bin/rialto/runtime/src/lib.rs | 2 +- primitives/messages/src/lib.rs | 2 +- primitives/test-utils/src/lib.rs | 2 +- relays/finality/src/sync_loop_metrics.rs | 2 +- .../lib-substrate-relay/src/finality/engine.rs | 4 ++-- .../lib-substrate-relay/src/messages_metrics.rs | 16 ++++++++-------- .../lib-substrate-relay/src/messages_source.rs | 2 +- .../lib-substrate-relay/src/parachains/target.rs | 2 +- relays/messages/src/relay_strategy/mod.rs | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index cb0862bc04..b048bf5e60 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -423,7 +423,7 @@ parameter_types! { /// /// Assuming the worst case of every header being finalized, we will keep headers at least for a /// week. - pub const HeadersToKeep: u32 = 7 * bp_rialto::DAYS as u32; + pub const HeadersToKeep: u32 = 7 * bp_rialto::DAYS; } parameter_types! { diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 161b031950..506806d0ae 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -416,7 +416,7 @@ parameter_types! { /// /// Assuming the worst case of every header being finalized, we will keep headers at least for a /// week. - pub const HeadersToKeep: u32 = 7 * bp_rialto::DAYS as u32; + pub const HeadersToKeep: u32 = 7 * bp_rialto::DAYS; /// Maximal number of authorities at Millau. pub const MaxAuthoritiesAtMillau: u32 = bp_millau::MAX_AUTHORITIES_COUNT; diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index d5b2b9c9db..8742ff8448 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -414,7 +414,7 @@ mod tests { .len(); let difference = (expected_size.unwrap() as f64 - actual_size as f64).abs(); assert!( - difference / (std::cmp::min(actual_size, expected_size.unwrap() as usize) as f64) < 0.1, + difference / (std::cmp::min(actual_size, expected_size.unwrap()) as f64) < 0.1, "Too large difference between actual ({}) and expected ({:?}) inbound lane data size. Test case: {}+{}", actual_size, expected_size, diff --git a/primitives/test-utils/src/lib.rs b/primitives/test-utils/src/lib.rs index 66dbe9e738..e16c43c981 100644 --- a/primitives/test-utils/src/lib.rs +++ b/primitives/test-utils/src/lib.rs @@ -112,7 +112,7 @@ pub fn make_justification_for_header( }; // Note: Adding 1 to account for the target header - let chain = generate_chain(i as u32, depth + 1, &header); + let chain = generate_chain(i, depth + 1, &header); // We don't include our finality target header in the vote ancestries for child in &chain[1..] { diff --git a/relays/finality/src/sync_loop_metrics.rs b/relays/finality/src/sync_loop_metrics.rs index a003a47d89..fcfdbbd99f 100644 --- a/relays/finality/src/sync_loop_metrics.rs +++ b/relays/finality/src/sync_loop_metrics.rs @@ -72,7 +72,7 @@ impl SyncLoopMetrics { /// Update using-same-fork flag. pub fn update_using_same_fork(&self, using_same_fork: bool) { - self.using_different_forks.set(if using_same_fork { 0 } else { 1 }) + self.using_different_forks.set((!using_same_fork).into()) } } diff --git a/relays/lib-substrate-relay/src/finality/engine.rs b/relays/lib-substrate-relay/src/finality/engine.rs index b2b72e4f2c..aaa58ff3ed 100644 --- a/relays/lib-substrate-relay/src/finality/engine.rs +++ b/relays/lib-substrate-relay/src/finality/engine.rs @@ -154,7 +154,7 @@ impl Engine for Grandpa { .await .map_err(|e| Error::ReadJustification(C::NAME, e)) .and_then(|justification| { - justification.ok_or(Error::ReadJustificationStreamEnded(C::NAME)) + justification.ok_or_else(|| Error::ReadJustificationStreamEnded(C::NAME)) })?; // Read initial header. @@ -207,7 +207,7 @@ impl Engine for Grandpa { let mut initial_authorities_set_id = 0; let mut min_possible_block_number = C::BlockNumber::zero(); let authorities_for_verification = VoterSet::new(authorities_for_verification.clone()) - .ok_or(Error::ReadInvalidAuthorities(C::NAME, authorities_for_verification))?; + .ok_or_else(|| Error::ReadInvalidAuthorities(C::NAME, authorities_for_verification))?; loop { log::trace!( target: "bridge", "Trying {} GRANDPA authorities set id: {}", diff --git a/relays/lib-substrate-relay/src/messages_metrics.rs b/relays/lib-substrate-relay/src/messages_metrics.rs index 805d002b65..1c321a0511 100644 --- a/relays/lib-substrate-relay/src/messages_metrics.rs +++ b/relays/lib-substrate-relay/src/messages_metrics.rs @@ -153,12 +153,12 @@ pub fn standalone_metrics( .map(|source_chain_token_id| { crate::helpers::token_price_metric(source_chain_token_id).map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, target_to_base_conversion_rate: P::TargetChain::TOKEN_ID .map(|target_chain_token_id| { crate::helpers::token_price_metric(target_chain_token_id).map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, source_to_target_conversion_rate: P::SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -181,7 +181,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, target_to_source_conversion_rate: P::TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -204,7 +204,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, source_fee_multiplier: P::AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME .map(|pallet| bp_runtime::storage_value_key(pallet, NEXT_FEE_MULTIPLIER_VALUE_NAME)) .map(|key| { @@ -218,7 +218,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, source_fee_multiplier_at_target: P::SOURCE_FEE_MULTIPLIER_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -235,7 +235,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, target_fee_multiplier: P::AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME .map(|pallet| bp_runtime::storage_value_key(pallet, NEXT_FEE_MULTIPLIER_VALUE_NAME)) .map(|key| { @@ -249,7 +249,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, target_fee_multiplier_at_source: P::TARGET_FEE_MULTIPLIER_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -266,7 +266,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or(Ok(None))?, + .unwrap_or_else(|| Ok(None))?, }) } diff --git a/relays/lib-substrate-relay/src/messages_source.rs b/relays/lib-substrate-relay/src/messages_source.rs index e34f477e5f..4eac180db1 100644 --- a/relays/lib-substrate-relay/src/messages_source.rs +++ b/relays/lib-substrate-relay/src/messages_source.rs @@ -553,7 +553,7 @@ where ) .map_err(SubstrateError::ResponseParseFailed)? .map(Ok) - .unwrap_or(Err(SubstrateError::BridgePalletIsNotInitialized)) + .unwrap_or_else(|| Err(SubstrateError::BridgePalletIsNotInitialized)) } fn validate_out_msgs_details( diff --git a/relays/lib-substrate-relay/src/parachains/target.rs b/relays/lib-substrate-relay/src/parachains/target.rs index 8d0d361984..28320787d7 100644 --- a/relays/lib-substrate-relay/src/parachains/target.rs +++ b/relays/lib-substrate-relay/src/parachains/target.rs @@ -113,7 +113,7 @@ where ) .map_err(SubstrateError::ResponseParseFailed)? .map(Ok) - .unwrap_or(Err(SubstrateError::BridgePalletIsNotInitialized)) + .unwrap_or_else(|| Err(SubstrateError::BridgePalletIsNotInitialized)) } async fn parachain_head( diff --git a/relays/messages/src/relay_strategy/mod.rs b/relays/messages/src/relay_strategy/mod.rs index 7bfd74c479..aa28e63582 100644 --- a/relays/messages/src/relay_strategy/mod.rs +++ b/relays/messages/src/relay_strategy/mod.rs @@ -144,7 +144,7 @@ impl< (self.hard_selected_begin_nonce + self.index as MessageNonce), self.selected_prepaid_nonces, self.selected_unpaid_weight, - self.selected_size as u32, + self.selected_size, ) .await?; From 10f882cbeff9b8305da70840ce694d1be7e34292 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 18 Oct 2022 13:40:41 +0300 Subject: [PATCH 2/2] revert some fixes that newest clippy reports as issues, but older does not --- .../lib-substrate-relay/src/finality/engine.rs | 4 ++-- .../lib-substrate-relay/src/messages_metrics.rs | 16 ++++++++-------- .../lib-substrate-relay/src/messages_source.rs | 2 +- .../lib-substrate-relay/src/parachains/target.rs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/relays/lib-substrate-relay/src/finality/engine.rs b/relays/lib-substrate-relay/src/finality/engine.rs index aaa58ff3ed..b2b72e4f2c 100644 --- a/relays/lib-substrate-relay/src/finality/engine.rs +++ b/relays/lib-substrate-relay/src/finality/engine.rs @@ -154,7 +154,7 @@ impl Engine for Grandpa { .await .map_err(|e| Error::ReadJustification(C::NAME, e)) .and_then(|justification| { - justification.ok_or_else(|| Error::ReadJustificationStreamEnded(C::NAME)) + justification.ok_or(Error::ReadJustificationStreamEnded(C::NAME)) })?; // Read initial header. @@ -207,7 +207,7 @@ impl Engine for Grandpa { let mut initial_authorities_set_id = 0; let mut min_possible_block_number = C::BlockNumber::zero(); let authorities_for_verification = VoterSet::new(authorities_for_verification.clone()) - .ok_or_else(|| Error::ReadInvalidAuthorities(C::NAME, authorities_for_verification))?; + .ok_or(Error::ReadInvalidAuthorities(C::NAME, authorities_for_verification))?; loop { log::trace!( target: "bridge", "Trying {} GRANDPA authorities set id: {}", diff --git a/relays/lib-substrate-relay/src/messages_metrics.rs b/relays/lib-substrate-relay/src/messages_metrics.rs index 1c321a0511..805d002b65 100644 --- a/relays/lib-substrate-relay/src/messages_metrics.rs +++ b/relays/lib-substrate-relay/src/messages_metrics.rs @@ -153,12 +153,12 @@ pub fn standalone_metrics( .map(|source_chain_token_id| { crate::helpers::token_price_metric(source_chain_token_id).map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, target_to_base_conversion_rate: P::TargetChain::TOKEN_ID .map(|target_chain_token_id| { crate::helpers::token_price_metric(target_chain_token_id).map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, source_to_target_conversion_rate: P::SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -181,7 +181,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, target_to_source_conversion_rate: P::TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -204,7 +204,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, source_fee_multiplier: P::AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME .map(|pallet| bp_runtime::storage_value_key(pallet, NEXT_FEE_MULTIPLIER_VALUE_NAME)) .map(|key| { @@ -218,7 +218,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, source_fee_multiplier_at_target: P::SOURCE_FEE_MULTIPLIER_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -235,7 +235,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, target_fee_multiplier: P::AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME .map(|pallet| bp_runtime::storage_value_key(pallet, NEXT_FEE_MULTIPLIER_VALUE_NAME)) .map(|key| { @@ -249,7 +249,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, target_fee_multiplier_at_source: P::TARGET_FEE_MULTIPLIER_PARAMETER_NAME .map(bp_runtime::storage_parameter_key) .map(|key| { @@ -266,7 +266,7 @@ pub fn standalone_metrics( ) .map(Some) }) - .unwrap_or_else(|| Ok(None))?, + .unwrap_or(Ok(None))?, }) } diff --git a/relays/lib-substrate-relay/src/messages_source.rs b/relays/lib-substrate-relay/src/messages_source.rs index 4eac180db1..e34f477e5f 100644 --- a/relays/lib-substrate-relay/src/messages_source.rs +++ b/relays/lib-substrate-relay/src/messages_source.rs @@ -553,7 +553,7 @@ where ) .map_err(SubstrateError::ResponseParseFailed)? .map(Ok) - .unwrap_or_else(|| Err(SubstrateError::BridgePalletIsNotInitialized)) + .unwrap_or(Err(SubstrateError::BridgePalletIsNotInitialized)) } fn validate_out_msgs_details( diff --git a/relays/lib-substrate-relay/src/parachains/target.rs b/relays/lib-substrate-relay/src/parachains/target.rs index 28320787d7..8d0d361984 100644 --- a/relays/lib-substrate-relay/src/parachains/target.rs +++ b/relays/lib-substrate-relay/src/parachains/target.rs @@ -113,7 +113,7 @@ where ) .map_err(SubstrateError::ResponseParseFailed)? .map(Ok) - .unwrap_or_else(|| Err(SubstrateError::BridgePalletIsNotInitialized)) + .unwrap_or(Err(SubstrateError::BridgePalletIsNotInitialized)) } async fn parachain_head(