From 788e873b0018683fe3a01775a0b51c82ce0bbb6f Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Wed, 15 Jan 2025 19:19:41 +0800 Subject: [PATCH 1/2] init --- polkadot/xcm/pallet-xcm/src/lib.rs | 9 ++++++++- polkadot/xcm/xcm-runtime-apis/src/fees.rs | 2 +- polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs | 8 +++++++- polkadot/xcm/xcm-runtime-apis/tests/mock.rs | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 6360298b21c36..6cb14730e73fa 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -2669,8 +2669,9 @@ impl Pallet { pub fn query_delivery_fees( destination: VersionedLocation, message: VersionedXcm<()>, + custom_asset: VersionedAssetId, ) -> Result { - let result_version = destination.identify_version().max(message.identify_version()); + let result_version = custom_asset.identify_version(); let destination: Location = destination .clone() @@ -2691,6 +2692,12 @@ impl Pallet { XcmPaymentApiError::Unroutable })?; + // fees.into_inner().iter().for_each(|asset| { + // if asset.id != custom_asset { + // tracing::error!(target: "xcm::pallet_xcm::query_delivery_fees", ?asset, + // ?result_version, "Asset version mismatch"); } + // }); + VersionedAssets::from(fees) .into_version(result_version) .map_err(|e| { diff --git a/polkadot/xcm/xcm-runtime-apis/src/fees.rs b/polkadot/xcm/xcm-runtime-apis/src/fees.rs index 9500a7f7281f4..f65bf99fdef60 100644 --- a/polkadot/xcm/xcm-runtime-apis/src/fees.rs +++ b/polkadot/xcm/xcm-runtime-apis/src/fees.rs @@ -65,7 +65,7 @@ sp_api::decl_runtime_apis! { /// size of the message. /// * `destination`: The destination to send the message to. Different destinations may use /// different senders that charge different fees. - fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result; + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result; } } diff --git a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs index c3046b134d1fe..02ff0443edf4f 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/fee_estimation.rs @@ -153,9 +153,15 @@ fn fee_estimation_for_teleport() { let (destination, remote_messages) = forwarded_xcms_iter.next().unwrap(); let remote_message = &remote_messages[0]; + let costum_asset = VersionedAssetId::from(AssetId(HereLocation::get())); let delivery_fees = runtime_api - .query_delivery_fees(H256::zero(), destination.clone(), remote_message.clone()) + .query_delivery_fees( + H256::zero(), + destination.clone(), + remote_message.clone(), + costum_asset, + ) .unwrap() .unwrap(); assert_eq!(delivery_fees, VersionedAssets::from((Here, 20u128))); diff --git a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs index 56a77094f1774..08c655064015a 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs @@ -476,8 +476,8 @@ sp_api::mock_impl_runtime_apis! { } } - fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { - XcmPallet::query_delivery_fees(destination, message) + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result { + XcmPallet::query_delivery_fees(destination, message, asset) } } From dc171e54a225bd8fb72f2310f6f3ff169131ae34 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Sat, 8 Mar 2025 11:53:57 +0800 Subject: [PATCH 2/2] adjust version --- polkadot/xcm/pallet-xcm/src/lib.rs | 9 +-------- polkadot/xcm/xcm-runtime-apis/src/fees.rs | 14 +++++++++++++- polkadot/xcm/xcm-runtime-apis/tests/mock.rs | 6 ++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 6cb14730e73fa..6360298b21c36 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -2669,9 +2669,8 @@ impl Pallet { pub fn query_delivery_fees( destination: VersionedLocation, message: VersionedXcm<()>, - custom_asset: VersionedAssetId, ) -> Result { - let result_version = custom_asset.identify_version(); + let result_version = destination.identify_version().max(message.identify_version()); let destination: Location = destination .clone() @@ -2692,12 +2691,6 @@ impl Pallet { XcmPaymentApiError::Unroutable })?; - // fees.into_inner().iter().for_each(|asset| { - // if asset.id != custom_asset { - // tracing::error!(target: "xcm::pallet_xcm::query_delivery_fees", ?asset, - // ?result_version, "Asset version mismatch"); } - // }); - VersionedAssets::from(fees) .into_version(result_version) .map_err(|e| { diff --git a/polkadot/xcm/xcm-runtime-apis/src/fees.rs b/polkadot/xcm/xcm-runtime-apis/src/fees.rs index f65bf99fdef60..e7d0ca54a1eeb 100644 --- a/polkadot/xcm/xcm-runtime-apis/src/fees.rs +++ b/polkadot/xcm/xcm-runtime-apis/src/fees.rs @@ -34,6 +34,7 @@ sp_api::decl_runtime_apis! { /// /// To determine the execution weight of the calls required for /// [`xcm::latest::Instruction::Transact`] instruction, `TransactionPaymentCallApi` can be used. + #[api_version(5)] pub trait XcmPaymentApi { /// Returns a list of acceptable payment assets. /// @@ -65,7 +66,18 @@ sp_api::decl_runtime_apis! { /// size of the message. /// * `destination`: The destination to send the message to. Different destinations may use /// different senders that charge different fees. - fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result; + #[changed_in(5)] + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result; + + /// Get delivery fees for sending a specific `message` to a `destination`. + /// These always come in a specific asset, defined by the chain. + /// + /// # Arguments + /// * `message`: The message that'll be sent, necessary because most delivery fees are based on the + /// size of the message. + /// * `destination`: The destination to send the message to. Different destinations may use + /// different senders that charge different fees. + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset_id: VersionedAssetId) -> Result; } } diff --git a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs index 08c655064015a..6ab0d53708b55 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs @@ -476,8 +476,10 @@ sp_api::mock_impl_runtime_apis! { } } - fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset: VersionedAssetId) -> Result { - XcmPallet::query_delivery_fees(destination, message, asset) + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>, asset_id: VersionedAssetId) -> Result { + let delivery_fee_dot = XcmPallet::query_delivery_fees(destination, message)?; + quote_price_tokens_for_exact_tokens(delivery_fee_dot, asset_id) + .map_err(|_| XcmPaymentApiError::AssetNotFound) } }