Skip to content

Commit

Permalink
[xcm] runtime api for LocationToAccount conversions (paritytech#4857)
Browse files Browse the repository at this point in the history
Closes: paritytech#4298

This PR also merges `xcm-fee-payment-runtime-api` module to the
`xcm-runtime-api`.

## TODO

- [x] rename `convert` to `convert_location` and add new one
`convert_account` (opposite direction)
- [x] add to the all testnet runtimes
- [x] check polkadot-js if supports that automatically or if needs to be
added manually polkadot-js/api#5917
- [ ] backport/patch for fellows and release (asap)

## Open questions
- [x] should we merge `xcm-runtime-api` and
`xcm-fee-payment-runtime-api` to the one module `xcm-runtime-api` ?

## Usage
Input:
 - `location:  VersionedLocation`

Output:
 - account_id bytes

![image](https://github.com/paritytech/polkadot-sdk/assets/8159517/4607b15a-77d2-462b-806c-606107776c0d)

---------

Co-authored-by: Bastian Köcher <[email protected]>
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	cumulus/parachains/integration-tests/emulated/chains/relays/westend/Cargo.toml
#	cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml
#	cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml
#	cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml
#	cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
#	cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml
#	cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
#	cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml
#	cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs
#	cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml
#	cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs
#	cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml
#	cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs
#	cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml
#	cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs
#	cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml
#	cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs
#	cumulus/parachains/runtimes/people/people-rococo/Cargo.toml
#	cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
#	cumulus/parachains/runtimes/people/people-westend/Cargo.toml
#	cumulus/parachains/runtimes/people/people-westend/src/lib.rs
#	cumulus/parachains/runtimes/testing/penpal/Cargo.toml
#	cumulus/parachains/runtimes/testing/penpal/src/lib.rs
#	cumulus/polkadot-parachain/Cargo.toml
#	polkadot/node/service/Cargo.toml
#	polkadot/runtime/rococo/Cargo.toml
#	polkadot/runtime/westend/Cargo.toml
#	polkadot/xcm/pallet-xcm/Cargo.toml
#	polkadot/xcm/xcm-runtime-apis/Cargo.toml
#	umbrella/Cargo.toml
#	umbrella/src/lib.rs
  • Loading branch information
bkontur authored and fgamundi committed Jul 17, 2024
1 parent dc13e26 commit 4800cba
Show file tree
Hide file tree
Showing 47 changed files with 920 additions and 120 deletions.
69 changes: 45 additions & 24 deletions Cargo.lock

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

39 changes: 38 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ members = [
"polkadot/xcm/xcm-builder",
"polkadot/xcm/xcm-executor",
"polkadot/xcm/xcm-executor/integration-tests",
"polkadot/xcm/xcm-fee-payment-runtime-api",
"polkadot/xcm/xcm-runtime-apis",
"polkadot/xcm/xcm-simulator",
"polkadot/xcm/xcm-simulator/example",
"polkadot/xcm/xcm-simulator/fuzzer",
Expand Down Expand Up @@ -570,6 +570,43 @@ serde_yaml = { version = "0.9" }
syn = { version = "2.0.53" }
thiserror = { version = "1.0.48" }
tracing-subscriber = { version = "0.3.18" }
tracking-allocator = { path = "polkadot/node/tracking-allocator", default-features = false, package = "staging-tracking-allocator" }
trie-bench = { version = "0.39.0" }
trie-db = { version = "0.29.0", default-features = false }
trie-root = { version = "0.18.0", default-features = false }
trie-standardmap = { version = "0.16.0" }
trybuild = { version = "1.0.88" }
tt-call = { version = "1.0.8" }
tuplex = { version = "0.1", default-features = false }
twox-hash = { version = "1.6.3", default-features = false }
unsigned-varint = { version = "0.7.2" }
url = { version = "2.4.0" }
void = { version = "1.0.2" }
w3f-bls = { version = "0.1.3", default-features = false }
wait-timeout = { version = "0.2" }
walkdir = { version = "2.4.0" }
wasm-bindgen-test = { version = "0.3.19" }
wasm-instrument = { version = "0.4", default-features = false }
wasm-opt = { version = "0.116" }
wasm-timer = { version = "0.2.5" }
wasmi = { version = "0.32.3", default-features = false }
wasmtime = { version = "8.0.1", default-features = false }
wat = { version = "1.0.0" }
westend-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/relays/westend", default-features = false }
westend-runtime = { path = "polkadot/runtime/westend" }
westend-runtime-constants = { path = "polkadot/runtime/westend/constants", default-features = false }
westend-system-emulated-network = { path = "cumulus/parachains/integration-tests/emulated/networks/westend-system" }
x25519-dalek = { version = "2.0" }
xcm = { path = "polkadot/xcm", default-features = false, package = "staging-xcm" }
xcm-builder = { path = "polkadot/xcm/xcm-builder", default-features = false, package = "staging-xcm-builder" }
xcm-docs = { path = "polkadot/xcm/docs" }
xcm-emulator = { path = "cumulus/xcm/xcm-emulator", default-features = false }
xcm-executor = { path = "polkadot/xcm/xcm-executor", default-features = false, package = "staging-xcm-executor" }
xcm-procedural = { path = "polkadot/xcm/procedural", default-features = false }
xcm-runtime-apis = { path = "polkadot/xcm/xcm-runtime-apis", default-features = false }
xcm-simulator = { path = "polkadot/xcm/xcm-simulator", default-features = false }
zeroize = { version = "1.7.0", default-features = false }
zstd = { version = "0.12.4", default-features = false }

[profile.release]
# Polkadot runtime requires unwinding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ polkadot-primitives = { path = "../../../../../../../polkadot/primitives", defau
westend-runtime-constants = { path = "../../../../../../../polkadot/runtime/westend/constants", default-features = false }
westend-runtime = { path = "../../../../../../../polkadot/runtime/westend" }
xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false }
xcm-fee-payment-runtime-api = { path = "../../../../../../../polkadot/xcm/xcm-fee-payment-runtime-api", default-features = false }
xcm-runtime-apis = { path = "../../../../../../../polkadot/xcm/xcm-runtime-apis", default-features = false }

# Cumulus
parachains-common = { path = "../../../../../common" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ polkadot-runtime-common = { path = "../../../../../../../polkadot/runtime/common
xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false }
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../../polkadot/xcm/xcm-executor", default-features = false }
pallet-xcm = { path = "../../../../../../../polkadot/xcm/pallet-xcm", default-features = false }
xcm-fee-payment-runtime-api = { path = "../../../../../../../polkadot/xcm/xcm-fee-payment-runtime-api", default-features = false }
xcm-runtime-apis = { path = "../../../../../../../polkadot/xcm/xcm-runtime-apis", default-features = false }
westend-runtime = { path = "../../../../../../../polkadot/runtime/westend" }

# Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::imports::*;

use frame_system::RawOrigin;
use xcm_fee_payment_runtime_api::{
use xcm_runtime_apis::{
dry_run::runtime_decl_for_dry_run_api::DryRunApiV1,
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", def
xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false }
xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false }
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false }
xcm-fee-payment-runtime-api = { path = "../../../../../polkadot/xcm/xcm-fee-payment-runtime-api", default-features = false }
xcm-runtime-apis = { path = "../../../../../polkadot/xcm/xcm-runtime-apis", default-features = false }

# Cumulus
cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false }
Expand Down Expand Up @@ -138,7 +138,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand Down Expand Up @@ -248,7 +248,7 @@ std = [
"testnet-parachains-constants/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-runtime-apis/std",
"xcm/std",
]

Expand Down
22 changes: 17 additions & 5 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use xcm::{
latest::prelude::{AssetId, BodyId},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::{
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};
Expand Down Expand Up @@ -1284,7 +1284,7 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
let acceptable = vec![
// native token
Expand All @@ -1304,11 +1304,11 @@ impl_runtime_apis! {
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!");
Err(XcmPaymentApiError::AssetNotFound)
},
Err(_) => {
log::trace!(target: "xcm::xcm_fee_payment_runtime_api", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!");
Err(XcmPaymentApiError::VersionedConversionFailed)
}
}
Expand All @@ -1323,7 +1323,7 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}
Expand All @@ -1333,6 +1333,18 @@ impl_runtime_apis! {
}
}

impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
fn convert_location(location: VersionedLocation) -> Result<
AccountId,
xcm_runtime_apis::conversions::Error
> {
xcm_runtime_apis::conversions::LocationToAccountHelper::<
AccountId,
xcm_config::LocationToAccountId,
>::convert_location(location)
}
}

impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info(header)
Expand Down
Loading

0 comments on commit 4800cba

Please sign in to comment.