Skip to content

Commit

Permalink
xcm: Change TypeInfo::path to not include staging (#1948)
Browse files Browse the repository at this point in the history
The `xcm` crate was renamed to `staging-xcm` to be able to publish it to
crates.io as someone as squatted `xcm`. The problem with this rename is
that the `TypeInfo` includes the crate name which ultimately lands in
the metadata. The metadata is consumed by downstream users like
`polkadot-js` or people building on top of `polkadot-js`. These people
are using the entire `path` to find the type in the type registry. Thus,
their code would break as the type path would now be [`staging_xcm`,
`VersionedXcm`] instead of [`xcm`, `VersionedXcm`]. This pull request
fixes this by renaming the path segment `staging_xcm` to `xcm`.

This requires: paritytech/scale-info#197

---------

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
  • Loading branch information
bkchr and franciscoaguirre authored Oct 20, 2023
1 parent 48a4578 commit 6363deb
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ derivative = { version = "2.2.0", default-features = false, features = [ "use_co
impl-trait-for-tuples = "0.2.2"
log = { version = "0.4.17", default-features = false }
parity-scale-codec = { version = "3.6.1", default-features = false, features = [ "derive", "max-encoded-len" ] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive", "serde"] }
sp-weights = { path = "../../substrate/primitives/weights", default-features = false, features = ["serde"] }
serde = { version = "1.0.188", default-features = false, features = ["alloc", "derive"] }
xcm-procedural = { path = "procedural" }
Expand Down
2 changes: 1 addition & 1 deletion pallet-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
frame-support = { path = "../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../substrate/frame/system", default-features = false}
sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false}
Expand Down
2 changes: 1 addition & 1 deletion pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license.workspace = true
[dependencies]
bounded-collections = { version = "0.1.8", default-features = false }
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.188", optional = true, features = ["derive"] }
log = { version = "0.4.17", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions src/double_encoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use parity_scale_codec::{Decode, DecodeLimit, Encode};
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(bounds(), skip_type_params(T))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct DoubleEncoded<T> {
encoded: Vec<u8>,
#[codec(skip)]
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ macro_rules! versioned_type {
)]
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
$(#[$attr])*
pub enum $n {
$(#[$index3])*
Expand Down Expand Up @@ -150,6 +151,7 @@ macro_rules! versioned_type {
)]
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
$(#[$attr])*
pub enum $n {
$(#[$index2])*
Expand Down Expand Up @@ -310,6 +312,7 @@ versioned_type! {
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(bounds(), skip_type_params(RuntimeCall))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum VersionedXcm<RuntimeCall> {
#[codec(index = 2)]
V2(v2::Xcm<RuntimeCall>),
Expand Down
9 changes: 9 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,12 @@ fn encode_decode_versioned_xcm_v3() {
let decoded = VersionedXcm::decode(&mut &encoded[..]).unwrap();
assert_eq!(xcm, decoded);
}

// With the renaming of the crate to `staging-xcm` the naming in the metadata changed as well and
// this broke downstream users. This test ensures that the name in the metadata isn't changed.
#[test]
fn ensure_type_info_is_correct() {
let type_info = VersionedXcm::<()>::type_info();

assert_eq!(type_info.path.segments, vec!["xcm", "VersionedXcm"]);
}
1 change: 1 addition & 0 deletions src/v2/junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use scale_info::TypeInfo;
/// Each item assumes a pre-existing location as its context and is defined in terms of it.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
Expand Down
8 changes: 8 additions & 0 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub use traits::{Error, ExecuteXcm, GetWeight, Outcome, Result, SendError, SendR

/// Basically just the XCM (more general) version of `ParachainDispatchOrigin`.
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum OriginKind {
/// Origin should just be the native dispatch origin representation for the sender in the
/// local runtime framework. For Cumulus/Frame chains this is the `Parachain` or `Relay` origin
Expand All @@ -105,6 +106,7 @@ pub enum OriginKind {
/// A global identifier of an account-bearing consensus system.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum NetworkId {
/// Unidentified/any.
Any,
Expand Down Expand Up @@ -141,6 +143,7 @@ impl TryFrom<NewNetworkId> for NetworkId {
/// An identifier of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum BodyId {
/// The only body in its context.
Unit,
Expand Down Expand Up @@ -195,6 +198,7 @@ impl From<NewBodyId> for BodyId {
/// A part of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum BodyPart {
/// The body's declaration, under whatever means it decides.
Voice,
Expand Down Expand Up @@ -262,6 +266,7 @@ pub type QueryId = u64;
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(bounds(), skip_type_params(RuntimeCall))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct Xcm<RuntimeCall>(pub Vec<Instruction<RuntimeCall>>);

impl<RuntimeCall> Xcm<RuntimeCall> {
Expand Down Expand Up @@ -357,6 +362,7 @@ pub mod prelude {

/// Response data to a query.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Response {
/// No response. Serves as a neutral default.
Null,
Expand All @@ -376,6 +382,7 @@ impl Default for Response {

/// An optional weight limit.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WeightLimit {
/// No weight limit imposed.
Unlimited,
Expand Down Expand Up @@ -428,6 +435,7 @@ pub type Weight = u64;
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(bounds(), skip_type_params(RuntimeCall))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Instruction<RuntimeCall> {
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding
/// Register.
Expand Down
8 changes: 8 additions & 0 deletions src/v2/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use scale_info::TypeInfo;
/// A general identifier for an instance of a non-fungible asset class.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum AssetInstance {
/// Undefined - used if the non-fungible asset class has only one instance.
Undefined,
Expand Down Expand Up @@ -119,6 +120,7 @@ impl TryFrom<NewAssetInstance> for AssetInstance {
/// Classification of an asset being concrete or abstract.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum AssetId {
Concrete(MultiLocation),
Abstract(Vec<u8>),
Expand Down Expand Up @@ -185,6 +187,7 @@ impl AssetId {
/// instance.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Fungibility {
Fungible(#[codec(compact)] u128),
NonFungible(AssetInstance),
Expand Down Expand Up @@ -224,6 +227,7 @@ impl TryFrom<NewFungibility> for Fungibility {

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct MultiAsset {
pub id: AssetId,
pub fun: Fungibility,
Expand Down Expand Up @@ -309,6 +313,7 @@ impl TryFrom<NewMultiAsset> for MultiAsset {
/// they must be sorted.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct MultiAssets(Vec<MultiAsset>);

impl Decode for MultiAssets {
Expand Down Expand Up @@ -479,6 +484,7 @@ impl MultiAssets {
/// Classification of whether an asset is fungible or not.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WildFungibility {
Fungible,
NonFungible,
Expand All @@ -498,6 +504,7 @@ impl TryFrom<NewWildFungibility> for WildFungibility {
/// A wildcard representing a set of assets.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WildMultiAsset {
/// All assets in the holding register, up to `usize` individual assets (different instances of
/// non-fungibles could be separate assets).
Expand Down Expand Up @@ -543,6 +550,7 @@ impl<A: Into<AssetId>, B: Into<WildFungibility>> From<(A, B)> for WildMultiAsset
/// in this implementation and will result in a decode error.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum MultiAssetFilter {
Definite(MultiAssets),
Wild(WildMultiAsset),
Expand Down
2 changes: 2 additions & 0 deletions src/v2/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use scale_info::TypeInfo;
/// The `MultiLocation` value of `Null` simply refers to the interpreting consensus system.
#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct MultiLocation {
/// The number of parent junctions at the beginning of this `MultiLocation`.
pub parents: u8,
Expand Down Expand Up @@ -465,6 +466,7 @@ const MAX_JUNCTIONS: usize = 8;
/// instructions on constructing parent junctions.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Junctions {
/// The interpreting consensus system.
Here,
Expand Down
3 changes: 3 additions & 0 deletions src/v2/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub trait GetWeight<W> {
}

#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Error {
// Errors that happen due to instructions being executed. These alone are defined in the
// XCM specification.
Expand Down Expand Up @@ -165,6 +166,7 @@ pub type Result = result::Result<(), Error>;

/// Outcome of an XCM execution.
#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Outcome {
/// Execution completed successfully; given weight was used.
Complete(Weight),
Expand Down Expand Up @@ -246,6 +248,7 @@ impl<C> ExecuteXcm<C> for () {

/// Error result value when attempting to send an XCM message.
#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug, scale_info::TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum SendError {
/// The message and destination combination was not recognized as being reachable.
///
Expand Down
4 changes: 4 additions & 0 deletions src/v3/junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use serde::{Deserialize, Serialize};
Serialize,
Deserialize,
)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum NetworkId {
/// Network specified by the first 32 bytes of its genesis block.
ByGenesis([u8; 32]),
Expand Down Expand Up @@ -116,6 +117,7 @@ impl TryFrom<OldNetworkId> for NetworkId {
Serialize,
Deserialize,
)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum BodyId {
/// The only body in its context.
Unit,
Expand Down Expand Up @@ -186,6 +188,7 @@ impl TryFrom<OldBodyId> for BodyId {
Serialize,
Deserialize,
)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum BodyPart {
/// The body's declaration, under whatever means it decides.
Voice,
Expand Down Expand Up @@ -261,6 +264,7 @@ impl TryFrom<OldBodyPart> for BodyPart {
Serialize,
Deserialize,
)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
Expand Down
1 change: 1 addition & 0 deletions src/v3/junctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) const MAX_JUNCTIONS: usize = 8;
serde::Serialize,
serde::Deserialize,
)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Junctions {
/// The interpreting consensus system.
Here,
Expand Down
7 changes: 7 additions & 0 deletions src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub type QueryId = u64;
#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))]
#[codec(encode_bound())]
#[scale_info(bounds(), skip_type_params(Call))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct Xcm<Call>(pub Vec<Instruction<Call>>);

pub const MAX_INSTRUCTIONS_TO_DECODE: u8 = 100;
Expand Down Expand Up @@ -236,6 +237,7 @@ parameter_types! {
}

#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct PalletInfo {
#[codec(compact)]
index: u32,
Expand Down Expand Up @@ -266,6 +268,7 @@ impl PalletInfo {
}

#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum MaybeErrorCode {
Success,
Error(BoundedVec<u8, MaxDispatchErrorLen>),
Expand All @@ -289,6 +292,7 @@ impl Default for MaybeErrorCode {

/// Response data to a query.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Response {
/// No response. Serves as a neutral default.
Null,
Expand All @@ -312,6 +316,7 @@ impl Default for Response {

/// Information regarding the composition of a query response.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct QueryResponseInfo {
/// The destination to which the query response message should be send.
pub destination: MultiLocation,
Expand All @@ -324,6 +329,7 @@ pub struct QueryResponseInfo {

/// An optional weight limit.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WeightLimit {
/// No weight limit imposed.
Unlimited,
Expand Down Expand Up @@ -400,6 +406,7 @@ impl XcmContext {
#[codec(encode_bound())]
#[codec(decode_bound())]
#[scale_info(bounds(), skip_type_params(Call))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Instruction<Call> {
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding
/// Register.
Expand Down
Loading

0 comments on commit 6363deb

Please sign in to comment.