From 17dbf5fbc451702e5489fe537e40a6b6b849aaec Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Mon, 14 Oct 2024 13:36:22 +0200 Subject: [PATCH 01/42] fix: update switch pallet read me to change file paths (#756) Code paths changed which broke documentation that replied on this file. --- pallets/pallet-asset-switch/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/pallet-asset-switch/README.md b/pallets/pallet-asset-switch/README.md index af035d584..6ab4bb902 100644 --- a/pallets/pallet-asset-switch/README.md +++ b/pallets/pallet-asset-switch/README.md @@ -142,12 +142,12 @@ The pallet itself implements the [OnResponse trait][on-response-trait], that mus The trait implementation validates the received query response message based on the state of the switch pair, and then performs the required action on the pending transfer info accordingly. [asset-switch-runtime-api]: ../../runtime-api/asset-switch/ -[xcm-convert]: ./src/xcm/convert.rs -[xcm-match]: ./src/xcm/match.rs +[xcm-convert]: ./src/xcm/convert/mod.rs +[xcm-match]: ./src/xcm/match/mod.rs [XcmExecutorError::AssetNotHandled]: https://github.com/paritytech/polkadot-sdk/blob/33324fe01c5b1f341687cef2aa6e767f6acf40f3/polkadot/xcm/xcm-executor/src/traits/token_matching.rs#L54 [XcmExecutor::Config]: https://github.com/paritytech/polkadot-sdk/blob/33324fe01c5b1f341687cef2aa6e767f6acf40f3/polkadot/xcm/xcm-executor/src/config.rs#L31 -[xcm-trade]: ./src/xcm/trade.rs +[xcm-trade]: ./src/xcm/trade/mod.rs [Error::AssetNotFound]: https://github.com/paritytech/polkadot-sdk/blob/e5791a56dcc35e308a80985cc3b6b7f2ed1eb6ec/polkadot/xcm/src/v3/traits.rs#L68 -[xcm-transact]: ./src/xcm/transact.rs -[xcm-transfer]: ./src/xcm/transfer.rs +[xcm-transact]: ./src/xcm/transact/mod.rs +[xcm-transfer]: ./src/xcm/transfer/mod.rs [on-response-trait]: https://github.com/paritytech/polkadot-sdk/blob/33324fe01c5b1f341687cef2aa6e767f6acf40f3/polkadot/xcm/xcm-executor/src/traits/on_response.rs#L29 From f057961868d2d865a8d3ff4a5f977cc5e381472a Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 18 Oct 2024 14:45:46 +0300 Subject: [PATCH 02/42] chore: clippy lints (#737) Fixes https://github.com/KILTprotocol/ticket/issues/3325. Add some basic lints (can always be expanded for either runtime-specific code or all code via the configurable rustc flags in the new config file). I updated the code to address all places in which the new lints generate an error, including all weight files and weight templates. I also updated the CI check step to check for the specific WASM-targeted, no-std code that will be part of our runtime. ## How to test To check runtime code against the new lint, just run the same command as in the check workflow file: `cargo clippy --locked --target wasm32-unknown-unknown --no-default-features --workspace --exclude kilt-parachain --exclude standalone-node --exclude xcm-integration-tests --exclude 'dip-provider*' --exclude 'dip-consumer*'` --- .cargo/config.toml | 26 +++++++++++++++++++ .github/workflows/check-code.yml | 14 ++++++---- .gitlab-ci.yml | 1 + .maintain/runtime-weight-template.hbs | 2 +- .maintain/weight-template.hbs | 2 +- crates/assets/src/asset.rs | 9 +++++++ crates/assets/src/chain.rs | 6 +++++ crates/assets/src/v1.rs | 1 + .../merkle_proofs/v0/provider_state/mod.rs | 1 + .../src/verifier/parachain/error.rs | 2 ++ .../src/verifier/parachain/v0/mod.rs | 1 + .../src/verifier/relaychain/error.rs | 2 ++ .../src/verifier/relaychain/v0/mod.rs | 1 + dip-template/pallets/pallet-postit/src/lib.rs | 4 +++ .../dip-consumer/src/weights/frame_system.rs | 6 ++--- .../src/weights/pallet_dip_consumer.rs | 2 +- .../src/weights/pallet_relay_store.rs | 2 +- .../runtimes/dip-provider/src/weights/did.rs | 2 +- .../dip-provider/src/weights/frame_system.rs | 6 ++--- .../src/weights/pallet_deposit_storage.rs | 2 +- .../src/weights/pallet_did_lookup.rs | 2 +- .../src/weights/pallet_dip_provider.rs | 2 +- .../src/weights/pallet_web3_names.rs | 2 +- pallets/attestation/src/default_weights.rs | 2 +- pallets/attestation/src/lib.rs | 4 +++ pallets/ctype/src/default_weights.rs | 2 +- pallets/ctype/src/lib.rs | 4 +++ pallets/delegation/src/default_weights.rs | 2 +- .../delegation/src/delegation_hierarchy.rs | 1 + pallets/delegation/src/lib.rs | 4 +++ pallets/did/src/default_weights.rs | 2 +- pallets/did/src/lib.rs | 5 +++- pallets/did/src/tests/dispatch_as.rs | 4 +-- .../src/default_weights.rs | 2 +- pallets/pallet-asset-switch/src/lib.rs | 4 +++ .../src/default_weights.rs | 2 +- pallets/pallet-configuration/src/lib.rs | 4 +++ .../src/default_weights.rs | 2 +- pallets/pallet-deposit-storage/src/lib.rs | 4 +++ .../src/associate_account_request.rs | 4 +++ .../pallet-did-lookup/src/default_weights.rs | 2 +- pallets/pallet-did-lookup/src/lib.rs | 4 +++ .../pallet-did-lookup/src/tests/associate.rs | 3 --- .../src/default_weights.rs | 2 +- pallets/pallet-dip-consumer/src/lib.rs | 4 +++ .../src/default_weights.rs | 2 +- pallets/pallet-dip-provider/src/lib.rs | 4 +++ .../pallet-inflation/src/default_weights.rs | 2 +- pallets/pallet-inflation/src/lib.rs | 4 +++ .../pallet-migration/src/default_weights.rs | 2 +- pallets/pallet-migration/src/lib.rs | 4 +++ .../pallet-relay-store/src/default_weights.rs | 2 +- pallets/pallet-relay-store/src/lib.rs | 4 +++ pallets/pallet-web3-names/Cargo.toml | 1 + .../pallet-web3-names/src/default_weights.rs | 2 +- pallets/pallet-web3-names/src/lib.rs | 6 ++++- pallets/parachain-staking/src/api.rs | 1 + .../parachain-staking/src/default_weights.rs | 2 +- pallets/parachain-staking/src/inflation.rs | 2 ++ pallets/parachain-staking/src/lib.rs | 6 +++++ pallets/parachain-staking/src/set.rs | 7 +++++ pallets/parachain-staking/src/types.rs | 2 ++ .../public-credentials/src/default_weights.rs | 2 +- pallets/public-credentials/src/lib.rs | 4 +++ runtimes/common/src/constants.rs | 13 +++++++++- runtimes/common/src/fees.rs | 2 ++ runtimes/common/src/lib.rs | 20 +++++++++++--- runtimes/common/src/xcm_config.rs | 8 +++++- runtimes/peregrine/src/lib.rs | 23 +++++++++++++--- runtimes/peregrine/src/weights/attestation.rs | 2 +- runtimes/peregrine/src/weights/ctype.rs | 2 +- .../cumulus_pallet_parachain_system.rs | 2 +- runtimes/peregrine/src/weights/delegation.rs | 2 +- runtimes/peregrine/src/weights/did.rs | 2 +- .../peregrine/src/weights/frame_system.rs | 2 +- .../src/weights/pallet_asset_switch.rs | 2 +- .../peregrine/src/weights/pallet_assets.rs | 2 +- .../peregrine/src/weights/pallet_balances.rs | 2 +- .../src/weights/pallet_collective_council.rs | 2 +- .../pallet_collective_technical_committee.rs | 2 +- .../peregrine/src/weights/pallet_democracy.rs | 2 +- .../src/weights/pallet_deposit_storage.rs | 2 +- .../src/weights/pallet_did_lookup.rs | 2 +- .../src/weights/pallet_dip_provider.rs | 2 +- .../peregrine/src/weights/pallet_indices.rs | 2 +- .../peregrine/src/weights/pallet_inflation.rs | 2 +- .../src/weights/pallet_membership.rs | 2 +- .../src/weights/pallet_message_queue.rs | 2 +- .../peregrine/src/weights/pallet_migration.rs | 2 +- .../peregrine/src/weights/pallet_multisig.rs | 2 +- .../peregrine/src/weights/pallet_preimage.rs | 2 +- .../peregrine/src/weights/pallet_proxy.rs | 2 +- .../peregrine/src/weights/pallet_scheduler.rs | 2 +- .../peregrine/src/weights/pallet_session.rs | 2 +- runtimes/peregrine/src/weights/pallet_sudo.rs | 15 +++++++++-- .../peregrine/src/weights/pallet_timestamp.rs | 2 +- runtimes/peregrine/src/weights/pallet_tips.rs | 2 +- .../peregrine/src/weights/pallet_treasury.rs | 2 +- .../peregrine/src/weights/pallet_utility.rs | 2 +- .../peregrine/src/weights/pallet_vesting.rs | 2 +- .../src/weights/pallet_web3_names.rs | 2 +- runtimes/peregrine/src/weights/pallet_xcm.rs | 2 +- .../src/weights/parachain_staking.rs | 2 +- .../src/weights/public_credentials.rs | 2 +- runtimes/spiritnet/src/lib.rs | 23 +++++++++++++--- runtimes/spiritnet/src/weights/attestation.rs | 2 +- runtimes/spiritnet/src/weights/ctype.rs | 2 +- .../cumulus_pallet_parachain_system.rs | 2 +- runtimes/spiritnet/src/weights/delegation.rs | 2 +- runtimes/spiritnet/src/weights/did.rs | 2 +- .../spiritnet/src/weights/frame_system.rs | 2 +- .../src/weights/pallet_asset_switch.rs | 2 +- .../spiritnet/src/weights/pallet_assets.rs | 2 +- .../spiritnet/src/weights/pallet_balances.rs | 2 +- .../src/weights/pallet_collective_council.rs | 2 +- .../pallet_collective_technical_committee.rs | 2 +- .../spiritnet/src/weights/pallet_democracy.rs | 2 +- .../src/weights/pallet_deposit_storage.rs | 2 +- .../src/weights/pallet_did_lookup.rs | 2 +- .../src/weights/pallet_dip_provider.rs | 2 +- .../spiritnet/src/weights/pallet_indices.rs | 2 +- .../spiritnet/src/weights/pallet_inflation.rs | 2 +- .../src/weights/pallet_membership.rs | 2 +- .../src/weights/pallet_message_queue.rs | 2 +- .../spiritnet/src/weights/pallet_migration.rs | 2 +- .../spiritnet/src/weights/pallet_multisig.rs | 2 +- .../spiritnet/src/weights/pallet_preimage.rs | 2 +- .../spiritnet/src/weights/pallet_proxy.rs | 2 +- .../spiritnet/src/weights/pallet_scheduler.rs | 2 +- .../spiritnet/src/weights/pallet_session.rs | 2 +- .../spiritnet/src/weights/pallet_timestamp.rs | 2 +- runtimes/spiritnet/src/weights/pallet_tips.rs | 2 +- .../spiritnet/src/weights/pallet_treasury.rs | 2 +- .../spiritnet/src/weights/pallet_utility.rs | 2 +- .../spiritnet/src/weights/pallet_vesting.rs | 2 +- .../src/weights/pallet_web3_names.rs | 2 +- runtimes/spiritnet/src/weights/pallet_xcm.rs | 2 +- .../src/weights/parachain_staking.rs | 2 +- .../src/weights/public_credentials.rs | 2 +- 139 files changed, 338 insertions(+), 126 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..b93dd3548 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,26 @@ +# Deployment runtime lints +[target.'cfg(all(target_arch = "wasm32", not(test)))'] +rustflags = [ + "-Dclippy::arithmetic_side_effects", + "-Dclippy::as_conversions", + "-Dclippy::assertions_on_result_states", + "-Dclippy::cast_possible_wrap", + "-Dclippy::dbg_macro", + "-Dclippy::expect_used", + "-Dclippy::float_arithmetic", + "-Dclippy::float_cmp_const", + "-Dclippy::index_refutable_slice", + "-Dclippy::indexing_slicing", + "-Dclippy::lossy_float_literal", + "-Dclippy::panic", + "-Dclippy::string_slice", + "-Dclippy::todo", + "-Dclippy::unimplemented", + "-Dclippy::unreachable", + "-Dclippy::unwrap_used", + "-Funsafe_code", + "-Wclippy::integer_division", + "-Wclippy::modulo_arithmetic", + "-Wclippy::print_stderr", + "-Wclippy::print_stdout", +] diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml index 34765665b..526e8294f 100644 --- a/.github/workflows/check-code.yml +++ b/.github/workflows/check-code.yml @@ -46,9 +46,13 @@ jobs: strategy: matrix: - features: - - - - --all-features + cargo-flags: + # Generic clippy checks for all features + - --all-targets --all-features + # Generic clippy checks for no features (catches some missing `no_std`-only lints) + - --all-targets + # Clippy lints specifically for all runtime code, excluding all test and binary crates + - --target wasm32-unknown-unknown --no-default-features --workspace --exclude kilt-parachain --exclude standalone-node --exclude xcm-integration-tests --exclude 'dip-provider*' --exclude 'dip-consumer*' fail-fast: false steps: @@ -63,11 +67,11 @@ jobs: ${{ env.CARGO_HOME }}/registry/index/ ${{ env.CARGO_HOME }}/registry/cache/ ${{ env.CARGO_HOME }}/git/db/ - key: ${{ github.job }}-${{ github.ref }}-${{ matrix.features }}-${{ hashFiles('**/Cargo.lock') }} + key: ${{ github.job }}-${{ github.ref }}-${{ matrix.cargo-flags }}-${{ hashFiles('**/Cargo.lock') }} save-always: true - name: Run `cargo clippy` - run: cargo clippy --all-targets --locked ${{ matrix.features }} + run: cargo clippy --locked ${{ matrix.cargo-flags }} cargo-fmt: name: Check formatting diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8f5caca41..d7179cedf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,7 @@ build-production-wasm: - export PARACHAIN_PALLET_ID=0x50 - export AUTHORIZE_UPGRADE_PREFIX=0x02 - export AUTHORIZE_UPGRADE_CHECK_VERSION=true + - export VERBOSE=true - cp -r * /build - /srtool/build build - subwasm meta --format=json+scale /out/${RUNTIME}_runtime.compact.wasm > /out/${RUNTIME}-metadata.json diff --git a/.maintain/runtime-weight-template.hbs b/.maintain/runtime-weight-template.hbs index 291a1672a..a4038572f 100644 --- a/.maintain/runtime-weight-template.hbs +++ b/.maintain/runtime-weight-template.hbs @@ -13,8 +13,8 @@ {{/each}} #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/.maintain/weight-template.hbs b/.maintain/weight-template.hbs index bdcf1d461..65febeb14 100644 --- a/.maintain/weight-template.hbs +++ b/.maintain/weight-template.hbs @@ -14,8 +14,8 @@ {{/each}} #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/crates/assets/src/asset.rs b/crates/assets/src/asset.rs index 2df3dba31..2caf3c390 100644 --- a/crates/assets/src/asset.rs +++ b/crates/assets/src/asset.rs @@ -44,16 +44,19 @@ pub mod v1 { pub const MINIMUM_ASSET_NAMESPACE_LENGTH: usize = 3; /// The maximum length of a valid asset ID namespace. pub const MAXIMUM_NAMESPACE_LENGTH: usize = 8; + #[allow(clippy::as_conversions)] const MAXIMUM_ASSET_NAMESPACE_LENGTH_U32: u32 = MAXIMUM_NAMESPACE_LENGTH as u32; /// The minimum length of a valid asset ID reference. pub const MINIMUM_ASSET_REFERENCE_LENGTH: usize = 1; /// The maximum length of a valid asset ID reference. pub const MAXIMUM_ASSET_REFERENCE_LENGTH: usize = 128; + #[allow(clippy::as_conversions)] const MAXIMUM_ASSET_REFERENCE_LENGTH_U32: u32 = MAXIMUM_ASSET_REFERENCE_LENGTH as u32; /// The minimum length of a valid asset ID identifier. pub const MINIMUM_ASSET_IDENTIFIER_LENGTH: usize = 1; /// The maximum length of a valid asset ID reference. pub const MAXIMUM_ASSET_IDENTIFIER_LENGTH: usize = 78; + #[allow(clippy::as_conversions)] const MAXIMUM_ASSET_IDENTIFIER_LENGTH_U32: u32 = MAXIMUM_ASSET_IDENTIFIER_LENGTH as u32; /// Separator between asset namespace and asset reference. @@ -168,6 +171,7 @@ pub mod v1 { } impl Display for AssetId { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Slip44(reference) => { @@ -335,6 +339,7 @@ pub mod v1 { // TODO: This could be enforced at compilation time once constraints on generics // will be available. // https://rust-lang.github.io/rfcs/2000-const-generics.html + #[allow(clippy::expect_used)] if value <= U256::from_str_radix("9999999999999999999999999999999999999999999999999999999999999999", 10) .expect("Casting the maximum value for a Slip44 reference into a U256 should never fail.") @@ -480,6 +485,7 @@ pub mod v1 { } impl Display for EvmSmartContractNonFungibleIdentifier { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid digits. write!( @@ -578,6 +584,7 @@ pub mod v1 { } impl Display for GenericAssetNamespace { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid UTF8 // (actually ASCII) characters. @@ -627,6 +634,7 @@ pub mod v1 { } impl Display for GenericAssetReference { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid UTF8 // (actually ASCII) characters. @@ -676,6 +684,7 @@ pub mod v1 { } impl Display for GenericAssetIdentifier { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid UTF8 // (actually ASCII) characters. diff --git a/crates/assets/src/chain.rs b/crates/assets/src/chain.rs index e9ae7b8c9..0eb20243c 100644 --- a/crates/assets/src/chain.rs +++ b/crates/assets/src/chain.rs @@ -45,11 +45,13 @@ mod v1 { pub const MINIMUM_CHAIN_NAMESPACE_LENGTH: usize = 3; /// The maximum length of a valid chain ID namespace. pub const MAXIMUM_CHAIN_NAMESPACE_LENGTH: usize = 8; + #[allow(clippy::as_conversions)] const MAXIMUM_CHAIN_NAMESPACE_LENGTH_U32: u32 = MAXIMUM_CHAIN_NAMESPACE_LENGTH as u32; /// The minimum length of a valid chain ID reference. pub const MINIMUM_CHAIN_REFERENCE_LENGTH: usize = 1; /// The maximum length of a valid chain ID reference. pub const MAXIMUM_CHAIN_REFERENCE_LENGTH: usize = 32; + #[allow(clippy::as_conversions)] const MAXIMUM_CHAIN_REFERENCE_LENGTH_U32: u32 = MAXIMUM_CHAIN_REFERENCE_LENGTH as u32; /// Separator between chain namespace and chain reference. @@ -192,6 +194,7 @@ mod v1 { } impl Display for ChainId { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Bip122(reference) => { @@ -438,6 +441,7 @@ mod v1 { impl GenesisBase58Hash32Reference { /// The CAIP-2 reference for the Solana mainnet. + #[allow(clippy::expect_used)] pub fn solana_mainnet() -> Self { // Base58 decoding of Solana genesis hash 4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ Self( @@ -565,6 +569,7 @@ mod v1 { } impl Display for GenericChainNamespace { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid UTF8 // (actually ASCII) characters. @@ -614,6 +619,7 @@ mod v1 { } impl Display for GenericChainReference { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // We checked when the type is created that all characters are valid UTF8 // (actually ASCII) characters. diff --git a/crates/assets/src/v1.rs b/crates/assets/src/v1.rs index 684af2ae8..3093477cb 100644 --- a/crates/assets/src/v1.rs +++ b/crates/assets/src/v1.rs @@ -146,6 +146,7 @@ impl AssetDid { } impl Display for AssetDid { + #[allow(clippy::expect_used)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( f, diff --git a/crates/kilt-dip-primitives/src/merkle_proofs/v0/provider_state/mod.rs b/crates/kilt-dip-primitives/src/merkle_proofs/v0/provider_state/mod.rs index 1722bcdd4..a4eccc2e3 100644 --- a/crates/kilt-dip-primitives/src/merkle_proofs/v0/provider_state/mod.rs +++ b/crates/kilt-dip-primitives/src/merkle_proofs/v0/provider_state/mod.rs @@ -187,6 +187,7 @@ impl< if input.len() < 2 { return None; } + #[allow(clippy::indexing_slicing)] let mut trimmed_input = &input[2..]; ProviderHeader::decode(&mut trimmed_input).ok() }, diff --git a/crates/kilt-dip-primitives/src/verifier/parachain/error.rs b/crates/kilt-dip-primitives/src/verifier/parachain/error.rs index 30104794f..d9f800b55 100644 --- a/crates/kilt-dip-primitives/src/verifier/parachain/error.rs +++ b/crates/kilt-dip-primitives/src/verifier/parachain/error.rs @@ -32,6 +32,8 @@ impl From> f where DidOriginError: Into, { + #[allow(clippy::as_conversions)] + #[allow(clippy::arithmetic_side_effects)] fn from(value: DipParachainStateProofVerifierError) -> Self { match value { // DO NOT USE 0 diff --git a/crates/kilt-dip-primitives/src/verifier/parachain/v0/mod.rs b/crates/kilt-dip-primitives/src/verifier/parachain/v0/mod.rs index c363210eb..4a9525789 100644 --- a/crates/kilt-dip-primitives/src/verifier/parachain/v0/mod.rs +++ b/crates/kilt-dip-primitives/src/verifier/parachain/v0/mod.rs @@ -165,6 +165,7 @@ impl< MAX_DID_MERKLE_LEAVES_REVEALED, >; + #[allow(clippy::as_conversions)] fn verify_proof_for_call_against_details( call: &RuntimeCallOf, subject: &::Identifier, diff --git a/crates/kilt-dip-primitives/src/verifier/relaychain/error.rs b/crates/kilt-dip-primitives/src/verifier/relaychain/error.rs index bffd19ba3..bdb173ad3 100644 --- a/crates/kilt-dip-primitives/src/verifier/relaychain/error.rs +++ b/crates/kilt-dip-primitives/src/verifier/relaychain/error.rs @@ -32,6 +32,8 @@ impl From> where DidOriginError: Into, { + #[allow(clippy::as_conversions)] + #[allow(clippy::arithmetic_side_effects)] fn from(value: DipRelaychainStateProofVerifierError) -> Self { match value { // DO NOT USE 0 diff --git a/crates/kilt-dip-primitives/src/verifier/relaychain/v0/mod.rs b/crates/kilt-dip-primitives/src/verifier/relaychain/v0/mod.rs index 1691490c8..2a0bc2316 100644 --- a/crates/kilt-dip-primitives/src/verifier/relaychain/v0/mod.rs +++ b/crates/kilt-dip-primitives/src/verifier/relaychain/v0/mod.rs @@ -146,6 +146,7 @@ impl< MAX_DID_MERKLE_LEAVES_REVEALED, >; + #[allow(clippy::as_conversions)] fn verify_proof_for_call_against_details( call: &RuntimeCallOf, subject: &ConsumerRuntime::Identifier, diff --git a/dip-template/pallets/pallet-postit/src/lib.rs b/dip-template/pallets/pallet-postit/src/lib.rs index e3c9c38b9..29379f179 100644 --- a/dip-template/pallets/pallet-postit/src/lib.rs +++ b/dip-template/pallets/pallet-postit/src/lib.rs @@ -24,6 +24,10 @@ pub mod traits; pub use pallet::*; #[frame_support::pallet(dev_mode)] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/dip-template/runtimes/dip-consumer/src/weights/frame_system.rs b/dip-template/runtimes/dip-consumer/src/weights/frame_system.rs index 00b52d06f..b48241b1e 100644 --- a/dip-template/runtimes/dip-consumer/src/weights/frame_system.rs +++ b/dip-template/runtimes/dip-consumer/src/weights/frame_system.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-consumer/src/weights/frame_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; @@ -50,10 +50,10 @@ pub struct WeightInfo(PhantomData); impl frame_system::WeightInfo for WeightInfo { fn apply_authorized_upgrade() -> Weight { - todo!() + Weight::zero() } fn authorize_upgrade() -> Weight { - todo!() + Weight::zero() } /// The range of component `b` is `[0, 3932160]`. fn remark(b: u32, ) -> Weight { diff --git a/dip-template/runtimes/dip-consumer/src/weights/pallet_dip_consumer.rs b/dip-template/runtimes/dip-consumer/src/weights/pallet_dip_consumer.rs index 6ec7b5c28..ca1a4ad73 100644 --- a/dip-template/runtimes/dip-consumer/src/weights/pallet_dip_consumer.rs +++ b/dip-template/runtimes/dip-consumer/src/weights/pallet_dip_consumer.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-consumer/src/weights/pallet_dip_consumer.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-consumer/src/weights/pallet_relay_store.rs b/dip-template/runtimes/dip-consumer/src/weights/pallet_relay_store.rs index 7fd11d1e4..2f42feac8 100644 --- a/dip-template/runtimes/dip-consumer/src/weights/pallet_relay_store.rs +++ b/dip-template/runtimes/dip-consumer/src/weights/pallet_relay_store.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-consumer/src/weights/pallet_relay_store.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-provider/src/weights/did.rs b/dip-template/runtimes/dip-provider/src/weights/did.rs index a6f5f82d8..5a85289bc 100644 --- a/dip-template/runtimes/dip-provider/src/weights/did.rs +++ b/dip-template/runtimes/dip-provider/src/weights/did.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/did.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-provider/src/weights/frame_system.rs b/dip-template/runtimes/dip-provider/src/weights/frame_system.rs index 7036084bf..eadc20349 100644 --- a/dip-template/runtimes/dip-provider/src/weights/frame_system.rs +++ b/dip-template/runtimes/dip-provider/src/weights/frame_system.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/frame_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; @@ -49,10 +49,10 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl frame_system::WeightInfo for WeightInfo { fn apply_authorized_upgrade() -> Weight { - todo!() + Weight::zero() } fn authorize_upgrade() -> Weight { - todo!() + Weight::zero() } /// The range of component `b` is `[0, 3932160]`. fn remark(b: u32, ) -> Weight { diff --git a/dip-template/runtimes/dip-provider/src/weights/pallet_deposit_storage.rs b/dip-template/runtimes/dip-provider/src/weights/pallet_deposit_storage.rs index b0c9b8042..5d2d8901c 100644 --- a/dip-template/runtimes/dip-provider/src/weights/pallet_deposit_storage.rs +++ b/dip-template/runtimes/dip-provider/src/weights/pallet_deposit_storage.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/pallet_deposit_storage.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-provider/src/weights/pallet_did_lookup.rs b/dip-template/runtimes/dip-provider/src/weights/pallet_did_lookup.rs index 1853ae220..56d07d023 100644 --- a/dip-template/runtimes/dip-provider/src/weights/pallet_did_lookup.rs +++ b/dip-template/runtimes/dip-provider/src/weights/pallet_did_lookup.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/pallet_did_lookup.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-provider/src/weights/pallet_dip_provider.rs b/dip-template/runtimes/dip-provider/src/weights/pallet_dip_provider.rs index 66784780a..fef731cfb 100644 --- a/dip-template/runtimes/dip-provider/src/weights/pallet_dip_provider.rs +++ b/dip-template/runtimes/dip-provider/src/weights/pallet_dip_provider.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/pallet_dip_provider.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/dip-template/runtimes/dip-provider/src/weights/pallet_web3_names.rs b/dip-template/runtimes/dip-provider/src/weights/pallet_web3_names.rs index 33c8a2a4d..530de847c 100644 --- a/dip-template/runtimes/dip-provider/src/weights/pallet_web3_names.rs +++ b/dip-template/runtimes/dip-provider/src/weights/pallet_web3_names.rs @@ -39,8 +39,8 @@ // --output=./dip-template/runtimes/dip-provider/src/weights/pallet_web3_names.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/pallets/attestation/src/default_weights.rs b/pallets/attestation/src/default_weights.rs index eb5bc0662..37b002403 100644 --- a/pallets/attestation/src/default_weights.rs +++ b/pallets/attestation/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/attestation/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/attestation/src/lib.rs b/pallets/attestation/src/lib.rs index ba4d7ba14..d69ab4a64 100644 --- a/pallets/attestation/src/lib.rs +++ b/pallets/attestation/src/lib.rs @@ -84,6 +84,10 @@ pub use crate::{ }; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/ctype/src/default_weights.rs b/pallets/ctype/src/default_weights.rs index 3b0e01ffc..584e5802f 100644 --- a/pallets/ctype/src/default_weights.rs +++ b/pallets/ctype/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/ctype/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index e6fee0620..e406a1541 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -58,6 +58,10 @@ mod tests; pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; use frame_support::{ diff --git a/pallets/delegation/src/default_weights.rs b/pallets/delegation/src/default_weights.rs index 2882af20a..29576b062 100644 --- a/pallets/delegation/src/default_weights.rs +++ b/pallets/delegation/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/delegation/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/delegation/src/delegation_hierarchy.rs b/pallets/delegation/src/delegation_hierarchy.rs index 1b1ba5802..7faacd00b 100644 --- a/pallets/delegation/src/delegation_hierarchy.rs +++ b/pallets/delegation/src/delegation_hierarchy.rs @@ -37,6 +37,7 @@ bitflags! { impl Permissions { /// Encode permission bitflags into u8 array. + #[allow(clippy::as_conversions)] pub fn as_u8(self) -> [u8; 4] { let x: u32 = self.bits; let b1: u8 = ((x >> 24) & 0xff) as u8; diff --git a/pallets/delegation/src/lib.rs b/pallets/delegation/src/lib.rs index 2dae2d882..f211f20b1 100644 --- a/pallets/delegation/src/lib.rs +++ b/pallets/delegation/src/lib.rs @@ -88,6 +88,10 @@ use sp_runtime::{traits::Hash, DispatchError}; use sp_std::{marker::PhantomData, vec::Vec}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/did/src/default_weights.rs b/pallets/did/src/default_weights.rs index dc27e93c1..1582d5c7c 100644 --- a/pallets/did/src/default_weights.rs +++ b/pallets/did/src/default_weights.rs @@ -24,8 +24,8 @@ // --template=.maintain/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/did/src/lib.rs b/pallets/did/src/lib.rs index 1fbdf5263..008d72a6b 100644 --- a/pallets/did/src/lib.rs +++ b/pallets/did/src/lib.rs @@ -78,7 +78,6 @@ //! time has elapsed, the operation is considered invalid. #![cfg_attr(not(feature = "std"), no_std)] -#![allow(clippy::unused_unit)] #![recursion_limit = "256"] #[cfg(feature = "runtime-benchmarks")] @@ -136,6 +135,10 @@ use sp_std::{boxed::Box, fmt::Debug, prelude::Clone}; use frame_system::RawOrigin; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; use did_details::DidCreationDetails; diff --git a/pallets/did/src/tests/dispatch_as.rs b/pallets/did/src/tests/dispatch_as.rs index fd33c2d38..003347bc7 100644 --- a/pallets/did/src/tests/dispatch_as.rs +++ b/pallets/did/src/tests/dispatch_as.rs @@ -29,7 +29,7 @@ mod authentication; mod delegation; mod error_cases; -fn blueprint_successful_dispatch (), FA: FnOnce() -> ()>( +fn blueprint_successful_dispatch( did_identifier: DidIdentifierOf, caller: AccountIdOf, did_details: DidDetails, @@ -57,7 +57,7 @@ fn blueprint_successful_dispatch (), FA: FnOnce() -> ()>( }); } -fn blueprint_failed_dispatch ()>( +fn blueprint_failed_dispatch( did_identifier: DidIdentifierOf, caller: AccountIdOf, did_details: Option>, diff --git a/pallets/pallet-asset-switch/src/default_weights.rs b/pallets/pallet-asset-switch/src/default_weights.rs index 25d3b03f3..f3ccae600 100644 --- a/pallets/pallet-asset-switch/src/default_weights.rs +++ b/pallets/pallet-asset-switch/src/default_weights.rs @@ -45,8 +45,8 @@ // ./pallets/pallet-asset-switch/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-asset-switch/src/lib.rs b/pallets/pallet-asset-switch/src/lib.rs index ffc63f9bc..65787ce20 100644 --- a/pallets/pallet-asset-switch/src/lib.rs +++ b/pallets/pallet-asset-switch/src/lib.rs @@ -61,6 +61,10 @@ pub use crate::pallet::*; const LOG_TARGET: &str = "runtime::pallet-asset-switch"; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use crate::{ switch::{NewSwitchPairInfo, SwitchPairInfo, SwitchPairInfoV4, SwitchPairStatus, UnconfirmedSwitchInfo}, diff --git a/pallets/pallet-configuration/src/default_weights.rs b/pallets/pallet-configuration/src/default_weights.rs index 280fa1ed1..9d2189406 100644 --- a/pallets/pallet-configuration/src/default_weights.rs +++ b/pallets/pallet-configuration/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/pallet-configuration/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-configuration/src/lib.rs b/pallets/pallet-configuration/src/lib.rs index 51676b274..35bb46fd9 100644 --- a/pallets/pallet-configuration/src/lib.rs +++ b/pallets/pallet-configuration/src/lib.rs @@ -43,6 +43,10 @@ mod tests; pub use crate::{configuration::Configuration, default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/pallet-deposit-storage/src/default_weights.rs b/pallets/pallet-deposit-storage/src/default_weights.rs index 6d0618067..bfb66f379 100644 --- a/pallets/pallet-deposit-storage/src/default_weights.rs +++ b/pallets/pallet-deposit-storage/src/default_weights.rs @@ -22,8 +22,8 @@ // ./pallets/pallet-deposit-storage/src/defaul_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-deposit-storage/src/lib.rs b/pallets/pallet-deposit-storage/src/lib.rs index 86939fecc..035b24324 100644 --- a/pallets/pallet-deposit-storage/src/lib.rs +++ b/pallets/pallet-deposit-storage/src/lib.rs @@ -43,6 +43,10 @@ pub use crate::{default_weights::WeightInfo, deposit::FixedDepositCollectorViaDe const LOG_TARGET: &str = "pallet_deposit_storage"; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use crate::{ default_weights::WeightInfo, diff --git a/pallets/pallet-did-lookup/src/associate_account_request.rs b/pallets/pallet-did-lookup/src/associate_account_request.rs index 72d0e99f5..81aa2ea18 100644 --- a/pallets/pallet-did-lookup/src/associate_account_request.rs +++ b/pallets/pallet-did-lookup/src/associate_account_request.rs @@ -81,6 +81,8 @@ pub fn get_challenge, BlockNumber: Debug>( // Copied from https://github.com/paritytech/substrate/blob/ad5399644aebc54e32a107ac37ae08e6cd1f0cfb/primitives/core/src/crypto.rs#L324 // Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 +#[allow(clippy::expect_used)] +#[allow(clippy::as_conversions)] fn to_ss58(public_key: &[u8], prefix: u16) -> String { // We mask out the upper two bits of the ident - SS58 Prefix currently only // supports 14-bits @@ -95,10 +97,12 @@ fn to_ss58(public_key: &[u8], prefix: u16) -> String { let second = ((ident >> 8) as u8) | ((ident & 0b0000_0000_0000_0011) as u8) << 6; vec![first | 0b01000000, second] } + #[allow(clippy::unreachable)] _ => unreachable!("masked out the upper two bits; qed"), }; v.extend(public_key); let r = ss58hash(&v); + #[allow(clippy::indexing_slicing)] v.extend(&r[0..2]); v.to_base58() } diff --git a/pallets/pallet-did-lookup/src/default_weights.rs b/pallets/pallet-did-lookup/src/default_weights.rs index 6657af975..f4bca9148 100644 --- a/pallets/pallet-did-lookup/src/default_weights.rs +++ b/pallets/pallet-did-lookup/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/pallet-did-lookup/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-did-lookup/src/lib.rs b/pallets/pallet-did-lookup/src/lib.rs index f97d8a163..c043c95b3 100644 --- a/pallets/pallet-did-lookup/src/lib.rs +++ b/pallets/pallet-did-lookup/src/lib.rs @@ -48,6 +48,10 @@ mod benchmarking; pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use crate::{ associate_account_request::AssociateAccountRequest, default_weights::WeightInfo, diff --git a/pallets/pallet-did-lookup/src/tests/associate.rs b/pallets/pallet-did-lookup/src/tests/associate.rs index a7941ea0a..cee7bfb21 100644 --- a/pallets/pallet-did-lookup/src/tests/associate.rs +++ b/pallets/pallet-did-lookup/src/tests/associate.rs @@ -132,9 +132,6 @@ fn test_add_association_account() { AssociateAccountRequest::Polkadot(account_hash_alice.clone(), sig_alice_1.clone()), expire_at, ); - if let Err(err) = res { - println!("Error overwriting association: {:?}", err); - } assert!(res.is_ok()); assert_eq!( ConnectedDids::::get(LinkableAccountId::from(account_hash_alice.clone())), diff --git a/pallets/pallet-dip-consumer/src/default_weights.rs b/pallets/pallet-dip-consumer/src/default_weights.rs index f425e7da3..e1d342581 100644 --- a/pallets/pallet-dip-consumer/src/default_weights.rs +++ b/pallets/pallet-dip-consumer/src/default_weights.rs @@ -22,8 +22,8 @@ // ./pallets/pallet-dip-consumer/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-dip-consumer/src/lib.rs b/pallets/pallet-dip-consumer/src/lib.rs index 564e6ba57..eaedee1d1 100644 --- a/pallets/pallet-dip-consumer/src/lib.rs +++ b/pallets/pallet-dip-consumer/src/lib.rs @@ -39,6 +39,10 @@ pub use crate::{default_weights::WeightInfo, origin::*, pallet::*, traits::Succe const LOG_TARGET: &str = "dip::consumer::pallet_dip_consumer"; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/pallet-dip-provider/src/default_weights.rs b/pallets/pallet-dip-provider/src/default_weights.rs index 51c54bbe0..93b927b60 100644 --- a/pallets/pallet-dip-provider/src/default_weights.rs +++ b/pallets/pallet-dip-provider/src/default_weights.rs @@ -22,8 +22,8 @@ // ./pallets/pallet-dip-provider/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-dip-provider/src/lib.rs b/pallets/pallet-dip-provider/src/lib.rs index 1f8ab4205..f77a7988e 100644 --- a/pallets/pallet-dip-provider/src/lib.rs +++ b/pallets/pallet-dip-provider/src/lib.rs @@ -39,6 +39,10 @@ pub use crate::{ const LOG_TARGET: &str = "dip::provider::pallet_dip_provider"; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/pallet-inflation/src/default_weights.rs b/pallets/pallet-inflation/src/default_weights.rs index 2063cdbb5..483e4ef79 100644 --- a/pallets/pallet-inflation/src/default_weights.rs +++ b/pallets/pallet-inflation/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/pallet-inflation/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-inflation/src/lib.rs b/pallets/pallet-inflation/src/lib.rs index 1fe2a79ee..8ca6975db 100644 --- a/pallets/pallet-inflation/src/lib.rs +++ b/pallets/pallet-inflation/src/lib.rs @@ -43,6 +43,10 @@ mod benchmarking; pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::WeightInfo; use frame_support::{ diff --git a/pallets/pallet-migration/src/default_weights.rs b/pallets/pallet-migration/src/default_weights.rs index 6340209cb..d05b954f8 100644 --- a/pallets/pallet-migration/src/default_weights.rs +++ b/pallets/pallet-migration/src/default_weights.rs @@ -24,8 +24,8 @@ // --template=.maintain/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-migration/src/lib.rs b/pallets/pallet-migration/src/lib.rs index ea9d44c30..5903531b8 100644 --- a/pallets/pallet-migration/src/lib.rs +++ b/pallets/pallet-migration/src/lib.rs @@ -30,6 +30,10 @@ mod test; pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/pallet-relay-store/src/default_weights.rs b/pallets/pallet-relay-store/src/default_weights.rs index 1ba0ff20f..02eaeaa29 100644 --- a/pallets/pallet-relay-store/src/default_weights.rs +++ b/pallets/pallet-relay-store/src/default_weights.rs @@ -41,8 +41,8 @@ // --output=./pallets/pallet-relay-store/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-relay-store/src/lib.rs b/pallets/pallet-relay-store/src/lib.rs index ed50bb5b7..3907f2d26 100644 --- a/pallets/pallet-relay-store/src/lib.rs +++ b/pallets/pallet-relay-store/src/lib.rs @@ -40,6 +40,10 @@ pub use crate::{default_weights::WeightInfo, pallet::*, relay::*}; const LOG_TARGET: &str = "pallet_relay_store"; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/pallets/pallet-web3-names/Cargo.toml b/pallets/pallet-web3-names/Cargo.toml index ea0b98dbd..e63fb174d 100644 --- a/pallets/pallet-web3-names/Cargo.toml +++ b/pallets/pallet-web3-names/Cargo.toml @@ -54,6 +54,7 @@ std = [ "frame-benchmarking?/std", "frame-support/std", "frame-system/std", + "kilt-support/std", "log/std", "parity-scale-codec/std", "scale-info/std", diff --git a/pallets/pallet-web3-names/src/default_weights.rs b/pallets/pallet-web3-names/src/default_weights.rs index 8e220ee74..63b439896 100644 --- a/pallets/pallet-web3-names/src/default_weights.rs +++ b/pallets/pallet-web3-names/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/pallet-web3-names/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/pallet-web3-names/src/lib.rs b/pallets/pallet-web3-names/src/lib.rs index 71abd83a5..279369706 100644 --- a/pallets/pallet-web3-names/src/lib.rs +++ b/pallets/pallet-web3-names/src/lib.rs @@ -40,6 +40,10 @@ mod benchmarking; pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use frame_support::{ pallet_prelude::*, @@ -484,7 +488,7 @@ pub mod pallet { /// `check_releasing_preconditions` as it does not verify all the /// preconditions again. fn unregister_name(name: &Web3NameOf) -> Result, DispatchError> { - let name_ownership = Owner::::take(name).unwrap(); + let name_ownership = Owner::::take(name).ok_or(Error::::OwnerNotFound)?; Names::::remove(&name_ownership.owner); let is_key_migrated = diff --git a/pallets/parachain-staking/src/api.rs b/pallets/parachain-staking/src/api.rs index 6ab4b8ac7..43d32b8da 100644 --- a/pallets/parachain-staking/src/api.rs +++ b/pallets/parachain-staking/src/api.rs @@ -70,6 +70,7 @@ impl Pallet { /// delegators. /// /// At least used in Runtime API. + #[allow(clippy::arithmetic_side_effects)] pub fn get_staking_rates() -> kilt_runtime_api_staking::StakingRates { let total_issuance = T::Currency::total_issuance(); let total_stake = TotalCollatorStake::::get(); diff --git a/pallets/parachain-staking/src/default_weights.rs b/pallets/parachain-staking/src/default_weights.rs index f39ca4588..9174763b9 100644 --- a/pallets/parachain-staking/src/default_weights.rs +++ b/pallets/parachain-staking/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/parachain-staking/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/parachain-staking/src/inflation.rs b/pallets/parachain-staking/src/inflation.rs index 7e7f94dc9..49983d920 100644 --- a/pallets/parachain-staking/src/inflation.rs +++ b/pallets/parachain-staking/src/inflation.rs @@ -37,6 +37,7 @@ impl MaxEncodedLen for RewardRate { } /// Convert annual reward rate to per_block. +#[allow(clippy::arithmetic_side_effects)] fn annual_to_per_block(blocks_per_year: u64, rate: Perquintill) -> Perquintill { rate / blocks_per_year.max(1) } @@ -80,6 +81,7 @@ impl StakingInfo { /// /// NOTE: If we exceed the max staking rate, the reward will be reduced by /// max_rate / current_rate. + #[allow(clippy::arithmetic_side_effects)] pub fn compute_reward( &self, stake: BalanceOf, diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index de7d6020c..00edc428d 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -137,6 +137,12 @@ use frame_support::pallet; pub use crate::{default_weights::WeightInfo, pallet::*}; #[pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] +// We do plain arithmetic operations only after we've made sure they will go through. +#[allow(clippy::arithmetic_side_effects)] pub mod pallet { use super::*; pub use crate::inflation::{InflationInfo, RewardRate, StakingInfo}; diff --git a/pallets/parachain-staking/src/set.rs b/pallets/parachain-staking/src/set.rs index dbb60c1bf..36503b87e 100644 --- a/pallets/parachain-staking/src/set.rs +++ b/pallets/parachain-staking/src/set.rs @@ -53,6 +53,7 @@ impl> OrderedSet { let mut v = bv.into_inner(); v.sort_by(|a, b| b.cmp(a)); v.dedup(); + #[allow(clippy::expect_used)] Self::from_sorted_set(v.try_into().map_err(|_| ()).expect("No values were added")) } @@ -74,6 +75,7 @@ impl> OrderedSet { let mut i: usize = 0; let mut next = i.saturating_add(1); while next < self.len() { + #[allow(clippy::indexing_slicing)] if self[i] == self[next] { self.0.remove(next); } else { @@ -124,6 +126,7 @@ impl> OrderedSet { // accessing by index wont panic since we checked the index, inserting the item // at the end of the list to ensure last-in-least-priority-rule for collators. // sorting algorithm must be stable! + #[allow(clippy::indexing_slicing)] let old = sp_std::mem::replace(&mut self.0[last_idx], value); self.sort_greatest_to_lowest(); Ok(Some(old)) @@ -144,6 +147,7 @@ impl> OrderedSet { pub fn try_upsert(&mut self, value: T) -> Result, ()> { match self.linear_search(&value) { Ok(i) => { + #[allow(clippy::indexing_slicing)] let old = sp_std::mem::replace(&mut self.0[i], value); self.sort_greatest_to_lowest(); Ok(Some(old)) @@ -243,6 +247,7 @@ impl> From> for OrderedSet { impl> Index for OrderedSet { type Output = T; + #[allow(clippy::indexing_slicing)] fn index(&self, index: usize) -> &Self::Output { &self.0[index] } @@ -251,6 +256,7 @@ impl> Index for OrderedSet { impl> Index> for OrderedSet { type Output = [T]; + #[allow(clippy::indexing_slicing)] fn index(&self, range: Range) -> &Self::Output { &self.0[range] } @@ -259,6 +265,7 @@ impl> Index> for OrderedSet { impl> Index for OrderedSet { type Output = [T]; + #[allow(clippy::indexing_slicing)] fn index(&self, range: RangeFull) -> &Self::Output { &self.0[range] } diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index 874a65a8c..dbc9e8e33 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -128,6 +128,8 @@ where pub status: CandidateStatus, } +// We access indices only after making sure they are properly verified. +#[allow(clippy::indexing_slicing)] impl Candidate where A: Ord + Clone + Debug, diff --git a/pallets/public-credentials/src/default_weights.rs b/pallets/public-credentials/src/default_weights.rs index 976cd0c01..04f52f399 100644 --- a/pallets/public-credentials/src/default_weights.rs +++ b/pallets/public-credentials/src/default_weights.rs @@ -42,8 +42,8 @@ // --output=./pallets/public-credentials/src/default_weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; diff --git a/pallets/public-credentials/src/lib.rs b/pallets/public-credentials/src/lib.rs index c3299047c..089dd0af0 100644 --- a/pallets/public-credentials/src/lib.rs +++ b/pallets/public-credentials/src/lib.rs @@ -52,6 +52,10 @@ pub use crate::{ }; #[frame_support::pallet] +// `.expect()` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::expect_used)] +// `unreachable` is used in the macro-generated code, and we have to ignore it. +#[allow(clippy::unreachable)] pub mod pallet { use super::*; diff --git a/runtimes/common/src/constants.rs b/runtimes/common/src/constants.rs index 2de723671..71d05e889 100644 --- a/runtimes/common/src/constants.rs +++ b/runtimes/common/src/constants.rs @@ -47,10 +47,13 @@ pub const MILLISECS_PER_BLOCK: u64 = 12_000; pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; // Time is measured by number of blocks. +#[allow(clippy::integer_division)] +#[allow(clippy::as_conversions)] pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; // Julian year as Substrate handles it +#[allow(clippy::integer_division)] pub const BLOCKS_PER_YEAR: BlockNumber = DAYS * 36525 / 100; pub const MAX_COLLATOR_STAKE: Balance = 200_000 * KILT; @@ -82,6 +85,7 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); /// used by Operational extrinsics. pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); /// We allow for 0.5 seconds of compute with a 12 second average block time. +#[allow(clippy::as_conversions)] pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, @@ -115,6 +119,8 @@ pub fn kilt_inflation_config() -> InflationInfo { /// Calculate the storage deposit based on the number of storage items and the /// combined byte size of those items. +#[allow(clippy::as_conversions)] +#[allow(clippy::arithmetic_side_effects)] pub const fn deposit(items: u32, bytes: u32) -> Balance { items as Balance * DEPOSIT_STORAGE_ITEM + (bytes as Balance) * DEPOSIT_STORAGE_BYTE } @@ -458,6 +464,8 @@ pub mod treasury { pub const INITIAL_PERIOD_LENGTH: BlockNumber = BLOCKS_PER_YEAR.saturating_mul(5); const YEARLY_REWARD: Balance = 2_000_000u128 * KILT; + #[allow(clippy::as_conversions)] + #[allow(clippy::integer_division)] pub const INITIAL_PERIOD_REWARD_PER_BLOCK: Balance = YEARLY_REWARD / (BLOCKS_PER_YEAR as Balance); parameter_types! { @@ -529,6 +537,9 @@ pub mod fee { } } +#[allow(clippy::as_conversions)] +const MAX_SUBJECT_ID_LENGTH: u32 = kilt_asset_dids::MAXIMUM_ASSET_DID_LENGTH as u32; + pub mod public_credentials { use super::*; @@ -540,7 +551,7 @@ pub mod public_credentials { parameter_types! { pub const Deposit: Balance = PUBLIC_CREDENTIAL_DEPOSIT; pub const MaxEncodedClaimsLength: u32 = 100_000; // 100 Kb - pub const MaxSubjectIdLength: u32 = kilt_asset_dids::MAXIMUM_ASSET_DID_LENGTH as u32; + pub const MaxSubjectIdLength: u32 = MAX_SUBJECT_ID_LENGTH; } } diff --git a/runtimes/common/src/fees.rs b/runtimes/common/src/fees.rs index b970d5bf8..511e875e8 100644 --- a/runtimes/common/src/fees.rs +++ b/runtimes/common/src/fees.rs @@ -115,6 +115,8 @@ where u128: From<<::OnChargeTransaction as OnChargeTransaction>::Balance>, { type Balance = Balance; + #[allow(clippy::integer_division)] + #[allow(clippy::arithmetic_side_effects)] fn polynomial() -> WeightToFeeCoefficients { // The should be fee let wanted_fee: Balance = 10 * MILLI_KILT; diff --git a/runtimes/common/src/lib.rs b/runtimes/common/src/lib.rs index b4b16b6de..190acef6d 100644 --- a/runtimes/common/src/lib.rs +++ b/runtimes/common/src/lib.rs @@ -43,6 +43,7 @@ use sp_runtime::{ FixedPointNumber, MultiSignature, Perquintill, SaturatedConversion, }; use sp_std::marker::PhantomData; +use sp_weights::Weight; pub mod asset_switch; pub mod assets; @@ -122,6 +123,19 @@ pub type DidIdentifier = AccountId; pub type NegativeImbalanceOf = as Currency<::AccountId>>::NegativeImbalance; +#[allow(clippy::arithmetic_side_effects)] +const MAX_BLOCK_LENGTH: u32 = 5 * 1024 * 1024; +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn normal_class_max_weight() -> Weight { + NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT +} +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn operational_class_reserved_weight() -> Weight { + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT +} + // Common constants used in all runtimes. parameter_types! { pub const BlockHashCount: BlockNumber = 2400; @@ -139,7 +153,7 @@ parameter_types! { pub MaximumMultiplier: Multiplier = Bounded::max_value(); /// Maximum length of block. Up to 5MB. pub BlockLength: limits::BlockLength = - limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); + limits::BlockLength::max_with_normal_ratio(MAX_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO); /// Block weights base values and limits. pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder() .base_block(BlockExecutionWeight::get()) @@ -147,14 +161,14 @@ parameter_types! { weights.base_extrinsic = ExtrinsicBaseWeight::get(); }) .for_class(DispatchClass::Normal, |weights| { - weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); + weights.max_total = Some(normal_class_max_weight()); }) .for_class(DispatchClass::Operational, |weights| { weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); // Operational transactions have some extra reserved space, so that they // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. weights.reserved = Some( - MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT, + operational_class_reserved_weight() ); }) .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) diff --git a/runtimes/common/src/xcm_config.rs b/runtimes/common/src/xcm_config.rs index f0269af99..231f8cc3c 100644 --- a/runtimes/common/src/xcm_config.rs +++ b/runtimes/common/src/xcm_config.rs @@ -27,6 +27,12 @@ use xcm_executor::traits::{Properties, ShouldExecute}; use crate::{AccountId, BlockWeights}; +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn service_weight() -> Weight { + Perbill::from_percent(35) * BlockWeights::get().max_block +} + parameter_types! { // One XCM operation is 200_000_000 weight, cross-chain transfer ~= 2x of transfer. pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); @@ -34,7 +40,7 @@ parameter_types! { pub const MaxAssetsIntoHolding: u32 = 64; pub const MaxStale: u32 = 8; pub const HeapSize: u32 = 64 * 1024; - pub ServiceWeight: Weight = Perbill::from_percent(35) * BlockWeights::get().max_block; + pub ServiceWeight: Weight = service_weight(); pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; } diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index f5ae31cfe..ac3bc1d23 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -174,8 +174,11 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +#[allow(clippy::integer_division)] +const MINIMUM_PERIOD: u64 = constants::SLOT_DURATION / 2; + parameter_types! { - pub const MinimumPeriod: u64 = constants::SLOT_DURATION / 2; + pub const MinimumPeriod: u64 = MINIMUM_PERIOD; } impl pallet_timestamp::Config for Runtime { @@ -350,8 +353,14 @@ impl pallet_preimage::Config for Runtime { >; } +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn maximum_scheduler_weight() -> Weight { + Perbill::from_percent(80) * BlockWeights::get().max_block +} + parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; + pub MaximumSchedulerWeight: Weight = maximum_scheduler_weight(); pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(10); } @@ -377,7 +386,7 @@ impl PrivilegeCmp for OriginPrivilegeCmp { ( OriginCaller::Council(pallet_collective::RawOrigin::Members(l_yes_votes, l_count)), OriginCaller::Council(pallet_collective::RawOrigin::Members(r_yes_votes, r_count)), - ) => Some((l_yes_votes * r_count).cmp(&(r_yes_votes * l_count))), + ) => Some((l_yes_votes.saturating_mul(*r_count)).cmp(&(r_yes_votes.saturating_mul(*l_count)))), // For every other origin we don't care, as they are not used for `ScheduleOrigin`. _ => None, } @@ -455,13 +464,19 @@ impl pallet_democracy::Config for Runtime { type SubmitOrigin = EnsureSigned; } +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn maximum_proposal_weight() -> Weight { + Perbill::from_percent(80) * BlockWeights::get().max_block +} + parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 20 * KILT; pub const SpendPeriod: BlockNumber = constants::governance::SPEND_PERIOD; pub const Burn: Permill = Permill::zero(); pub const MaxApprovals: u32 = 100; - pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block; + pub MaxProposalWeight: Weight = maximum_proposal_weight(); pub TreasuryAccount: AccountId = Treasury::account_id(); } diff --git a/runtimes/peregrine/src/weights/attestation.rs b/runtimes/peregrine/src/weights/attestation.rs index 6e7e3beeb..681c8463a 100644 --- a/runtimes/peregrine/src/weights/attestation.rs +++ b/runtimes/peregrine/src/weights/attestation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/attestation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/ctype.rs b/runtimes/peregrine/src/weights/ctype.rs index a81c19ef0..eee80dafc 100644 --- a/runtimes/peregrine/src/weights/ctype.rs +++ b/runtimes/peregrine/src/weights/ctype.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/ctype.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/cumulus_pallet_parachain_system.rs b/runtimes/peregrine/src/weights/cumulus_pallet_parachain_system.rs index 3af3b85d7..3c49a8240 100644 --- a/runtimes/peregrine/src/weights/cumulus_pallet_parachain_system.rs +++ b/runtimes/peregrine/src/weights/cumulus_pallet_parachain_system.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/cumulus_pallet_parachain_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/delegation.rs b/runtimes/peregrine/src/weights/delegation.rs index 6d5a6286d..dbd2816e2 100644 --- a/runtimes/peregrine/src/weights/delegation.rs +++ b/runtimes/peregrine/src/weights/delegation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/delegation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/did.rs b/runtimes/peregrine/src/weights/did.rs index 4b7a6177d..cc1130b29 100644 --- a/runtimes/peregrine/src/weights/did.rs +++ b/runtimes/peregrine/src/weights/did.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/did.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/frame_system.rs b/runtimes/peregrine/src/weights/frame_system.rs index 7797ee08f..218e83d36 100644 --- a/runtimes/peregrine/src/weights/frame_system.rs +++ b/runtimes/peregrine/src/weights/frame_system.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/frame_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_asset_switch.rs b/runtimes/peregrine/src/weights/pallet_asset_switch.rs index 941a33cfd..fd14a0cde 100644 --- a/runtimes/peregrine/src/weights/pallet_asset_switch.rs +++ b/runtimes/peregrine/src/weights/pallet_asset_switch.rs @@ -44,8 +44,8 @@ // ./runtimes/peregrine/src/weights/pallet_asset_switch.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_assets.rs b/runtimes/peregrine/src/weights/pallet_assets.rs index caa46f97c..83b219070 100644 --- a/runtimes/peregrine/src/weights/pallet_assets.rs +++ b/runtimes/peregrine/src/weights/pallet_assets.rs @@ -42,8 +42,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_assets.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_balances.rs b/runtimes/peregrine/src/weights/pallet_balances.rs index ffda812b1..0fc3a85e0 100644 --- a/runtimes/peregrine/src/weights/pallet_balances.rs +++ b/runtimes/peregrine/src/weights/pallet_balances.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_balances.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_collective_council.rs b/runtimes/peregrine/src/weights/pallet_collective_council.rs index 0d20a5914..8736e1070 100644 --- a/runtimes/peregrine/src/weights/pallet_collective_council.rs +++ b/runtimes/peregrine/src/weights/pallet_collective_council.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_collective_technical_committee.rs b/runtimes/peregrine/src/weights/pallet_collective_technical_committee.rs index a1617ccae..2101f6d43 100644 --- a/runtimes/peregrine/src/weights/pallet_collective_technical_committee.rs +++ b/runtimes/peregrine/src/weights/pallet_collective_technical_committee.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_democracy.rs b/runtimes/peregrine/src/weights/pallet_democracy.rs index f98779bef..13ee2cd57 100644 --- a/runtimes/peregrine/src/weights/pallet_democracy.rs +++ b/runtimes/peregrine/src/weights/pallet_democracy.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_democracy.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_deposit_storage.rs b/runtimes/peregrine/src/weights/pallet_deposit_storage.rs index 78778127e..0b821fd18 100644 --- a/runtimes/peregrine/src/weights/pallet_deposit_storage.rs +++ b/runtimes/peregrine/src/weights/pallet_deposit_storage.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_deposit_storage.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_did_lookup.rs b/runtimes/peregrine/src/weights/pallet_did_lookup.rs index fdd0b6298..740d3d9ff 100644 --- a/runtimes/peregrine/src/weights/pallet_did_lookup.rs +++ b/runtimes/peregrine/src/weights/pallet_did_lookup.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_did_lookup.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_dip_provider.rs b/runtimes/peregrine/src/weights/pallet_dip_provider.rs index ef232a603..a8d229a79 100644 --- a/runtimes/peregrine/src/weights/pallet_dip_provider.rs +++ b/runtimes/peregrine/src/weights/pallet_dip_provider.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_dip_provider.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_indices.rs b/runtimes/peregrine/src/weights/pallet_indices.rs index fe625e87d..d19ba877d 100644 --- a/runtimes/peregrine/src/weights/pallet_indices.rs +++ b/runtimes/peregrine/src/weights/pallet_indices.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_indices.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_inflation.rs b/runtimes/peregrine/src/weights/pallet_inflation.rs index ff7b59e96..d9567a46d 100644 --- a/runtimes/peregrine/src/weights/pallet_inflation.rs +++ b/runtimes/peregrine/src/weights/pallet_inflation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_inflation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_membership.rs b/runtimes/peregrine/src/weights/pallet_membership.rs index 951c30ae9..39d599716 100644 --- a/runtimes/peregrine/src/weights/pallet_membership.rs +++ b/runtimes/peregrine/src/weights/pallet_membership.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_membership.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_message_queue.rs b/runtimes/peregrine/src/weights/pallet_message_queue.rs index 4e59a4d55..440761e2f 100644 --- a/runtimes/peregrine/src/weights/pallet_message_queue.rs +++ b/runtimes/peregrine/src/weights/pallet_message_queue.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_message_queue.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_migration.rs b/runtimes/peregrine/src/weights/pallet_migration.rs index 308415746..a24b3f129 100644 --- a/runtimes/peregrine/src/weights/pallet_migration.rs +++ b/runtimes/peregrine/src/weights/pallet_migration.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_migration.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_multisig.rs b/runtimes/peregrine/src/weights/pallet_multisig.rs index 22c6383fb..c84e0dfce 100644 --- a/runtimes/peregrine/src/weights/pallet_multisig.rs +++ b/runtimes/peregrine/src/weights/pallet_multisig.rs @@ -38,8 +38,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] #![allow(clippy::unnecessary_cast)] use frame_support::{traits::Get, weights::Weight}; diff --git a/runtimes/peregrine/src/weights/pallet_preimage.rs b/runtimes/peregrine/src/weights/pallet_preimage.rs index 97bf171cd..0212411fc 100644 --- a/runtimes/peregrine/src/weights/pallet_preimage.rs +++ b/runtimes/peregrine/src/weights/pallet_preimage.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_preimage.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_proxy.rs b/runtimes/peregrine/src/weights/pallet_proxy.rs index 2214c1f4a..3f7aeadb5 100644 --- a/runtimes/peregrine/src/weights/pallet_proxy.rs +++ b/runtimes/peregrine/src/weights/pallet_proxy.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_proxy.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_scheduler.rs b/runtimes/peregrine/src/weights/pallet_scheduler.rs index 2b7b3f950..ed9c02b03 100644 --- a/runtimes/peregrine/src/weights/pallet_scheduler.rs +++ b/runtimes/peregrine/src/weights/pallet_scheduler.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_scheduler.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_session.rs b/runtimes/peregrine/src/weights/pallet_session.rs index 4aba9f00a..7e4467c1f 100644 --- a/runtimes/peregrine/src/weights/pallet_session.rs +++ b/runtimes/peregrine/src/weights/pallet_session.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_session.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_sudo.rs b/runtimes/peregrine/src/weights/pallet_sudo.rs index ccb45802b..9c691702b 100644 --- a/runtimes/peregrine/src/weights/pallet_sudo.rs +++ b/runtimes/peregrine/src/weights/pallet_sudo.rs @@ -40,8 +40,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; @@ -50,7 +50,18 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_sudo::WeightInfo for WeightInfo { - fn remove_key() -> cumulus_primitives_core::Weight { todo!() } + /// Storage: `Sudo::Key` (r:1 w:1) + /// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + fn remove_key() -> Weight { + // Proof Size summary in bytes: + // Measured: `165` + // Estimated: `1517` + // Minimum execution time: 9_474_000 picoseconds. + Weight::from_parts(10_034_000, 0) + .saturating_add(Weight::from_parts(0, 1517)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } /// Storage: Sudo Key (r:1 w:1) /// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) fn set_key() -> Weight { diff --git a/runtimes/peregrine/src/weights/pallet_timestamp.rs b/runtimes/peregrine/src/weights/pallet_timestamp.rs index dc22a2e07..1f0275cb1 100644 --- a/runtimes/peregrine/src/weights/pallet_timestamp.rs +++ b/runtimes/peregrine/src/weights/pallet_timestamp.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_timestamp.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_tips.rs b/runtimes/peregrine/src/weights/pallet_tips.rs index 157e7b202..09b790295 100644 --- a/runtimes/peregrine/src/weights/pallet_tips.rs +++ b/runtimes/peregrine/src/weights/pallet_tips.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_tips.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_treasury.rs b/runtimes/peregrine/src/weights/pallet_treasury.rs index cf8bcbbd9..1bade513d 100644 --- a/runtimes/peregrine/src/weights/pallet_treasury.rs +++ b/runtimes/peregrine/src/weights/pallet_treasury.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_treasury.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_utility.rs b/runtimes/peregrine/src/weights/pallet_utility.rs index 33fa9027c..889b1178f 100644 --- a/runtimes/peregrine/src/weights/pallet_utility.rs +++ b/runtimes/peregrine/src/weights/pallet_utility.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_utility.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_vesting.rs b/runtimes/peregrine/src/weights/pallet_vesting.rs index dd6490c32..bdca6b043 100644 --- a/runtimes/peregrine/src/weights/pallet_vesting.rs +++ b/runtimes/peregrine/src/weights/pallet_vesting.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_vesting.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_web3_names.rs b/runtimes/peregrine/src/weights/pallet_web3_names.rs index 6314a294b..edfdbcff1 100644 --- a/runtimes/peregrine/src/weights/pallet_web3_names.rs +++ b/runtimes/peregrine/src/weights/pallet_web3_names.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_web3_names.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/pallet_xcm.rs b/runtimes/peregrine/src/weights/pallet_xcm.rs index 68a08614d..cc64e66b1 100644 --- a/runtimes/peregrine/src/weights/pallet_xcm.rs +++ b/runtimes/peregrine/src/weights/pallet_xcm.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_xcm.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/parachain_staking.rs b/runtimes/peregrine/src/weights/parachain_staking.rs index 4c4e249b1..44d667061 100644 --- a/runtimes/peregrine/src/weights/parachain_staking.rs +++ b/runtimes/peregrine/src/weights/parachain_staking.rs @@ -43,8 +43,8 @@ // --output=./runtimes/peregrine/src/weights/parachain_staking.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/peregrine/src/weights/public_credentials.rs b/runtimes/peregrine/src/weights/public_credentials.rs index 74ce73f90..21d4aede0 100644 --- a/runtimes/peregrine/src/weights/public_credentials.rs +++ b/runtimes/peregrine/src/weights/public_credentials.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/public_credentials.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index d0bb014de..83f4d50c3 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -173,8 +173,11 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +#[allow(clippy::integer_division)] +const MINIMUM_PERIOD: u64 = constants::SLOT_DURATION / 2; + parameter_types! { - pub const MinimumPeriod: u64 = constants::SLOT_DURATION / 2; + pub const MinimumPeriod: u64 = MINIMUM_PERIOD; } impl pallet_timestamp::Config for Runtime { @@ -343,8 +346,14 @@ impl pallet_preimage::Config for Runtime { >; } +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn maximum_scheduler_weight() -> Weight { + Perbill::from_percent(80) * BlockWeights::get().max_block +} + parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; + pub MaximumSchedulerWeight: Weight = maximum_scheduler_weight(); pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(10); } @@ -370,7 +379,7 @@ impl PrivilegeCmp for OriginPrivilegeCmp { ( OriginCaller::Council(pallet_collective::RawOrigin::Members(l_yes_votes, l_count)), OriginCaller::Council(pallet_collective::RawOrigin::Members(r_yes_votes, r_count)), - ) => Some((l_yes_votes * r_count).cmp(&(r_yes_votes * l_count))), + ) => Some((l_yes_votes.saturating_mul(*r_count)).cmp(&(r_yes_votes.saturating_mul(*l_count)))), // For every other origin we don't care, as they are not used for `ScheduleOrigin`. _ => None, } @@ -448,13 +457,19 @@ impl pallet_democracy::Config for Runtime { type SubmitOrigin = EnsureSigned; } +#[allow(clippy::arithmetic_side_effects)] +#[inline] +fn maximum_proposal_weight() -> Weight { + Perbill::from_percent(50) * BlockWeights::get().max_block +} + parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 20 * KILT; pub const SpendPeriod: BlockNumber = constants::governance::SPEND_PERIOD; pub const Burn: Permill = Permill::zero(); pub const MaxApprovals: u32 = 100; - pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block; + pub MaxProposalWeight: Weight = maximum_proposal_weight(); pub TreasuryAccount: AccountId = Treasury::account_id(); } diff --git a/runtimes/spiritnet/src/weights/attestation.rs b/runtimes/spiritnet/src/weights/attestation.rs index 234523159..3c212bb59 100644 --- a/runtimes/spiritnet/src/weights/attestation.rs +++ b/runtimes/spiritnet/src/weights/attestation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/attestation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/ctype.rs b/runtimes/spiritnet/src/weights/ctype.rs index 9420876cc..5f2710979 100644 --- a/runtimes/spiritnet/src/weights/ctype.rs +++ b/runtimes/spiritnet/src/weights/ctype.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/ctype.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/cumulus_pallet_parachain_system.rs b/runtimes/spiritnet/src/weights/cumulus_pallet_parachain_system.rs index f6c3f332b..9359715e4 100644 --- a/runtimes/spiritnet/src/weights/cumulus_pallet_parachain_system.rs +++ b/runtimes/spiritnet/src/weights/cumulus_pallet_parachain_system.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/cumulus_pallet_parachain_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/delegation.rs b/runtimes/spiritnet/src/weights/delegation.rs index 510e62824..0b3799069 100644 --- a/runtimes/spiritnet/src/weights/delegation.rs +++ b/runtimes/spiritnet/src/weights/delegation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/delegation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/did.rs b/runtimes/spiritnet/src/weights/did.rs index a5c92f282..50d25088a 100644 --- a/runtimes/spiritnet/src/weights/did.rs +++ b/runtimes/spiritnet/src/weights/did.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/did.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/frame_system.rs b/runtimes/spiritnet/src/weights/frame_system.rs index 28e16b657..ef58405fd 100644 --- a/runtimes/spiritnet/src/weights/frame_system.rs +++ b/runtimes/spiritnet/src/weights/frame_system.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/frame_system.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_asset_switch.rs b/runtimes/spiritnet/src/weights/pallet_asset_switch.rs index 5cdbfd9a2..56778f4ef 100644 --- a/runtimes/spiritnet/src/weights/pallet_asset_switch.rs +++ b/runtimes/spiritnet/src/weights/pallet_asset_switch.rs @@ -23,8 +23,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_assets.rs b/runtimes/spiritnet/src/weights/pallet_assets.rs index a636a8ee8..5717f115b 100644 --- a/runtimes/spiritnet/src/weights/pallet_assets.rs +++ b/runtimes/spiritnet/src/weights/pallet_assets.rs @@ -23,8 +23,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_balances.rs b/runtimes/spiritnet/src/weights/pallet_balances.rs index f1584f926..767313482 100644 --- a/runtimes/spiritnet/src/weights/pallet_balances.rs +++ b/runtimes/spiritnet/src/weights/pallet_balances.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_balances.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_collective_council.rs b/runtimes/spiritnet/src/weights/pallet_collective_council.rs index 3632a450d..d0aedb9da 100644 --- a/runtimes/spiritnet/src/weights/pallet_collective_council.rs +++ b/runtimes/spiritnet/src/weights/pallet_collective_council.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_collective_technical_committee.rs b/runtimes/spiritnet/src/weights/pallet_collective_technical_committee.rs index 0054884db..5bf1844be 100644 --- a/runtimes/spiritnet/src/weights/pallet_collective_technical_committee.rs +++ b/runtimes/spiritnet/src/weights/pallet_collective_technical_committee.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_democracy.rs b/runtimes/spiritnet/src/weights/pallet_democracy.rs index 2cf0da8c7..f0fca3874 100644 --- a/runtimes/spiritnet/src/weights/pallet_democracy.rs +++ b/runtimes/spiritnet/src/weights/pallet_democracy.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_democracy.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_deposit_storage.rs b/runtimes/spiritnet/src/weights/pallet_deposit_storage.rs index 2f442bdff..03033e0c2 100644 --- a/runtimes/spiritnet/src/weights/pallet_deposit_storage.rs +++ b/runtimes/spiritnet/src/weights/pallet_deposit_storage.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_deposit_storage.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_did_lookup.rs b/runtimes/spiritnet/src/weights/pallet_did_lookup.rs index 0f8f30fe0..b9310a445 100644 --- a/runtimes/spiritnet/src/weights/pallet_did_lookup.rs +++ b/runtimes/spiritnet/src/weights/pallet_did_lookup.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_did_lookup.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_dip_provider.rs b/runtimes/spiritnet/src/weights/pallet_dip_provider.rs index e05380bf3..89823dfcf 100644 --- a/runtimes/spiritnet/src/weights/pallet_dip_provider.rs +++ b/runtimes/spiritnet/src/weights/pallet_dip_provider.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_dip_provider.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_indices.rs b/runtimes/spiritnet/src/weights/pallet_indices.rs index 58ccc483a..34f5a824e 100644 --- a/runtimes/spiritnet/src/weights/pallet_indices.rs +++ b/runtimes/spiritnet/src/weights/pallet_indices.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_indices.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_inflation.rs b/runtimes/spiritnet/src/weights/pallet_inflation.rs index dc886eb46..62033c092 100644 --- a/runtimes/spiritnet/src/weights/pallet_inflation.rs +++ b/runtimes/spiritnet/src/weights/pallet_inflation.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_inflation.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_membership.rs b/runtimes/spiritnet/src/weights/pallet_membership.rs index 42a2bc69f..1ed068f3a 100644 --- a/runtimes/spiritnet/src/weights/pallet_membership.rs +++ b/runtimes/spiritnet/src/weights/pallet_membership.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_membership.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_message_queue.rs b/runtimes/spiritnet/src/weights/pallet_message_queue.rs index f95a6f09f..70f4f8945 100644 --- a/runtimes/spiritnet/src/weights/pallet_message_queue.rs +++ b/runtimes/spiritnet/src/weights/pallet_message_queue.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_message_queue.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_migration.rs b/runtimes/spiritnet/src/weights/pallet_migration.rs index 5913eb16f..dacd76e6a 100644 --- a/runtimes/spiritnet/src/weights/pallet_migration.rs +++ b/runtimes/spiritnet/src/weights/pallet_migration.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_migration.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_multisig.rs b/runtimes/spiritnet/src/weights/pallet_multisig.rs index d8870fc36..50ce04680 100644 --- a/runtimes/spiritnet/src/weights/pallet_multisig.rs +++ b/runtimes/spiritnet/src/weights/pallet_multisig.rs @@ -38,8 +38,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] #![allow(clippy::unnecessary_cast)] use frame_support::{traits::Get, weights::Weight}; diff --git a/runtimes/spiritnet/src/weights/pallet_preimage.rs b/runtimes/spiritnet/src/weights/pallet_preimage.rs index 77911d7df..7ad28c1de 100644 --- a/runtimes/spiritnet/src/weights/pallet_preimage.rs +++ b/runtimes/spiritnet/src/weights/pallet_preimage.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_preimage.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_proxy.rs b/runtimes/spiritnet/src/weights/pallet_proxy.rs index 78c683d06..d4ce60430 100644 --- a/runtimes/spiritnet/src/weights/pallet_proxy.rs +++ b/runtimes/spiritnet/src/weights/pallet_proxy.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_proxy.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_scheduler.rs b/runtimes/spiritnet/src/weights/pallet_scheduler.rs index f33fbe031..f242e3c6a 100644 --- a/runtimes/spiritnet/src/weights/pallet_scheduler.rs +++ b/runtimes/spiritnet/src/weights/pallet_scheduler.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_scheduler.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_session.rs b/runtimes/spiritnet/src/weights/pallet_session.rs index 669eadb18..f88ae899d 100644 --- a/runtimes/spiritnet/src/weights/pallet_session.rs +++ b/runtimes/spiritnet/src/weights/pallet_session.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_session.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_timestamp.rs b/runtimes/spiritnet/src/weights/pallet_timestamp.rs index 2afc6742a..d1931519b 100644 --- a/runtimes/spiritnet/src/weights/pallet_timestamp.rs +++ b/runtimes/spiritnet/src/weights/pallet_timestamp.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_timestamp.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_tips.rs b/runtimes/spiritnet/src/weights/pallet_tips.rs index 3e44f9c99..0043e826f 100644 --- a/runtimes/spiritnet/src/weights/pallet_tips.rs +++ b/runtimes/spiritnet/src/weights/pallet_tips.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_tips.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_treasury.rs b/runtimes/spiritnet/src/weights/pallet_treasury.rs index 4ce8ea8bf..427edc689 100644 --- a/runtimes/spiritnet/src/weights/pallet_treasury.rs +++ b/runtimes/spiritnet/src/weights/pallet_treasury.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_treasury.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_utility.rs b/runtimes/spiritnet/src/weights/pallet_utility.rs index c35d2f51a..0361edd74 100644 --- a/runtimes/spiritnet/src/weights/pallet_utility.rs +++ b/runtimes/spiritnet/src/weights/pallet_utility.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_utility.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_vesting.rs b/runtimes/spiritnet/src/weights/pallet_vesting.rs index 745623719..acb2cb3f7 100644 --- a/runtimes/spiritnet/src/weights/pallet_vesting.rs +++ b/runtimes/spiritnet/src/weights/pallet_vesting.rs @@ -40,8 +40,8 @@ // --output=./runtimes/peregrine/src/weights/pallet_vesting.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_web3_names.rs b/runtimes/spiritnet/src/weights/pallet_web3_names.rs index 20ad676dd..c51c57a35 100644 --- a/runtimes/spiritnet/src/weights/pallet_web3_names.rs +++ b/runtimes/spiritnet/src/weights/pallet_web3_names.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_web3_names.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/pallet_xcm.rs b/runtimes/spiritnet/src/weights/pallet_xcm.rs index 92e5ace14..6292ffba7 100644 --- a/runtimes/spiritnet/src/weights/pallet_xcm.rs +++ b/runtimes/spiritnet/src/weights/pallet_xcm.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/pallet_xcm.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; diff --git a/runtimes/spiritnet/src/weights/parachain_staking.rs b/runtimes/spiritnet/src/weights/parachain_staking.rs index b4daf9542..830f49bdf 100644 --- a/runtimes/spiritnet/src/weights/parachain_staking.rs +++ b/runtimes/spiritnet/src/weights/parachain_staking.rs @@ -38,8 +38,8 @@ // --template=.maintain/runtime-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] #![allow(clippy::unnecessary_cast)] use frame_support::{traits::Get, weights::Weight}; diff --git a/runtimes/spiritnet/src/weights/public_credentials.rs b/runtimes/spiritnet/src/weights/public_credentials.rs index 0c96cdf01..2dc07c607 100644 --- a/runtimes/spiritnet/src/weights/public_credentials.rs +++ b/runtimes/spiritnet/src/weights/public_credentials.rs @@ -40,8 +40,8 @@ // --output=./runtimes/spiritnet/src/weights/public_credentials.rs #![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::as_conversions)] use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; From 09b67ae0e46888d7bdd43c05ce41cb1dc8bbeb8b Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 25 Oct 2024 10:20:25 +0300 Subject: [PATCH 03/42] chore: more lints (#762) Add more lints to our codebase. I have taken all lints that are allowed by default, and made either either warnings or strong denies. **I have not added any lints from the [pedantic](https://rust-lang.github.io/rust-clippy/master/index.html?groups=pedantic) group, as those tend to be opinionated and I don't think should be enforced on a shared codebase.** Unfortunately, there is an [open cargo issue](https://github.com/rust-lang/cargo/issues/8170) which makes it impossible to enable/disable lints based on the `#[cfg(test)]` or `#[cfg(feature = "...")]` features, hence I have had to enable lints for either the whole codebase (`[target.'cfg(all())']`), or for runtime-only code `[target.'cfg(target_arch = "wasm32")']`. The changeset is huge but just because I tackled all the new lints generated, so reviewing the new lints (in case some are unwanted or in case I missed some) would be sufficient, since the CI has been updated to verify all lints are properly addressed. Last but not least, I had to enable the `-Dwarnings` flag for ALL clippy invocations, so also on local machines, because it's not possible to pass custom `--cfg` either to rustc via cargo, e.g., `cargo clippy -- --cfg ci` and then have a `[target.'cfg(ci)']` entry in the config file. This might go away in future versions of cargo (we are currently on 1.74), but until then we either never fail on the CI, or we fail for everything also locally, and I think the latter is a better choice. This is also because rustc takes additional flags either from the `RUSTFLAGS` env variable or the `.cargo/config.toml` file. Hence specifying `RUSTFLAGS="-Dwarnings"` in the CI would not enable any additional lints as the env variable would take precedence over the config file, rendering them useless. --- .cargo/config.toml | 76 +++++++++- .github/workflows/check-code.yml | 3 +- crates/assets/src/asset.rs | 116 ++++++++------- crates/assets/src/chain.rs | 70 +++++----- crates/assets/src/v1.rs | 18 +-- crates/kilt-dip-primitives/Cargo.toml | 3 + .../src/merkle_proofs/v0/input_common.rs | 2 +- .../merkle_proofs/v0/provider_state/mod.rs | 27 ++-- .../src/state_proofs/mod.rs | 48 ++++--- .../nodes/dip-consumer/src/chain_spec.rs | 6 +- .../nodes/dip-consumer/src/command.rs | 14 +- dip-template/nodes/dip-consumer/src/rpc.rs | 7 +- .../nodes/dip-consumer/src/service.rs | 64 +++++---- .../nodes/dip-provider/src/chain_spec.rs | 6 +- .../nodes/dip-provider/src/command.rs | 14 +- dip-template/nodes/dip-provider/src/rpc.rs | 7 +- .../nodes/dip-provider/src/service.rs | 64 +++++---- dip-template/pallets/pallet-postit/src/lib.rs | 27 ++-- dip-template/runtimes/dip-consumer/src/dip.rs | 2 +- dip-template/runtimes/dip-consumer/src/lib.rs | 2 + dip-template/runtimes/dip-provider/src/lib.rs | 2 + integration-tests/emulated/Cargo.toml | 7 +- .../emulated/src/mock/para_chains.rs | 11 +- .../peregrine/did_pallets/attestation.rs | 2 +- .../src/tests/peregrine/did_pallets/w3n.rs | 7 +- .../spiritnet/did_pallets/attestation.rs | 2 +- .../src/tests/spiritnet/did_pallets/w3n.rs | 2 +- nodes/parachain/src/chain_spec/mod.rs | 4 + nodes/parachain/src/cli.rs | 2 +- nodes/parachain/src/command.rs | 11 +- nodes/parachain/src/rpc.rs | 8 +- nodes/parachain/src/service.rs | 57 ++++---- nodes/standalone/src/chain_spec.rs | 4 +- nodes/standalone/src/main.rs | 2 + nodes/standalone/src/rpc.rs | 9 +- nodes/standalone/src/service.rs | 6 +- pallets/attestation/src/lib.rs | 7 + pallets/attestation/src/migrations.rs | 4 +- pallets/ctype/src/lib.rs | 11 +- .../delegation/src/delegation_hierarchy.rs | 4 +- pallets/delegation/src/lib.rs | 15 +- pallets/delegation/src/migrations.rs | 4 +- pallets/delegation/src/mock.rs | 2 +- pallets/did/src/did_details.rs | 22 +-- pallets/did/src/lib.rs | 19 ++- pallets/did/src/migrations.rs | 4 +- pallets/did/src/mock_utils.rs | 2 +- pallets/did/src/origin.rs | 2 +- .../pallet-asset-switch/src/benchmarking.rs | 4 +- pallets/pallet-asset-switch/src/lib.rs | 13 +- pallets/pallet-asset-switch/src/switch.rs | 4 +- .../src/tests/set_switch_pair.rs | 2 +- .../pallet-asset-switch/src/tests/switch.rs | 2 +- .../src/xcm/query/tests/expecting_response.rs | 10 +- .../src/xcm/query/tests/on_response.rs | 2 +- .../xcm/trade/switch_pair_remote_asset/mod.rs | 8 +- .../src/xcm/trade/xcm_fee_asset/mod.rs | 2 +- pallets/pallet-configuration/Cargo.toml | 1 + .../pallet-configuration/src/benchmarking.rs | 2 +- pallets/pallet-configuration/src/lib.rs | 7 + pallets/pallet-configuration/src/mock.rs | 2 +- pallets/pallet-configuration/src/tests.rs | 6 +- pallets/pallet-deposit-storage/Cargo.toml | 2 +- pallets/pallet-deposit-storage/src/lib.rs | 7 + pallets/pallet-did-lookup/src/account.rs | 22 ++- .../src/associate_account_request.rs | 4 +- pallets/pallet-did-lookup/src/lib.rs | 11 +- pallets/pallet-did-lookup/src/migrations.rs | 4 +- .../pallet-did-lookup/src/tests/associate.rs | 35 +++-- pallets/pallet-dip-consumer/src/lib.rs | 7 + pallets/pallet-dip-consumer/src/mock.rs | 4 +- pallets/pallet-dip-provider/src/lib.rs | 11 +- pallets/pallet-inflation/src/lib.rs | 7 + pallets/pallet-inflation/src/mock.rs | 2 +- pallets/pallet-migration/src/lib.rs | 21 ++- pallets/pallet-relay-store/src/lib.rs | 10 ++ pallets/pallet-web3-names/src/lib.rs | 18 ++- pallets/pallet-web3-names/src/migrations.rs | 4 +- pallets/pallet-web3-names/src/web3_name.rs | 28 ++-- pallets/parachain-staking/src/benchmarking.rs | 25 ++-- pallets/parachain-staking/src/lib.rs | 132 ++++++++++-------- pallets/parachain-staking/src/mock.rs | 2 +- pallets/parachain-staking/src/set.rs | 9 +- .../parachain-staking/src/tests/rewards.rs | 2 +- pallets/parachain-staking/src/tests/round.rs | 4 +- pallets/parachain-staking/src/types.rs | 24 +--- pallets/public-credentials/src/lib.rs | 9 +- pallets/public-credentials/src/migrations.rs | 7 +- runtimes/common/src/authorization.rs | 20 +-- runtimes/common/src/constants.rs | 5 +- runtimes/common/src/dip/deposit/mod.rs | 3 + runtimes/common/src/dip/did/mod.rs | 4 +- runtimes/common/src/dip/merkle/mod.rs | 2 +- .../src/dip/merkle/tests/generate_proof.rs | 3 +- runtimes/common/src/dip/merkle/v0/mod.rs | 46 +++--- .../merkle/v0/tests/generate_commitment.rs | 13 +- .../src/dip/merkle/v0/tests/generate_proof.rs | 57 +++----- runtimes/common/src/dip/mock.rs | 10 +- runtimes/common/src/fees.rs | 12 +- runtimes/common/src/lib.rs | 7 +- runtimes/kestrel/src/lib.rs | 12 +- runtimes/peregrine/src/lib.rs | 14 +- runtimes/peregrine/src/xcm_config.rs | 11 +- runtimes/spiritnet/src/lib.rs | 14 +- runtimes/spiritnet/src/xcm_config.rs | 11 +- support/src/migration.rs | 2 +- support/src/traits.rs | 20 ++- 107 files changed, 889 insertions(+), 661 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index b93dd3548..be3fa2d13 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,61 @@ -# Deployment runtime lints -[target.'cfg(all(target_arch = "wasm32", not(test)))'] +# Unfortunately we cannot add any lints based on `cfg(test)` nor `cfg(feature = "feat")`: https://github.com/rust-lang/cargo/issues/8170. +# Hence, we can only define lints that are applied codebase-wide (including tests), and lints that are applied only to runtime code. + +# Codebase-wide lints. +[target.'cfg(all())'] +rustflags = [ + # We need to deny warnings here instead of with the `RUSTFLAGS` env since the env variable would completely override these settings -> https://github.com/rust-lang/cargo/issues/5376. + "-Dwarnings", + "-Wclippy::as_underscore", + "-Wclippy::assertions_on_result_states", + "-Wclippy::branches_sharing_code", + "-Wclippy::clear_with_drain", + "-Wclippy::clone_on_ref_ptr", + "-Wclippy::collection_is_never_read", + "-Wclippy::derive_partial_eq_without_eq", + "-Wclippy::else_if_without_else", + "-Wclippy::empty_drop", + "-Wclippy::empty_structs_with_brackets", + "-Wclippy::equatable_if_let", + "-Wclippy::if_then_some_else_none", + "-Wclippy::impl_trait_in_params", + "-Wclippy::iter_on_empty_collections", + "-Wclippy::iter_on_single_items", + "-Wclippy::iter_with_drain", + "-Wclippy::needless_collect", + "-Wclippy::needless_pass_by_ref_mut", + "-Wclippy::negative_feature_names", + "-Wclippy::option_if_let_else", + "-Wclippy::or_fun_call", + "-Wclippy::pub_without_shorthand", + "-Wclippy::redundant_clone", + "-Wclippy::redundant_type_annotations", + "-Wclippy::ref_patterns", + "-Wclippy::rest_pat_in_fully_bound_structs", + "-Wclippy::suspicious_operation_groupings", + "-Wclippy::type_repetition_in_bounds", + "-Wclippy::unnecessary_self_imports", + "-Wclippy::unnecessary_struct_initialization", + "-Wclippy::unneeded_field_pattern", + "-Wclippy::unused_peekable", + "-Wclippy::useless_let_if_seq", + "-Wclippy::wildcard_dependencies", + # TODO: Add after upgrading to 1.76 + # "-Wclippy::infinite_loop", + # TODO: Add after upgrading to 1.77 + #"-Wclippy::empty_enum_variants_with_brackets" + # TODO: Add after upgrading to 1.80 + #"-Wclippy::renamed_function_params" + # TODO: Add after upgrading to 1.81 + #"-Wclippy::cfg_not_test" + #"-Wclippy::allow_attributes", + # "-Wclippy::allow_attributes_without_reason", + # TODO: Add after upgrading to 1.83 + #"-Wclippy::unused_trait_names" +] + +# Deployment runtime lints. +[target.'cfg(target_arch = "wasm32")'] rustflags = [ "-Dclippy::arithmetic_side_effects", "-Dclippy::as_conversions", @@ -12,6 +68,7 @@ rustflags = [ "-Dclippy::index_refutable_slice", "-Dclippy::indexing_slicing", "-Dclippy::lossy_float_literal", + "-Dclippy::modulo_arithmetic", "-Dclippy::panic", "-Dclippy::string_slice", "-Dclippy::todo", @@ -19,8 +76,21 @@ rustflags = [ "-Dclippy::unreachable", "-Dclippy::unwrap_used", "-Funsafe_code", + "-Wclippy::alloc_instead_of_core", + "-Wclippy::decimal_literal_representation", + "-Wclippy::default_numeric_fallback", + "-Wclippy::error_impl_error", "-Wclippy::integer_division", - "-Wclippy::modulo_arithmetic", + "-Wclippy::let_underscore_must_use", + "-Wclippy::let_underscore_untyped", + "-Wclippy::missing_const_for_fn", + "-Wclippy::mixed_read_write_in_expression", "-Wclippy::print_stderr", "-Wclippy::print_stdout", + "-Wclippy::shadow_reuse", + "-Wclippy::shadow_same", + "-Wclippy::shadow_unrelated", + "-Wclippy::str_to_string", + "-Wclippy::string_slice", + "-Wclippy::string_to_string", ] diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml index 526e8294f..3250b9ff1 100644 --- a/.github/workflows/check-code.yml +++ b/.github/workflows/check-code.yml @@ -39,7 +39,6 @@ jobs: env: # Configured by the Docker image. We can't change this unless the image does it. CARGO_HOME: /usr/local/cargo - RUSTFLAGS: -D warnings SKIP_WASM_BUILD: 1 needs: get-commit-head if: ${{ !contains(needs.get-commit-head.outputs.headCommitMsg, 'ci-skip-rust') }} @@ -71,7 +70,7 @@ jobs: save-always: true - name: Run `cargo clippy` - run: cargo clippy --locked ${{ matrix.cargo-flags }} + run: cargo clippy --locked --no-deps ${{ matrix.cargo-flags }} cargo-fmt: name: Check formatting diff --git a/crates/assets/src/asset.rs b/crates/assets/src/asset.rs index 2caf3c390..5ee17721b 100644 --- a/crates/assets/src/asset.rs +++ b/crates/assets/src/asset.rs @@ -109,8 +109,8 @@ pub mod v1 { where I: AsRef<[u8]> + Into>, { - let input = input.as_ref(); - let input_length = input.len(); + let input_ref = input.as_ref(); + let input_length = input_ref.len(); if !(MINIMUM_ASSET_ID_LENGTH..=MAXIMUM_ASSET_ID_LENGTH).contains(&input_length) { log::trace!( "Length of provided input {} is not included in the inclusive range [{},{}]", @@ -122,12 +122,12 @@ pub mod v1 { } let AssetComponents { - namespace, - reference, - identifier, - } = split_components(input); + namespace: encoded_namespace, + reference: encoded_reference, + identifier: encoded_identifier, + } = split_components(input_ref); - match (namespace, reference, identifier) { + match (encoded_namespace, encoded_reference, encoded_identifier) { // "slip44:" assets -> https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-20.md (Some(SLIP44_NAMESPACE), _, Some(_)) => { log::trace!("Slip44 namespace does not accept an asset identifier."); @@ -145,9 +145,9 @@ pub mod v1 { EvmSmartContractFungibleReference::from_utf8_encoded(erc20_reference).map(Self::Erc20) } // "erc721:" assets -> https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md - (Some(ERC721_NAMESPACE), Some(erc721_reference), identifier) => { + (Some(ERC721_NAMESPACE), Some(erc721_reference), erc721_identifier) => { let reference = EvmSmartContractFungibleReference::from_utf8_encoded(erc721_reference)?; - let identifier = identifier.map_or(Ok(None), |id| { + let identifier = erc721_identifier.map_or(Ok(None), |id| { EvmSmartContractNonFungibleIdentifier::from_utf8_encoded(id).map(Some) })?; Ok(Self::Erc721(EvmSmartContractNonFungibleReference( @@ -155,9 +155,9 @@ pub mod v1 { ))) } // "erc1155:" assets-> https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-29.md - (Some(ERC1155_NAMESPACE), Some(erc1155_reference), identifier) => { + (Some(ERC1155_NAMESPACE), Some(erc1155_reference), erc1155_identifier) => { let reference = EvmSmartContractFungibleReference::from_utf8_encoded(erc1155_reference)?; - let identifier = identifier.map_or(Ok(None), |id| { + let identifier = erc1155_identifier.map_or(Ok(None), |id| { EvmSmartContractNonFungibleIdentifier::from_utf8_encoded(id).map(Some) })?; Ok(Self::Erc1155(EvmSmartContractNonFungibleReference( @@ -165,7 +165,7 @@ pub mod v1 { ))) } // Generic yet valid asset IDs - _ => GenericAssetId::from_utf8_encoded(input).map(Self::Generic), + _ => GenericAssetId::from_utf8_encoded(input_ref).map(Self::Generic), } } } @@ -276,23 +276,20 @@ pub mod v1 { /// Split the given input into its components, i.e., namespace, reference, /// and identifier, if the proper separators are found. fn split_components(input: &[u8]) -> AssetComponents { - let mut split = input.splitn(2, |c| *c == ASSET_NAMESPACE_REFERENCE_SEPARATOR); - let (namespace, reference) = (split.next(), split.next()); + let mut namespace_reference_split = input.splitn(2, |c| *c == ASSET_NAMESPACE_REFERENCE_SEPARATOR); + let (parsed_namespace, reference) = (namespace_reference_split.next(), namespace_reference_split.next()); // Split the remaining reference to extract the identifier, if present - let (reference, identifier) = if let Some(r) = reference { - let mut split = r.splitn(2, |c| *c == ASSET_REFERENCE_IDENTIFIER_SEPARATOR); + let (parsed_reference, parsed_identifier) = reference.map_or((reference, None), |r| { + let mut reference_identifier_split = r.splitn(2, |c| *c == ASSET_REFERENCE_IDENTIFIER_SEPARATOR); // Split the reference further, if present - (split.next(), split.next()) - } else { - // Return the old reference, which is None if we are at this point - (reference, None) - }; + (reference_identifier_split.next(), reference_identifier_split.next()) + }); AssetComponents { - namespace, - reference, - identifier, + namespace: parsed_namespace, + reference: parsed_reference, + identifier: parsed_identifier, } } @@ -315,10 +312,10 @@ pub mod v1 { where I: AsRef<[u8]> + Into>, { - let input = input.as_ref(); - check_reference_length_bounds(input)?; + let input_ref = input.as_ref(); + check_reference_length_bounds(input_ref)?; - let decoded = str::from_utf8(input).map_err(|_| { + let decoded = str::from_utf8(input_ref).map_err(|_| { log::trace!("Provided input is not a valid UTF8 string as expected by a Slip44 reference."); ReferenceError::InvalidFormat })?; @@ -359,7 +356,7 @@ pub mod v1 { // Getters impl Slip44Reference { - pub fn inner(&self) -> &U256 { + pub const fn inner(&self) -> &U256 { &self.0 } } @@ -383,9 +380,9 @@ pub mod v1 { where I: AsRef<[u8]> + Into>, { - let input = input.as_ref(); + let input_ref = input.as_ref(); // If the prefix is "0x" => parse the address - if let [b'0', b'x', contract_address @ ..] = input { + if let [b'0', b'x', contract_address @ ..] = input_ref { check_reference_length_bounds(contract_address)?; let decoded = hex::decode(contract_address).map_err(|_| { @@ -407,7 +404,7 @@ pub mod v1 { // Getters impl EvmSmartContractFungibleReference { - pub fn inner(&self) -> &[u8] { + pub const fn inner(&self) -> &[u8] { &self.0 } } @@ -431,11 +428,11 @@ pub mod v1 { // Getters impl EvmSmartContractNonFungibleReference { - pub fn smart_contract(&self) -> &EvmSmartContractFungibleReference { + pub const fn smart_contract(&self) -> &EvmSmartContractFungibleReference { &self.0 } - pub fn identifier(&self) -> &Option { + pub const fn identifier(&self) -> &Option { &self.1 } } @@ -457,10 +454,10 @@ pub mod v1 { where I: AsRef<[u8]> + Into>, { - let input = input.as_ref(); - check_identifier_length_bounds(input)?; + let input_ref = input.as_ref(); + check_identifier_length_bounds(input_ref)?; - input.iter().try_for_each(|c| { + input_ref.iter().try_for_each(|c| { if !c.is_ascii_digit() { log::trace!("Provided input has some invalid values as expected by a smart contract-based asset identifier."); Err(IdentifierError::InvalidFormat) @@ -470,7 +467,7 @@ pub mod v1 { })?; Ok(Self( - Vec::::from(input) + Vec::::from(input_ref) .try_into() .map_err(|_| IdentifierError::InvalidFormat)?, )) @@ -519,12 +516,13 @@ pub mod v1 { } = split_components(input.as_ref()); match (namespace, reference, identifier) { - (Some(namespace), Some(reference), identifier) => Ok(Self { - namespace: GenericAssetNamespace::from_utf8_encoded(namespace)?, - reference: GenericAssetReference::from_utf8_encoded(reference)?, + (Some(encoded_namespace), Some(encoded_reference), encoded_identifier) => Ok(Self { + namespace: GenericAssetNamespace::from_utf8_encoded(encoded_namespace)?, + reference: GenericAssetReference::from_utf8_encoded(encoded_reference)?, // Transform Option to Result