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

Companion for paritytech/substrate#11631 #5671

Merged
merged 9 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
360 changes: 187 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "3.1.2", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "3.1.2", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.17", default-features = false }
rustc-hex = { version = "2.1.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
Expand Down
11 changes: 10 additions & 1 deletion runtime/parachains/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ pub mod pallet {

/// Origin for the parachains.
#[pallet::origin]
#[derive(PartialEq, Eq, Clone, Encode, Decode, sp_core::RuntimeDebug, scale_info::TypeInfo)]
#[derive(
PartialEq,
Eq,
Clone,
Encode,
Decode,
sp_core::RuntimeDebug,
scale_info::TypeInfo,
MaxEncodedLen,
)]
pub enum Origin {
/// It comes from a parachain.
Parachain(ParaId),
Expand Down
3 changes: 2 additions & 1 deletion runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ use xcm_builder::{
parameter_types! {
pub const WndLocation: MultiLocation = Here.into();
pub const Ancestry: MultiLocation = Here.into();
pub WestendNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec());
pub WestendNetwork: NetworkId =
NetworkId::Named(b"Westend".to_vec().try_into().expect("shorter than length limit; qed"));
pub CheckAccount: AccountId = XcmPallet::check_account();
}

Expand Down
8 changes: 6 additions & 2 deletions xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ edition = "2021"

[dependencies]
impl-trait-for-tuples = "0.2.2"
parity-scale-codec = { version = "3.1.2", default-features = false, features = [ "derive" ] }
parity-scale-codec = { version = "3.1.2", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
derivative = {version = "2.2.0", default-features = false, features = [ "use_core" ] }
log = { version = "0.4.17", default-features = false }
xcm-procedural = { path = "procedural" }

[features]
default = ["std"]
wasm-api = []
runtime-benchmarks = []
runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
]
std = [
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
]
4 changes: 2 additions & 2 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod mock;
#[cfg(test)]
mod tests;

use codec::{Decode, Encode, EncodeLike};
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use frame_support::traits::{Contains, EnsureOrigin, Get, OriginTrait};
use scale_info::TypeInfo;
use sp_runtime::{
Expand Down Expand Up @@ -212,7 +212,7 @@ pub mod pallet {
}

#[pallet::origin]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum Origin {
/// It comes from somewhere in the XCM space wanting to transact.
Xcm(MultiLocation),
Expand Down
18 changes: 9 additions & 9 deletions xcm/src/v0/junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@

//! Support data structures for `MultiLocation`, primarily the `Junction` datatype.

use alloc::vec::Vec;
use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{traits::ConstU32, WeakBoundedVec};

/// A global identifier of an account-bearing consensus system.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum NetworkId {
/// Unidentified/any.
Any,
/// Some named network.
Named(Vec<u8>),
Named(WeakBoundedVec<u8, ConstU32<32>>),
/// The Polkadot Relay chain
Polkadot,
/// Kusama.
Kusama,
}

/// An identifier of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum BodyId {
/// The only body in its context.
Unit,
/// A named body.
Named(Vec<u8>),
Named(WeakBoundedVec<u8, ConstU32<32>>),
/// An indexed body.
Index(#[codec(compact)] u32),
/// The unambiguous executive body (for Polkadot, this would be the Polkadot council).
Expand All @@ -55,7 +55,7 @@ pub enum BodyId {
}

/// A part of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum BodyPart {
/// The body's declaration, under whatever means it decides.
Voice,
Expand Down Expand Up @@ -102,7 +102,7 @@ impl BodyPart {
/// A single item in a path to describe the relative location of a consensus system.
///
/// 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)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junction {
/// The consensus system of which the context is a member and state-wise super-set.
///
Expand Down Expand Up @@ -147,7 +147,7 @@ pub enum Junction {
/// Usage will vary widely owing to its generality.
///
/// NOTE: Try to avoid using this and instead use a more specific item.
GeneralKey(Vec<u8>),
GeneralKey(WeakBoundedVec<u8, ConstU32<32>>),
/// The unambiguous child.
///
/// Not currently used except as a fallback when deriving ancestry.
Expand Down
8 changes: 4 additions & 4 deletions xcm/src/v1/junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

use super::{BodyId, BodyPart, Junctions, MultiLocation, NetworkId};
use crate::v0::Junction as Junction0;
use alloc::vec::Vec;
use parity_scale_codec::{self, Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{traits::ConstU32, WeakBoundedVec};

/// A single item in a path to describe the relative location of a consensus system.
///
/// 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)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
Expand Down Expand Up @@ -65,7 +65,7 @@ pub enum Junction {
/// Usage will vary widely owing to its generality.
///
/// NOTE: Try to avoid using this and instead use a more specific item.
GeneralKey(Vec<u8>),
GeneralKey(WeakBoundedVec<u8, ConstU32<32>>),
/// The unambiguous child.
///
/// Not currently used except as a fallback when deriving ancestry.
Expand Down
14 changes: 9 additions & 5 deletions xcm/src/v1/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::Junction;
use core::{mem, result};
use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

/// A relative path between state-bearing consensus systems.
Expand Down Expand Up @@ -47,7 +47,7 @@ use scale_info::TypeInfo;
/// that a value is strictly an interior location, in those cases, `Junctions` may be used.
///
/// The `MultiLocation` value of `Null` simply refers to the interpreting consensus system.
#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo)]
#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo, MaxEncodedLen)]
pub struct MultiLocation {
/// The number of parent junctions at the beginning of this `MultiLocation`.
pub parents: u8,
Expand Down Expand Up @@ -425,7 +425,7 @@ const MAX_JUNCTIONS: usize = 8;
///
/// Parent junctions cannot be constructed with this type. Refer to `MultiLocation` for
/// instructions on constructing parent junctions.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junctions {
/// The interpreting consensus system.
Here,
Expand Down Expand Up @@ -1011,6 +1011,7 @@ mod tests {
#[test]
fn conversion_from_other_types_works() {
use crate::v0;
use sp_runtime::WeakBoundedVec;

fn takes_multilocation<Arg: Into<MultiLocation>>(_arg: Arg) {}

Expand Down Expand Up @@ -1042,10 +1043,13 @@ mod tests {
v0::MultiLocation::X3(
v0::Junction::Parent,
v0::Junction::Parent,
v0::Junction::GeneralKey(b"foo".to_vec()),
v0::Junction::GeneralKey(b"foo".to_vec().try_into().unwrap()),
)
.try_into(),
Ok(MultiLocation { parents: 2, interior: X1(GeneralKey(b"foo".to_vec())) }),
Ok(MultiLocation {
parents: 2,
interior: X1(GeneralKey(b"foo".to_vec().try_into().unwrap()))
}),
);
}
}