Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XcmPaymentApi and DryRunApi to all runtimes #380

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d4570a0
feat(xcm): add XcmPaymentApi and DryRunApi to all runtimes
franciscoaguirre Jun 25, 2024
c44c69f
fix: fmt
franciscoaguirre Jul 12, 2024
2e748fb
feat(coretime-kusama-runtime): add XcmPaymentApi and DryRunApi
franciscoaguirre Jun 26, 2024
ee2e870
fix: fmt
franciscoaguirre Jul 12, 2024
555eb1a
fix(encointer): AssetId -> XcmAssetId
franciscoaguirre Jul 12, 2024
f1cf7f9
feat(xcm-fee-payment-runtime-api): update Cargo.lock
franciscoaguirre Jul 12, 2024
7d867b5
fix(kusama-runtime): feature propagation
franciscoaguirre Jul 12, 2024
6b05e7d
doc: update CHANGELOG
franciscoaguirre Jun 25, 2024
5e3e2db
doc: update CHANGELOG
franciscoaguirre Jul 12, 2024
138c5cc
test(asset-hub-polkadot): add XCM fee estimation test (not working)
franciscoaguirre Jul 12, 2024
5fbe49a
fix(asset-hub-polkadot-integration-tests): reverse order A -> B to B …
franciscoaguirre Jul 15, 2024
57df088
fix: fmt
franciscoaguirre Jul 15, 2024
d464252
feat(asset-hub-kusama-integration-tests): add test for XCM fee estima…
franciscoaguirre Jul 15, 2024
4a53b10
chore: address feedback
franciscoaguirre Jul 15, 2024
1c215b1
feat(integration-tests-helpers): use XCM runtime apis to estimate del…
franciscoaguirre Jul 15, 2024
7a2fd64
feat(integration-tests-helpers): use XCM runtime apis to estimate del…
franciscoaguirre Jul 15, 2024
5aa919a
fix: fmt
franciscoaguirre Jul 15, 2024
181b9d4
feat(people): add delivery fees
franciscoaguirre Jul 16, 2024
e59f4a1
feat(people-kusama-integration-tests): teleport tests with delivery fees
franciscoaguirre Jul 16, 2024
708aa26
revert(people): delivery fees
franciscoaguirre Jul 16, 2024
0d1794c
fix: fmt
franciscoaguirre Jul 16, 2024
92ff22c
feat(people-polkadot): teleport test with delivery fees
franciscoaguirre Jul 16, 2024
ffc6c1b
feat(coretime-kusama-integration-tests): initial setup and test
franciscoaguirre Jul 16, 2024
c1cc4c3
fix: fmt
franciscoaguirre Jul 16, 2024
59ed358
feat(bridge-hub-kusama-integration-tests): teleport test with deliver…
franciscoaguirre Jul 16, 2024
9b22b37
feat(bridge-hub-polkadot-integration-tests): add teleport test with d…
franciscoaguirre Jul 16, 2024
55b5191
WIP
franciscoaguirre Jul 17, 2024
5068ea7
Merge branch 'main' into xcm-runtime-apis
franciscoaguirre Jul 22, 2024
79a8340
Merge branch 'xcm-runtime-apis' of github.com:franciscoaguirre/polkad…
franciscoaguirre Jul 22, 2024
899dcd7
fix: fmt
franciscoaguirre Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- New call `hrmp.establish_channel_with_system` to allow parachains to establish a channel with a system parachain ([SDK v1.11 #3721](https://github.com/paritytech/polkadot-sdk/pull/3721)).
- New runtime api to check if a validator has pending pages of rewards for an era ([SDK v1.12 #4301](https://github.com/paritytech/polkadot-sdk/pull/4301)).
- Pallet-xcm: add new extrinsic for asset transfers using explicit reserve ([SDK v1.11 #3695](https://github.com/paritytech/polkadot-sdk/pull/3695)).
- All runtimes: XcmPaymentApi and DryRunApi ([polkadot-fellows/runtimes#359](https://github.com/polkadot-fellows/runtimes/pull/359))
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
- Ranked collective introduce `Add` and `Remove` origins ([SDK v1.8 #3212](https://github.com/paritytech/polkadot-sdk/pull/3212)).
- Runtime apis to help with delegate-stake based Nomination Pools ([SDK v1.13 #4537](https://github.com/paritytech/polkadot-sdk/pull/4537)).
- Kusama system chains: enable PoV-reclaim.
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ xcm = { version = "14.0.0", default-features = false, package = "staging-xcm" }
xcm-builder = { version = "14.0.0", default-features = false, package = "staging-xcm-builder" }
xcm-emulator = { version = "0.12.0" }
xcm-executor = { version = "14.0.0", default-features = false, package = "staging-xcm-executor" }
xcm-fee-payment-runtime-api = { version = "0.4.0", default-features = false }
anyhow = { version = "1.0.82" }
subxt = { version = "0.35.0", default-features = false }
tracing-subscriber = { version = "0.3.18" }
Expand Down
3 changes: 3 additions & 0 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ polkadot-primitives = { workspace = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-builder = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

sp-debug-derive = { workspace = true }

Expand Down Expand Up @@ -208,6 +209,7 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"xcm-fee-payment-runtime-api/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -258,6 +260,7 @@ runtime-benchmarks = [
"sp-staking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks"
]
try-runtime = [
"frame-election-provider-support/try-runtime",
Expand Down
53 changes: 48 additions & 5 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use frame_support::{
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage,
ProcessMessageError, StorageMapShim, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
};
use frame_system::EnsureRoot;
Expand All @@ -102,11 +102,12 @@ use sp_staking::SessionIndex;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{
latest::{InteriorLocation, Junction, Junction::PalletInstance},
VersionedLocation,
};
use xcm::prelude::*;
use xcm_builder::PayOverXcm;
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
Expand Down Expand Up @@ -2285,6 +2286,48 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
XcmPallet::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
match asset.try_as::<AssetId>() {
Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => {
// for native token
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
Err(XcmPaymentApiError::AssetNotFound)
},
Err(_) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
Err(XcmPaymentApiError::VersionedConversionFailed)
}
}
}

fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
XcmPallet::query_xcm_weight(message)
}

fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
XcmPallet::query_delivery_fees(destination, message)
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
XcmPallet::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
XcmPallet::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl pallet_nomination_pools_runtime_api::NominationPoolsApi<
Block,
AccountId,
Expand Down
3 changes: 3 additions & 0 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ polkadot-primitives = { workspace = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-builder = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

sp-debug-derive = { workspace = true }

Expand Down Expand Up @@ -205,6 +206,7 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"xcm-fee-payment-runtime-api/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -253,6 +255,7 @@ runtime-benchmarks = [
"sp-staking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
]
try-runtime = [
"frame-election-provider-support/try-runtime",
Expand Down
1 change: 0 additions & 1 deletion relay/polkadot/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use frame_system::RawOrigin;
use polkadot_primitives::Id as ParaId;
use polkadot_runtime_common::identity_migrator::{OnReapIdentity, WeightInfo};
use polkadot_runtime_constants::system_parachain::PEOPLE_ID;
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::IsChildSystemParachain;
use xcm_executor::traits::TransactAsset;

Expand Down
53 changes: 48 additions & 5 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use frame_support::{
Get, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage,
ProcessMessageError, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -102,11 +102,12 @@ use sp_std::{
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{
latest::{InteriorLocation, Junction, Junction::PalletInstance},
VersionedLocation,
};
use xcm::prelude::*;
use xcm_builder::PayOverXcm;
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
Expand Down Expand Up @@ -2393,6 +2394,48 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable_assets = vec![AssetId(xcm_config::TokenLocation::get())];
XcmPallet::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
match asset.try_as::<AssetId>() {
Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => {
// for native token
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
Err(XcmPaymentApiError::AssetNotFound)
},
Err(_) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
Err(XcmPaymentApiError::VersionedConversionFailed)
}
}
}

fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
XcmPallet::query_xcm_weight(message)
}

fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
XcmPallet::query_delivery_fees(destination, message)
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
XcmPallet::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
XcmPallet::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
Expand Down
3 changes: 3 additions & 0 deletions system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ polkadot-runtime-common = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# Cumulus
cumulus-pallet-aura-ext = { workspace = true }
Expand Down Expand Up @@ -157,6 +158,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand Down Expand Up @@ -272,6 +274,7 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"xcm-fee-payment-runtime-api/std",
]

# Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.
Expand Down
Loading
Loading