Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(xcm): add xcm-payment-api #2

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c471add
feat(xcm): add `xcm-payment-api`
PraetorP Feb 20, 2024
137d129
doc: `XcmPaymentRuntimeApi`
PraetorP Feb 26, 2024
c4b070b
add prdoc
PraetorP Feb 26, 2024
6bc4e95
refactor: signatures for XcmPaymentRuntimeApi & mpl for roroco Runtime
PraetorP Feb 27, 2024
c649ad2
rename trait to `XcmPaymentApi`
PraetorP Feb 27, 2024
1b93e2a
fix comment
PraetorP Feb 27, 2024
16d9d22
doc: add `Error` description
PraetorP Feb 28, 2024
a8337b9
refactor
PraetorP Feb 28, 2024
7b17ece
format non context diffs
PraetorP Feb 29, 2024
f6201bf
feat: add `XcmPaymentApi` into `Wesend`
PraetorP Feb 29, 2024
55b1a03
fix non context diffs
PraetorP Feb 29, 2024
707f0b0
fix missed feature
PraetorP Feb 29, 2024
a27c70f
refactor
PraetorP Mar 5, 2024
f45f9dd
cargo fmt
PraetorP Mar 7, 2024
18e54e7
feat(xcm-fee-payment-api): add query_delivery_fees function
franciscoaguirre Mar 18, 2024
4caea72
Merge pull request #3 from paritytech/pr3607
PraetorP Mar 20, 2024
e348602
Update polkadot/xcm/xcm-builder/xcm-payment-runtime-api/README.md
PraetorP Mar 20, 2024
fc06767
refactor: add missed imports, fmt, add xcm api errors log
PraetorP Mar 20, 2024
60a88a6
number assigned to the `prdoc`
PraetorP Mar 20, 2024
fee8d7b
remove unused import
PraetorP Mar 20, 2024
cceafd4
Update polkadot/xcm/xcm-builder/xcm-payment-runtime-api/src/lib.rs
PraetorP Mar 20, 2024
618f17f
Update prdoc/pr_3607.prdoc
PraetorP Mar 20, 2024
4a83147
rename crate
PraetorP Mar 20, 2024
e7c752a
revert changes
PraetorP Mar 20, 2024
3ce306f
update doc
PraetorP Mar 20, 2024
ddae561
replace crate
PraetorP Mar 20, 2024
25252b8
fix: feature propagation
franciscoaguirre Mar 22, 2024
3cd6503
Merge pull request #5 from paritytech/pr3607
PraetorP Mar 25, 2024
32ea4f5
fix typos
PraetorP Mar 25, 2024
81b7e39
Update prdoc/pr_3607.prdoc
PraetorP Mar 25, 2024
d706cd0
Update prdoc/pr_3607.prdoc
PraetorP Mar 25, 2024
fc3ca43
fix: remove RuntimeCall from xcm-fee-payment-runtime-api
mrshiposha Mar 25, 2024
f9f3f67
fix: minor doc fix for api error
mrshiposha Mar 25, 2024
6287558
feat: impl IdentifyVersion for VersionedXcm
mrshiposha Mar 25, 2024
4fe5985
fix: remove unneeded package TOML setting
mrshiposha Mar 25, 2024
c04e4d8
refactor: move weight and delivery fee payment stuff to pallet-xcm
mrshiposha Mar 25, 2024
1cc0119
chore: cargo fmt
mrshiposha Mar 25, 2024
ea964fb
chore: taplo format
mrshiposha Mar 25, 2024
01942ea
chore: remove empty README
mrshiposha Mar 26, 2024
d5ed17b
chore: remove readme from Cargo.toml
mrshiposha Mar 26, 2024
faba8a1
Update polkadot/node/service/Cargo.toml
mrshiposha Mar 26, 2024
e02f957
Update polkadot/node/service/Cargo.toml
mrshiposha Mar 26, 2024
01857a4
fix: remove unneeded xcm-builder dep
mrshiposha Mar 26, 2024
806f29d
fix: Cargo.lock
mrshiposha Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
PraetorP committed Mar 7, 2024
commit a27c70f539a42e9a5c4e39ec75939e05bc6ab5d7
56 changes: 29 additions & 27 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,7 +219,7 @@ pub struct OriginPrivilegeCmp;
impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
if left == right {
return Some(Ordering::Equal)
return Some(Ordering::Equal);
}

match (left, right) {
Expand Down Expand Up @@ -380,10 +380,12 @@ impl OpaqueKeys for OldSessionKeys {
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
self.para_assignment.as_ref(),
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
self.authority_discovery.as_ref(),
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
self.para_assignment.as_ref()
},
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
self.authority_discovery.as_ref()
},
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
_ => &[],
}
Expand Down Expand Up @@ -882,19 +884,19 @@ impl InstanceFilter<RuntimeCall> 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(..)),
Expand Down Expand Up @@ -1510,11 +1512,11 @@ pub mod migrations {
let now = frame_system::Pallet::<Runtime>::block_number();
let lease = slots::Pallet::<Runtime>::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, _) =
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
Expand Down Expand Up @@ -1576,7 +1578,7 @@ pub mod migrations {
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, 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");
Expand Down Expand Up @@ -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 <Runtime as frame_system::Config>::DbWeight::get().reads(1)
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
}
log::trace!("Upgrading session keys");
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
Expand All @@ -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();
Expand Down Expand Up @@ -1802,33 +1804,33 @@ sp_api::impl_runtime_apis! {
}

impl xcm_payment_runtime_api::XcmPaymentApi<Block, RuntimeCall> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentError> {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, 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()
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
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<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
let mut message = message
.try_into()
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
.map_err(|_| XcmPaymentError::WeightNotComputable)
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
}
}

Expand Down Expand Up @@ -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();
Expand Down
69 changes: 36 additions & 33 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -442,10 +442,12 @@ impl OpaqueKeys for OldSessionKeys {
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
self.para_assignment.as_ref(),
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
self.authority_discovery.as_ref(),
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
self.para_assignment.as_ref()
},
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
self.authority_discovery.as_ref()
},
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
_ => &[],
}
Expand Down Expand Up @@ -1052,11 +1054,12 @@ impl InstanceFilter<RuntimeCall> 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 => {
Expand All @@ -1072,24 +1075,24 @@ impl InstanceFilter<RuntimeCall> 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(..)
),
}
}
Expand Down Expand Up @@ -1592,11 +1595,11 @@ pub mod migrations {
let now = frame_system::Pallet::<Runtime>::block_number();
let lease = slots::Pallet::<Runtime>::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, _) =
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
Expand All @@ -1618,7 +1621,7 @@ pub mod migrations {
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, 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");
Expand Down Expand Up @@ -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 <Runtime as frame_system::Config>::DbWeight::get().reads(1)
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
}
log::info!("Upgrading session keys");
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
Expand All @@ -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();
Expand Down Expand Up @@ -2259,33 +2262,33 @@ sp_api::impl_runtime_apis! {
}

impl xcm_payment_runtime_api::XcmPaymentApi<Block, RuntimeCall> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentError> {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, 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()
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
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<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
let mut message = message
.try_into()
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
.map_err(|_| XcmPaymentError::WeightNotComputable)
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
}
}

Expand Down Expand Up @@ -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();
Expand Down
Loading