diff --git a/Cargo.toml b/Cargo.toml index 7a73c298a..fb1c1f6ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,19 @@ members = [ default-members = ["nodes/*", "pallets/*"] resolver = "2" +[workspace.lints.clippy] +#all = { level = "warn", priority = -1} +#pedantic = { level = "warn", priority = -1} +all = { level = "allow", priority = -1} +pedantic = { level = "allow", priority = -1} + +wildcard_imports = "deny" +inconsistent_digit_grouping = "allow" +zero_prefixed_literal = "allow" + +[workspace.lints.rust] +unreachable_patterns = "deny" + [workspace.package] authors = ['Polimec Foundation '] documentation = "https://wiki.polimec.org/" diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 000000000..e69de29bb diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 78e5a199e..9c239c6aa 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [build-dependencies] substrate-wasm-builder.workspace = true diff --git a/integration-tests/penpal/Cargo.toml b/integration-tests/penpal/Cargo.toml index f676cfbf0..9921e67f4 100644 --- a/integration-tests/penpal/Cargo.toml +++ b/integration-tests/penpal/Cargo.toml @@ -8,6 +8,9 @@ homepage = "https://substrate.io" repository.workspace = true edition.workspace = true +[lints] +workspace = true + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 4b1113d49..23c8df381 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -3,6 +3,9 @@ name = "macros" version.workspace = true edition.workspace = true +[lints] +workspace = true + [lib] name = "macros" path = "src/lib.rs" diff --git a/macros/src/generate_accounts.rs b/macros/src/generate_accounts.rs index a55b0d649..3f83dd37d 100644 --- a/macros/src/generate_accounts.rs +++ b/macros/src/generate_accounts.rs @@ -31,7 +31,7 @@ use syn::{ Expr, GenericArgument, GenericParam, Generics, Ident, ItemMod, Result, Token, Type, Visibility, WhereClause, }; -pub fn generate_accounts_impl(input: TokenStream) -> TokenStream { +pub fn macro_impl(input: TokenStream) -> TokenStream { let inputs = parse_macro_input!(input with Punctuated::::parse_terminated); let mut output = quote! {}; let mut insertions = Vec::new(); @@ -40,9 +40,7 @@ pub fn generate_accounts_impl(input: TokenStream) -> TokenStream { let name = input.to_string(); // Ensure the name is all uppercase - if name != name.to_uppercase() { - panic!("Name must be in all uppercase"); - } + assert_eq!(name, name.to_uppercase(), "Name must be in all uppercase"); // Generate a unique [u8; 32] value for the constant let mut value = [0u8; 32]; diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 450287d26..6bd11d912 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -21,5 +21,5 @@ mod generate_accounts; #[proc_macro] pub fn generate_accounts(input: TokenStream) -> TokenStream { - generate_accounts::generate_accounts_impl(input) + generate_accounts::macro_impl(input) } diff --git a/macros/tests/Cargo.toml b/macros/tests/Cargo.toml index 399ccba17..c9d93fd10 100644 --- a/macros/tests/Cargo.toml +++ b/macros/tests/Cargo.toml @@ -3,6 +3,9 @@ name = "macros-tests" version.workspace = true edition.workspace = true +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index f2db29fd2..a9bfa3314 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [dependencies] clap = { workspace = true, features = ["derive"] } log.workspace = true diff --git a/nodes/parachain/src/chain_spec/polimec_paseo.rs b/nodes/parachain/src/chain_spec/polimec_paseo.rs index 7387bf20b..7266468a3 100644 --- a/nodes/parachain/src/chain_spec/polimec_paseo.rs +++ b/nodes/parachain/src/chain_spec/polimec_paseo.rs @@ -20,7 +20,10 @@ use sc_service::ChainType; -use crate::chain_spec::{common::*, get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID}; +use crate::chain_spec::{ + common::{alice, bob, charlie, dave, eve, genesis_config, GenesisConfigParams}, + get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID, +}; use polimec_runtime::{AccountId, MinCandidateStk}; pub fn get_local_chain_spec() -> GenericChainSpec { diff --git a/pallets/democracy/Cargo.toml b/pallets/democracy/Cargo.toml index e90d491a2..ed657078f 100644 --- a/pallets/democracy/Cargo.toml +++ b/pallets/democracy/Cargo.toml @@ -9,6 +9,10 @@ repository.workspace = true description = "FRAME pallet for democracy" readme = "README.md" +[lints] +clippy.all = "allow" +clippy.pedantic = "allow" + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/democracy/src/lib.rs b/pallets/democracy/src/lib.rs index 552e6167a..c96b6407b 100644 --- a/pallets/democracy/src/lib.rs +++ b/pallets/democracy/src/lib.rs @@ -145,6 +145,8 @@ #![recursion_limit = "256"] #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] use frame_support::{ ensure, diff --git a/pallets/dispenser/Cargo.toml b/pallets/dispenser/Cargo.toml index 08f08d953..1ee47c4bc 100644 --- a/pallets/dispenser/Cargo.toml +++ b/pallets/dispenser/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/dispenser/src/extensions.rs b/pallets/dispenser/src/extensions.rs index b56e92b1a..7531f2c07 100644 --- a/pallets/dispenser/src/extensions.rs +++ b/pallets/dispenser/src/extensions.rs @@ -16,7 +16,7 @@ // If you feel like getting in touch with us, you can do so at info@polimec.org -use crate::*; +use crate::{Call, Config}; use frame_support::{ dispatch::{CheckIfFeeless, DispatchInfo}, pallet_prelude::*, diff --git a/pallets/dispenser/src/lib.rs b/pallets/dispenser/src/lib.rs index 5b3982a02..94b57e0fc 100644 --- a/pallets/dispenser/src/lib.rs +++ b/pallets/dispenser/src/lib.rs @@ -17,6 +17,9 @@ // If you feel like getting in touch with us, you can do so at info@polimec.org #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] + pub use pallet::*; pub use crate::weights::WeightInfo; @@ -45,6 +48,7 @@ pub type AccountIdOf = ::AccountId; type CurrencyOf = <::VestingSchedule as VestingSchedule>>::Currency; #[frame_support::pallet] pub mod pallet { + #[allow(clippy::wildcard_imports)] use super::*; use crate::weights::WeightInfo; use frame_support::{ diff --git a/pallets/elections-phragmen/Cargo.toml b/pallets/elections-phragmen/Cargo.toml index 4f33d2d14..863d10a16 100644 --- a/pallets/elections-phragmen/Cargo.toml +++ b/pallets/elections-phragmen/Cargo.toml @@ -9,6 +9,10 @@ repository.workspace = true description = "FRAME pallet based on seq-Phragmén election method." readme = "README.md" +[lints] +clippy.all = "allow" +clippy.pedantic = "allow" + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/elections-phragmen/src/lib.rs b/pallets/elections-phragmen/src/lib.rs index 304d14b4b..395a3a89e 100644 --- a/pallets/elections-phragmen/src/lib.rs +++ b/pallets/elections-phragmen/src/lib.rs @@ -91,6 +91,8 @@ //! - [`Module`] #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] use frame_support::{ pallet_prelude::DispatchResult, @@ -102,7 +104,6 @@ use frame_support::{ }, weights::Weight, }; -use log; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_npos_elections::{ElectionResult, ExtendedBalance}; diff --git a/pallets/elections-phragmen/src/weights.rs b/pallets/elections-phragmen/src/weights.rs index 96c0c73c3..7707b5c32 100644 --- a/pallets/elections-phragmen/src/weights.rs +++ b/pallets/elections-phragmen/src/weights.rs @@ -302,7 +302,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `0 + e * (28 ±0) + v * (606 ±0)` // Estimated: `178887 + c * (2135 ±7) + e * (12 ±0) + v * (2653 ±6)` // Minimum execution time: 1_281_877_000 picoseconds. - Weight::from_parts(1_288_147_000, 178887) + Weight::from_parts(1_288_147_000, 178_887) // Standard Error: 528_851 .saturating_add(Weight::from_parts(17_761_407, 0).saturating_mul(v.into())) // Standard Error: 33_932 @@ -559,7 +559,7 @@ impl WeightInfo for () { // Measured: `0 + e * (28 ±0) + v * (606 ±0)` // Estimated: `178887 + c * (2135 ±7) + e * (12 ±0) + v * (2653 ±6)` // Minimum execution time: 1_281_877_000 picoseconds. - Weight::from_parts(1_288_147_000, 178887) + Weight::from_parts(1_288_147_000, 178_887) // Standard Error: 528_851 .saturating_add(Weight::from_parts(17_761_407, 0).saturating_mul(v.into())) // Standard Error: 33_932 diff --git a/pallets/funding/Cargo.toml b/pallets/funding/Cargo.toml index ad77bdab3..83adfa447 100644 --- a/pallets/funding/Cargo.toml +++ b/pallets/funding/Cargo.toml @@ -10,6 +10,12 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + +#[lints.clippy] +#inconsistent_digit_grouping = "allow" + [dependencies] serde = { workspace = true } parity-scale-codec = { workspace = true, features = [ diff --git a/pallets/funding/src/functions/1_application.rs b/pallets/funding/src/functions/1_application.rs index 22e17f37f..cc04109f5 100644 --- a/pallets/funding/src/functions/1_application.rs +++ b/pallets/funding/src/functions/1_application.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/funding/src/functions/2_evaluation.rs b/pallets/funding/src/functions/2_evaluation.rs index b4ac49342..fd8545fbb 100644 --- a/pallets/funding/src/functions/2_evaluation.rs +++ b/pallets/funding/src/functions/2_evaluation.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/funding/src/functions/3_auction.rs b/pallets/funding/src/functions/3_auction.rs index b27506e3e..89ddc3943 100644 --- a/pallets/funding/src/functions/3_auction.rs +++ b/pallets/funding/src/functions/3_auction.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/funding/src/functions/4_contribution.rs b/pallets/funding/src/functions/4_contribution.rs index 1e967ce7c..ef8212a93 100644 --- a/pallets/funding/src/functions/4_contribution.rs +++ b/pallets/funding/src/functions/4_contribution.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/funding/src/functions/5_funding_end.rs b/pallets/funding/src/functions/5_funding_end.rs index d1dc7fb2a..9c94a4f50 100644 --- a/pallets/funding/src/functions/5_funding_end.rs +++ b/pallets/funding/src/functions/5_funding_end.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/funding/src/functions/6_settlement.rs b/pallets/funding/src/functions/6_settlement.rs index eca7da42d..d168fbf5b 100644 --- a/pallets/funding/src/functions/6_settlement.rs +++ b/pallets/funding/src/functions/6_settlement.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; use crate::traits::VestingDurationCalculation; use frame_support::{ diff --git a/pallets/funding/src/functions/7_ct_migration.rs b/pallets/funding/src/functions/7_ct_migration.rs index 310fcd6f5..15d9d74e6 100644 --- a/pallets/funding/src/functions/7_ct_migration.rs +++ b/pallets/funding/src/functions/7_ct_migration.rs @@ -1,4 +1,6 @@ +#[allow(clippy::wildcard_imports)] use super::*; + use xcm::v3::MaxPalletNameLen; // Offchain migration functions diff --git a/pallets/funding/src/functions/misc.rs b/pallets/funding/src/functions/misc.rs index a94f20305..ec64c353a 100644 --- a/pallets/funding/src/functions/misc.rs +++ b/pallets/funding/src/functions/misc.rs @@ -1,5 +1,6 @@ use sp_runtime::traits::CheckedAdd; +#[allow(clippy::wildcard_imports)] use super::*; // Helper functions @@ -34,7 +35,7 @@ impl Pallet { ) -> Result, DispatchError> { let plmc_usd_price = T::PriceProvider::get_decimals_aware_price(PLMC_FOREIGN_ID, USD_DECIMALS, PLMC_DECIMALS) .ok_or(Error::::PriceNotFound)?; - let usd_bond = multiplier.calculate_bonding_requirement::(ticket_size).map_err(|_| Error::::BadMath)?; + let usd_bond = multiplier.calculate_bonding_requirement::(ticket_size).ok_or(Error::::BadMath)?; plmc_usd_price .reciprocal() .ok_or(Error::::BadMath)? diff --git a/pallets/funding/src/functions/mod.rs b/pallets/funding/src/functions/mod.rs index d7db28bb8..1aaa82ee7 100644 --- a/pallets/funding/src/functions/mod.rs +++ b/pallets/funding/src/functions/mod.rs @@ -1,6 +1,5 @@ -use super::*; - -use crate::traits::{BondingRequirementCalculation, ProvideAssetPrice, VestingDurationCalculation}; +#[allow(clippy::wildcard_imports)] +use super::{traits::*, *}; use core::ops::Not; use frame_support::{ dispatch::{DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, PostDispatchInfo}, diff --git a/pallets/funding/src/instantiator/calculations.rs b/pallets/funding/src/instantiator/calculations.rs index 36cd3a257..8d55acee7 100644 --- a/pallets/funding/src/instantiator/calculations.rs +++ b/pallets/funding/src/instantiator/calculations.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; use itertools::GroupBy; use polimec_common::USD_DECIMALS; diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index 12a8798e3..ef0f33e1f 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; // general chain interactions diff --git a/pallets/funding/src/instantiator/mod.rs b/pallets/funding/src/instantiator/mod.rs index a5291fa91..3c4e8f0e1 100644 --- a/pallets/funding/src/instantiator/mod.rs +++ b/pallets/funding/src/instantiator/mod.rs @@ -13,11 +13,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - -use crate::{ - traits::{BondingRequirementCalculation, ProvideAssetPrice}, - *, -}; +#[allow(clippy::wildcard_imports)] +use crate::{traits::*, *}; use frame_support::{ pallet_prelude::*, traits::{ @@ -42,7 +39,7 @@ use sp_arithmetic::{ use sp_runtime::traits::{Convert, Member, One}; use sp_std::{ cell::RefCell, - collections::{btree_map::*, btree_set::*}, + collections::{btree_map::BTreeMap, btree_set::BTreeSet}, iter::zip, marker::PhantomData, }; diff --git a/pallets/funding/src/instantiator/traits.rs b/pallets/funding/src/instantiator/traits.rs index 5eee8ccaa..cfbe9a378 100644 --- a/pallets/funding/src/instantiator/traits.rs +++ b/pallets/funding/src/instantiator/traits.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Config, UserToPLMCBalance, Vec}; pub trait Deposits { fn existential_deposits(&self) -> Vec>; diff --git a/pallets/funding/src/instantiator/types.rs b/pallets/funding/src/instantiator/types.rs index ab219e4c1..27d672d61 100644 --- a/pallets/funding/src/instantiator/types.rs +++ b/pallets/funding/src/instantiator/types.rs @@ -1,3 +1,4 @@ +#[allow(clippy::wildcard_imports)] use super::*; use frame_support::{Deserialize, Serialize}; diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 6b6b5c692..5a072e158 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -111,6 +111,8 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] // This recursion limit is needed because we have too many benchmarks and benchmarking will fail if // we add more without this limit. #![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "512")] @@ -129,7 +131,7 @@ pub use pallet::*; use pallet_xcm::ensure_response; use polimec_common::{ credentials::{Cid, Did, EnsureOriginWithCredentials, InvestorType, UntrustedToken}, - migration_types::*, + migration_types::{Migration, MigrationStatus, ParticipationType}, }; use polkadot_parachain_primitives::primitives::Id as ParaId; use sp_arithmetic::traits::{One, Saturating}; @@ -193,6 +195,7 @@ pub const PLMC_DECIMALS: u8 = 10; #[frame_support::pallet] pub mod pallet { + #[allow(clippy::wildcard_imports)] use super::*; use crate::traits::{BondingRequirementCalculation, ProvideAssetPrice, VestingDurationCalculation}; use frame_support::{ @@ -1090,6 +1093,7 @@ pub mod pallet { } pub mod xcm_executor_impl { + #[allow(clippy::wildcard_imports)] use super::*; pub struct HrmpHandler(PhantomData); diff --git a/pallets/funding/src/runtime_api.rs b/pallets/funding/src/runtime_api.rs index 61edaa376..294018695 100644 --- a/pallets/funding/src/runtime_api.rs +++ b/pallets/funding/src/runtime_api.rs @@ -1,4 +1,5 @@ -use crate::{traits::ProvideAssetPrice, *}; +#[allow(clippy::wildcard_imports)] +use crate::{traits::*, *}; use alloc::collections::BTreeMap; use frame_support::traits::fungibles::{metadata::Inspect as MetadataInspect, Inspect, InspectEnumerable}; use itertools::Itertools; diff --git a/pallets/funding/src/tests/3_auction.rs b/pallets/funding/src/tests/3_auction.rs index 4703b3168..a53702060 100644 --- a/pallets/funding/src/tests/3_auction.rs +++ b/pallets/funding/src/tests/3_auction.rs @@ -872,7 +872,7 @@ mod bid_extrinsic { assert_eq!(frozen_balance, frozen_amount); let vest_duration = - MultiplierOf::::new(5u8).unwrap().calculate_vesting_duration::(); + MultiplierOf::::try_from(5u8).unwrap().calculate_vesting_duration::(); let now = inst.current_block(); inst.jump_to_block(now + vest_duration + 1u64); inst.execute(|| { diff --git a/pallets/funding/src/tests/4_contribution.rs b/pallets/funding/src/tests/4_contribution.rs index 67c003c71..6f08f8e54 100644 --- a/pallets/funding/src/tests/4_contribution.rs +++ b/pallets/funding/src/tests/4_contribution.rs @@ -965,7 +965,7 @@ mod contribute_extrinsic { assert_eq!(frozen_balance, frozen_amount); let vest_duration = - MultiplierOf::::new(5u8).unwrap().calculate_vesting_duration::(); + MultiplierOf::::try_from(5u8).unwrap().calculate_vesting_duration::(); let now = inst.current_block(); inst.jump_to_block(now + vest_duration + 1u64); inst.execute(|| { diff --git a/pallets/funding/src/tests/misc.rs b/pallets/funding/src/tests/misc.rs index a7550667d..456cee4c1 100644 --- a/pallets/funding/src/tests/misc.rs +++ b/pallets/funding/src/tests/misc.rs @@ -337,31 +337,31 @@ mod inner_functions { let default_multiplier_duration = default_multiplier.calculate_vesting_duration::(); assert_eq!(default_multiplier_duration, 1u64); - let multiplier_1 = MultiplierOf::::new(1u8).unwrap(); + let multiplier_1 = MultiplierOf::::try_from(1u8).unwrap(); let multiplier_1_duration = multiplier_1.calculate_vesting_duration::(); assert_eq!(multiplier_1_duration, 1u64); - let multiplier_2 = MultiplierOf::::new(2u8).unwrap(); + let multiplier_2 = MultiplierOf::::try_from(2u8).unwrap(); let multiplier_2_duration = multiplier_2.calculate_vesting_duration::(); assert_eq!(multiplier_2_duration, FixedU128::from_rational(2167, 1000).saturating_mul_int((DAYS * 7) as u64)); - let multiplier_3 = MultiplierOf::::new(3u8).unwrap(); + let multiplier_3 = MultiplierOf::::try_from(3u8).unwrap(); let multiplier_3_duration = multiplier_3.calculate_vesting_duration::(); assert_eq!(multiplier_3_duration, FixedU128::from_rational(4334, 1000).saturating_mul_int((DAYS * 7) as u64)); - let multiplier_19 = MultiplierOf::::new(19u8).unwrap(); + let multiplier_19 = MultiplierOf::::try_from(19u8).unwrap(); let multiplier_19_duration = multiplier_19.calculate_vesting_duration::(); assert_eq!(multiplier_19_duration, FixedU128::from_rational(39006, 1000).saturating_mul_int((DAYS * 7) as u64)); - let multiplier_20 = MultiplierOf::::new(20u8).unwrap(); + let multiplier_20 = MultiplierOf::::try_from(20u8).unwrap(); let multiplier_20_duration = multiplier_20.calculate_vesting_duration::(); assert_eq!(multiplier_20_duration, FixedU128::from_rational(41173, 1000).saturating_mul_int((DAYS * 7) as u64)); - let multiplier_24 = MultiplierOf::::new(24u8).unwrap(); + let multiplier_24 = MultiplierOf::::try_from(24u8).unwrap(); let multiplier_24_duration = multiplier_24.calculate_vesting_duration::(); assert_eq!(multiplier_24_duration, FixedU128::from_rational(49841, 1000).saturating_mul_int((DAYS * 7) as u64)); - let multiplier_25 = MultiplierOf::::new(25u8).unwrap(); + let multiplier_25 = MultiplierOf::::try_from(25u8).unwrap(); let multiplier_25_duration = multiplier_25.calculate_vesting_duration::(); assert_eq!(multiplier_25_duration, FixedU128::from_rational(52008, 1000).saturating_mul_int((DAYS * 7) as u64)); } diff --git a/pallets/funding/src/traits.rs b/pallets/funding/src/traits.rs index 932c26a07..94af27f2d 100644 --- a/pallets/funding/src/traits.rs +++ b/pallets/funding/src/traits.rs @@ -24,7 +24,7 @@ use sp_arithmetic::{ use sp_runtime::DispatchError; pub trait BondingRequirementCalculation { - fn calculate_bonding_requirement(&self, ticket_size: BalanceOf) -> Result, ()>; + fn calculate_bonding_requirement(&self, ticket_size: BalanceOf) -> Option>; } pub trait VestingDurationCalculation { diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index 30159362b..bc88533de 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -23,21 +23,22 @@ pub use config_types::*; use frame_support::{pallet_prelude::*, traits::tokens::Balance as BalanceT}; use frame_system::pallet_prelude::BlockNumberFor; pub use inner_types::*; +use parachains_common::DAYS; use polimec_common::USD_DECIMALS; use polkadot_parachain_primitives::primitives::Id as ParaId; use serde::{Deserialize, Serialize}; -use sp_arithmetic::{FixedPointNumber, FixedPointOperand, Percent}; -use sp_runtime::traits::{CheckedDiv, CheckedMul, One}; +use sp_arithmetic::{traits::Saturating, FixedPointNumber, FixedPointOperand, FixedU128, Percent}; +use sp_runtime::traits::{CheckedDiv, CheckedMul, Convert, One}; use sp_std::{cmp::Eq, prelude::*}; pub use storage_types::*; -pub mod config_types { - use parachains_common::DAYS; - use sp_arithmetic::{traits::Saturating, FixedU128}; - use sp_runtime::traits::{Convert, One}; +use crate::{traits::VestingDurationCalculation, Config}; - use crate::{traits::VestingDurationCalculation, Config}; +use sp_runtime::traits::Zero; +use variant_count::VariantCount; +pub mod config_types { + #[allow(clippy::wildcard_imports)] use super::*; #[derive( @@ -58,28 +59,15 @@ pub mod config_types { pub struct Multiplier(u8); impl Multiplier { - /// Creates a new `Multiplier` if the value is between 1 and 25, otherwise returns an error. - pub const fn new(x: u8) -> Result { - // The minimum and maximum values are chosen to be 1 and 25 respectively, as defined in the Knowledge Hub. - const MIN_VALID: u8 = 1; - const MAX_VALID: u8 = 25; - - if x >= MIN_VALID && x <= MAX_VALID { - Ok(Self(x)) - } else { - Err(()) - } - } - pub const fn force_new(x: u8) -> Self { Self(x) } } impl BondingRequirementCalculation for Multiplier { - fn calculate_bonding_requirement(&self, ticket_size: BalanceOf) -> Result, ()> { + fn calculate_bonding_requirement(&self, ticket_size: BalanceOf) -> Option> { let balance_multiplier = BalanceOf::::from(self.0); - ticket_size.checked_div(&balance_multiplier).ok_or(()) + ticket_size.checked_div(&balance_multiplier) } } @@ -104,10 +92,18 @@ pub mod config_types { } impl TryFrom for Multiplier { - type Error = (); + type Error = &'static str; + + fn try_from(x: u8) -> Result { + // The minimum and maximum values are chosen to be 1 and 25 respectively, as defined in the Knowledge Hub. + const MIN_VALID: u8 = 1; + const MAX_VALID: u8 = 25; - fn try_from(x: u8) -> Result { - Self::new(x) + if x >= MIN_VALID && x <= MAX_VALID { + Ok(Self(x)) + } else { + Err("u8 outside the allowed multiplier range") + } } } @@ -155,8 +151,8 @@ pub mod config_types { } pub mod storage_types { + #[allow(clippy::wildcard_imports)] use super::*; - use sp_runtime::traits::Zero; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] pub struct ProjectMetadata { @@ -515,8 +511,8 @@ pub mod storage_types { } pub mod inner_types { + #[allow(clippy::wildcard_imports)] use super::*; - use variant_count::VariantCount; pub enum MetadataError { /// The minimum price per token is too low. diff --git a/pallets/linear-release/Cargo.toml b/pallets/linear-release/Cargo.toml index 07879f547..7cc437dc4 100644 --- a/pallets/linear-release/Cargo.toml +++ b/pallets/linear-release/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/linear-release/src/impls.rs b/pallets/linear-release/src/impls.rs index 6ad347ac0..3feb1f0c6 100644 --- a/pallets/linear-release/src/impls.rs +++ b/pallets/linear-release/src/impls.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#[allow(clippy::wildcard_imports)] use super::*; impl Pallet { diff --git a/pallets/linear-release/src/lib.rs b/pallets/linear-release/src/lib.rs index 86ffb8c02..88b633611 100644 --- a/pallets/linear-release/src/lib.rs +++ b/pallets/linear-release/src/lib.rs @@ -16,6 +16,8 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] mod benchmarking; pub mod weights; @@ -25,19 +27,15 @@ use frame_support::{ ensure, pallet_prelude::*, traits::{ - fungible::*, + fungible::{BalancedHold, Inspect, InspectHold, Mutate, MutateHold}, tokens::{Balance, Precision}, Get, WithdrawReasons, }, }; use frame_system::pallet_prelude::*; -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use parity_scale_codec::MaxEncodedLen; use polimec_common::ReleaseSchedule; -use scale_info::TypeInfo; -use sp_runtime::{ - traits::{AtLeast32BitUnsigned, Bounded, Convert, One, Saturating, Zero}, - RuntimeDebug, -}; +use sp_runtime::traits::{Convert, One, Saturating, Zero}; use sp_std::{marker::PhantomData, prelude::*}; // Re-export pallet items so that they can be accessed from the crate namespace. @@ -110,6 +108,7 @@ impl Get for MaxVestingSchedulesGet { /// Enable `dev_mode` for this pallet. #[frame_support::pallet(dev_mode)] pub mod pallet { + #[allow(clippy::wildcard_imports)] use super::*; #[pallet::config] diff --git a/pallets/linear-release/src/tests.rs b/pallets/linear-release/src/tests.rs index 901e860b3..d5d81baa9 100644 --- a/pallets/linear-release/src/tests.rs +++ b/pallets/linear-release/src/tests.rs @@ -125,9 +125,9 @@ fn check_vesting_status_for_multi_schedule_account() { assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 20 * ED); assert_ok!(Vesting::vested_transfer(Some(4).into(), 2, sched1, MockRuntimeHoldReason::Reason)); assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 29 * ED); // Why 29 and not 30? Because sched1 is already unlocking. - // Free balance is the one set in Genesis inside the Balances pallet - // + the one from the vested transfer. - // BUT NOT the one in sched0, since the vesting will start at block #10. + // Free balance is the one set in Genesis inside the Balances pallet + // + the one from the vested transfer. + // BUT NOT the one in sched0, since the vesting will start at block #10. let balance = Balances::balance(&2); assert_eq!(balance, ED * (2)); // The most recently added schedule exists. @@ -193,7 +193,7 @@ fn unvested_balance_should_not_transfer() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(1); assert_eq!(user1_free_balance, 50); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5)); // Account 1 cannot send more than vested amount... assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 56), TokenError::FundsUnavailable); }); @@ -205,13 +205,13 @@ fn vested_balance_should_transfer() { assert_eq!(System::block_number(), 1); let user1_free_balance = Balances::free_balance(1); assert_eq!(user1_free_balance, 50); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5)); assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 45), TokenError::Frozen); // Account 1 free balance - ED is < 45 assert_ok!(Vesting::vest(Some(1).into(), MockRuntimeHoldReason::Reason)); let user1_free_balance = Balances::free_balance(1); assert_eq!(user1_free_balance, 55); // Account 1 has free balance - // Account 1 has vested 1 unit at block 1 (plus 50 unvested) + // Account 1 has vested 1 unit at block 1 (plus 50 unvested) assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 45)); // After the vest it can now send the 45 UNIT }); } @@ -259,7 +259,7 @@ fn vested_balance_should_transfer_using_vest_other() { ExtBuilder::default().existential_deposit(10).build().execute_with(|| { let user1_free_balance = Balances::free_balance(1); assert_eq!(user1_free_balance, 50); // Account 1 has free balance - // Account 1 has only 5 units vested at block 1 (plus 50 unvested) + // Account 1 has only 5 units vested at block 1 (plus 50 unvested) assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5)); assert_ok!(Vesting::vest_other(Some(2).into(), 1, MockRuntimeHoldReason::Reason)); assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55 - 10)); @@ -317,7 +317,7 @@ fn extra_balance_should_transfer() { // Account 2 has no units vested at block 1, but gained 100 assert_ok!(Balances::transfer_allow_death(Some(2).into(), 3, 100 - 10)); // Account 2 can send extra - // units gained + // units gained }); } @@ -327,7 +327,7 @@ fn liquid_funds_should_transfer_with_delayed_vesting() { let user12_free_balance = Balances::free_balance(12); assert_eq!(user12_free_balance, 1280); // Account 12 has free balance - // Account 12 has liquid funds + // Account 12 has liquid funds assert_eq!(Vesting::vesting_balance(&12, MockRuntimeHoldReason::Reason), Some(0)); // Account 12 has delayed vesting diff --git a/pallets/linear-release/src/types.rs b/pallets/linear-release/src/types.rs index afdb779bc..09ca6e6ac 100644 --- a/pallets/linear-release/src/types.rs +++ b/pallets/linear-release/src/types.rs @@ -14,7 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::*; +use sp_runtime::traits::Zero; + +use sp_runtime::traits::Convert; + +use sp_runtime::traits::One; + +use sp_runtime::traits::Bounded; + +use sp_runtime::traits::AtLeast32BitUnsigned; + +use frame_support::pallet_prelude::TypeInfo; + +use frame_support::pallet_prelude::MaxEncodedLen; + +use frame_support::pallet_prelude::RuntimeDebug; + +use frame_support::pallet_prelude::Decode; + +use frame_support::pallet_prelude::Encode; /// Struct to encode the vesting schedule of an individual account. #[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] diff --git a/pallets/oracle-ocw/Cargo.toml b/pallets/oracle-ocw/Cargo.toml index ac25baf86..84a11f701 100644 --- a/pallets/oracle-ocw/Cargo.toml +++ b/pallets/oracle-ocw/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/oracle-ocw/src/lib.rs b/pallets/oracle-ocw/src/lib.rs index c39de5abc..54a991648 100644 --- a/pallets/oracle-ocw/src/lib.rs +++ b/pallets/oracle-ocw/src/lib.rs @@ -16,6 +16,9 @@ //! Offchain Worker for Oracle price feed #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] + use crate::{ traits::FetchPrice, types::{ @@ -24,10 +27,20 @@ use crate::{ }, }; use core::ops::Rem; -use frame_system::offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer}; +use frame_support::{pallet_prelude::*, traits::Contains}; +use frame_system::{ + offchain::{AppCrypto, CreateSignedTransaction, SendSignedTransaction, Signer, SigningTypes}, + pallet_prelude::*, +}; +use orml_oracle::Call as OracleCall; pub use pallet::*; use sp_runtime::{ - traits::{Convert, Saturating, Zero}, + offchain::{ + storage::{StorageRetrievalError, StorageValueRef}, + storage_lock::{StorageLock, Time}, + Duration, + }, + traits::{Convert, IdentifyAccount, Saturating, Zero}, FixedU128, RuntimeAppPublic, }; use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec}; @@ -47,18 +60,8 @@ pub(crate) const NUMBER_OF_CANDLES: usize = 15; #[frame_support::pallet] pub mod pallet { + #[allow(clippy::wildcard_imports)] use super::*; - use frame_support::{pallet_prelude::*, traits::Contains}; - use frame_system::{offchain::SigningTypes, pallet_prelude::*}; - use orml_oracle::Call as OracleCall; - use sp_runtime::{ - offchain::{ - storage::{StorageRetrievalError, StorageValueRef}, - storage_lock::{StorageLock, Time}, - Duration, - }, - traits::{IdentifyAccount, Zero}, - }; const LOCK_TIMEOUT_EXPIRATION: u64 = 30_000; // 30 seconds diff --git a/pallets/oracle-ocw/src/traits.rs b/pallets/oracle-ocw/src/traits.rs index 708d3b19e..a09a3555e 100644 --- a/pallets/oracle-ocw/src/traits.rs +++ b/pallets/oracle-ocw/src/traits.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::*; +use super::{AssetName, AssetRequest, OpenCloseVolume, Vec, Zero}; use sp_runtime::{ offchain::{ diff --git a/pallets/oracle-ocw/src/types.rs b/pallets/oracle-ocw/src/types.rs index 7f8dfcf89..fa1bea193 100644 --- a/pallets/oracle-ocw/src/types.rs +++ b/pallets/oracle-ocw/src/types.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::*; +use super::{FetchPrice, FixedU128, LOG_TARGET, NUMBER_OF_CANDLES}; use core::{ops::Mul, str::FromStr}; use heapless::{LinearMap, Vec as HVec}; use parity_scale_codec::{Decode, Encode}; diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index 139857441..ef5cafcb0 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -10,6 +10,10 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +clippy.all = "allow" +clippy.pedantic = "allow" + [dependencies] serde = { workspace = true } log = { workspace = true } diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 8dce7dabd..54798f7d2 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -49,6 +49,8 @@ //! To leave the set of delegators and revoke all delegations, call `leave_delegators`. #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] mod auto_compound; mod delegation_requests; diff --git a/pallets/polimec-receiver/Cargo.toml b/pallets/polimec-receiver/Cargo.toml index d8fd00c08..c7861f3be 100644 --- a/pallets/polimec-receiver/Cargo.toml +++ b/pallets/polimec-receiver/Cargo.toml @@ -8,6 +8,9 @@ homepage = "https://substrate.io" repository = "https://github.com/paritytech/substrate/" edition = "2021" +[lints] +workspace = true + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/polimec-receiver/src/lib.rs b/pallets/polimec-receiver/src/lib.rs index 89501a452..5365a7ec2 100644 --- a/pallets/polimec-receiver/src/lib.rs +++ b/pallets/polimec-receiver/src/lib.rs @@ -15,6 +15,9 @@ // along with this program. If not, see . #![cfg_attr(not(feature = "std"), no_std)] +// Needed due to empty sections raising the warning +#![allow(unreachable_patterns)] + /// Edit this file to define custom logic or remove it if it is not needed. /// Learn more about FRAME and the core library of Substrate FRAME pallets: /// diff --git a/pallets/xcm-executor/Cargo.toml b/pallets/xcm-executor/Cargo.toml index 39976363e..44c73eca4 100644 --- a/pallets/xcm-executor/Cargo.toml +++ b/pallets/xcm-executor/Cargo.toml @@ -10,6 +10,10 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +clippy.all = "allow" +clippy.pedantic = "allow" + [dependencies] environmental = { version = "1.1.4", default-features = false } parity-scale-codec = { workspace = true, default-features = false, features = ["derive"] } diff --git a/polimec-common/common/Cargo.toml b/polimec-common/common/Cargo.toml index 542e164ad..53dceb579 100644 --- a/polimec-common/common/Cargo.toml +++ b/polimec-common/common/Cargo.toml @@ -10,6 +10,9 @@ readme = "README.md" repository = "https://github.com/Polimec/polimec-node" version.workspace = true +[lints] +workspace = true + [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] } diff --git a/polimec-common/common/src/credentials/mod.rs b/polimec-common/common/src/credentials/mod.rs index 3a73b10ce..313b9ce9c 100644 --- a/polimec-common/common/src/credentials/mod.rs +++ b/polimec-common/common/src/credentials/mod.rs @@ -82,7 +82,7 @@ where ) -> Result { let Some(who) = origin.clone().into_signer() else { return Err(origin) }; let Ok(token) = Self::verify_token(token, verifying_key) else { return Err(origin) }; - let Ok(claims) = Self::extract_claims(&token) else { return Err(origin) }; + let claims = token.claims(); // Get the current timestamp from the pallet_timestamp. It is in milliseconds. let Ok(now) = Now::::get().try_into() else { return Err(origin) }; let Some(date_time) = claims.expiration else { return Err(origin) }; @@ -100,6 +100,7 @@ where } } +#[allow(clippy::module_name_repetitions)] pub trait EnsureOriginWithCredentials where OuterOrigin: OriginTrait, @@ -121,10 +122,6 @@ where Self::try_origin(origin, token, verifying_key).map_err(|_| BadOrigin) } - fn extract_claims(token: &jwt_compact::Token) -> Result<&StandardClaims, ()> { - Ok(token.claims()) - } - fn verify_token( token: &jwt_compact::UntrustedToken, verifying_key: [u8; 32], diff --git a/polimec-common/common/src/lib.rs b/polimec-common/common/src/lib.rs index 6c302958d..fa62aa320 100644 --- a/polimec-common/common/src/lib.rs +++ b/polimec-common/common/src/lib.rs @@ -102,8 +102,8 @@ pub trait ReleaseSchedule { } pub mod migration_types { + #[allow(clippy::wildcard_imports)] use super::*; - use xcm::latest::MultiLocation; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct MigrationOrigin { diff --git a/polimec-common/test-utils/Cargo.toml b/polimec-common/test-utils/Cargo.toml index ef12a7a58..ad7ea3c83 100644 --- a/polimec-common/test-utils/Cargo.toml +++ b/polimec-common/test-utils/Cargo.toml @@ -10,6 +10,9 @@ readme = "README.md" repository = "https://github.com/Polimec/polimec-node" version.workspace = true +[lints] +workspace = true + [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } jwt-compact = { workspace = true, features = [ diff --git a/runtimes/polimec/Cargo.toml b/runtimes/polimec/Cargo.toml index 316d919eb..1ef7573a3 100644 --- a/runtimes/polimec/Cargo.toml +++ b/runtimes/polimec/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + [build-dependencies] substrate-wasm-builder.workspace = true diff --git a/runtimes/polimec/build.rs b/runtimes/polimec/build.rs index 657bcc0d1..fcbbf573c 100644 --- a/runtimes/polimec/build.rs +++ b/runtimes/polimec/build.rs @@ -17,5 +17,5 @@ use substrate_wasm_builder::WasmBuilder; fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build() + WasmBuilder::new().with_current_project().export_heap_base().import_memory().build(); } diff --git a/runtimes/polimec/src/custom_migrations/deposit_dust.rs b/runtimes/polimec/src/custom_migrations/deposit_dust.rs deleted file mode 100644 index 74ff5a4ec..000000000 --- a/runtimes/polimec/src/custom_migrations/deposit_dust.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// The Polimec Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Polimec Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#[allow(unused_imports)] -use crate::*; - -// Substrate -use frame_support::traits::tokens::Precision::Exact; -#[cfg(feature = "try-runtime")] -use log; - -pub struct DepositDust; -impl frame_support::traits::OnRuntimeUpgrade for DepositDust { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - log::info!("Pre-upgrade"); - Ok(Vec::new()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { - log::info!("Post-upgrade"); - let total_issuance = Balances::total_issuance(); - assert_eq!(total_issuance, 100_000_000 * PLMC); - Ok(()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - // +1 R - let total_issuance = Balances::total_issuance(); - - // Idempotent check. - if total_issuance != 100_000_000 * PLMC { - log::info!("⚠️ Correcting total issuance from {} to {}", total_issuance, 100_000_000 * PLMC); - // +1 R - let treasury_account = BlockchainOperationTreasury::get(); - // +1 W - // The values are coming from these `DustLost` events: - // - https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polimec.org#/explorer/query/0x6fec4ce782f42afae1437f53e3382d9e6804692de868a28908ed6b9104bdd536 - // - https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polimec.org#/explorer/query/0x390d04247334df9d9eb02e1dc7c6d01910c950d99a5d8d17441eb202cd751f42 - let _ = >::deposit( - &treasury_account, - 39988334 + 70094167, - Exact, - ); - } - - ::DbWeight::get().reads_writes(2, 1) - } -} diff --git a/runtimes/polimec/src/custom_migrations/init_pallet.rs b/runtimes/polimec/src/custom_migrations/init_pallet.rs index e8ec37872..5903d0c38 100644 --- a/runtimes/polimec/src/custom_migrations/init_pallet.rs +++ b/runtimes/polimec/src/custom_migrations/init_pallet.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#[allow(unused_imports)] -use crate::*; +#![allow(dead_code)] + +use crate::Runtime; use frame_support::traits::{GetStorageVersion, PalletInfoAccess, StorageVersion}; @@ -28,6 +29,13 @@ pub struct InitializePallet + PalletInfoAccess> frame_support::traits::OnRuntimeUpgrade for InitializePallet { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + if Pallet::on_chain_storage_version() == StorageVersion::new(0) { + Pallet::current_storage_version().put::(); + } + ::DbWeight::get().reads_writes(1, 1) + } + #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, DispatchError> { log::info!("{} migrating from {:#?}", Pallet::name(), Pallet::on_chain_storage_version()); @@ -39,11 +47,4 @@ impl + PalletI log::info!("{} migrated to {:#?}", Pallet::name(), Pallet::on_chain_storage_version()); Ok(()) } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - if Pallet::on_chain_storage_version() == StorageVersion::new(0) { - Pallet::current_storage_version().put::(); - } - ::DbWeight::get().reads_writes(1, 1) - } } diff --git a/runtimes/polimec/src/custom_migrations/mod.rs b/runtimes/polimec/src/custom_migrations/mod.rs index 78b2f04e5..e40ad0560 100644 --- a/runtimes/polimec/src/custom_migrations/mod.rs +++ b/runtimes/polimec/src/custom_migrations/mod.rs @@ -17,6 +17,4 @@ // the generated files do not pass clippy #![allow(clippy::all)] -pub mod deposit_dust; pub mod init_pallet; -pub mod unhashed_migration; diff --git a/runtimes/polimec/src/custom_migrations/unhashed_migration.rs b/runtimes/polimec/src/custom_migrations/unhashed_migration.rs deleted file mode 100644 index 0b74932a2..000000000 --- a/runtimes/polimec/src/custom_migrations/unhashed_migration.rs +++ /dev/null @@ -1,104 +0,0 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// The Polimec Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Polimec Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#[allow(unused_imports)] -use crate::*; - -// Substrate -use frame_support::storage::unhashed; -use sp_runtime::AccountId32; - -#[cfg(feature = "try-runtime")] -use sp_core::crypto::Ss58Codec; - -#[cfg(feature = "try-runtime")] -use pallet_vesting::Vesting; - -#[cfg(feature = "try-runtime")] -use log; - -// The `VestingInfo` fields from `pallet_vesting` are private, so we need to define them here. -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, sp_runtime::RuntimeDebug, Eq, PartialEq)] -struct VestingInfo { - locked: Balance, - per_block: Balance, - starting_block: BlockNumber, -} - -pub struct UnhashedMigration; -impl frame_support::traits::OnRuntimeUpgrade for UnhashedMigration { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - log::info!("Pre-upgrade"); - check_balances(); - Ok(Vec::new()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { - log::info!("Post-upgrade"); - check_balances(); - Ok(()) - } - - fn on_runtime_upgrade() -> frame_support::weights::Weight { - // This account received a wrong vesting schedule. - // Hex encoded representation of 5Ag8zhuoZjKzc3YzmkWFrrmU5GvxdHLtpAN425RW9ZgWS5V7. - let acct: AccountId32 = - hex_literal::hex!["c28dbf096b5acf3c0d87dd8ef8cabea0794cc72200a2368751a0fe470d5f9f69"].into(); - - // The vesting.Vesting(5Ag8zhuoZjKzc3YzmkWFrrmU5GvxdHLtpAN425RW9ZgWS5V7) encoded storage key. - const ENCODED_STORAGE_KEY: &str = -"0x5f27b51b5ec208ee9cb25b55d87282435f27b51b5ec208ee9cb25b55d872824334f5503ce555ea3ee18396f4bde1b40bc28dbf096b5acf3c0d87dd8ef8cabea0794cc72200a2368751a0fe470d5f9f69"; - - if let Ok(k) = array_bytes::hex2bytes(ENCODED_STORAGE_KEY) { - // If `is_some` which means it has a vesting schedule, that we could potentially have to correct. - // +1 R - if let Some(value) = unhashed::get::>(&k) { - let v = vec![ - VestingInfo { locked: 119574300000000, per_block: 182000456, starting_block: 249000 }, - VestingInfo { locked: 6485400000000, per_block: 9870000, starting_block: 249000 }, - ]; - // Idempotent check. - if value != v { - log::info!("⚠️ Correcting storage for {:?}", acct.encode()); - // +1 W - unhashed::put::>(&k, &v); - } else { - log::info!("✅ Storage for {:?} is already correct", acct.encode()); - } - } - } - - ::DbWeight::get().reads_writes(1, 1) - } -} - -#[cfg(feature = "try-runtime")] -fn check_balances() { - let acct: AccountId32 = - hex_literal::hex!["c28dbf096b5acf3c0d87dd8ef8cabea0794cc72200a2368751a0fe470d5f9f69"].into(); - let balance = Balances::balance(&acct); - log::info!("Account: {} | Balance: {}", acct.to_ss58check(), balance); - let vesting_stored = >::get(acct.clone()); - if let Some(vesting) = vesting_stored { - log::info!("Vesting: {:?}", vesting); - } else { - log::info!("Vesting: None"); - } - let total_issuance = Balances::total_issuance(); - log::info!("Total Issuance: {}", total_issuance); -} diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 0a3a18e8b..74653294a 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -180,7 +180,7 @@ pub type Executive = frame_executive::Executive< /// of data like extrinsics, allowing for them to continue syncing the network through upgrades /// to even the core data structures. pub mod opaque { - use super::*; + use super::BlockNumber; use sp_runtime::{ generic, traits::{BlakeTwo256, Hash as HashT}, diff --git a/runtimes/shared-configuration/Cargo.toml b/runtimes/shared-configuration/Cargo.toml index 0e72af673..e370204e1 100644 --- a/runtimes/shared-configuration/Cargo.toml +++ b/runtimes/shared-configuration/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true repository.workspace = true version.workspace = true +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/runtimes/shared-configuration/src/currency.rs b/runtimes/shared-configuration/src/currency.rs index 2e1b81ad9..133647402 100644 --- a/runtimes/shared-configuration/src/currency.rs +++ b/runtimes/shared-configuration/src/currency.rs @@ -67,10 +67,9 @@ parameter_types! { } pub mod vesting { + use super::{parameter_types, Balance, PLMC}; use frame_support::traits::WithdrawReasons; - use super::*; - parameter_types! { pub const MinVestedTransfer: Balance = PLMC; pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =