diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index 266b63cb2..ede53f13b 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -9,31 +9,11 @@ on: - main jobs: - build-check: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: ./.github/actions/shared - - - name: Install toolchain - # Call `rustup show` as a hack so that the toolchain defined in rust-toolchain.toml is installed - run: rustup show - - # Enable this for clippy linting. - # - name: Check and Lint Code - # run: cargo +nightly-2021-12-01 clippy -- -D warnings - - - name: Install Protoc - uses: arduino/setup-protoc@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Check Code - run: cargo check - test-code: runs-on: ubuntu-latest + env: + # Make sure CI fails on all warnings, including Clippy lints + RUSTFLAGS: "-Dwarnings" steps: - uses: actions/checkout@v3 @@ -64,3 +44,27 @@ jobs: with: toolchain: nightly-2024-04-18 command: test + + - name: Clippy -- Main + uses: actions-rs/cargo@v1 + with: + toolchain: nightly-2024-04-18 + command: clippy + args: --all-features -- -W clippy::all -A clippy::style -A forgetting_copy_types -A forgetting_references + + - name: Clippy -- All Targets (except integration) + uses: actions-rs/cargo@v1 + with: + toolchain: nightly-2024-04-18 + command: clippy + # We are a bit more forgiving when it comes to the code in tests and only check for correctness + args: --workspace --all-features --all-targets --exclude runtime-integration-tests -- -A clippy::all -W clippy::correctness -A forgetting_copy_types -A forgetting_references + + - name: Clippy -- Integration + uses: actions-rs/cargo@v1 + with: + toolchain: nightly-2024-04-18 + command: clippy + # We are a bit more forgiving when it comes to the code in tests and only check for correctness + args: --package runtime-integration-tests --all-features --all-targets -- -A clippy::all -W clippy::correctness -A forgetting_copy_types -A forgetting_references + \ No newline at end of file diff --git a/chain-extensions/price/src/lib.rs b/chain-extensions/price/src/lib.rs index 766832705..411905a9f 100644 --- a/chain-extensions/price/src/lib.rs +++ b/chain-extensions/price/src/lib.rs @@ -46,7 +46,7 @@ where T: SysConfig + pallet_contracts::Config + dia_oracle::Config, <T as SysConfig>::AccountId: UncheckedFrom<<T as SysConfig>::Hash> + AsRef<[u8]>, { - fn call<E: Ext>(&mut self, env: Environment<E, InitState>) -> Result<RetVal, DispatchError> + fn call<E>(&mut self, env: Environment<E, InitState>) -> Result<RetVal, DispatchError> where E: Ext<T = T>, <E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>, @@ -74,7 +74,7 @@ where } } -fn get_coin_info<E: Ext, T>( +fn get_coin_info<E, T>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 5cc87a251..961f3d485 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -73,9 +73,9 @@ where + orml_currencies_allowance_extension::Config, <T as SysConfig>::AccountId: UncheckedFrom<<T as SysConfig>::Hash> + AsRef<[u8]>, Tokens: orml_traits::MultiCurrency<AccountId, CurrencyId = CurrencyId>, - AccountId: sp_std::fmt::Debug + Decode, + AccountId: sp_std::fmt::Debug + Decode + core::clone::Clone, { - fn call<E: Ext>(&mut self, env: Environment<E, InitState>) -> Result<RetVal, DispatchError> + fn call<E>(&mut self, env: Environment<E, InitState>) -> Result<RetVal, DispatchError> where E: Ext<T = T>, <E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>, @@ -92,15 +92,14 @@ where 0, ); - let result = match func_id { + match func_id { FuncId::TotalSupply => total_supply(env, overhead_weight), FuncId::BalanceOf => balance_of(env, overhead_weight), FuncId::Transfer => transfer(env, overhead_weight), FuncId::Allowance => allowance(env, overhead_weight), FuncId::Approve => approve(env, overhead_weight), FuncId::TransferFrom => transfer_from(env, overhead_weight), - }; - result + } } fn enabled() -> bool { @@ -108,7 +107,7 @@ where } } -fn total_supply<E: Ext, T, Tokens, AccountId>( +fn total_supply<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -147,7 +146,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn balance_of<E: Ext, T, Tokens, AccountId>( +fn balance_of<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -189,7 +188,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn transfer<E: Ext, T, Tokens, AccountId>( +fn transfer<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -200,7 +199,7 @@ where + orml_currencies::Config<MultiCurrency = Tokens, AccountId = AccountId> + orml_currencies_allowance_extension::Config, E: Ext<T = T>, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency<AccountId, CurrencyId = CurrencyId>, (CurrencyId, AccountId, <Tokens as MultiCurrency<AccountId>>::Balance): Decode, { @@ -229,14 +228,14 @@ where <orml_currencies::Pallet<T> as MultiCurrency<T::AccountId>>::transfer( currency_id, - &env.ext().caller(), + env.ext().caller(), &recipient, amount, )?; return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn allowance<E: Ext, T, Tokens, AccountId>( +fn allowance<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -281,7 +280,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn approve<E: Ext, T, Tokens, AccountId>( +fn approve<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -292,7 +291,7 @@ where + orml_currencies::Config<MultiCurrency = Tokens, AccountId = AccountId> + orml_currencies_allowance_extension::Config, E: Ext<T = T>, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency<AccountId, CurrencyId = CurrencyId>, (CurrencyId, AccountId, <Tokens as MultiCurrency<AccountId>>::Balance): Decode, { @@ -320,14 +319,14 @@ where orml_currencies_allowance_extension::Pallet::<T>::do_approve_transfer( currency_id, - &env.ext().caller(), + env.ext().caller(), &spender, amount, )?; return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn transfer_from<E: Ext, T, Tokens, AccountId>( +fn transfer_from<E, T, Tokens, AccountId>( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result<RetVal, DispatchError> @@ -338,7 +337,7 @@ where + orml_currencies::Config<MultiCurrency = Tokens, AccountId = AccountId> + orml_currencies_allowance_extension::Config, E: Ext<T = T>, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency<AccountId, CurrencyId = CurrencyId>, (AccountId, CurrencyId, AccountId, <Tokens as MultiCurrency<AccountId>>::Balance): Decode, { @@ -372,7 +371,7 @@ where orml_currencies_allowance_extension::Pallet::<T>::do_transfer_approved( currency_id, &owner, - &env.ext().caller(), + env.ext().caller(), &recipient, amount, )?; diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 72ee6970d..1fbdc1c7a 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -34,7 +34,7 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; pub fn create_pendulum_multisig_account(id: &str) -> AccountId { let mut signatories: Vec<_> = pendulum::SUDO_SIGNATORIES .iter() - .chain(vec![id].iter()) + .chain([id].iter()) .map(|ss58| AccountId::from_ss58check(ss58).unwrap()) .collect(); signatories.sort(); @@ -384,7 +384,7 @@ pub fn pendulum_config() -> PendulumChainSpec { pendulum::TREASURY_ALLOCATION * 20 / 100, )); - let multisig_identifiers = vec![ + let multisig_identifiers = [ pendulum::MULTISIG_ID_GENESIS, pendulum::MULTISIG_ID_TEAM, pendulum::MULTISIG_ID_CL_RESERVES, diff --git a/node/src/command.rs b/node/src/command.rs index 7a71636f8..ec33c71e6 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -404,19 +404,19 @@ pub fn run() -> Result<()> { .map_err(|e| format!("Error: {:?}", e))?; match runner.config().chain_spec.identify() { - ChainIdentity::Amplitude => runner.async_run(|config| { + ChainIdentity::Amplitude => runner.async_run(|_config| { Ok((cmd.run::<Block, ExtendedHostFunctions< sp_io::SubstrateHostFunctions, <AmplitudeRuntimeExecutor as NativeExecutionDispatch>::ExtendHostFunctions, >, _>(Some(substrate_info(BLOCK_TIME_MILLIS))), task_manager)) }), - ChainIdentity::Foucoco => runner.async_run(|config| { + ChainIdentity::Foucoco => runner.async_run(|_config| { Ok((cmd.run::<Block, ExtendedHostFunctions< sp_io::SubstrateHostFunctions, <FoucocoRuntimeExecutor as NativeExecutionDispatch>::ExtendHostFunctions, >, _>(Some(substrate_info(BLOCK_TIME_MILLIS))), task_manager)) }), - ChainIdentity::Pendulum => runner.async_run(|config| { + ChainIdentity::Pendulum => runner.async_run(|_config| { Ok((cmd.run::<Block, ExtendedHostFunctions< sp_io::SubstrateHostFunctions, <PendulumRuntimeExecutor as NativeExecutionDispatch>::ExtendHostFunctions, diff --git a/pallets/orml-currencies-allowance-extension/src/lib.rs b/pallets/orml-currencies-allowance-extension/src/lib.rs index 57874bece..c23f93984 100644 --- a/pallets/orml-currencies-allowance-extension/src/lib.rs +++ b/pallets/orml-currencies-allowance-extension/src/lib.rs @@ -238,7 +238,7 @@ pub mod pallet { } } -#[allow(clippy::forget_non_drop, clippy::swap_ptr_to_ref, clippy::forget_ref, clippy::forget_copy)] +#[allow(clippy::forget_non_drop, clippy::swap_ptr_to_ref, forgetting_references, forgetting_copy_types)] #[cfg_attr(test, mockable)] impl<T: Config> Pallet<T> { // Check the amount approved to be spent by an owner to a delegate diff --git a/pallets/orml-tokens-management-extension/src/lib.rs b/pallets/orml-tokens-management-extension/src/lib.rs index 59f1c6e2d..d2c35e962 100644 --- a/pallets/orml-tokens-management-extension/src/lib.rs +++ b/pallets/orml-tokens-management-extension/src/lib.rs @@ -124,14 +124,14 @@ pub mod pallet { T::CurrencyIdChecker::is_valid_currency_id(¤cy_id), Error::<T>::NotOwnableCurrency ); - ensure!(!CurrencyData::<T>::contains_key(¤cy_id), Error::<T>::AlreadyCreated); + ensure!(!CurrencyData::<T>::contains_key(currency_id), Error::<T>::AlreadyCreated); let deposit = T::AssetDeposit::get(); ext::orml_tokens::reserve::<T>(T::DepositCurrency::get(), &creator, deposit) .map_err(|_| Error::<T>::InsufficientBalance)?; CurrencyData::<T>::insert( - currency_id.clone(), + currency_id, CurrencyDetails { owner: creator.clone(), issuer: creator.clone(), @@ -175,7 +175,7 @@ pub mod pallet { ensure!(origin == currency_data.issuer, Error::<T>::NoPermission); // do mint via orml-currencies - let _ = ext::orml_tokens::mint::<T>(currency_id, &to, amount)?; + ext::orml_tokens::mint::<T>(currency_id, &to, amount)?; Self::deposit_event(Event::Mint { currency_id, to, amount }); Ok(()) @@ -207,7 +207,7 @@ pub mod pallet { ensure!(origin == currency_data.admin, Error::<T>::NoPermission); // do burn via orml-currencies - let _ = ext::orml_tokens::burn::<T>(currency_id, &from, amount)?; + ext::orml_tokens::burn::<T>(currency_id, &from, amount)?; Self::deposit_event(Event::Burned { currency_id, from, amount }); Ok(()) @@ -231,7 +231,7 @@ pub mod pallet { ) -> DispatchResult { let origin = ensure_signed(origin)?; - CurrencyData::<T>::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::<T>::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::<T>::NotCreated)?; ensure!(origin == details.owner, Error::<T>::NoPermission); @@ -241,7 +241,7 @@ pub mod pallet { details.owner = new_owner.clone(); // move reserved balance to the new owner's account - let _ = ext::orml_tokens::repatriate_reserve::<T>( + ext::orml_tokens::repatriate_reserve::<T>( T::DepositCurrency::get(), &origin, &new_owner, @@ -271,13 +271,13 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; - CurrencyData::<T>::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::<T>::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::<T>::NotCreated)?; if details.owner == new_owner { return Ok(()) } - let _ = ext::orml_tokens::repatriate_reserve::<T>( + ext::orml_tokens::repatriate_reserve::<T>( T::DepositCurrency::get(), &details.owner, &new_owner, @@ -311,7 +311,7 @@ pub mod pallet { ) -> DispatchResult { let origin = ensure_signed(origin)?; - CurrencyData::<T>::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::<T>::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::<T>::NotCreated)?; ensure!(origin == details.owner, Error::<T>::NoPermission); diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index fe74b9581..869191bad 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -36,9 +36,10 @@ frame-benchmarking = {git = "https://github.com/paritytech/substrate", branch = [features] default = ["std"] runtime-benchmarks = [ - "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", ] std = [ "frame-support/std", diff --git a/pallets/parachain-staking/rpc/src/lib.rs b/pallets/parachain-staking/rpc/src/lib.rs index bf60f8d1f..10d0ccbbf 100644 --- a/pallets/parachain-staking/rpc/src/lib.rs +++ b/pallets/parachain-staking/rpc/src/lib.rs @@ -72,7 +72,7 @@ where let at = at.unwrap_or_else(|| self.client.info().best_hash); api.get_unclaimed_staking_rewards(at, account) - .map_err(|_e| internal_err(format!("Unable to get unclaimed staking rewards"))) + .map_err(|_e| internal_err("Unable to get unclaimed staking rewards")) } fn get_staking_rates(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<StakingRates> { @@ -80,6 +80,6 @@ where let at = at.unwrap_or_else(|| self.client.info().best_hash); api.get_staking_rates(at) - .map_err(|_e| internal_err(format!("Unable to get staking rates"))) + .map_err(|_e| internal_err("Unable to get staking rates")) } } diff --git a/pallets/parachain-staking/src/benchmarking.rs b/pallets/parachain-staking/src/benchmarking.rs index 9f536fc47..053003a51 100644 --- a/pallets/parachain-staking/src/benchmarking.rs +++ b/pallets/parachain-staking/src/benchmarking.rs @@ -307,7 +307,7 @@ benchmarks! { let n in (T::MinCollators::get() + 1) .. T::MaxTopCandidates::get() - 1; let m in 0 .. T::MaxDelegatorsPerCollator::get(); - let u = T::MaxUnstakeRequests::get() as u32 - 1; + let u = T::MaxUnstakeRequests::get() - 1; let candidates = setup_collator_candidates::<T>(n, None); for (i, c) in candidates.iter().enumerate() { fill_delegators::<T>(m, c.clone(), i.saturated_into::<u32>()); @@ -532,7 +532,7 @@ benchmarks! { } unlock_unstaked { - let u in 1 .. (T::MaxUnstakeRequests::get() as u32 - 1); + let u in 1 .. (T::MaxUnstakeRequests::get() - 1); let candidate = account("collator", 0u32, COLLATOR_ACCOUNT_SEED); let free_balance = T::CurrencyBalance::from(u128::MAX); diff --git a/pallets/parachain-staking/src/try_state.rs b/pallets/parachain-staking/src/try_state.rs index 899b7bb9e..2deaea2ac 100644 --- a/pallets/parachain-staking/src/try_state.rs +++ b/pallets/parachain-staking/src/try_state.rs @@ -35,6 +35,7 @@ pub fn log_and_return_error_message(error_message: String) -> &'static str { "Sanity test error" } +#[allow(dead_code)] pub(crate) fn do_try_state<T: Config>() -> Result<(), &'static str> { validate_candiate_pool::<T>()?; validate_delegators::<T>()?; diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index 9b74b089e..b2a60a607 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -84,20 +84,17 @@ impl<AccountId: Ord, Balance: PartialEq + Ord> Ord for Stake<AccountId, Balance> } /// The activity status of the collator. -#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive( + Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen, Default, +)] pub enum CandidateStatus { /// Committed to be online and producing valid blocks (not equivocating) + #[default] Active, /// Staked until the inner round Leaving(SessionIndex), } -impl Default for CandidateStatus { - fn default() -> CandidateStatus { - CandidateStatus::Active - } -} - #[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(MaxDelegatorsPerCandidate))] #[codec(mel_bound(AccountId: MaxEncodedLen, Balance: MaxEncodedLen))] diff --git a/pallets/treasury-buyout-extension/src/lib.rs b/pallets/treasury-buyout-extension/src/lib.rs index a19e52ede..4c8b91c72 100644 --- a/pallets/treasury-buyout-extension/src/lib.rs +++ b/pallets/treasury-buyout-extension/src/lib.rs @@ -266,7 +266,7 @@ pub mod pallet { // Update `AllowedCurrencies` storage with provided `assets` for asset in assets.clone() { // Check for duplicates - if !AllowedCurrencies::<T>::contains_key(&asset) { + if !AllowedCurrencies::<T>::contains_key(asset) { AllowedCurrencies::<T>::insert(asset, ()); allowed_assets.push(asset); } @@ -291,7 +291,7 @@ impl<T: Config> Pallet<T> { <frame_system::Pallet<T>>::block_number().saturated_into::<u32>(); let current_period_start_number = current_block_number .checked_div(buyout_period) - .and_then(|n| Some(n.saturating_mul(buyout_period))) + .map(|n| n.saturating_mul(buyout_period)) .unwrap_or_default(); let (mut buyouts, last_buyout) = Buyouts::<T>::get(account_id); @@ -454,12 +454,10 @@ impl<T: Config> Pallet<T> { fn fetch_prices( assets: (&CurrencyIdOf<T>, &CurrencyIdOf<T>), ) -> Result<(FixedU128, FixedU128), DispatchError> { - let basic_asset_price: FixedU128 = T::PriceGetter::get_price::<FixedU128>(*assets.0) - .map_err(|_| Error::<T>::NoPrice)? - .into(); - let exchange_asset_price: FixedU128 = T::PriceGetter::get_price::<FixedU128>(*assets.1) - .map_err(|_| Error::<T>::NoPrice)? - .into(); + let basic_asset_price: FixedU128 = + T::PriceGetter::get_price::<FixedU128>(*assets.0).map_err(|_| Error::<T>::NoPrice)?; + let exchange_asset_price: FixedU128 = + T::PriceGetter::get_price::<FixedU128>(*assets.1).map_err(|_| Error::<T>::NoPrice)?; Ok((basic_asset_price, exchange_asset_price)) } @@ -626,32 +624,30 @@ where _info: &DispatchInfoOf<Self::Call>, _len: usize, ) -> TransactionValidity { - if let Some(local_call) = call.is_sub_type() { - if let Call::buyout { asset, amount } = local_call { - Pallet::<T>::ensure_asset_allowed_for_buyout(asset).map_err(|_| { - InvalidTransaction::Custom(ValidityError::WrongAssetToBuyout.into()) - })?; - - let (buyout_amount, exchange_amount) = - Pallet::<T>::split_to_buyout_and_exchange(*asset, *amount) - .map_err(|_| InvalidTransaction::Custom(ValidityError::Math.into()))?; - - ensure!( - buyout_amount >= T::MinAmountToBuyout::get(), - InvalidTransaction::Custom(ValidityError::LessThanMinBuyoutAmount.into()) - ); - - let free_balance = T::Currency::free_balance(*asset, who); - - ensure!( - free_balance >= exchange_amount, - InvalidTransaction::Custom(ValidityError::NotEnoughToBuyout.into()) - ); - - Pallet::<T>::ensure_buyout_limit_not_exceeded(who, buyout_amount).map_err( - |_| InvalidTransaction::Custom(ValidityError::BuyoutLimitExceeded.into()), - )?; - } + if let Some(Call::buyout { asset, amount }) = call.is_sub_type() { + Pallet::<T>::ensure_asset_allowed_for_buyout(asset).map_err(|_| { + InvalidTransaction::Custom(ValidityError::WrongAssetToBuyout.into()) + })?; + + let (buyout_amount, exchange_amount) = + Pallet::<T>::split_to_buyout_and_exchange(*asset, *amount) + .map_err(|_| InvalidTransaction::Custom(ValidityError::Math.into()))?; + + ensure!( + buyout_amount >= T::MinAmountToBuyout::get(), + InvalidTransaction::Custom(ValidityError::LessThanMinBuyoutAmount.into()) + ); + + let free_balance = T::Currency::free_balance(*asset, who); + + ensure!( + free_balance >= exchange_amount, + InvalidTransaction::Custom(ValidityError::NotEnoughToBuyout.into()) + ); + + Pallet::<T>::ensure_buyout_limit_not_exceeded(who, buyout_amount).map_err(|_| { + InvalidTransaction::Custom(ValidityError::BuyoutLimitExceeded.into()) + })?; } Ok(ValidTransaction::default()) diff --git a/pallets/treasury-buyout-extension/src/tests.rs b/pallets/treasury-buyout-extension/src/tests.rs index d38119317..83d0ca525 100644 --- a/pallets/treasury-buyout-extension/src/tests.rs +++ b/pallets/treasury-buyout-extension/src/tests.rs @@ -167,7 +167,7 @@ fn root_update_buyout_amount_limit_succeeds() { let buyout_amount_limit = 200 * UNIT; assert_ok!(crate::Pallet::<Test>::update_buyout_limit( RuntimeOrigin::root(), - Some(buyout_amount_limit.into()), + Some(buyout_amount_limit), )); assert_eq!(BuyoutLimit::<Test>::get(), buyout_amount_limit.into()); @@ -191,7 +191,7 @@ fn user_update_buyout_amount_limit_fails() { assert_noop!( crate::Pallet::<Test>::update_buyout_limit( RuntimeOrigin::signed(user), - Some(buyout_amount_limit.into()), + Some(buyout_amount_limit), ), BadOrigin ); @@ -606,7 +606,7 @@ mod signed_extension { // With buyout limit BuyoutLimit::<Test>::put(100 * UNIT); // Previous buyout at current_block - Buyouts::<Test>::insert(&user, (80 * UNIT, current_block)); + Buyouts::<Test>::insert(user, (80 * UNIT, current_block)); let check = CheckBuyout::<Test>::new(); let info = info_from_weight(Weight::zero()); diff --git a/pallets/vesting-manager/Cargo.toml b/pallets/vesting-manager/Cargo.toml index 0443644ae..707011fb2 100644 --- a/pallets/vesting-manager/Cargo.toml +++ b/pallets/vesting-manager/Cargo.toml @@ -27,6 +27,7 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks" ] std = [ "frame-support/std", diff --git a/pallets/vesting-manager/src/lib.rs b/pallets/vesting-manager/src/lib.rs index 30579255b..a732746db 100644 --- a/pallets/vesting-manager/src/lib.rs +++ b/pallets/vesting-manager/src/lib.rs @@ -30,8 +30,10 @@ pub mod pallet { #[pallet::call] impl<T: Config> Pallet<T> { + // TODO to remove this manually assigned weight, we need to add benchmarks to the pallet #[pallet::call_index(0)] - #[pallet::weight(10_000_000)] + #[pallet::weight(Weight::from_parts(10_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn remove_vesting_schedule( origin: OriginFor<T>, who: AccountIdLookupOf<T>, diff --git a/runtime/amplitude/src/chain_ext.rs b/runtime/amplitude/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/amplitude/src/chain_ext.rs +++ b/runtime/amplitude/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension<Runtime> for TokensChainExtension<Runtime, Tokens, AccountId> { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension<Runtime> for PriceChainExtension<Runtime> { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index d034434e6..acfb3bd13 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -1824,11 +1824,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec<TrackedStorageKey> = vec![ @@ -2029,6 +2033,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents { diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 28350211f..471334ab0 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -69,5 +69,6 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", "treasury-buyout-extension/runtime-benchmarks", ] diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 3152f6b35..1ff272816 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -3,12 +3,15 @@ use asset_registry::CustomMetadata; use core::{fmt::Debug, marker::PhantomData}; -use dia_oracle::{CoinInfo, DiaOracle}; +#[cfg(feature = "runtime-benchmarks")] +use dia_oracle::CoinInfo; +use dia_oracle::DiaOracle; use orml_traits::asset_registry::Inspect; use sp_runtime::{ traits::{Convert, IdentifyAccount, One, Verify, Zero}, DispatchError, FixedPointNumber, FixedU128, MultiSignature, }; +#[cfg(feature = "runtime-benchmarks")] use sp_std::vec; use spacewalk_primitives::CurrencyId; use treasury_buyout_extension::PriceGetter; diff --git a/runtime/foucoco/src/chain_ext.rs b/runtime/foucoco/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/foucoco/src/chain_ext.rs +++ b/runtime/foucoco/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension<Runtime> for TokensChainExtension<Runtime, Tokens, AccountId> { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension<Runtime> for PriceChainExtension<Runtime> { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 898c74687..039a0c3fc 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -1806,11 +1806,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec<TrackedStorageKey> = vec![ @@ -2027,6 +2031,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents { diff --git a/runtime/foucoco/src/weights/redeem.rs b/runtime/foucoco/src/weights/redeem.rs index 973a689c8..da4c4b23e 100644 --- a/runtime/foucoco/src/weights/redeem.rs +++ b/runtime/foucoco/src/weights/redeem.rs @@ -30,6 +30,7 @@ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] +#![allow(dead_code)] #![allow(unused_imports)] #![allow(missing_docs)] diff --git a/runtime/integration-tests/src/pendulum_tests.rs b/runtime/integration-tests/src/pendulum_tests.rs index 7a9226838..d193c05ba 100644 --- a/runtime/integration-tests/src/pendulum_tests.rs +++ b/runtime/integration-tests/src/pendulum_tests.rs @@ -13,6 +13,7 @@ use crate::{ }; use frame_support::assert_ok; +#[allow(unused_imports)] use pendulum_runtime::definitions::moonbeam::PARA_ID as MOONBEAM_PARA_ID; use statemint_runtime as polkadot_asset_hub_runtime; use xcm::latest::NetworkId; diff --git a/runtime/integration-tests/src/sibling.rs b/runtime/integration-tests/src/sibling.rs index d6063ab8e..9809a89e0 100644 --- a/runtime/integration-tests/src/sibling.rs +++ b/runtime/integration-tests/src/sibling.rs @@ -258,6 +258,8 @@ match_types! { //TODO: move DenyThenTry to polkadot's xcm module. /// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. /// If it passes the Deny, and matches one of the Allow cases then it is let through. + +#[allow(dead_code)] pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>) where Deny: ShouldExecute, @@ -280,6 +282,7 @@ where } // See issue #5233 +#[allow(dead_code)] pub struct DenyReserveTransferToRelayChain; impl ShouldExecute for DenyReserveTransferToRelayChain { fn should_execute<RuntimeCall>( diff --git a/runtime/pendulum/src/chain_ext.rs b/runtime/pendulum/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/pendulum/src/chain_ext.rs +++ b/runtime/pendulum/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension<Runtime> for TokensChainExtension<Runtime, Tokens, AccountId> { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension<Runtime> for PriceChainExtension<Runtime> { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index ea33c3730..79d0690a8 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -1809,11 +1809,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} @@ -2015,6 +2019,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {