From f7baa84f48aa72b96e8c9a9ec8a1934431de6709 Mon Sep 17 00:00:00 2001 From: Dastan <88332432+dastansam@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:12:41 +0600 Subject: [PATCH] [FRAME] `pallet_asset_tx_payment`: replace `AssetId` bound from `Copy` to `Clone` (#7194) closes https://github.com/paritytech/polkadot-sdk/issues/6911 --- prdoc/pr_7194.prdoc | 15 +++++++++++++++ .../asset-tx-payment/src/lib.rs | 6 +++--- .../asset-tx-payment/src/payment.rs | 15 +++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 prdoc/pr_7194.prdoc diff --git a/prdoc/pr_7194.prdoc b/prdoc/pr_7194.prdoc new file mode 100644 index 00000000000..3a9db46ceae --- /dev/null +++ b/prdoc/pr_7194.prdoc @@ -0,0 +1,15 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: '[FRAME] `pallet_asset_tx_payment`: replace `AssetId` bound from `Copy` to `Clone`' + +doc: + - audience: Runtime Dev + description: | + `OnChargeAssetTransaction`'s associated type `AssetId` is bounded by `Copy` which makes it impossible + to use `staging_xcm::v4::Location` as `AssetId`. This PR bounds `AssetId` to `Clone` instead, which is + more lenient. + +crates: + - name: pallet-asset-tx-payment + bump: minor diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs index dd752989c36..4a96cbcacb5 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs @@ -202,7 +202,7 @@ where debug_assert!(self.tip <= fee, "tip should be included in the computed fee"); if fee.is_zero() { Ok((fee, InitialPayment::Nothing)) - } else if let Some(asset_id) = self.asset_id { + } else if let Some(asset_id) = self.asset_id.clone() { T::OnChargeAssetTransaction::withdraw_fee( who, call, @@ -233,7 +233,7 @@ where debug_assert!(self.tip <= fee, "tip should be included in the computed fee"); if fee.is_zero() { Ok(()) - } else if let Some(asset_id) = self.asset_id { + } else if let Some(asset_id) = self.asset_id.clone() { T::OnChargeAssetTransaction::can_withdraw_fee( who, call, @@ -358,7 +358,7 @@ where tip, who, initial_payment, - asset_id: self.asset_id, + asset_id: self.asset_id.clone(), weight: self.weight(call), }) }, diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs index 2074b1476f4..7b7ae855bf8 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs @@ -40,7 +40,7 @@ pub trait OnChargeAssetTransaction<T: Config> { /// The underlying integer type in which fees are calculated. type Balance: Balance; /// The type used to identify the assets used for transaction payment. - type AssetId: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo; + type AssetId: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo; /// The type used to store the intermediate values between pre- and post-dispatch. type LiquidityInfo; @@ -112,7 +112,7 @@ where T: Config, CON: ConversionToAssetBalance<BalanceOf<T>, AssetIdOf<T>, AssetBalanceOf<T>>, HC: HandleCredit<T::AccountId, T::Fungibles>, - AssetIdOf<T>: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo, + AssetIdOf<T>: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo, { type Balance = BalanceOf<T>; type AssetId = AssetIdOf<T>; @@ -133,11 +133,14 @@ where // less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum // fee. let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() }; - let converted_fee = CON::to_asset_balance(fee, asset_id) + let converted_fee = CON::to_asset_balance(fee, asset_id.clone()) .map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))? .max(min_converted_fee); - let can_withdraw = - <T::Fungibles as Inspect<T::AccountId>>::can_withdraw(asset_id, who, converted_fee); + let can_withdraw = <T::Fungibles as Inspect<T::AccountId>>::can_withdraw( + asset_id.clone(), + who, + converted_fee, + ); if can_withdraw != WithdrawConsequence::Success { return Err(InvalidTransaction::Payment.into()) } @@ -167,7 +170,7 @@ where // less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum // fee. let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() }; - let converted_fee = CON::to_asset_balance(fee, asset_id) + let converted_fee = CON::to_asset_balance(fee, asset_id.clone()) .map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))? .max(min_converted_fee); let can_withdraw = -- GitLab