From c471add28ce356f26425f50250c15b79598e8700 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 20 Feb 2024 16:27:01 +0700 Subject: [PATCH 01/42] feat(xcm): add `xcm-payment-api` refactor: rpc signatures feat(rococo): full impl `XcmPaymentApi` fix cargo fix use fix use --- Cargo.lock | 17 ++++++++ Cargo.toml | 1 + polkadot/node/service/Cargo.toml | 9 +++-- polkadot/node/service/src/fake_runtime_api.rs | 19 ++++++++- polkadot/runtime/rococo/Cargo.toml | 16 ++++++-- polkadot/runtime/rococo/src/lib.rs | 20 +++++++++- .../xcm-payment-runtime-api/Cargo.toml | 36 +++++++++++++++++ .../xcm-payment-runtime-api/README.md | 2 + .../xcm-payment-runtime-api/src/lib.rs | 40 +++++++++++++++++++ 9 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml create mode 100644 polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md create mode 100644 polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 177d76b87062..c0346abf767e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13570,12 +13570,15 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", + "staging-xcm", + "staging-xcm-builder", "substrate-prometheus-endpoint", "tempfile", "thiserror", "tracing-gum", "westend-runtime", "westend-runtime-constants", + "xcm-payment-runtime-api", ] [[package]] @@ -15156,6 +15159,7 @@ dependencies = [ "substrate-wasm-builder", "tiny-keccak", "tokio", + "xcm-payment-runtime-api", ] [[package]] @@ -22521,6 +22525,19 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "xcm-payment-runtime-api" +version = "1.0.0" +dependencies = [ + "frame-support", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std 14.0.0", + "sp-weights", + "staging-xcm", +] + [[package]] name = "xcm-procedural" version = "7.0.0" diff --git a/Cargo.toml b/Cargo.toml index a2e22e0b9271..1de3a463e19e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,6 +212,7 @@ members = [ "polkadot/xcm/pallet-xcm-benchmarks", "polkadot/xcm/procedural", "polkadot/xcm/xcm-builder", + "polkadot/xcm/xcm-builder/xcm-payment-runtime-api", "polkadot/xcm/xcm-executor", "polkadot/xcm/xcm-executor/integration-tests", "polkadot/xcm/xcm-simulator", diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 180de70ad6c5..f6f6d72ea781 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -142,6 +142,10 @@ polkadot-node-core-pvf-checker = { path = "../core/pvf-checker", optional = true polkadot-node-core-runtime-api = { path = "../core/runtime-api", optional = true } polkadot-statement-distribution = { path = "../network/statement-distribution", optional = true } +xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } +xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } +xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } + [dev-dependencies] polkadot-test-client = { path = "../test/client" } polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" } @@ -219,10 +223,7 @@ try-runtime = [ "sp-runtime/try-runtime", "westend-runtime?/try-runtime", ] -fast-runtime = [ - "rococo-runtime?/fast-runtime", - "westend-runtime?/fast-runtime", -] +fast-runtime = ["rococo-runtime?/fast-runtime", "westend-runtime?/fast-runtime"] malus = ["full-node"] runtime-metrics = [ diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index 085ea93fdc78..86b5bb1dbdea 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -30,6 +30,8 @@ use polkadot_primitives::{ ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, }; +use rococo_runtime::RuntimeCall; + use sp_core::OpaqueMetadata; use sp_runtime::{ traits::Block as BlockT, @@ -39,7 +41,7 @@ use sp_runtime::{ use sp_version::RuntimeVersion; use sp_weights::Weight; use std::collections::BTreeMap; - +use xcm::latest::{AssetId, Xcm}; sp_api::decl_runtime_apis! { /// This runtime API is only implemented for the test runtime! pub trait GetLastTimestamp { @@ -396,4 +398,19 @@ sp_api::impl_runtime_apis! { unimplemented!() } } + + impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { + + fn query_acceptable_payment_assets() -> Vec { + unimplemented!() + } + + fn query_weight_to_asset_fee(_: Weight, _: AssetId) -> Option { + unimplemented!() + } + + fn query_xcm_weight(_: Xcm) -> Result> { + unimplemented!() + } + } } diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 61ca1635ac95..860488bc053a 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -11,8 +11,13 @@ license.workspace = true workspace = true [dependencies] -parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = [ + "derive", + "max-encoded-len", +] } +scale-info = { version = "2.10.0", default-features = false, features = [ + "derive", +] } log = { workspace = true } serde = { workspace = true } serde_derive = { optional = true, workspace = true } @@ -77,7 +82,9 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur pallet-session = { path = "../../../substrate/frame/session", default-features = false } pallet-society = { path = "../../../substrate/frame/society", default-features = false } pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ + "tuples-96", +] } pallet-staking = { path = "../../../substrate/frame/staking", default-features = false } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } @@ -104,7 +111,7 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } - +xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } keyring = { package = "sp-keyring", path = "../../../substrate/primitives/keyring" } @@ -209,6 +216,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "xcm-payment-runtime-api/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index ff54c7776701..55d756fef05b 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -75,7 +75,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, EnsureSigned}; @@ -1799,6 +1799,23 @@ sp_api::impl_runtime_apis! { } } + impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { + fn query_acceptable_payment_assets() -> Vec { + vec![AssetId::Concrete(xcm_config::TokenLocation::get())] + } + + fn query_weight_to_asset_fee(weight: Weight, asset: AssetId) -> Option { + let local_asset = AssetId::Concrete(xcm_config::TokenLocation::get()); + if asset != local_asset { return None; } + Some(WeightToFee::weight_to_fee(&weight)) + } + + fn query_xcm_weight(message: Xcm) -> Result> { + >::prepare(message) + .map(|wm| wm.weight_of()) + } + } + impl sp_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) @@ -2495,6 +2512,7 @@ sp_api::impl_runtime_apis! { build_config::(config) } } + } #[cfg(all(test, feature = "try-runtime"))] diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml new file mode 100644 index 000000000000..edb07d72aaf3 --- /dev/null +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "xcm-payment-runtime-api" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage = "https://substrate.io" +repository.workspace = true +description = "" +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ + "derive", +] } + +sp-api = { path = "../../../../substrate/primitives/api", default-features = false } +sp-std = { path = "../../../../substrate/primitives/std", default-features = false } +sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false } +sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } +xcm = { package = "staging-xcm", path = "../..", default-features = false } +frame-support = { path = "../../../../substrate/frame/support", default-features = false } +[features] +default = ["std"] +std = [ + "codec/std", + "sp-api/std", + "sp-std/std", + "sp-runtime/std", + "sp-weights/std", + "xcm/std", + "frame-support/std", +] diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md new file mode 100644 index 000000000000..4eaddae1786e --- /dev/null +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md @@ -0,0 +1,2 @@ + +License: Apache-2.0 diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs new file mode 100644 index 000000000000..b39bff828018 --- /dev/null +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -0,0 +1,40 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Runtime API definition for xcm transaction payment. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Codec; +use sp_std::vec::Vec; +use sp_weights::Weight; +use xcm::latest::{AssetId, Xcm}; +sp_api::decl_runtime_apis! { + + pub trait XcmPaymentRuntimeApi + where + Call: Codec, + { + /// TODO. + fn query_acceptable_payment_assets() -> Vec; + + /// TODO + fn query_weight_to_asset_fee(weight: Weight, asset: AssetId) -> Option; + + /// TODO + fn query_xcm_weight(message: Xcm) -> Result>; + } +} From 137d129a06444ef0a76afcfc7c62712181b043fc Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 26 Feb 2024 13:39:52 +0700 Subject: [PATCH 02/42] doc: `XcmPaymentRuntimeApi` --- .../xcm-payment-runtime-api/src/lib.rs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index b39bff828018..9bda1140ea80 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -23,18 +23,37 @@ use sp_std::vec::Vec; use sp_weights::Weight; use xcm::latest::{AssetId, Xcm}; sp_api::decl_runtime_apis! { - + /// A trait of XCM payment API. + /// + /// API provides functionality for obtaining + /// the weight required to execute an XCM message, + /// a list of accepted `AssetId` for payment for its + /// execution and the cost in the specified supported `AssetId`. + /// + /// To determine the execution weight of the calls required + /// for some instructions (for example, [`xcm::latest::Instruction::Transact`]) + /// `TransactionPaymentCallApi`can be used. pub trait XcmPaymentRuntimeApi where Call: Codec, { - /// TODO. + /// Returns a list of acceptable payment assets. fn query_acceptable_payment_assets() -> Vec; - /// TODO + /// Converts a weight into a fee for the specified `AssetId`. + /// Returns `None` if the `AssetId` isn't supported as a acceptable for the fee payment. + /// + /// # Arguments + /// + /// * `weight`: convertible `Weight`. + /// * `asset`: `AssetId`. fn query_weight_to_asset_fee(weight: Weight, asset: AssetId) -> Option; - /// TODO + /// Returns a weight needed to execute a XCM. + /// + /// # Arguments + /// + /// * `message`: `Xcm`. fn query_xcm_weight(message: Xcm) -> Result>; } } From c4b070bebb4c0f784e52dc114b498da7ac4dc3c4 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 26 Feb 2024 16:59:57 +0700 Subject: [PATCH 03/42] add prdoc --- prdoc/pr_XXXX.prdoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 prdoc/pr_XXXX.prdoc diff --git a/prdoc/pr_XXXX.prdoc b/prdoc/pr_XXXX.prdoc new file mode 100644 index 000000000000..3d4f2dcf08af --- /dev/null +++ b/prdoc/pr_XXXX.prdoc @@ -0,0 +1,19 @@ +# 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: "XCM payment API" + +doc: + - audience: Runtime Dev + description: | + A trait of XCM payment API was added. + API provides functionality for obtaining + the weight required to execute an XCM message, + a list of accepted `AssetId` for payment for its + execution and the cost in the specified supported `AssetId`. + +crates: + - name: xcm-payment-runtime-api + - name: rococo-runtime + - name: westend-runtime + From 6bc4e95c17aee347f897c89657601fd48a597624 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 27 Feb 2024 18:49:43 +0700 Subject: [PATCH 04/42] refactor: signatures for XcmPaymentRuntimeApi & mpl for roroco Runtime --- Cargo.lock | 1 + polkadot/node/service/src/fake_runtime_api.rs | 8 +- polkadot/runtime/rococo/src/lib.rs | 74 ++++++++++++------- .../xcm-payment-runtime-api/Cargo.toml | 8 +- .../xcm-payment-runtime-api/src/lib.rs | 36 +++++++-- 5 files changed, 85 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0346abf767e..90d3560515d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22531,6 +22531,7 @@ version = "1.0.0" dependencies = [ "frame-support", "parity-scale-codec", + "scale-info", "sp-api", "sp-runtime", "sp-std 14.0.0", diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index 86b5bb1dbdea..afba3a1c0063 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -41,7 +41,7 @@ use sp_runtime::{ use sp_version::RuntimeVersion; use sp_weights::Weight; use std::collections::BTreeMap; -use xcm::latest::{AssetId, Xcm}; +use xcm::{VersionedAssetId, VersionedXcm}; sp_api::decl_runtime_apis! { /// This runtime API is only implemented for the test runtime! pub trait GetLastTimestamp { @@ -401,15 +401,15 @@ sp_api::impl_runtime_apis! { impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { - fn query_acceptable_payment_assets() -> Vec { + fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_payment_runtime_api::Error> { unimplemented!() } - fn query_weight_to_asset_fee(_: Weight, _: AssetId) -> Option { + fn query_weight_to_asset_fee(_: Weight, _: VersionedAssetId) -> Result { unimplemented!() } - fn query_xcm_weight(_: Xcm) -> Result> { + fn query_xcm_weight(_: VersionedXcm) -> Result { unimplemented!() } } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 55d756fef05b..4f9e71e8fb52 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -98,7 +98,7 @@ use sp_staking::SessionIndex; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm::{latest::prelude::*, VersionedLocation}; +use xcm::{latest::prelude::*, IntoVersion, VersionedAssetId, VersionedLocation, VersionedXcm}; use xcm_builder::PayOverXcm; pub use frame_system::Call as SystemCall; @@ -123,6 +123,8 @@ use governance::{ pallet_custom_origins, AuctionAdmin, Fellows, GeneralAdmin, LeaseAdmin, Treasurer, TreasurySpender, }; +use xcm_executor::traits::WeightBounds; +use xcm_payment_runtime_api::Error as XcmPaymentError; #[cfg(test)] mod tests; @@ -217,7 +219,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal) + return Some(Ordering::Equal); } match (left, right) { @@ -378,10 +380,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -880,19 +884,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } | - RuntimeCall::Crowdloan { .. } | - RuntimeCall::Registrar { .. } | - RuntimeCall::Multisig(..) | - RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } + | RuntimeCall::Crowdloan { .. } + | RuntimeCall::Registrar { .. } + | RuntimeCall::Multisig(..) + | RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), @@ -1508,11 +1512,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None + return None; } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None + return None; } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1574,7 +1578,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()) + return Ok(Vec::new()); } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1603,7 +1607,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::info!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1) + return ::DbWeight::get().reads(1); } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1616,7 +1620,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()) + return Ok(()); } let key_ids = SessionKeys::key_ids(); @@ -1800,19 +1804,33 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { - fn query_acceptable_payment_assets() -> Vec { - vec![AssetId::Concrete(xcm_config::TokenLocation::get())] + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + if !matches!(xcm_version, 3 | 4) { + return Err(XcmPaymentError::UnhandledXcmVersion); + } + Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] + .into_iter() + .filter_map(|asset| asset.into_version(xcm_version).ok()) + .collect()) } - fn query_weight_to_asset_fee(weight: Weight, asset: AssetId) -> Option { - let local_asset = AssetId::Concrete(xcm_config::TokenLocation::get()); - if asset != local_asset { return None; } - Some(WeightToFee::weight_to_fee(&weight)) + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); + let asset = asset + .into_version(4) + .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + + if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + + Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: Xcm) -> Result> { - >::prepare(message) - .map(|wm| wm.weight_of()) + fn query_xcm_weight(message: VersionedXcm) -> Result { + <::Weigher as WeightBounds<_>>::weight(&mut message + .try_into() + .map_err(|_| XcmPaymentError::VersionedConversionFailed)? + ) + .map_err(|_| XcmPaymentError::WeightNotComputable) } } @@ -2527,7 +2545,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple(); diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml index edb07d72aaf3..9649dda841ba 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml @@ -4,9 +4,8 @@ version = "1.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" -homepage = "https://substrate.io" repository.workspace = true -description = "" +description = "XCM payment runtime API" readme = "README.md" [package.metadata.docs.rs] @@ -18,6 +17,10 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = ] } sp-api = { path = "../../../../substrate/primitives/api", default-features = false } +scale-info = { version = "2.10.0", default-features = false, features = [ + "derive", + "serde", +] } sp-std = { path = "../../../../substrate/primitives/std", default-features = false } sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false } sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } @@ -27,6 +30,7 @@ frame-support = { path = "../../../../substrate/frame/support", default-features default = ["std"] std = [ "codec/std", + "scale-info/std", "sp-api/std", "sp-std/std", "sp-runtime/std", diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index 9bda1140ea80..2c9b4e06f5eb 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -18,17 +18,19 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::Codec; +use codec::{Codec, Decode, Encode}; +use frame_support::pallet_prelude::TypeInfo; use sp_std::vec::Vec; use sp_weights::Weight; -use xcm::latest::{AssetId, Xcm}; +use xcm::{Version, VersionedAssetId, VersionedXcm}; + sp_api::decl_runtime_apis! { /// A trait of XCM payment API. /// /// API provides functionality for obtaining /// the weight required to execute an XCM message, /// a list of accepted `AssetId` for payment for its - /// execution and the cost in the specified supported `AssetId`. + /// execution and the cost in the specified supported one. /// /// To determine the execution weight of the calls required /// for some instructions (for example, [`xcm::latest::Instruction::Transact`]) @@ -38,7 +40,11 @@ sp_api::decl_runtime_apis! { Call: Codec, { /// Returns a list of acceptable payment assets. - fn query_acceptable_payment_assets() -> Vec; + /// + /// # Arguments + /// + /// * `xcm_version`: Version. + fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; /// Converts a weight into a fee for the specified `AssetId`. /// Returns `None` if the `AssetId` isn't supported as a acceptable for the fee payment. @@ -46,14 +52,28 @@ sp_api::decl_runtime_apis! { /// # Arguments /// /// * `weight`: convertible `Weight`. - /// * `asset`: `AssetId`. - fn query_weight_to_asset_fee(weight: Weight, asset: AssetId) -> Option; + /// * `asset`: `VersionedAssetId`. + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; /// Returns a weight needed to execute a XCM. /// /// # Arguments /// - /// * `message`: `Xcm`. - fn query_xcm_weight(message: Xcm) -> Result>; + /// * `message`: `VersionedXcm`. + fn query_xcm_weight(message: VersionedXcm) -> Result; } } + +#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] +pub enum Error { + #[codec(index = 0)] + Unimplemented, + #[codec(index = 1)] + VersionedConversionFailed, + #[codec(index = 2)] + WeightNotComputable, + /// XCM version not able to be handled. + UnhandledXcmVersion, + #[codec(index = 4)] + AssetNotFound, +} From c649ad2b04aeeace9398c54151af35e1246c2aef Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 27 Feb 2024 21:37:49 +0700 Subject: [PATCH 05/42] rename trait to `XcmPaymentApi` --- polkadot/node/service/src/fake_runtime_api.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 2 +- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index afba3a1c0063..34111d007beb 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -399,7 +399,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { + impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_payment_runtime_api::Error> { unimplemented!() diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4f9e71e8fb52..1591d37edc75 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1803,7 +1803,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_payment_runtime_api::XcmPaymentRuntimeApi for Runtime { + impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { if !matches!(xcm_version, 3 | 4) { return Err(XcmPaymentError::UnhandledXcmVersion); diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index 2c9b4e06f5eb..9246f641e992 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -35,7 +35,7 @@ sp_api::decl_runtime_apis! { /// To determine the execution weight of the calls required /// for some instructions (for example, [`xcm::latest::Instruction::Transact`]) /// `TransactionPaymentCallApi`can be used. - pub trait XcmPaymentRuntimeApi + pub trait XcmPaymentApi where Call: Codec, { From 1b93e2a3df34526456cca61ce847b2e499b234a8 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 27 Feb 2024 21:39:31 +0700 Subject: [PATCH 06/42] fix comment --- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index 9246f641e992..3ba98b7367b7 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -47,7 +47,6 @@ sp_api::decl_runtime_apis! { fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; /// Converts a weight into a fee for the specified `AssetId`. - /// Returns `None` if the `AssetId` isn't supported as a acceptable for the fee payment. /// /// # Arguments /// From 16d9d226956c46c1de9fe1cdbae0a206c5cd52c7 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 28 Feb 2024 16:05:40 +0700 Subject: [PATCH 07/42] doc: add `Error` description --- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index 3ba98b7367b7..ee4559fc2876 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -65,14 +65,18 @@ sp_api::decl_runtime_apis! { #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] pub enum Error { + /// An API part is unsupported. #[codec(index = 0)] Unimplemented, + /// Converting a versioned data structure from one version to another failed. #[codec(index = 1)] VersionedConversionFailed, + /// XCM message weight calculation failed. #[codec(index = 2)] WeightNotComputable, /// XCM version not able to be handled. UnhandledXcmVersion, + /// The given asset is not handled(as a fee payment). #[codec(index = 4)] AssetNotFound, } From a8337b9d5a0c29b54863f2ded871c242806ddc8b Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 28 Feb 2024 20:45:39 +0700 Subject: [PATCH 08/42] refactor --- Cargo.lock | 2 +- polkadot/runtime/rococo/src/lib.rs | 6 ++-- .../xcm-payment-runtime-api/Cargo.toml | 2 +- .../xcm-payment-runtime-api/src/lib.rs | 28 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90d3560515d5..0d89c7f645f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22527,7 +22527,7 @@ dependencies = [ [[package]] name = "xcm-payment-runtime-api" -version = "1.0.0" +version = "0.1.0" dependencies = [ "frame-support", "parity-scale-codec", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 1591d37edc75..f8d8370ae809 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1826,10 +1826,10 @@ sp_api::impl_runtime_apis! { } fn query_xcm_weight(message: VersionedXcm) -> Result { - <::Weigher as WeightBounds<_>>::weight(&mut message + let mut message = message .try_into() - .map_err(|_| XcmPaymentError::VersionedConversionFailed)? - ) + .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + ::Weigher::weight(&mut message) .map_err(|_| XcmPaymentError::WeightNotComputable) } } diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml index 9649dda841ba..38c95606ee39 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xcm-payment-runtime-api" -version = "1.0.0" +version = "0.1.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index ee4559fc2876..ef55dda51a7f 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -27,14 +27,14 @@ use xcm::{Version, VersionedAssetId, VersionedXcm}; sp_api::decl_runtime_apis! { /// A trait of XCM payment API. /// - /// API provides functionality for obtaining - /// the weight required to execute an XCM message, - /// a list of accepted `AssetId` for payment for its - /// execution and the cost in the specified supported one. + /// API provides functionality for obtaining: /// - /// To determine the execution weight of the calls required - /// for some instructions (for example, [`xcm::latest::Instruction::Transact`]) - /// `TransactionPaymentCallApi`can be used. + /// * the weight required to execute an XCM message, + /// * a list of acceptable `AssetId`s for message execution payment, + /// * the cost of the weight in the specified acceptable `AssetId`. + /// + /// To determine the execution weight of the calls required for + /// [`xcm::latest::Instruction::Transact`] instruction, `TransactionPaymentCallApi` can be used. pub trait XcmPaymentApi where Call: Codec, @@ -46,20 +46,20 @@ sp_api::decl_runtime_apis! { /// * `xcm_version`: Version. fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; - /// Converts a weight into a fee for the specified `AssetId`. + /// Returns a weight needed to execute a XCM. /// /// # Arguments /// - /// * `weight`: convertible `Weight`. - /// * `asset`: `VersionedAssetId`. - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; + /// * `message`: `VersionedXcm`. + fn query_xcm_weight(message: VersionedXcm) -> Result; - /// Returns a weight needed to execute a XCM. + /// Converts a weight into a fee for the specified `AssetId`. /// /// # Arguments /// - /// * `message`: `VersionedXcm`. - fn query_xcm_weight(message: VersionedXcm) -> Result; + /// * `weight`: convertible `Weight`. + /// * `asset`: `VersionedAssetId`. + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; } } From 7b17ece26afa32dce943154ed0d959e961f584bf Mon Sep 17 00:00:00 2001 From: PraetorP Date: Thu, 29 Feb 2024 12:38:42 +0700 Subject: [PATCH 09/42] format non context diffs --- polkadot/node/service/Cargo.toml | 5 ++++- polkadot/runtime/rococo/Cargo.toml | 13 +++-------- polkadot/runtime/rococo/src/lib.rs | 36 ++++++++++++++---------------- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index f6f6d72ea781..890b4a9ba7e1 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -223,7 +223,10 @@ try-runtime = [ "sp-runtime/try-runtime", "westend-runtime?/try-runtime", ] -fast-runtime = ["rococo-runtime?/fast-runtime", "westend-runtime?/fast-runtime"] +fast-runtime = [ + "rococo-runtime?/fast-runtime", + "westend-runtime?/fast-runtime", +] malus = ["full-node"] runtime-metrics = [ diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 860488bc053a..1ca975e6a433 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -11,13 +11,8 @@ license.workspace = true workspace = true [dependencies] -parity-scale-codec = { version = "3.6.1", default-features = false, features = [ - "derive", - "max-encoded-len", -] } -scale-info = { version = "2.10.0", default-features = false, features = [ - "derive", -] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } log = { workspace = true } serde = { workspace = true } serde_derive = { optional = true, workspace = true } @@ -82,9 +77,7 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur pallet-session = { path = "../../../substrate/frame/session", default-features = false } pallet-society = { path = "../../../substrate/frame/society", default-features = false } pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ - "tuples-96", -] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } pallet-staking = { path = "../../../substrate/frame/staking", default-features = false } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index f8d8370ae809..55e30dd5c487 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -219,7 +219,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal); + return Some(Ordering::Equal) } match (left, right) { @@ -380,12 +380,10 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => { - self.para_assignment.as_ref() - }, - <::Public>::ID => { - self.authority_discovery.as_ref() - }, + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -884,19 +882,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } - | RuntimeCall::Crowdloan { .. } - | RuntimeCall::Registrar { .. } - | RuntimeCall::Multisig(..) - | RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } | + RuntimeCall::Crowdloan { .. } | + RuntimeCall::Registrar { .. } | + RuntimeCall::Multisig(..) | + RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), @@ -1512,11 +1510,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None; + return None } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None; + return None } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1578,7 +1576,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()); + return Ok(Vec::new()) } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1607,7 +1605,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::info!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1); + return ::DbWeight::get().reads(1) } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1620,7 +1618,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()); + return Ok(()) } let key_ids = SessionKeys::key_ids(); From f6201bf453eac7ac6bb119ec83e9722ef36b0021 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Thu, 29 Feb 2024 13:13:32 +0700 Subject: [PATCH 10/42] feat: add `XcmPaymentApi` into `Wesend` --- Cargo.lock | 1 + polkadot/runtime/rococo/Cargo.toml | 1 + polkadot/runtime/westend/Cargo.toml | 1 + polkadot/runtime/westend/src/lib.rs | 38 +++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d89c7f645f9..f39ab8a503f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22052,6 +22052,7 @@ dependencies = [ "tiny-keccak", "tokio", "westend-runtime-constants", + "xcm-payment-runtime-api", ] [[package]] diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 1ca975e6a433..5769300944b4 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -105,6 +105,7 @@ xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } + [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } keyring = { package = "sp-keyring", path = "../../../substrate/primitives/keyring" } diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 6899edeeaeb8..482830a34dd5 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -114,6 +114,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } +xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } [dev-dependencies] hex-literal = "0.4.1" diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 45bbd0260e5e..a52438b1f26c 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -35,7 +35,7 @@ use frame_support::{ InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage, ProcessMessageError, WithdrawReasons, }, - weights::{ConstantMultiplier, WeightMeter}, + weights::{ConstantMultiplier, WeightMeter, WeightToFee as _}, PalletId, }; use frame_system::{EnsureRoot, EnsureSigned}; @@ -102,10 +102,13 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::{ latest::{InteriorLocation, Junction, Junction::PalletInstance}, - VersionedLocation, + IntoVersion, VersionedAssetId, VersionedLocation, VersionedXcm, }; use xcm_builder::PayOverXcm; +use xcm_executor::traits::WeightBounds; +use xcm_payment_runtime_api::Error as XcmPaymentError; + pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::{Call as EPMCall, GeometricDepositBase}; @@ -2255,6 +2258,37 @@ sp_api::impl_runtime_apis! { } } + impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + if !matches!(xcm_version, 3 | 4) { + return Err(XcmPaymentError::UnhandledXcmVersion); + } + Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] + .into_iter() + .filter_map(|asset| asset.into_version(xcm_version).ok()) + .collect()) + } + + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); + let asset = asset + .into_version(4) + .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + + if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + + Ok(WeightToFee::weight_to_fee(&weight)) + } + + fn query_xcm_weight(message: VersionedXcm) -> Result { + let mut message = message + .try_into() + .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + ::Weigher::weight(&mut message) + .map_err(|_| XcmPaymentError::WeightNotComputable) + } + } + impl pallet_nomination_pools_runtime_api::NominationPoolsApi< Block, AccountId, From 55b1a03277ed50e7aa0dc09a4418ab0051206745 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Thu, 29 Feb 2024 13:23:09 +0700 Subject: [PATCH 11/42] fix non context diffs --- polkadot/runtime/rococo/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 55e30dd5c487..c6b0c478602c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2528,7 +2528,6 @@ sp_api::impl_runtime_apis! { build_config::(config) } } - } #[cfg(all(test, feature = "try-runtime"))] @@ -2543,7 +2542,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return; + return } sp_tracing::try_init_simple(); From 707f0b01ff40f0aee389c68694e8776671a5031f Mon Sep 17 00:00:00 2001 From: PraetorP Date: Thu, 29 Feb 2024 13:32:05 +0700 Subject: [PATCH 12/42] fix missed feature --- polkadot/runtime/westend/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 482830a34dd5..e3ca0a77e8cb 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -229,6 +229,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "xcm-payment-runtime-api/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", From a27c70f539a42e9a5c4e39ec75939e05bc6ab5d7 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 5 Mar 2024 17:22:34 +0700 Subject: [PATCH 13/42] refactor --- polkadot/runtime/rococo/src/lib.rs | 56 ++++++++++++----------- polkadot/runtime/westend/src/lib.rs | 69 +++++++++++++++-------------- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index c6b0c478602c..58ebd2264661 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -124,7 +124,7 @@ use governance::{ TreasurySpender, }; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentError; +use xcm_payment_runtime_api::Error as XcmPaymentApiError; #[cfg(test)] mod tests; @@ -219,7 +219,7 @@ pub struct OriginPrivilegeCmp; impl PrivilegeCmp for OriginPrivilegeCmp { fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { if left == right { - return Some(Ordering::Equal) + return Some(Ordering::Equal); } match (left, right) { @@ -380,10 +380,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -882,19 +884,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } | - RuntimeCall::Crowdloan { .. } | - RuntimeCall::Registrar { .. } | - RuntimeCall::Multisig(..) | - RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } + | RuntimeCall::Crowdloan { .. } + | RuntimeCall::Registrar { .. } + | RuntimeCall::Multisig(..) + | RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), @@ -1510,11 +1512,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None + return None; } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None + return None; } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1576,7 +1578,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()) + return Ok(Vec::new()); } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1605,7 +1607,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::info!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1) + return ::DbWeight::get().reads(1); } log::trace!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1618,7 +1620,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()) + return Ok(()); } let key_ids = SessionKeys::key_ids(); @@ -1802,9 +1804,9 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { - return Err(XcmPaymentError::UnhandledXcmVersion); + return Err(XcmPaymentApiError::UnhandledXcmVersion); } Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] .into_iter() @@ -1812,23 +1814,23 @@ sp_api::impl_runtime_apis! { .collect()) } - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); let asset = asset .into_version(4) - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); } Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm) -> Result { let mut message = message .try_into() - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentError::WeightNotComputable) + .map_err(|_| XcmPaymentApiError::WeightNotComputable) } } @@ -2542,7 +2544,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple(); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index a52438b1f26c..ae833435071b 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -107,7 +107,7 @@ use xcm::{ use xcm_builder::PayOverXcm; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentError; +use xcm_payment_runtime_api::Error as XcmPaymentApiError; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; @@ -442,10 +442,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -1052,11 +1054,12 @@ impl InstanceFilter for ProxyType { ProxyType::Staking => { matches!( c, - RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | - RuntimeCall::FastUnstake(..) | - RuntimeCall::VoterList(..) | - RuntimeCall::NominationPools(..) + RuntimeCall::Staking(..) + | RuntimeCall::Session(..) + | RuntimeCall::Utility(..) + | RuntimeCall::FastUnstake(..) + | RuntimeCall::VoterList(..) + | RuntimeCall::NominationPools(..) ) }, ProxyType::NominationPools => { @@ -1072,24 +1075,24 @@ impl InstanceFilter for ProxyType { ProxyType::Governance => matches!( c, // OpenGov calls - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions(..) | - RuntimeCall::Crowdloan(..) | - RuntimeCall::Registrar(..) | - RuntimeCall::Slots(..) + RuntimeCall::Auctions(..) + | RuntimeCall::Crowdloan(..) + | RuntimeCall::Registrar(..) + | RuntimeCall::Slots(..) ), } } @@ -1592,11 +1595,11 @@ pub mod migrations { let now = frame_system::Pallet::::block_number(); let lease = slots::Pallet::::lease(para); if lease.is_empty() { - return None + return None; } // Lease not yet started, ignore: if lease.iter().any(Option::is_none) { - return None + return None; } let (index, _) = as Leaser>::lease_period_index(now)?; @@ -1618,7 +1621,7 @@ pub mod migrations { fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); - return Ok(Vec::new()) + return Ok(Vec::new()); } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); @@ -1647,7 +1650,7 @@ pub mod migrations { fn on_runtime_upgrade() -> Weight { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!("Skipping session keys upgrade: already applied"); - return ::DbWeight::get().reads(1) + return ::DbWeight::get().reads(1); } log::info!("Upgrading session keys"); Session::upgrade_keys::(transform_session_keys); @@ -1660,7 +1663,7 @@ pub mod migrations { ) -> Result<(), sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)"); - return Ok(()) + return Ok(()); } let key_ids = SessionKeys::key_ids(); @@ -2259,9 +2262,9 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentError> { + fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { - return Err(XcmPaymentError::UnhandledXcmVersion); + return Err(XcmPaymentApiError::UnhandledXcmVersion); } Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())] .into_iter() @@ -2269,23 +2272,23 @@ sp_api::impl_runtime_apis! { .collect()) } - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result { let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into()); let asset = asset .into_version(4) - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); } + if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); } Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm) -> Result { let mut message = message .try_into() - .map_err(|_| XcmPaymentError::VersionedConversionFailed)?; + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentError::WeightNotComputable) + .map_err(|_| XcmPaymentApiError::WeightNotComputable) } } @@ -2609,7 +2612,7 @@ mod remote_tests { #[tokio::test] async fn run_migrations() { if var("RUN_MIGRATION_TESTS").is_err() { - return + return; } sp_tracing::try_init_simple(); From f45f9dd023b803407e72a775f727752e80b48501 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Thu, 7 Mar 2024 15:38:51 +0700 Subject: [PATCH 14/42] cargo fmt --- polkadot/runtime/rococo/src/lib.rs | 24 ++++++++---------- polkadot/runtime/westend/src/lib.rs | 39 +++++++++++++---------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 58ebd2264661..bd4b8cd2dd76 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -380,12 +380,10 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => { - self.para_assignment.as_ref() - }, - <::Public>::ID => { - self.authority_discovery.as_ref() - }, + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -884,19 +882,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } - | RuntimeCall::Crowdloan { .. } - | RuntimeCall::Registrar { .. } - | RuntimeCall::Multisig(..) - | RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } | + RuntimeCall::Crowdloan { .. } | + RuntimeCall::Registrar { .. } | + RuntimeCall::Multisig(..) | + RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index ae833435071b..41d0460f3cc7 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -442,12 +442,10 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => { - self.para_assignment.as_ref() - }, - <::Public>::ID => { - self.authority_discovery.as_ref() - }, + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -1054,12 +1052,11 @@ impl InstanceFilter for ProxyType { ProxyType::Staking => { matches!( c, - RuntimeCall::Staking(..) - | RuntimeCall::Session(..) - | RuntimeCall::Utility(..) - | RuntimeCall::FastUnstake(..) - | RuntimeCall::VoterList(..) - | RuntimeCall::NominationPools(..) + RuntimeCall::Staking(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::FastUnstake(..) | + RuntimeCall::VoterList(..) | + RuntimeCall::NominationPools(..) ) }, ProxyType::NominationPools => { @@ -1075,24 +1072,24 @@ impl InstanceFilter for ProxyType { ProxyType::Governance => matches!( c, // OpenGov calls - RuntimeCall::ConvictionVoting(..) - | RuntimeCall::Referenda(..) - | RuntimeCall::Whitelist(..) + RuntimeCall::ConvictionVoting(..) | + RuntimeCall::Referenda(..) | + RuntimeCall::Whitelist(..) ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions(..) - | RuntimeCall::Crowdloan(..) - | RuntimeCall::Registrar(..) - | RuntimeCall::Slots(..) + RuntimeCall::Auctions(..) | + RuntimeCall::Crowdloan(..) | + RuntimeCall::Registrar(..) | + RuntimeCall::Slots(..) ), } } From 18e54e7a7315653136ffaf91752f51d14173cf69 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 18 Mar 2024 15:01:37 +0100 Subject: [PATCH 15/42] feat(xcm-fee-payment-api): add query_delivery_fees function --- polkadot/node/service/src/fake_runtime_api.rs | 7 +++++-- polkadot/runtime/rococo/src/lib.rs | 16 +++++++++++++++- polkadot/runtime/westend/src/lib.rs | 14 ++++++++++++++ .../xcm-payment-runtime-api/Cargo.toml | 1 + .../xcm-payment-runtime-api/src/lib.rs | 14 +++++++++++++- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index 34111d007beb..15c245829b09 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -41,7 +41,7 @@ use sp_runtime::{ use sp_version::RuntimeVersion; use sp_weights::Weight; use std::collections::BTreeMap; -use xcm::{VersionedAssetId, VersionedXcm}; +use xcm::{VersionedAssetId, VersionedXcm, VersionedLocation, VersionedAssets}; sp_api::decl_runtime_apis! { /// This runtime API is only implemented for the test runtime! pub trait GetLastTimestamp { @@ -400,7 +400,6 @@ sp_api::impl_runtime_apis! { } impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_payment_runtime_api::Error> { unimplemented!() } @@ -412,5 +411,9 @@ sp_api::impl_runtime_apis! { fn query_xcm_weight(_: VersionedXcm) -> Result { unimplemented!() } + + fn query_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result { + unimplemented!() + } } } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index bd4b8cd2dd76..61d00cfdd013 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -98,7 +98,7 @@ use sp_staking::SessionIndex; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm::{latest::prelude::*, IntoVersion, VersionedAssetId, VersionedLocation, VersionedXcm}; +use xcm::{latest::prelude::*, IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; use xcm_builder::PayOverXcm; pub use frame_system::Call as SystemCall; @@ -1830,6 +1830,20 @@ sp_api::impl_runtime_apis! { ::Weigher::weight(&mut message) .map_err(|_| XcmPaymentApiError::WeightNotComputable) } + + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { + let destination = destination + .try_into() + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; + let message = message + .try_into() + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; + let (_, fees) = xcm_config::XcmRouter::validate(&mut Some(destination), &mut Some(message)).map_err(|error| { + log::error!("Error when querying delivery fees: {:?}", error); + XcmPaymentApiError::Unroutable + })?; + Ok(VersionedAssets::from(fees)) + } } impl sp_api::Metadata for Runtime { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 41d0460f3cc7..5a4c4e7fdc39 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2287,6 +2287,20 @@ sp_api::impl_runtime_apis! { ::Weigher::weight(&mut message) .map_err(|_| XcmPaymentApiError::WeightNotComputable) } + + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { + let destination = destination + .try_into() + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; + let message = message + .try_into() + .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; + let (_, fees) = xcm_config::XcmRouter::validate(&mut Some(destination), &mut Some(message)).map_err(|error| { + log::error!("Error when querying delivery fees: {:?}", error); + XcmPaymentApiError::Unroutable + })?; + Ok(VersionedAssets::from(fees)) + } } impl pallet_nomination_pools_runtime_api::NominationPoolsApi< diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml index 38c95606ee39..c551e7c2edc2 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml @@ -26,6 +26,7 @@ sp-runtime = { path = "../../../../substrate/primitives/runtime", default-featur sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } xcm = { package = "staging-xcm", path = "../..", default-features = false } frame-support = { path = "../../../../substrate/frame/support", default-features = false } + [features] default = ["std"] std = [ diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index ef55dda51a7f..e5af1d7048be 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -22,7 +22,7 @@ use codec::{Codec, Decode, Encode}; use frame_support::pallet_prelude::TypeInfo; use sp_std::vec::Vec; use sp_weights::Weight; -use xcm::{Version, VersionedAssetId, VersionedXcm}; +use xcm::{Version, VersionedAssetId, VersionedXcm, VersionedLocation, VersionedAssets}; sp_api::decl_runtime_apis! { /// A trait of XCM payment API. @@ -60,6 +60,16 @@ sp_api::decl_runtime_apis! { /// * `weight`: convertible `Weight`. /// * `asset`: `VersionedAssetId`. fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> 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<()>) -> Result; } } @@ -79,4 +89,6 @@ pub enum Error { /// The given asset is not handled(as a fee payment). #[codec(index = 4)] AssetNotFound, + #[codec(index = 5)] + Unroutable, } From e3486021e2f612c9f3eff442cf24924f1650013a Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:31:07 +0700 Subject: [PATCH 16/42] Update polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md Co-authored-by: Francisco Aguirre --- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md index 4eaddae1786e..811207fd8c0f 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md @@ -1,2 +1 @@ - License: Apache-2.0 From fc06767273cc384e7c8d5378c000cbbc0209eb14 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 13:43:16 +0700 Subject: [PATCH 17/42] refactor: add missed imports, fmt, add xcm api errors log --- polkadot/node/service/src/fake_runtime_api.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 10 ++++++++-- polkadot/runtime/westend/src/lib.rs | 9 ++++++--- .../xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index 15c245829b09..e280e8255bf9 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -41,7 +41,7 @@ use sp_runtime::{ use sp_version::RuntimeVersion; use sp_weights::Weight; use std::collections::BTreeMap; -use xcm::{VersionedAssetId, VersionedXcm, VersionedLocation, VersionedAssets}; +use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; sp_api::decl_runtime_apis! { /// This runtime API is only implemented for the test runtime! pub trait GetLastTimestamp { diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 61d00cfdd013..15cc4a5e0037 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -98,7 +98,10 @@ use sp_staking::SessionIndex; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm::{latest::prelude::*, IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; +use xcm::{ + latest::prelude::*, IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, + VersionedXcm, +}; use xcm_builder::PayOverXcm; pub use frame_system::Call as SystemCall; @@ -1828,7 +1831,10 @@ sp_api::impl_runtime_apis! { .try_into() .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentApiError::WeightNotComputable) + .map_err(|error| { + log::error!("Error when querying XCM weight: {:?}", error); + XcmPaymentApiError::WeightNotComputable + }) } fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5a4c4e7fdc39..2882b0201aac 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -101,8 +101,8 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::{ - latest::{InteriorLocation, Junction, Junction::PalletInstance}, - IntoVersion, VersionedAssetId, VersionedLocation, VersionedXcm, + latest::prelude::*, IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, + VersionedXcm, }; use xcm_builder::PayOverXcm; @@ -2285,7 +2285,10 @@ sp_api::impl_runtime_apis! { .try_into() .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; ::Weigher::weight(&mut message) - .map_err(|_| XcmPaymentApiError::WeightNotComputable) + .map_err(|error| { + log::error!("Error when querying XCM weight: {:?}", error); + XcmPaymentApiError::WeightNotComputable + }) } fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index e5af1d7048be..a1fea6bcc5bb 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -22,7 +22,7 @@ use codec::{Codec, Decode, Encode}; use frame_support::pallet_prelude::TypeInfo; use sp_std::vec::Vec; use sp_weights::Weight; -use xcm::{Version, VersionedAssetId, VersionedXcm, VersionedLocation, VersionedAssets}; +use xcm::{Version, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; sp_api::decl_runtime_apis! { /// A trait of XCM payment API. From 60a88a6709a3a4e7696788c508f14795b12c7258 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 13:48:28 +0700 Subject: [PATCH 18/42] number assigned to the `prdoc` --- prdoc/{pr_XXXX.prdoc => pr_3607.prdoc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/{pr_XXXX.prdoc => pr_3607.prdoc} (100%) diff --git a/prdoc/pr_XXXX.prdoc b/prdoc/pr_3607.prdoc similarity index 100% rename from prdoc/pr_XXXX.prdoc rename to prdoc/pr_3607.prdoc From fee8d7b6bd06fad6dbc8c3bb1aa68bcd26357571 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 13:56:28 +0700 Subject: [PATCH 19/42] remove unused import --- polkadot/runtime/westend/src/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/runtime/westend/src/tests.rs b/polkadot/runtime/westend/src/tests.rs index 9f9963160590..bdd599d2b752 100644 --- a/polkadot/runtime/westend/src/tests.rs +++ b/polkadot/runtime/westend/src/tests.rs @@ -21,7 +21,6 @@ use std::collections::HashSet; use crate::*; use frame_support::traits::WhitelistedStorageKeys; use sp_core::hexdisplay::HexDisplay; -use xcm::latest::prelude::*; #[test] fn remove_keys_weight_is_sensible() { From cceafd47baec44b0df1f8ee6e9c81921395b8337 Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:30:47 +0700 Subject: [PATCH 20/42] Update polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs Co-authored-by: Francisco Aguirre --- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index a1fea6bcc5bb..41cb1032cf90 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -85,6 +85,7 @@ pub enum Error { #[codec(index = 2)] WeightNotComputable, /// XCM version not able to be handled. + #[codec(index = 3)] UnhandledXcmVersion, /// The given asset is not handled(as a fee payment). #[codec(index = 4)] From 618f17ff2b041b666b135c5788966b9b756bd44e Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:32:30 +0700 Subject: [PATCH 21/42] Update prdoc/pr_3607.prdoc Co-authored-by: Francisco Aguirre --- prdoc/pr_3607.prdoc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_3607.prdoc b/prdoc/pr_3607.prdoc index 3d4f2dcf08af..86bf780f5822 100644 --- a/prdoc/pr_3607.prdoc +++ b/prdoc/pr_3607.prdoc @@ -6,11 +6,18 @@ title: "XCM payment API" doc: - audience: Runtime Dev description: | - A trait of XCM payment API was added. - API provides functionality for obtaining - the weight required to execute an XCM message, - a list of accepted `AssetId` for payment for its - execution and the cost in the specified supported `AssetId`. + A runtime API was added for estimating the fees required for XCM execution and delivery. + This is the basic building block needed for UIs to accurately estimate fees. + An example implementation is shown in the PR. Ideally it's simple to implement, you only need to call existing parts of your XCM config. + The API looks like so: + ```rust + fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; + fn query_xcm_weight(message: VersionedXcm) -> Result; + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result; + ``` + The first three relate to XCM execution fees, given an XCM, you can query its weight, then which assets are acceptable for buying weight and convert weight to a number of those assets. + The last one takes in a destination and a message you want to send from the runtime you're executing this on, it will give you the delivery fees. crates: - name: xcm-payment-runtime-api From 4a831473f6fe26845aee4fcd630410ea52434028 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 17:22:31 +0700 Subject: [PATCH 22/42] rename crate --- Cargo.lock | 8 ++-- polkadot/node/service/Cargo.toml | 7 +-- polkadot/node/service/src/fake_runtime_api.rs | 10 ++--- polkadot/runtime/rococo/Cargo.toml | 17 +++++--- polkadot/runtime/rococo/src/lib.rs | 28 ++++++------ polkadot/runtime/westend/Cargo.toml | 17 +++++--- polkadot/runtime/westend/src/lib.rs | 43 ++++++++++--------- .../xcm-payment-runtime-api/Cargo.toml | 4 +- prdoc/pr_3607.prdoc | 4 +- 9 files changed, 77 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f39ab8a503f6..f377eb54bde4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13578,7 +13578,7 @@ dependencies = [ "tracing-gum", "westend-runtime", "westend-runtime-constants", - "xcm-payment-runtime-api", + "xcm-fee-payment-runtime-api", ] [[package]] @@ -15159,7 +15159,7 @@ dependencies = [ "substrate-wasm-builder", "tiny-keccak", "tokio", - "xcm-payment-runtime-api", + "xcm-fee-payment-runtime-api", ] [[package]] @@ -22052,7 +22052,7 @@ dependencies = [ "tiny-keccak", "tokio", "westend-runtime-constants", - "xcm-payment-runtime-api", + "xcm-fee-payment-runtime-api", ] [[package]] @@ -22527,7 +22527,7 @@ dependencies = [ ] [[package]] -name = "xcm-payment-runtime-api" +name = "xcm-fee-payment-runtime-api" version = "0.1.0" dependencies = [ "frame-support", diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 890b4a9ba7e1..d37dc8e3e7c1 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -144,7 +144,7 @@ polkadot-statement-distribution = { path = "../network/statement-distribution", xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } [dev-dependencies] polkadot-test-client = { path = "../test/client" } @@ -223,10 +223,7 @@ try-runtime = [ "sp-runtime/try-runtime", "westend-runtime?/try-runtime", ] -fast-runtime = [ - "rococo-runtime?/fast-runtime", - "westend-runtime?/fast-runtime", -] +fast-runtime = ["rococo-runtime?/fast-runtime", "westend-runtime?/fast-runtime"] malus = ["full-node"] runtime-metrics = [ diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index e280e8255bf9..f014fa32c14d 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -399,20 +399,20 @@ sp_api::impl_runtime_apis! { } } - impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { - fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_payment_runtime_api::Error> { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { + fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_fee_payment_runtime_api::Error> { unimplemented!() } - fn query_weight_to_asset_fee(_: Weight, _: VersionedAssetId) -> Result { + fn query_weight_to_asset_fee(_: Weight, _: VersionedAssetId) -> Result { unimplemented!() } - fn query_xcm_weight(_: VersionedXcm) -> Result { + fn query_xcm_weight(_: VersionedXcm) -> Result { unimplemented!() } - fn query_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result { + fn query_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result { unimplemented!() } } diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 5769300944b4..4416bcee55d7 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -11,8 +11,13 @@ license.workspace = true workspace = true [dependencies] -parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = [ + "derive", + "max-encoded-len", +] } +scale-info = { version = "2.10.0", default-features = false, features = [ + "derive", +] } log = { workspace = true } serde = { workspace = true } serde_derive = { optional = true, workspace = true } @@ -77,7 +82,9 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur pallet-session = { path = "../../../substrate/frame/session", default-features = false } pallet-society = { path = "../../../substrate/frame/society", default-features = false } pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ + "tuples-96", +] } pallet-staking = { path = "../../../substrate/frame/staking", default-features = false } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } @@ -104,7 +111,7 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } @@ -210,7 +217,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "xcm-payment-runtime-api/std", + "xcm-fee-payment-runtime-api/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 15cc4a5e0037..9dafce56004d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -127,7 +127,7 @@ use governance::{ TreasurySpender, }; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentApiError; +use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; #[cfg(test)] mod tests; @@ -383,10 +383,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -885,19 +887,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } | - RuntimeCall::Crowdloan { .. } | - RuntimeCall::Registrar { .. } | - RuntimeCall::Multisig(..) | - RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } + | RuntimeCall::Crowdloan { .. } + | RuntimeCall::Registrar { .. } + | RuntimeCall::Multisig(..) + | RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), @@ -1804,7 +1806,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { return Err(XcmPaymentApiError::UnhandledXcmVersion); diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index e3ca0a77e8cb..3fc204a34995 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -12,8 +12,13 @@ workspace = true [dependencies] bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] } -parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = [ + "derive", + "max-encoded-len", +] } +scale-info = { version = "2.10.0", default-features = false, features = [ + "derive", +] } log = { workspace = true } rustc-hex = { version = "2.1.0", default-features = false } serde = { workspace = true } @@ -45,7 +50,9 @@ sp-npos-elections = { path = "../../../substrate/primitives/npos-elections", def frame-election-provider-support = { path = "../../../substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "../../../substrate/frame/executive", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ + "tuples-96", +] } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } westend-runtime-constants = { package = "westend-runtime-constants", path = "constants", default-features = false } @@ -114,7 +121,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-payment-runtime-api = { package = "xcm-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } [dev-dependencies] hex-literal = "0.4.1" @@ -229,7 +236,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "xcm-payment-runtime-api/std", + "xcm-fee-payment-runtime-api/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 2882b0201aac..30e5ed6251a3 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -107,7 +107,7 @@ use xcm::{ use xcm_builder::PayOverXcm; use xcm_executor::traits::WeightBounds; -use xcm_payment_runtime_api::Error as XcmPaymentApiError; +use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; @@ -442,10 +442,12 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => - self.para_assignment.as_ref(), - <::Public>::ID => - self.authority_discovery.as_ref(), + <::Public>::ID => { + self.para_assignment.as_ref() + }, + <::Public>::ID => { + self.authority_discovery.as_ref() + }, <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -1052,11 +1054,12 @@ impl InstanceFilter for ProxyType { ProxyType::Staking => { matches!( c, - RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | - RuntimeCall::FastUnstake(..) | - RuntimeCall::VoterList(..) | - RuntimeCall::NominationPools(..) + RuntimeCall::Staking(..) + | RuntimeCall::Session(..) + | RuntimeCall::Utility(..) + | RuntimeCall::FastUnstake(..) + | RuntimeCall::VoterList(..) + | RuntimeCall::NominationPools(..) ) }, ProxyType::NominationPools => { @@ -1072,24 +1075,24 @@ impl InstanceFilter for ProxyType { ProxyType::Governance => matches!( c, // OpenGov calls - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | - RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions(..) | - RuntimeCall::Crowdloan(..) | - RuntimeCall::Registrar(..) | - RuntimeCall::Slots(..) + RuntimeCall::Auctions(..) + | RuntimeCall::Crowdloan(..) + | RuntimeCall::Registrar(..) + | RuntimeCall::Slots(..) ), } } @@ -2258,7 +2261,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { return Err(XcmPaymentApiError::UnhandledXcmVersion); diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml index c551e7c2edc2..dcf1b2beda80 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "xcm-payment-runtime-api" +name = "xcm-fee-payment-runtime-api" version = "0.1.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" repository.workspace = true -description = "XCM payment runtime API" +description = "XCM fee payment runtime API" readme = "README.md" [package.metadata.docs.rs] diff --git a/prdoc/pr_3607.prdoc b/prdoc/pr_3607.prdoc index 86bf780f5822..c25c9bbc42f7 100644 --- a/prdoc/pr_3607.prdoc +++ b/prdoc/pr_3607.prdoc @@ -1,7 +1,7 @@ # 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: "XCM payment API" +title: "XCM fee payment API" doc: - audience: Runtime Dev @@ -20,7 +20,7 @@ doc: The last one takes in a destination and a message you want to send from the runtime you're executing this on, it will give you the delivery fees. crates: - - name: xcm-payment-runtime-api + - name: xcm-fee-payment-runtime-api - name: rococo-runtime - name: westend-runtime From e7c752a095724336225834fafb71b0058dcda9e3 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 17:49:27 +0700 Subject: [PATCH 23/42] revert changes --- polkadot/runtime/rococo/Cargo.toml | 13 +++------- polkadot/runtime/rococo/src/lib.rs | 24 ++++++++---------- polkadot/runtime/westend/Cargo.toml | 13 +++------- polkadot/runtime/westend/src/lib.rs | 39 +++++++++++++---------------- 4 files changed, 35 insertions(+), 54 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 4416bcee55d7..deee1c19b8cf 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -11,13 +11,8 @@ license.workspace = true workspace = true [dependencies] -parity-scale-codec = { version = "3.6.1", default-features = false, features = [ - "derive", - "max-encoded-len", -] } -scale-info = { version = "2.10.0", default-features = false, features = [ - "derive", -] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } log = { workspace = true } serde = { workspace = true } serde_derive = { optional = true, workspace = true } @@ -82,9 +77,7 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur pallet-session = { path = "../../../substrate/frame/session", default-features = false } pallet-society = { path = "../../../substrate/frame/society", default-features = false } pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ - "tuples-96", -] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } pallet-staking = { path = "../../../substrate/frame/staking", default-features = false } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 9dafce56004d..4e7047c3b947 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -383,12 +383,10 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => { - self.para_assignment.as_ref() - }, - <::Public>::ID => { - self.authority_discovery.as_ref() - }, + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -887,19 +885,19 @@ impl InstanceFilter for ProxyType { ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions { .. } - | RuntimeCall::Crowdloan { .. } - | RuntimeCall::Registrar { .. } - | RuntimeCall::Multisig(..) - | RuntimeCall::Slots { .. } + RuntimeCall::Auctions { .. } | + RuntimeCall::Crowdloan { .. } | + RuntimeCall::Registrar { .. } | + RuntimeCall::Multisig(..) | + RuntimeCall::Slots { .. } ), ProxyType::Society => matches!(c, RuntimeCall::Society(..)), ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)), diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 3fc204a34995..c9ebbd02b427 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -12,13 +12,8 @@ workspace = true [dependencies] bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] } -parity-scale-codec = { version = "3.6.1", default-features = false, features = [ - "derive", - "max-encoded-len", -] } -scale-info = { version = "2.10.0", default-features = false, features = [ - "derive", -] } +parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } log = { workspace = true } rustc-hex = { version = "2.1.0", default-features = false } serde = { workspace = true } @@ -50,9 +45,7 @@ sp-npos-elections = { path = "../../../substrate/primitives/npos-elections", def frame-election-provider-support = { path = "../../../substrate/frame/election-provider-support", default-features = false } frame-executive = { path = "../../../substrate/frame/executive", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [ - "tuples-96", -] } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } westend-runtime-constants = { package = "westend-runtime-constants", path = "constants", default-features = false } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 30e5ed6251a3..c1f47242ea13 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -442,12 +442,10 @@ impl OpaqueKeys for OldSessionKeys { <::Public>::ID => self.babe.as_ref(), sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(), <::Public>::ID => self.para_validator.as_ref(), - <::Public>::ID => { - self.para_assignment.as_ref() - }, - <::Public>::ID => { - self.authority_discovery.as_ref() - }, + <::Public>::ID => + self.para_assignment.as_ref(), + <::Public>::ID => + self.authority_discovery.as_ref(), <::Public>::ID => self.beefy.as_ref(), _ => &[], } @@ -1054,12 +1052,11 @@ impl InstanceFilter for ProxyType { ProxyType::Staking => { matches!( c, - RuntimeCall::Staking(..) - | RuntimeCall::Session(..) - | RuntimeCall::Utility(..) - | RuntimeCall::FastUnstake(..) - | RuntimeCall::VoterList(..) - | RuntimeCall::NominationPools(..) + RuntimeCall::Staking(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::FastUnstake(..) | + RuntimeCall::VoterList(..) | + RuntimeCall::NominationPools(..) ) }, ProxyType::NominationPools => { @@ -1075,24 +1072,24 @@ impl InstanceFilter for ProxyType { ProxyType::Governance => matches!( c, // OpenGov calls - RuntimeCall::ConvictionVoting(..) - | RuntimeCall::Referenda(..) - | RuntimeCall::Whitelist(..) + RuntimeCall::ConvictionVoting(..) | + RuntimeCall::Referenda(..) | + RuntimeCall::Whitelist(..) ), ProxyType::IdentityJudgement => matches!( c, - RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) - | RuntimeCall::Utility(..) + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) | + RuntimeCall::Utility(..) ), ProxyType::CancelProxy => { matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })) }, ProxyType::Auction => matches!( c, - RuntimeCall::Auctions(..) - | RuntimeCall::Crowdloan(..) - | RuntimeCall::Registrar(..) - | RuntimeCall::Slots(..) + RuntimeCall::Auctions(..) | + RuntimeCall::Crowdloan(..) | + RuntimeCall::Registrar(..) | + RuntimeCall::Slots(..) ), } } From 3ce306f3ff2d9199664627263cc91228ff199664 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 17:54:16 +0700 Subject: [PATCH 24/42] update doc --- polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs index 41cb1032cf90..0263c741e19e 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs @@ -32,6 +32,7 @@ sp_api::decl_runtime_apis! { /// * the weight required to execute an XCM message, /// * a list of acceptable `AssetId`s for message execution payment, /// * the cost of the weight in the specified acceptable `AssetId`. + /// * the fees for an XCM message delivery. /// /// To determine the execution weight of the calls required for /// [`xcm::latest::Instruction::Transact`] instruction, `TransactionPaymentCallApi` can be used. From ddae561d4368bc6b7e99f2f4bc5b4e3ae4735ba5 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 20 Mar 2024 21:05:25 +0700 Subject: [PATCH 25/42] replace crate --- Cargo.toml | 2 +- polkadot/node/service/Cargo.toml | 2 +- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/westend/Cargo.toml | 2 +- .../Cargo.toml | 12 ++++++------ .../README.md | 0 .../src/lib.rs | 1 + 7 files changed, 11 insertions(+), 10 deletions(-) rename polkadot/xcm/{xcm-builder/xcm-payment-runtime-api => xcm-fee-payment-runtime-api}/Cargo.toml (57%) rename polkadot/xcm/{xcm-builder/xcm-payment-runtime-api => xcm-fee-payment-runtime-api}/README.md (100%) rename polkadot/xcm/{xcm-builder/xcm-payment-runtime-api => xcm-fee-payment-runtime-api}/src/lib.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 1de3a463e19e..339618ac6172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,7 +212,7 @@ members = [ "polkadot/xcm/pallet-xcm-benchmarks", "polkadot/xcm/procedural", "polkadot/xcm/xcm-builder", - "polkadot/xcm/xcm-builder/xcm-payment-runtime-api", + "polkadot/xcm/xcm-fee-payment-runtime-api", "polkadot/xcm/xcm-executor", "polkadot/xcm/xcm-executor/integration-tests", "polkadot/xcm/xcm-simulator", diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index d37dc8e3e7c1..01e385784986 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -144,7 +144,7 @@ polkadot-statement-distribution = { path = "../network/statement-distribution", xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } [dev-dependencies] polkadot-test-client = { path = "../test/client" } diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index deee1c19b8cf..11ed8afb6ab8 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -104,7 +104,7 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index c9ebbd02b427..267e2fd8e0da 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -114,7 +114,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-builder/xcm-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } [dev-dependencies] hex-literal = "0.4.1" diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml similarity index 57% rename from polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml rename to polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml index dcf1b2beda80..114de9f3fd71 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml @@ -16,16 +16,16 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = "derive", ] } -sp-api = { path = "../../../../substrate/primitives/api", default-features = false } +sp-api = { path = "../../../substrate/primitives/api", default-features = false } scale-info = { version = "2.10.0", default-features = false, features = [ "derive", "serde", ] } -sp-std = { path = "../../../../substrate/primitives/std", default-features = false } -sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false } -sp-weights = { path = "../../../../substrate/primitives/weights", default-features = false } -xcm = { package = "staging-xcm", path = "../..", default-features = false } -frame-support = { path = "../../../../substrate/frame/support", default-features = false } +sp-std = { path = "../../../substrate/primitives/std", default-features = false } +sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false } +sp-weights = { path = "../../../substrate/primitives/weights", default-features = false } +xcm = { package = "staging-xcm", path = "../", default-features = false } +frame-support = { path = "../../../substrate/frame/support", default-features = false } [features] default = ["std"] diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md b/polkadot/xcm/xcm-fee-payment-runtime-api/README.md similarity index 100% rename from polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md rename to polkadot/xcm/xcm-fee-payment-runtime-api/README.md diff --git a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs similarity index 98% rename from polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs rename to polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs index 0263c741e19e..5324cd3befb0 100644 --- a/polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs @@ -91,6 +91,7 @@ pub enum Error { /// The given asset is not handled(as a fee payment). #[codec(index = 4)] AssetNotFound, + // Destination is known to be unroutable. #[codec(index = 5)] Unroutable, } From 25252b8913162b3c238e57e3a40d2ede99bccfc2 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 22 Mar 2024 19:01:38 +0100 Subject: [PATCH 26/42] fix: feature propagation --- polkadot/node/service/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 01e385784986..83d97d3e9e37 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -210,6 +210,7 @@ runtime-benchmarks = [ "service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "westend-runtime?/runtime-benchmarks", + "xcm-builder/runtime-benchmarks,", ] try-runtime = [ "frame-support/try-runtime", From 32ea4f5b451c4bea30cde15e0eed5165412e8a67 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 25 Mar 2024 17:20:59 +0700 Subject: [PATCH 27/42] fix typos --- polkadot/node/service/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 83d97d3e9e37..e4a8ea3c2b30 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -210,7 +210,7 @@ runtime-benchmarks = [ "service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "westend-runtime?/runtime-benchmarks", - "xcm-builder/runtime-benchmarks,", + "xcm-builder/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", From 81b7e3982324139e046ae7e5a1f85de608b52ee5 Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:27:57 +0700 Subject: [PATCH 28/42] Update prdoc/pr_3607.prdoc Co-authored-by: Adrian Catangiu --- prdoc/pr_3607.prdoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_3607.prdoc b/prdoc/pr_3607.prdoc index c25c9bbc42f7..d93d157f94ce 100644 --- a/prdoc/pr_3607.prdoc +++ b/prdoc/pr_3607.prdoc @@ -11,10 +11,10 @@ doc: An example implementation is shown in the PR. Ideally it's simple to implement, you only need to call existing parts of your XCM config. The API looks like so: ```rust - fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; - fn query_xcm_weight(message: VersionedXcm) -> Result; - fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; - fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result; + fn query_acceptable_payment_assets(xcm_version: Version) -> Result, Error>; + fn query_xcm_weight(message: VersionedXcm) -> Result; + fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result; + fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result; ``` The first three relate to XCM execution fees, given an XCM, you can query its weight, then which assets are acceptable for buying weight and convert weight to a number of those assets. The last one takes in a destination and a message you want to send from the runtime you're executing this on, it will give you the delivery fees. From d706cd0b3997a5e2cea49800c5745b5508dad3de Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:28:11 +0700 Subject: [PATCH 29/42] Update prdoc/pr_3607.prdoc Co-authored-by: Adrian Catangiu --- prdoc/pr_3607.prdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_3607.prdoc b/prdoc/pr_3607.prdoc index d93d157f94ce..1a69b25ad255 100644 --- a/prdoc/pr_3607.prdoc +++ b/prdoc/pr_3607.prdoc @@ -18,9 +18,9 @@ doc: ``` The first three relate to XCM execution fees, given an XCM, you can query its weight, then which assets are acceptable for buying weight and convert weight to a number of those assets. The last one takes in a destination and a message you want to send from the runtime you're executing this on, it will give you the delivery fees. - + crates: - name: xcm-fee-payment-runtime-api - name: rococo-runtime - name: westend-runtime - + From fc3ca432a98f1150d04e11c0ed0dfc371303e90b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 16:35:29 +0100 Subject: [PATCH 30/42] fix: remove RuntimeCall from xcm-fee-payment-runtime-api --- polkadot/node/service/Cargo.toml | 2 +- polkadot/node/service/src/fake_runtime_api.rs | 5 ++--- polkadot/runtime/rococo/src/lib.rs | 4 ++-- polkadot/runtime/westend/src/lib.rs | 4 ++-- polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs | 9 +++------ 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index e4a8ea3c2b30..e415cf12ad2b 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -144,7 +144,7 @@ polkadot-statement-distribution = { path = "../network/statement-distribution", xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { path = "../../xcm/xcm-fee-payment-runtime-api" } [dev-dependencies] polkadot-test-client = { path = "../test/client" } diff --git a/polkadot/node/service/src/fake_runtime_api.rs b/polkadot/node/service/src/fake_runtime_api.rs index f014fa32c14d..c6cfb7a27d04 100644 --- a/polkadot/node/service/src/fake_runtime_api.rs +++ b/polkadot/node/service/src/fake_runtime_api.rs @@ -30,7 +30,6 @@ use polkadot_primitives::{ ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, }; -use rococo_runtime::RuntimeCall; use sp_core::OpaqueMetadata; use sp_runtime::{ @@ -399,7 +398,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(_: xcm::Version) -> Result, xcm_fee_payment_runtime_api::Error> { unimplemented!() } @@ -408,7 +407,7 @@ sp_api::impl_runtime_apis! { unimplemented!() } - fn query_xcm_weight(_: VersionedXcm) -> Result { + fn query_xcm_weight(_: VersionedXcm<()>) -> Result { unimplemented!() } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4e7047c3b947..1e04274900ec 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1804,7 +1804,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { return Err(XcmPaymentApiError::UnhandledXcmVersion); @@ -1826,7 +1826,7 @@ sp_api::impl_runtime_apis! { Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm<()>) -> Result { let mut message = message .try_into() .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index c1f47242ea13..f3baeda74eb8 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -2258,7 +2258,7 @@ sp_api::impl_runtime_apis! { } } - impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { if !matches!(xcm_version, 3 | 4) { return Err(XcmPaymentApiError::UnhandledXcmVersion); @@ -2280,7 +2280,7 @@ sp_api::impl_runtime_apis! { Ok(WeightToFee::weight_to_fee(&weight)) } - fn query_xcm_weight(message: VersionedXcm) -> Result { + fn query_xcm_weight(message: VersionedXcm<()>) -> Result { let mut message = message .try_into() .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; diff --git a/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs index 5324cd3befb0..cedfa4054c97 100644 --- a/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::{Codec, Decode, Encode}; +use codec::{Decode, Encode}; use frame_support::pallet_prelude::TypeInfo; use sp_std::vec::Vec; use sp_weights::Weight; @@ -36,10 +36,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. - pub trait XcmPaymentApi - where - Call: Codec, - { + pub trait XcmPaymentApi { /// Returns a list of acceptable payment assets. /// /// # Arguments @@ -52,7 +49,7 @@ sp_api::decl_runtime_apis! { /// # Arguments /// /// * `message`: `VersionedXcm`. - fn query_xcm_weight(message: VersionedXcm) -> Result; + fn query_xcm_weight(message: VersionedXcm<()>) -> Result; /// Converts a weight into a fee for the specified `AssetId`. /// From f9f3f67d8908fcd260d5faa63ce77daea68c0aaf Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:01:22 +0100 Subject: [PATCH 31/42] fix: minor doc fix for api error --- polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs index cedfa4054c97..20bf9236f1fb 100644 --- a/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/src/lib.rs @@ -76,19 +76,24 @@ pub enum Error { /// An API part is unsupported. #[codec(index = 0)] Unimplemented, + /// Converting a versioned data structure from one version to another failed. #[codec(index = 1)] VersionedConversionFailed, + /// XCM message weight calculation failed. #[codec(index = 2)] WeightNotComputable, + /// XCM version not able to be handled. #[codec(index = 3)] UnhandledXcmVersion, - /// The given asset is not handled(as a fee payment). + + /// The given asset is not handled as a fee asset. #[codec(index = 4)] AssetNotFound, - // Destination is known to be unroutable. + + /// Destination is known to be unroutable. #[codec(index = 5)] Unroutable, } From 62875587eed028b02f24d4dc917acc2511add5a3 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:02:01 +0100 Subject: [PATCH 32/42] feat: impl IdentifyVersion for VersionedXcm --- polkadot/xcm/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/polkadot/xcm/src/lib.rs b/polkadot/xcm/src/lib.rs index ba8d726aecff..86a17fa1e88f 100644 --- a/polkadot/xcm/src/lib.rs +++ b/polkadot/xcm/src/lib.rs @@ -443,6 +443,16 @@ impl IntoVersion for VersionedXcm { } } +impl IdentifyVersion for VersionedXcm { + fn identify_version(&self) -> Version { + match self { + Self::V2(_) => v2::VERSION, + Self::V3(_) => v3::VERSION, + Self::V4(_) => v4::VERSION, + } + } +} + impl From> for VersionedXcm { fn from(x: v2::Xcm) -> Self { VersionedXcm::V2(x) From 4fe598597b6b5fa259845d2f5095d78b77a536a3 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:03:18 +0100 Subject: [PATCH 33/42] fix: remove unneeded package TOML setting --- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/westend/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 11ed8afb6ab8..d5296375730c 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -104,7 +104,7 @@ polkadot-parachain-primitives = { path = "../../parachain", default-features = f xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } [dev-dependencies] tiny-keccak = { version = "2.0.2", features = ["keccak"] } diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 267e2fd8e0da..02daed3df04b 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -114,7 +114,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } -xcm-fee-payment-runtime-api = { package = "xcm-fee-payment-runtime-api", path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } +xcm-fee-payment-runtime-api = { path = "../../xcm/xcm-fee-payment-runtime-api", default-features = false } [dev-dependencies] hex-literal = "0.4.1" From c04e4d8998b534b0604e3f307db0bd089f3eb13c Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:04:58 +0100 Subject: [PATCH 34/42] refactor: move weight and delivery fee payment stuff to pallet-xcm --- Cargo.lock | 1 + polkadot/runtime/rococo/src/lib.rs | 22 ++----------------- polkadot/runtime/westend/src/lib.rs | 22 ++----------------- polkadot/xcm/pallet-xcm/Cargo.toml | 2 ++ polkadot/xcm/pallet-xcm/src/lib.rs | 33 +++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f377eb54bde4..40d432e5d257 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11239,6 +11239,7 @@ dependencies = [ "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", + "xcm-fee-payment-runtime-api", ] [[package]] diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 1e04274900ec..304acf387261 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -126,7 +126,6 @@ use governance::{ pallet_custom_origins, AuctionAdmin, Fellows, GeneralAdmin, LeaseAdmin, Treasurer, TreasurySpender, }; -use xcm_executor::traits::WeightBounds; use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; #[cfg(test)] @@ -1827,28 +1826,11 @@ sp_api::impl_runtime_apis! { } fn query_xcm_weight(message: VersionedXcm<()>) -> Result { - let mut message = message - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - ::Weigher::weight(&mut message) - .map_err(|error| { - log::error!("Error when querying XCM weight: {:?}", error); - XcmPaymentApiError::WeightNotComputable - }) + XcmPallet::query_xcm_weight(message) } fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { - let destination = destination - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - let message = message - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - let (_, fees) = xcm_config::XcmRouter::validate(&mut Some(destination), &mut Some(message)).map_err(|error| { - log::error!("Error when querying delivery fees: {:?}", error); - XcmPaymentApiError::Unroutable - })?; - Ok(VersionedAssets::from(fees)) + XcmPallet::query_delivery_fees(destination, message) } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index f3baeda74eb8..42aac11c0d63 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -106,7 +106,6 @@ use xcm::{ }; use xcm_builder::PayOverXcm; -use xcm_executor::traits::WeightBounds; use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; pub use frame_system::Call as SystemCall; @@ -2281,28 +2280,11 @@ sp_api::impl_runtime_apis! { } fn query_xcm_weight(message: VersionedXcm<()>) -> Result { - let mut message = message - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - ::Weigher::weight(&mut message) - .map_err(|error| { - log::error!("Error when querying XCM weight: {:?}", error); - XcmPaymentApiError::WeightNotComputable - }) + XcmPallet::query_xcm_weight(message) } fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { - let destination = destination - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - let message = message - .try_into() - .map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?; - let (_, fees) = xcm_config::XcmRouter::validate(&mut Some(destination), &mut Some(message)).map_err(|error| { - log::error!("Error when querying delivery fees: {:?}", error); - XcmPaymentApiError::Unroutable - })?; - Ok(VersionedAssets::from(fees)) + XcmPallet::query_delivery_fees(destination, message) } } diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index 4840b6127f55..694fb944dbab 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -26,6 +26,7 @@ sp-std = { path = "../../../substrate/primitives/std", default-features = false xcm = { package = "staging-xcm", path = "..", default-features = false } xcm-executor = { package = "staging-xcm-executor", path = "../xcm-executor", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../xcm-builder", default-features = false } +xcm-fee-payment-runtime-api = { path = "../xcm-fee-payment-runtime-api", default-features = false } # marked optional, used in benchmarking frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true } @@ -55,6 +56,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "xcm-fee-payment-runtime-api/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 1a1f8b402a39..9ee45c5c8325 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -61,6 +61,7 @@ use xcm_executor::{ }, AssetsInHolding, }; +use xcm_fee_payment_runtime_api::Error as FeePaymentError; #[cfg(any(feature = "try-runtime", test))] use sp_runtime::TryRuntimeError; @@ -2363,6 +2364,38 @@ impl Pallet { AccountIdConversion::::into_account_truncating(&ID) } + pub fn query_xcm_weight(message: VersionedXcm<()>) -> Result { + let message = Xcm::<()>::try_from(message) + .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + + T::Weigher::weight(&mut message.into()) + .map_err(|()| { + log::error!(target: "xcm::pallet_xcm::query_xcm_weight", "Error when querying XCM weight"); + FeePaymentError::WeightNotComputable + }) + } + + pub fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { + let result_version = destination.identify_version().max(message.identify_version()); + + let destination = destination + .try_into() + .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + + let message = message + .try_into() + .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + + let (_, fees) = validate_send::(destination, message).map_err(|error| { + log::error!(target: "xcm::pallet_xcm::query_delivery_fees", "Error when querying delivery fees: {:?}", error); + FeePaymentError::Unroutable + })?; + + VersionedAssets::from(fees) + .into_version(result_version) + .map_err(|_| FeePaymentError::VersionedConversionFailed) + } + /// Create a new expectation of a query response with the querier being here. fn do_new_query( responder: impl Into, From 1cc0119bcdf6c065376c5ce86f6cd1c31f2d9f48 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:10:59 +0100 Subject: [PATCH 35/42] chore: cargo fmt --- polkadot/xcm/pallet-xcm/src/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 9ee45c5c8325..0d0da1a90ee0 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -2365,26 +2365,25 @@ impl Pallet { } pub fn query_xcm_weight(message: VersionedXcm<()>) -> Result { - let message = Xcm::<()>::try_from(message) - .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + let message = + Xcm::<()>::try_from(message).map_err(|_| FeePaymentError::VersionedConversionFailed)?; - T::Weigher::weight(&mut message.into()) - .map_err(|()| { - log::error!(target: "xcm::pallet_xcm::query_xcm_weight", "Error when querying XCM weight"); - FeePaymentError::WeightNotComputable - }) + T::Weigher::weight(&mut message.into()).map_err(|()| { + log::error!(target: "xcm::pallet_xcm::query_xcm_weight", "Error when querying XCM weight"); + FeePaymentError::WeightNotComputable + }) } - pub fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result { + pub fn query_delivery_fees( + destination: VersionedLocation, + message: VersionedXcm<()>, + ) -> Result { let result_version = destination.identify_version().max(message.identify_version()); - let destination = destination - .try_into() - .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + let destination = + destination.try_into().map_err(|_| FeePaymentError::VersionedConversionFailed)?; - let message = message - .try_into() - .map_err(|_| FeePaymentError::VersionedConversionFailed)?; + let message = message.try_into().map_err(|_| FeePaymentError::VersionedConversionFailed)?; let (_, fees) = validate_send::(destination, message).map_err(|error| { log::error!(target: "xcm::pallet_xcm::query_delivery_fees", "Error when querying delivery fees: {:?}", error); From ea964fb835f3345e78fbb7ded1a0778b1008f22e Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Mar 2024 18:13:21 +0100 Subject: [PATCH 36/42] chore: taplo format --- Cargo.toml | 2 +- polkadot/runtime/rococo/Cargo.toml | 2 +- polkadot/runtime/westend/Cargo.toml | 2 +- polkadot/xcm/pallet-xcm/Cargo.toml | 2 +- polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 339618ac6172..8a1ab1031921 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,9 +212,9 @@ members = [ "polkadot/xcm/pallet-xcm-benchmarks", "polkadot/xcm/procedural", "polkadot/xcm/xcm-builder", - "polkadot/xcm/xcm-fee-payment-runtime-api", "polkadot/xcm/xcm-executor", "polkadot/xcm/xcm-executor/integration-tests", + "polkadot/xcm/xcm-fee-payment-runtime-api", "polkadot/xcm/xcm-simulator", "polkadot/xcm/xcm-simulator/example", "polkadot/xcm/xcm-simulator/fuzzer", diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index d5296375730c..b3f3674c3f5a 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -209,8 +209,8 @@ std = [ "tx-pool-api/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 02daed3df04b..238fa2df98ce 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -228,8 +228,8 @@ std = [ "westend-runtime-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/xcm/pallet-xcm/Cargo.toml b/polkadot/xcm/pallet-xcm/Cargo.toml index 694fb944dbab..08307c34f8a9 100644 --- a/polkadot/xcm/pallet-xcm/Cargo.toml +++ b/polkadot/xcm/pallet-xcm/Cargo.toml @@ -55,8 +55,8 @@ std = [ "sp-std/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml index 114de9f3fd71..9d91cf393f5c 100644 --- a/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml @@ -31,11 +31,11 @@ frame-support = { path = "../../../substrate/frame/support", default-features = default = ["std"] std = [ "codec/std", + "frame-support/std", "scale-info/std", "sp-api/std", - "sp-std/std", "sp-runtime/std", + "sp-std/std", "sp-weights/std", "xcm/std", - "frame-support/std", ] From 01942ea1603fb96b84be60239a46f896c1d75fdb Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 12:12:50 +0100 Subject: [PATCH 37/42] chore: remove empty README --- polkadot/xcm/xcm-fee-payment-runtime-api/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 polkadot/xcm/xcm-fee-payment-runtime-api/README.md diff --git a/polkadot/xcm/xcm-fee-payment-runtime-api/README.md b/polkadot/xcm/xcm-fee-payment-runtime-api/README.md deleted file mode 100644 index 811207fd8c0f..000000000000 --- a/polkadot/xcm/xcm-fee-payment-runtime-api/README.md +++ /dev/null @@ -1 +0,0 @@ -License: Apache-2.0 From d5ed17bb5758715a8cd1da68e69caa1c73dd2539 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 13:04:17 +0100 Subject: [PATCH 38/42] chore: remove readme from Cargo.toml --- polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml index 9d91cf393f5c..682642d13c3a 100644 --- a/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml +++ b/polkadot/xcm/xcm-fee-payment-runtime-api/Cargo.toml @@ -6,7 +6,6 @@ edition.workspace = true license = "Apache-2.0" repository.workspace = true description = "XCM fee payment runtime API" -readme = "README.md" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] From faba8a15de07c47e4cccd78044aaac1d82ad1fe1 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 17:32:40 +0100 Subject: [PATCH 39/42] Update polkadot/node/service/Cargo.toml Co-authored-by: Adrian Catangiu --- polkadot/node/service/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index e415cf12ad2b..3e43ff43be8b 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -210,7 +210,6 @@ runtime-benchmarks = [ "service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "westend-runtime?/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", From e02f957cddcaea8ecaa0f1722db5879eb8574e1b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 17:39:07 +0100 Subject: [PATCH 40/42] Update polkadot/node/service/Cargo.toml Co-authored-by: Francisco Aguirre --- polkadot/node/service/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 3e43ff43be8b..e8d30577140e 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -142,8 +142,8 @@ polkadot-node-core-pvf-checker = { path = "../core/pvf-checker", optional = true polkadot-node-core-runtime-api = { path = "../core/runtime-api", optional = true } polkadot-statement-distribution = { path = "../network/statement-distribution", optional = true } -xcm = { package = "staging-xcm", path = "../../xcm", default-features = false } -xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false } +xcm = { package = "staging-xcm", path = "../../xcm" } +xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder" } xcm-fee-payment-runtime-api = { path = "../../xcm/xcm-fee-payment-runtime-api" } [dev-dependencies] From 01857a49a955c6e20334dafeb1d4d9e2ceb8d540 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 18:18:13 +0100 Subject: [PATCH 41/42] fix: remove unneeded xcm-builder dep --- polkadot/node/service/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index e8d30577140e..e28861feb492 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -143,7 +143,6 @@ polkadot-node-core-runtime-api = { path = "../core/runtime-api", optional = true polkadot-statement-distribution = { path = "../network/statement-distribution", optional = true } xcm = { package = "staging-xcm", path = "../../xcm" } -xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder" } xcm-fee-payment-runtime-api = { path = "../../xcm/xcm-fee-payment-runtime-api" } [dev-dependencies] From 806f29d8eb080ae459997ae89f1a6abbe59a1ff8 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 26 Mar 2024 18:27:06 +0100 Subject: [PATCH 42/42] fix: Cargo.lock --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 40d432e5d257..de6c55cfdf2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13572,7 +13572,6 @@ dependencies = [ "sp-version", "sp-weights", "staging-xcm", - "staging-xcm-builder", "substrate-prometheus-endpoint", "tempfile", "thiserror",