Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM: Remove & replace XCM Convert trait #7329

Merged
merged 21 commits into from
Jun 5, 2023

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Jun 4, 2023

Cumulus Companion: paritytech/cumulus#2688

The Convert trait had a name collision with a similar trait in Substrate causing confusion; the trait itself was used for 4 things, each quite different and was better replaced by using more job-specific traits and more general conversion traits from Substrate.

API changes

  • xcm_executor::traits::Convert removed.
  • xcm_executor::traits::{Encoded, Decoded} removed.
  • xcm_executor::traits::{JustTry, Identity} deprecated (use sp_runtime equivalents instead).
  • xcm_executor::traits::ConvertLocation added.
  • xcm_builder::location_conversion::DescribeLocation added.
  • xcm_builder::location_conversion::HashedDescription and family added, which should be used to replace usages of ForeignChainAliasAccount.
  • ForeignChainAliasAccount deprecated.

Origin Conversion

  • EnsureXcmOrigin: Conversion bound changes from xcm_executor::traits::Convert<RuntimeOrigin, MultiLocation> to TryConvert<RuntimeOrigin, MultiLocation>.

Location Conversion

  • LocationConverter bound changes from xcm_executor::traits::Convert<MultiLocation, RuntimeOrigin::AccountId> to ConvertLocation<RuntimeOrigin::AccountId>.
  • AccountIdConverter bound changes from xcm_executor::traits::Convert<MultiLocation, AccountId> to ConvertLocation<AccountId>.
  • pallet_xcm::Config::SovereignAccountOf bound changes from xcm_executor::traits::Convert<MultiLocation, Self::AccountId> to ConvertLocation<Self::AccountId>.

Asset Conversion

  • ConvertClassId bound changes from xcm_executor::traits::Convert<[u8; 32], ClassId> to MaybeEquivalence<[u8; 32], ClassId> (same for AssetId).
  • ConvertInstanceId bound changes from xcm_executor::traits::Convert<AssetInstance, InstanceId> to MaybeEquivalence<AssetInstance, InstanceId>.
  • ConvertBalance bound changes from xcm_executor::traits::Convert<u128, Balance> to MaybeEquivalence<u128, Balance>.

Migrating code

Since almost all trait-implementors have also been changed in line with the bounds, there should be a good degree of compatibility for runtime maintainers. However, if there are custom implementations of the xcm_executor::traits::Convert trait, then these will need to be altered into an implementation of either ConvertLocation, MaybeEquivalence or TryConvert (depending on what kind of conversion it is performing).

The functions provided in the new traits are slightly different; if the xcm_executor::traits::Convert was being used directly (e.g. in tests) then the code will need to be adapted. The impl Borrow parameter types are not used in any of the new traits, instead favouring simpler pass-by-value (TryConvert) or pass-by-reference (ConvertLocation, MaybeEquivalence). The return types used in the new location conversion and asset conversion traits are Option, not Result (as was the case in xcm_executor::traits::Convert. Naming is also slightly different; convert_location is called instead of convert for location conversion. convert_ref and reverse_ref become convert and convert_back for asset conversion. For origin conversion, convert becomes try_convert.

This PR deprecates ForeignChainAliasAccount; if it is already in production usage in your runtime, it may be replaced with HashedDescription<AccountId, LegacyDescribeForeignChainAccount>. If not already in use, you are encouraged to use HashedDescription with the modules appropriate to your expected usage, such as HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>.

@gavofyork gavofyork added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. T1-runtime This PR/Issue is related to the topic “runtime”. B1-note_worthy Changes should be noted in the release notes labels Jun 4, 2023
@gavofyork gavofyork changed the title XCM: Remove & replace Polkadot's Convert trait XCM: Remove & replace XCM Convert trait Jun 5, 2023
};
#[allow(deprecated)]
pub use super::{Identity, JustTry};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to continue exporting these types after deprecation by re-exporting from sp_runtime? What's the plan otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll remove them eventually (hence deeprecation), but they're here to minimise breaking changes.

Cargo.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some clippy issues

xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
xcm/xcm-builder/src/location_conversion.rs Outdated Show resolved Hide resolved
gavofyork and others added 2 commits June 5, 2023 11:08
@gavofyork
Copy link
Member Author

bot merge

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/multichain-friendly-account-abstraction/1298/20

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/multichain-friendly-account-abstraction/1298/21

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants