From b12d7714875572f2981cd23848f3f1c41d8b3f37 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 22 May 2023 08:01:39 +0000 Subject: [PATCH] fix: make pallets build on 0.9.42 --- --- a/pallets/app-promotion/Cargo.toml +++ b/pallets/app-promotion/Cargo.toml @@ -48,7 +48,7 @@ frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } -pallet-balances = { workspace = true } +pallet-balances = { features = ["insecure_zero_ed"], workspace = true } pallet-evm = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } --- a/pallets/collator-selection/Cargo.toml +++ b/pallets/collator-selection/Cargo.toml @@ -33,7 +33,7 @@ [dev-dependencies] pallet-aura = { workspace = true } -pallet-balances = { workspace = true } +pallet-balances = { features = ["insecure_zero_ed"], workspace = true } pallet-timestamp = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } --- a/pallets/foreign-assets/Cargo.toml +++ b/pallets/foreign-assets/Cargo.toml @@ -15,7 +15,7 @@ frame-system = { workspace = true } log = { workspace = true } orml-tokens = { workspace = true } -pallet-balances = { workspace = true } +pallet-balances = { features = ["insecure_zero_ed"], workspace = true } pallet-common = { workspace = true } pallet-fungible = { workspace = true } serde = { workspace = true, optional = true } --- a/pallets/foreign-assets/src/impl_fungibles.rs +++ b/pallets/foreign-assets/src/impl_fungibles.rs @@ -19,7 +19,9 @@ use super::*; use frame_system::Config as SystemConfig; -use frame_support::traits::tokens::{DepositConsequence, WithdrawConsequence}; +use frame_support::traits::tokens::{ + DepositConsequence, WithdrawConsequence, Preservation, Fortitude, Provenance, Precision, +}; use pallet_common::CollectionHandle; use pallet_fungible::FungibleHandle; use pallet_common::CommonCollectionOperations; @@ -118,17 +120,24 @@ } } + fn total_balance(asset: Self::AssetId, who: &::AccountId) -> Self::Balance { + Self::balance(asset, who) + } + fn reducible_balance( asset: Self::AssetId, who: &::AccountId, - keep_alive: bool, + preservation: Preservation, + fortitude: Fortitude, ) -> Self::Balance { log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible reducible_balance"); match asset { AssetIds::NativeAssetId(NativeCurrency::Here) => { as fungible::Inspect>::reducible_balance( - who, keep_alive, + who, + preservation, + fortitude, ) .into() } @@ -136,7 +145,8 @@ as fungibles::Inspect>::reducible_balance( AssetIds::NativeAssetId(NativeCurrency::Parent), who, - keep_alive, + preservation, + fortitude, ) .into() } @@ -148,7 +158,7 @@ asset: Self::AssetId, who: &::AccountId, amount: Self::Balance, - mint: bool, + provenance: Provenance, ) -> DepositConsequence { log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible can_deposit"); @@ -157,7 +167,7 @@ as fungible::Inspect>::can_deposit( who, amount.into(), - mint, + provenance, ) } AssetIds::NativeAssetId(NativeCurrency::Parent) => { @@ -165,7 +175,7 @@ AssetIds::NativeAssetId(NativeCurrency::Parent), who, amount.into(), - mint, + provenance, ) } _ => { @@ -220,14 +230,14 @@ who, this_amount, ) { - WithdrawConsequence::NoFunds => WithdrawConsequence::NoFunds, + WithdrawConsequence::BalanceLow => WithdrawConsequence::BalanceLow, WithdrawConsequence::WouldDie => WithdrawConsequence::WouldDie, WithdrawConsequence::UnknownAsset => WithdrawConsequence::UnknownAsset, WithdrawConsequence::Underflow => WithdrawConsequence::Underflow, WithdrawConsequence::Overflow => WithdrawConsequence::Overflow, WithdrawConsequence::Frozen => WithdrawConsequence::Frozen, WithdrawConsequence::Success => WithdrawConsequence::Success, - _ => WithdrawConsequence::NoFunds, + _ => WithdrawConsequence::BalanceLow, } } AssetIds::NativeAssetId(NativeCurrency::Parent) => { @@ -242,19 +252,19 @@ who, parent_amount, ) { - WithdrawConsequence::NoFunds => WithdrawConsequence::NoFunds, + WithdrawConsequence::BalanceLow => WithdrawConsequence::BalanceLow, WithdrawConsequence::WouldDie => WithdrawConsequence::WouldDie, WithdrawConsequence::UnknownAsset => WithdrawConsequence::UnknownAsset, WithdrawConsequence::Underflow => WithdrawConsequence::Underflow, WithdrawConsequence::Overflow => WithdrawConsequence::Overflow, WithdrawConsequence::Frozen => WithdrawConsequence::Frozen, WithdrawConsequence::Success => WithdrawConsequence::Success, - _ => WithdrawConsequence::NoFunds, + _ => WithdrawConsequence::BalanceLow, } } _ => match Self::balance(asset, who).checked_sub(&amount) { Some(_) => WithdrawConsequence::Success, - None => WithdrawConsequence::NoFunds, + None => WithdrawConsequence::BalanceLow, }, } } @@ -280,7 +290,7 @@ asset: Self::AssetId, who: &::AccountId, amount: Self::Balance, - ) -> DispatchResult { + ) -> Result, DispatchError> { //Self::do_mint(asset, who, amount, None) log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible mint_into {:?}", asset); @@ -290,7 +300,7 @@ who, amount.into(), ) - .into() + .map(Into::into) } AssetIds::NativeAssetId(NativeCurrency::Parent) => { as fungibles::Mutate>::mint_into( @@ -298,7 +308,7 @@ who, amount.into(), ) - .into() + .map(Into::into) } AssetIds::ForeignAssetId(fid) => { let target_collection_id = match >::get(fid) { @@ -323,7 +333,7 @@ &Value::new(0), )?; - Ok(()) + Ok(amount.into()) } } } @@ -332,29 +342,31 @@ asset: Self::AssetId, who: &::AccountId, amount: Self::Balance, + precision: Precision, + fortitude: Fortitude, ) -> Result { // let f = DebitFlags { keep_alive: false, best_effort: false }; log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible burn_from"); match asset { AssetIds::NativeAssetId(NativeCurrency::Here) => { - match as fungible::Mutate>::burn_from( + as fungible::Mutate>::burn_from( who, amount.into(), - ) { - Ok(v) => Ok(v.into()), - Err(e) => Err(e), - } + precision, + fortitude, + ) + .map(Into::into) } AssetIds::NativeAssetId(NativeCurrency::Parent) => { - match as fungibles::Mutate>::burn_from( + as fungibles::Mutate>::burn_from( AssetIds::NativeAssetId(NativeCurrency::Parent), who, amount.into(), - ) { - Ok(v) => Ok(v.into()), - Err(e) => Err(e), - } + precision, + fortitude, + ) + .map(Into::into) } AssetIds::ForeignAssetId(fid) => { let target_collection_id = match >::get(fid) { @@ -376,45 +388,25 @@ Ok(amount) } } - } - - fn slash( - asset: Self::AssetId, - who: &::AccountId, - amount: Self::Balance, - ) -> Result { - // let f = DebitFlags { keep_alive: false, best_effort: true }; - log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible slash"); - Ok(Self::burn_from(asset, who, amount)?) } -} -impl fungibles::Transfer for Pallet -where - T: orml_tokens::Config, - BalanceOf: From<::Balance>, - BalanceOf: From<::Balance>, - ::Balance: From>, - ::Balance: From>, - u128: From>, -{ fn transfer( asset: Self::AssetId, source: &::AccountId, dest: &::AccountId, amount: Self::Balance, - keep_alive: bool, + preservation: Preservation, ) -> Result { // let f = TransferFlags { keep_alive, best_effort: false, burn_dust: false }; log::trace!(target: "fassets::impl_foreign_assets", "impl_fungible transfer"); match asset { AssetIds::NativeAssetId(NativeCurrency::Here) => { - match as fungible::Transfer>::transfer( + match as fungible::Mutate>::transfer( source, dest, amount.into(), - keep_alive, + preservation, ) { Ok(_) => Ok(amount), Err(_) => Err(DispatchError::Other( @@ -423,12 +415,12 @@ } } AssetIds::NativeAssetId(NativeCurrency::Parent) => { - match as fungibles::Transfer>::transfer( + match as fungibles::Mutate>::transfer( AssetIds::NativeAssetId(NativeCurrency::Parent), source, dest, amount.into(), - keep_alive, + preservation, ) { Ok(_) => Ok(amount), Err(e) => Err(e), @@ -460,3 +452,51 @@ } } } + +#[cfg(not(debug_assertions))] +extern "C" { + // This function does not exists, thus compilation will fail, if its call is + // not optimized away, which is only possible if it's not called at all. + // + // not(debug_assertions) is used to ensure compiler is dropping unused functions, as + // this option is enabled in release by defailt + // + // FIXME: maybe use build.rs, to ensure it will fail even in release with debug_assertions + // enabled? + fn unbalanced_fungible_is_called(); +} +macro_rules! ensure_balanced { + () => {{ + #[cfg(debug_assertions)] + panic!("unbalanced fungible methods should not be used"); + #[cfg(not(debug_assertions))] + { + unsafe { unbalanced_fungible_is_called() }; + unreachable!(); + } + }}; +} + +impl fungibles::Unbalanced<::AccountId> for Pallet +where + T: orml_tokens::Config, + BalanceOf: From<::Balance>, + BalanceOf: From<::Balance>, + ::Balance: From>, + ::Balance: From>, + u128: From>, +{ + fn handle_dust(_dust: fungibles::Dust<::AccountId, Self>) { + ensure_balanced!(); + } + fn write_balance( + _asset: Self::AssetId, + _who: &::AccountId, + _amount: Self::Balance, + ) -> Result, DispatchError> { + ensure_balanced!(); + } + fn set_total_issuance(_asset: Self::AssetId, _amount: Self::Balance) { + ensure_balanced!(); + } +} --- a/pallets/foreign-assets/src/lib.rs +++ b/pallets/foreign-assets/src/lib.rs @@ -448,9 +448,7 @@ pub use frame_support::{ traits::{ - fungibles::{Balanced, CreditOf}, - tokens::currency::Currency as CurrencyT, - OnUnbalanced as OnUnbalancedT, + fungibles::Balanced, tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, }, weights::{WeightToFeePolynomial, WeightToFee}, }; --- a/pallets/identity/Cargo.toml +++ b/pallets/identity/Cargo.toml @@ -26,7 +26,7 @@ sp-std = { workspace = true } [dev-dependencies] -pallet-balances = { workspace = true } +pallet-balances = { features = ["insecure_zero_ed"], workspace = true } sp-core = { workspace = true } [features] --- a/pallets/inflation/Cargo.toml +++ b/pallets/inflation/Cargo.toml @@ -37,7 +37,7 @@ frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } -pallet-balances = { workspace = true } +pallet-balances = { features = ["insecure_zero_ed"], workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } --- a/runtime/common/config/xcm/mod.rs +++ b/runtime/common/config/xcm/mod.rs @@ -114,12 +114,26 @@ ); pub trait TryPass { +<<<<<<< HEAD fn try_pass(origin: &MultiLocation, message: &mut [Instruction]) -> Result<(), ()>; +======= + fn try_pass( + origin: &MultiLocation, + message: &mut [Instruction], + ) -> Result<(), ProcessMessageError>; +>>>>>>> fd33b0ac (fixup pallets) } #[impl_trait_for_tuples::impl_for_tuples(30)] impl TryPass for Tuple { +<<<<<<< HEAD fn try_pass(origin: &MultiLocation, message: &mut [Instruction]) -> Result<(), ()> { +======= + fn try_pass( + origin: &MultiLocation, + message: &mut [Instruction], + ) -> Result<(), ProcessMessageError> { +>>>>>>> fd33b0ac (fixup pallets) for_tuples!( #( Tuple::try_pass(origin, message)?; )* ); --- a/test-pallets/utils/src/lib.rs +++ b/test-pallets/utils/src/lib.rs @@ -20,7 +20,7 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod pallet { use frame_support::{ pallet_prelude::*, -- gitstuff