Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Oct 2, 2024
1 parent 9e2fc49 commit 0c457c3
Show file tree
Hide file tree
Showing 28 changed files with 163 additions and 189 deletions.
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ correctness = { level = "deny", priority = 1 }
suspicious = { level = "deny", priority = 1 }

# Add some additional lints
as_underscore = { level = "warn", priority = 1 }
cast_lossless = { level = "warn", priority = 1 }
cast_possible_wrap = { level = "warn", priority = 1 }
cast_precision_loss = { level = "warn", priority = 1 }
cast_sign_loss = { level = "warn", priority = 1 }
debug_assert_with_mut_call = { level = "warn", priority = 1 }
fn_to_numeric_cast_any = { level = "warn", priority = 1 }
invalid_upcast_comparisons = { level = "warn", priority = 1 }
as_underscore = { level = "warn", priority = 2 }
cast_lossless = { level = "warn", priority = 2 }
cast_possible_wrap = { level = "warn", priority = 2 }
cast_precision_loss = { level = "warn", priority = 2 }
cast_sign_loss = { level = "warn", priority = 2 }
debug_assert_with_mut_call = { level = "warn", priority = 2 }
fn_to_numeric_cast_any = { level = "warn", priority = 2 }
invalid_upcast_comparisons = { level = "warn", priority = 2 }

# Allow annoying lints and false positives
erasing_op = { level = "allow", priority = 2 }
identity_op = { level = "allow", priority = 2 }
too-many-arguments = { level = "allow", priority = 2 }
type_complexity = { level = "allow", priority = 2 }
erasing_op = { level = "allow", priority = 3 }
identity_op = { level = "allow", priority = 3 }
manual_inspect = { level = "allow", priority = 3 }
too-many-arguments = { level = "allow", priority = 3 }
type_complexity = { level = "allow", priority = 3 }

[workspace.lints.rust]
unsafe-code = { level = "deny", priority = 1 }
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ impl MockRuntimeApi {
if let Some(para_id) = self.0 {
let _ =
sender.send(Ok(vec![CoreState::Scheduled(ScheduledCore {
para_id: para_id,
para_id,
collator: None,
})]));
} else {
Expand Down Expand Up @@ -889,7 +889,7 @@ impl CollatorLookaheadTestBuilder {
CancellationToken,
) {
// Creation of keystore
let _ = sp_tracing::try_init_simple();
sp_tracing::try_init_simple();
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
let alice_public = keystore
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async fn claim_slot_respects_min_slot_freq() {
#[tokio::test]
async fn collate_returns_correct_block() {
let net = AuraTestNet::new(4);
let _ = sp_tracing::try_init_simple();
sp_tracing::try_init_simple();

let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore.");
Expand Down
39 changes: 18 additions & 21 deletions client/service-container-chain/src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,11 @@ async fn get_latest_container_block_number_from_orchestrator(
container_chain_para_id: ParaId,
) -> Option<u32> {
// Get the container chain's latest block from orchestrator chain and compare with client's one
let last_container_block_from_orchestrator = orchestrator_chain_interface

orchestrator_chain_interface
.latest_block_number(orchestrator_block_hash, container_chain_para_id)
.await
.unwrap_or_default();

last_container_block_from_orchestrator
.unwrap_or_default()
}

#[derive(Debug)]
Expand Down Expand Up @@ -924,23 +923,21 @@ async fn db_needs_removal(
let last_container_block_temp = container_chain_client.chain_info().best_number;
if last_container_block_temp == 0 {
// Don't remove an empty database, as it may be in the process of a warp sync
} else {
if get_latest_container_block_number_from_orchestrator(
orchestrator_chain_interface,
orchestrator_block_hash,
container_chain_para_id,
)
.await
.unwrap_or(0)
.abs_diff(last_container_block_temp)
> MAX_BLOCK_DIFF_FOR_FULL_SYNC
{
// if the diff is big, delete db and restart using warp sync
return Ok(Some(DbRemovalReason::HighBlockDiff {
best_block_number_db: last_container_block_temp,
best_block_number_onchain: last_container_block_temp,
}));
}
} else if get_latest_container_block_number_from_orchestrator(
orchestrator_chain_interface,
orchestrator_block_hash,
container_chain_para_id,
)
.await
.unwrap_or(0)
.abs_diff(last_container_block_temp)
> MAX_BLOCK_DIFF_FOR_FULL_SYNC
{
// if the diff is big, delete db and restart using warp sync
return Ok(Some(DbRemovalReason::HighBlockDiff {
best_block_number_db: last_container_block_temp,
best_block_number_onchain: last_container_block_temp,
}));
}
}

Expand Down
3 changes: 1 addition & 2 deletions node/src/command/solochain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ impl SolochainRunner {
/// 2020-06-03 16:14:21 ⛓ Native runtime: node-251 (substrate-node-1.tx1.au10)
/// ```
fn print_node_infos(&self) {
use chrono::offset::Local;
use chrono::Datelike;
use chrono::{offset::Local, Datelike};
type C = ContainerChainCli;
info!("{}", C::impl_name());
info!("✌️ version {}", C::impl_version());
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ pub async fn start_solochain_node(
.base_path
.as_ref()
.expect("base_path is always set");
let config_dir = build_solochain_config_dir(&base_path);
let config_dir = build_solochain_config_dir(base_path);
let keystore = keystore_config(container_chain_cli.keystore_params(), &config_dir)
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;

Expand Down
13 changes: 4 additions & 9 deletions pallets/author-noting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,10 @@ impl<RCSP: RelaychainStateProvider> RelayOrPara for ParaMode<RCSP> {
type GenericStorageReader = GenericStateProof<cumulus_primitives_core::relay_chain::Block>;

fn create_inherent_arg(data: &InherentData) -> Self::InherentArg {
let data/*: tp_author_noting_inherent::OwnParachainInherentData*/ = data
.get_data(&INHERENT_IDENTIFIER)
data.get_data(&INHERENT_IDENTIFIER)
.ok()
.flatten()
.expect("there is not data to be posted; qed");

data
.expect("there is not data to be posted; qed")
}

fn create_storage_reader(data: Self::InherentArg) -> Self::GenericStorageReader {
Expand All @@ -482,11 +479,9 @@ impl<RCSP: RelaychainStateProvider> RelayOrPara for ParaMode<RCSP> {

let relay_chain_state = RCSP::current_relay_chain_state();
let relay_storage_root = relay_chain_state.state_root;
let relay_storage_rooted_proof =
GenericStateProof::new(relay_storage_root, relay_storage_proof)
.expect("Invalid relay chain state proof");

relay_storage_rooted_proof
GenericStateProof::new(relay_storage_root, relay_storage_proof)
.expect("Invalid relay chain state proof")
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
10 changes: 5 additions & 5 deletions pallets/collator-assignment/src/tests/with_core_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use crate::assignment::ChainNumCollators;
use crate::mock::*;
use crate::{CoreAllocationConfiguration, Pallet};
use sp_runtime::Perbill;
use tp_traits::ParaId;
use {
crate::{assignment::ChainNumCollators, mock::*, CoreAllocationConfiguration, Pallet},
sp_runtime::Perbill,
tp_traits::ParaId,
};

fn create_blank_chain_num_collator(id: u32) -> ChainNumCollators {
ChainNumCollators {
Expand Down
3 changes: 1 addition & 2 deletions pallets/pooled-staking/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use parity_scale_codec::MaxEncodedLen;
use {
core::{fmt::Debug, marker::PhantomData},
frame_system::pallet_prelude::BlockNumberFor,
parity_scale_codec::FullCodec,
parity_scale_codec::{FullCodec, MaxEncodedLen},
scale_info::TypeInfo,
sp_runtime::traits::{CheckedAdd, Get},
};
Expand Down
4 changes: 2 additions & 2 deletions pallets/registrar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ pub mod pallet {
//
// We only downgrade if the paraId is a parachain in the context of
// this pallet.
if let None = ParathreadParams::<T>::get(para_id) {
if ParathreadParams::<T>::get(para_id).is_none() {
T::InnerRegistrar::schedule_para_downgrade(para_id)?;
}

Expand Down Expand Up @@ -977,7 +977,7 @@ pub mod pallet {
//
// We only upgrade if the paraId is a parachain in the context of
// this pallet.
if let None = ParathreadParams::<T>::get(para_id) {
if ParathreadParams::<T>::get(para_id).is_none() {
T::InnerRegistrar::schedule_para_upgrade(para_id)?;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#[cfg(feature = "try-runtime")]
use frame_support::ensure;
use sp_runtime::Perbill;
use {
cumulus_primitives_core::ParaId,
frame_support::{
Expand All @@ -54,6 +53,7 @@ use {
pallet_migrations::{GetMigrations, Migration},
pallet_registrar::HoldReason,
sp_core::Get,
sp_runtime::Perbill,
sp_std::{collections::btree_set::BTreeSet, marker::PhantomData, prelude::*},
};

Expand Down
44 changes: 19 additions & 25 deletions runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use {
},
BOB,
},
Registrar, RuntimeOrigin, ServicesPayment, XcmCoreBuyer,
},
crate::{Registrar, RuntimeOrigin, ServicesPayment, XcmCoreBuyer},
core::marker::PhantomData,
cumulus_primitives_core::Weight,
frame_support::assert_ok,
Expand Down Expand Up @@ -64,13 +64,11 @@ pub fn assert_relay_order_event_not_emitted() {

let events = <Rococo as Chain>::events();
for event in events {
match event {
RuntimeEvent::OnDemandAssignmentProvider(
parachains_assigner_on_demand::Event::OnDemandOrderPlaced { .. },
) => {
panic!("Event should not have been emitted: {:?}", event);
}
_ => (),
if let RuntimeEvent::OnDemandAssignmentProvider(
parachains_assigner_on_demand::Event::OnDemandOrderPlaced { .. },
) = event
{
panic!("Event should not have been emitted: {:?}", event);
}
}
}
Expand All @@ -80,13 +78,11 @@ pub fn assert_xcm_notification_event_not_emitted() {

let events = <Dancebox as Chain>::events();
for event in events {
match event {
RuntimeEvent::XcmCoreBuyer(
pallet_xcm_core_buyer::Event::ReceivedBuyCoreXCMResult { .. },
) => {
panic!("Event should not have been emitted: {:?}", event);
}
_ => (),
if let RuntimeEvent::XcmCoreBuyer(
pallet_xcm_core_buyer::Event::ReceivedBuyCoreXCMResult { .. },
) = event
{
panic!("Event should not have been emitted: {:?}", event);
}
}
}
Expand All @@ -96,16 +92,14 @@ pub fn find_query_id_for_para_id(para_id: ParaId) -> QueryId {

let events = <Dancebox as Chain>::events();
for event in events {
match event {
RuntimeEvent::XcmCoreBuyer(pallet_xcm_core_buyer::Event::BuyCoreXcmSent {
para_id: event_para_id,
transaction_status_query_id,
}) => {
if event_para_id == para_id {
return transaction_status_query_id;
}
if let RuntimeEvent::XcmCoreBuyer(pallet_xcm_core_buyer::Event::BuyCoreXcmSent {
para_id: event_para_id,
transaction_status_query_id,
}) = event
{
if event_para_id == para_id {
return transaction_status_query_id;
}
_ => (),
}
}

Expand Down Expand Up @@ -342,7 +336,7 @@ fn core_buyer_sign_collator_nonce(para_id: ParaId, id: nimbus_primitives::Nimbus
signature,
};
XcmCoreBuyer::pre_dispatch(&pallet_xcm_core_buyer::Call::buy_core {
para_id: para_id,
para_id,
proof: proof.clone(),
})
.expect("collator signature predispatch should go through");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::UNIT as DANCE,
crate::{
assert_expected_events,
tests::common::xcm::{
Expand All @@ -27,6 +26,7 @@ use {
},
*,
},
UNIT as DANCE,
},
container_chain_template_frontier_runtime::currency::UNIT as FRONTIER_DEV,
frame_support::{
Expand Down
9 changes: 4 additions & 5 deletions runtime/dancebox/src/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

#![cfg(test)]

use rococo_runtime_constants::fee::Perbill;
use {
crate::tests::common::*,
crate::{
xcm_config::ForeignAssetsInstance, RewardsCollatorCommission, StreamPayment,
StreamPaymentAssetId, TimeUnit, TransactionPayment,
tests::common::*, xcm_config::ForeignAssetsInstance, RewardsCollatorCommission,
StreamPayment, StreamPaymentAssetId, TimeUnit, TransactionPayment,
},
cumulus_primitives_core::ParaId,
dp_consensus::runtime_decl_for_tanssi_authority_assignment_api::TanssiAuthorityAssignmentApiV1,
Expand All @@ -45,6 +43,7 @@ use {
runtime_decl_for_registrar_api::RegistrarApi, ContainerChainGenesisData,
},
parity_scale_codec::Encode,
rococo_runtime_constants::fee::Perbill,
sp_consensus_aura::AURA_ENGINE_ID,
sp_core::Get,
sp_runtime::{
Expand Down Expand Up @@ -6236,7 +6235,7 @@ fn test_migration_registrar_reserves_to_hold() {
ParaId::from(1001),
DepositInfo {
creator: account.clone(),
deposit: deposit,
deposit,
},
);
assert_eq!(Balances::reserved_balance(&account), deposit.clone(),);
Expand Down
5 changes: 2 additions & 3 deletions runtime/flashbox/src/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#![cfg(test)]

use {
crate::tests::common::*,
crate::{RuntimeOrigin, StreamPaymentAssetId, TimeUnit},
crate::{tests::common::*, RuntimeOrigin, StreamPaymentAssetId, TimeUnit},
cumulus_primitives_core::{ParaId, Weight},
dp_consensus::runtime_decl_for_tanssi_authority_assignment_api::TanssiAuthorityAssignmentApiV1,
dp_core::well_known_keys,
Expand Down Expand Up @@ -4096,7 +4095,7 @@ fn test_migration_registrar_reserves_to_hold() {
ParaId::from(1001),
DepositInfo {
creator: account.clone(),
deposit: deposit,
deposit,
},
);
assert_eq!(Balances::reserved_balance(&account), deposit.clone(),);
Expand Down
6 changes: 2 additions & 4 deletions solo-chains/client/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,9 @@ fn load_spec(
path => {
let path = std::path::PathBuf::from(path);

let chain_spec = Box::new(polkadot_service::GenericChainSpec::from_json_file(
(Box::new(polkadot_service::GenericChainSpec::from_json_file(
path.clone(),
)?) as Box<dyn polkadot_service::ChainSpec>;

chain_spec
)?)) as std::boxed::Box<dyn sc_cli::ChainSpec>
}
})
}
Loading

0 comments on commit 0c457c3

Please sign in to comment.