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

XCM: Automatic Version Negotiation #3736

Merged
merged 45 commits into from
Sep 2, 2021
Merged

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Aug 28, 2021

This introduces autonomous version negotiation in XCM, removing the need for manual intervention in order to ensure that chains use the most recent common version of XCM which they support.

It introduces a stateful WrapVersion implementation through the XCM Pallet, together with a new SubscribeVersion instruction (as well as UnsubscribeVersion) to provide a QueryResponse with the latest XCM a runtime supports together with further similar notifications when the version changes. When a message is sent to a destination whose version is unknown, the pallet queues up this destination for version querying and each block drains some number from this queue and posts a query. As they come in, it checks for responses and (assuming it knowingly subscribed for it) records it.

The Pallet maintains a list of locations which have asked for version notification subscriptions and whenever there is an upgrade sends them notifications of the new upgrade. This is done through a new trait VersionChangeNotifier.

Migration

XCM Pallet

pallet_xcm::Config trait get one new const VERSION_DISCOVERY_QUEUE_SIZE and one new type AdvertizeXcmVersion. A sensible value for the former is 100. For the latter, it's best to just reference pallet_xcm::CurrentXcmVersion. e.g.:

impl pallet_xcm::Config for Runtime {
	/* snip */
	const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
	type AdvertizeXcmVersion = pallet_xcm::CurrentXcmVersion;
}

XCM Config

Ensure that any xcm_executor::Config implementations includes a definition for the new type SubscriptionService. Generally this should be set to PalletXcm, the pallet_xcm concrete type. i.e.:

impl xcm_executor::Config for XcmConfig {
	/* snip */
	type SubscriptionService = XcmPallet;
}

Routers & WrapVersion

Any routers (XCM transport methods) which have a WrapVersion item (including cumulus_pallet_xcmp_queue and ParentAsUmp) should have that item set to be implemented by PalletXcm, the pallet_xcm concrete type. e.g.:

impl cumulus_pallet_xcmp_queue::Config for Runtime {
	/* snip */
	type VersionWrapper = ();
}
/* snip */
pub type XcmRouter = (
	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
	XcmpQueue,
);

would become:

impl cumulus_pallet_xcmp_queue::Config for Runtime {
	/* snip */
	type VersionWrapper = XcmPallet;
}
/* snip */
pub type XcmRouter = (
	cumulus_primitives_utility::ParentAsUmp<ParachainSystem, XcmPallet>,
	XcmpQueue,
);

NOTE In addition to this change, you should do at least one of two things to initialize your chain and ensure that XCM messages can be sent:

  • Whitelist destinations to which you wish to send messages with the force_xcm_version (root-callable) extrinsic.
  • Provide a general fallback version with the force_xcm_default_version (root-callable) extrinsic.

If you do the latter, then the automatic XCM version tracking code with work as expected and destination XCM versions will be kept up to date.

Barrier

An additional barrier AlllowSubscriptionsFrom should be included in your Barriers tuple. You can probably set the origin filter to Everything, unless you want to filter which locations can ask to be notified of your chain's XCM version changes:

pub type Barrier = (
	TakeWeightCredit,
	/* snip */
	AllowSubscriptionsFrom<Everything>,
);

TODO

  • Automatic subscription
  • Automatic unsubscription
  • Unsubscription extrinsic
  • Barrier
  • Expose remote origin in VM and ensure it is unchanged from actual origin in subscription instructions.
  • Cleanup for orphaned subscription requests
  • Unit tests for XCM executor
  • Unit tests for XCM pallet

Maybe here or another PR:

  • Remove top_level
  • Allow on_runtime_upgrade notifications to happen over multiple blocks
  • Break apart fn on_response

@gavofyork gavofyork added A3-in_progress Pull request is in progress. No review needed at this stage. B7-runtimenoteworthy C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited. labels Aug 28, 2021
@gavofyork gavofyork added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Aug 30, 2021
@gavofyork gavofyork marked this pull request as ready for review August 30, 2021 19:52
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
xcm/pallet-xcm/src/lib.rs Outdated Show resolved Hide resolved
@chevdor chevdor added this to the v0.9.10 milestone Sep 2, 2021
@chevdor chevdor mentioned this pull request Sep 2, 2021
@gavofyork gavofyork merged commit 66ef2d3 into master Sep 2, 2021
@gavofyork gavofyork deleted the gav-xcm-version-negotiation branch September 2, 2021 16:47
ordian added a commit that referenced this pull request Sep 6, 2021
* master:
  Add tests and modify as_vec implementation (#3715)
  Bump structopt from 0.3.22 to 0.3.23 (#3770)
  bump substrate and beefy (#3789)
  set `DisputesHandler` in initializer (#3788)
  Bump futures from 0.3.16 to 0.3.17 (#3742)
  Convert rococo chainspec to raw chainspec (#3785)
  feat/overseer: introduce closure init (#3775)
  comment out bridges runtime modules (broken) and update Rococo chain-spec (#3780)
  Add VoteLocking config (#3734)
  Enable disputes on rococo (#3764)
  XCM: Automatic Version Negotiation (#3736)
@gavofyork gavofyork modified the milestones: v0.9.10, v0.9.11 Sep 6, 2021
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. C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants