Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7bac2e4
Remove unused relaying XCM
gavofyork Apr 1, 2021
f2929f6
Aggregate HRMP (XCMP/HMP) messages. Payloads for spambot.
gavofyork Mar 31, 2021
3aae107
Revert lock
gavofyork Apr 1, 2021
016c785
Fix
gavofyork Apr 1, 2021
0be98c3
Broken example
gavofyork Apr 2, 2021
b908c5b
Introduce fee payment mechanics into XCM.
gavofyork Apr 2, 2021
03fa34c
Weight limitations on XCM execution
gavofyork Apr 3, 2021
92ec3c4
Mock environment for tests and the first test
gavofyork Apr 3, 2021
8b5b67e
Tests for XCM and a few refactors.
gavofyork Apr 4, 2021
cd713bf
Remove code that's not ready
gavofyork Apr 4, 2021
b1ff9f6
Fix for an XCM and an additional test
gavofyork Apr 4, 2021
9947a81
Query response system
gavofyork Apr 4, 2021
31b851e
XCMP message dispatch system reimagining
gavofyork Apr 5, 2021
24e5dcc
Some build fixes
gavofyork Apr 6, 2021
6a91561
Merge remote-tracking branch 'origin/master' into gav-rococo-stuff
gavofyork Apr 6, 2021
2c53ffe
Remove the Encode bounds sprayed around
gavofyork Apr 6, 2021
84826e8
More faff
gavofyork Apr 6, 2021
d0a5148
Fix bounds amek use latest scale codec.
gavofyork Apr 6, 2021
f1515bf
remove println
shawntabrizi Apr 6, 2021
df6a667
fixes
shawntabrizi Apr 6, 2021
9051563
Fix XcmExecutor Tests
shawntabrizi Apr 6, 2021
54fd800
Fix XCM bounds using derivative crate
gavofyork Apr 6, 2021
9e1500b
Merge branch 'gav-new-xcm' of github.com:paritytech/polkadot into gav…
gavofyork Apr 6, 2021
a959601
Refactor names of XcmGeneric &c into Xcm
gavofyork Apr 7, 2021
b7c4a30
Repot the xcm-executor into xcm-builder
gavofyork Apr 7, 2021
d1e3c3c
Docs
gavofyork Apr 7, 2021
b95a84c
Docs
gavofyork Apr 7, 2021
3f4719b
Fixes
gavofyork Apr 7, 2021
1bc7fb3
Update xcm/src/lib.rs
gavofyork Apr 7, 2021
7277157
Fixes
gavofyork Apr 7, 2021
a55ae8c
Merge branch 'gav-new-xcm' of github.com:paritytech/polkadot into gav…
gavofyork Apr 7, 2021
acfedbb
Docs
gavofyork Apr 7, 2021
9f4f279
Update runtime/parachains/src/ump.rs
gavofyork Apr 7, 2021
29767d4
Docs
gavofyork Apr 7, 2021
1016da9
Fixes
gavofyork Apr 7, 2021
f5c02c3
Fixes
gavofyork Apr 7, 2021
4eb6bb6
Fixes
gavofyork Apr 7, 2021
03d739b
Docs
gavofyork Apr 7, 2021
92b4eb1
Fixes
gavofyork Apr 7, 2021
ad6e55e
Fixes
gavofyork Apr 7, 2021
05716c9
Introduce transfer_asset specialisation.
gavofyork Apr 7, 2021
995bcb1
Fixes
gavofyork Apr 7, 2021
b082bd8
Fixes
gavofyork Apr 7, 2021
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
28 changes: 23 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion runtime/common/src/paras_sudo_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ decl_module! {
/// The given parachain should exist and the payload should not exceed the preconfigured size
/// `config.max_downward_message_size`.
#[weight = (1_000, DispatchClass::Operational)]
pub fn sudo_queue_downward_xcm(origin, id: ParaId, xcm: xcm::VersionedXcm) -> DispatchResult {
pub fn sudo_queue_downward_xcm(origin, id: ParaId, xcm: xcm::opaque::VersionedXcm) -> DispatchResult {
ensure_root(origin)?;
ensure!(<paras::Module<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
let config = <configuration::Module<T>>::config();
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use parity_scale_codec::Encode;
use sp_std::marker::PhantomData;
use xcm::{VersionedXcm, v0::{SendXcm, MultiLocation, Junction, Xcm, Result, Error}};
use xcm::opaque::{VersionedXcm, v0::{SendXcm, MultiLocation, Junction, Xcm, Result, Error}};
use runtime_parachains::{configuration, dmp};

/// Xcm sender for relay chain. It only sends downward message.
Expand All @@ -36,7 +36,7 @@ impl<T: configuration::Config + dmp::Config> SendXcm for RelayChainXcmSender<T>
).map_err(Into::<Error>::into)?;
Ok(())
} else {
Err(Error::CannotReachDestination)
Err(Error::CannotReachDestination("UnsupportedDestination"))
}
}
}
6 changes: 3 additions & 3 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl<T: Config> Module<T> {
<Self as Store>::HrmpOpenChannelRequestsList::append(channel_id);

let notification_bytes = {
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};
use parity_scale_codec::Encode as _;

VersionedXcm::from(Xcm::HrmpNewChannelOpenRequest {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ impl<T: Config> Module<T> {

let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};

VersionedXcm::from(Xcm::HrmpChannelAccepted {
recipient: u32::from(origin),
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<T: Config> Module<T> {
let config = <configuration::Module<T>>::config();
let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v0::Xcm, VersionedXcm};

VersionedXcm::from(Xcm::HrmpChannelClosing {
initiator: u32::from(origin),
Expand Down
20 changes: 11 additions & 9 deletions runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
};
use sp_std::{fmt, prelude::*};
use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque};
use sp_runtime::traits::Zero;
use frame_support::{decl_module, decl_storage, StorageMap, StorageValue, weights::Weight, traits::Get};
use primitives::v1::{Id as ParaId, UpwardMessage};

Expand Down Expand Up @@ -65,27 +66,28 @@ impl<Config: xcm_executor::Config> UmpSink for XcmSink<Config> {
use xcm::v0::{Junction, MultiLocation, ExecuteXcm};
use xcm_executor::XcmExecutor;

let weight: Weight = 0;

if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut &msg[..]) {
// TODO: #2841 #UMPQUEUE Get a proper weight limit here. Probably from Relay Chain Config
let weight_limit = Weight::max_value();
let weight = if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut &msg[..]) {
match versioned_xcm_message {
VersionedXcm::V0(xcm_message) => {
let xcm_junction: Junction = Junction::Parachain { id: origin.into() };
let xcm_location: MultiLocation = xcm_junction.into();
// TODO: Do something with result.
let _result = XcmExecutor::<Config>::execute_xcm(xcm_location, xcm_message);
let result = XcmExecutor::<Config>::execute_xcm(xcm_location, xcm_message, weight_limit);
result.weight_used()
}
}
} else {
log::error!(
target: LOG_TARGET,
"Failed to decode versioned XCM from upward message.",
);
}
Weight::zero()
};

// TODO: to be sound, this implementation must ensure that returned (and thus consumed)
// weight is limited to some small portion of the total block weight (as a ballpark, 1/4, 1/8
// or lower).
// TODO: #2841 #UMPQUEUE to be sound, this implementation must ensure that returned (and thus consumed)
// weight is limited to some small portion of the total block weight (as a ballpark, 1/4, 1/8
// or lower).
weight
}
}
Expand Down
11 changes: 10 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ pub use pallet_balances::Call as BalancesCall;

use polkadot_parachain::primitives::Id as ParaId;
use xcm::v0::{MultiLocation, NetworkId};
use xcm_executor::traits::IsConcrete;
use xcm_builder::{
AccountId32Aliases, ChildParachainConvertsVia, SovereignSignedViaLocation,
CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative,
SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter,
IsConcrete, FixedWeightBounds, FixedRateOfConcreteFungible,
};
use constants::{time::*, currency::*, fee::*};
use frame_support::traits::InstanceFilter;
Expand Down Expand Up @@ -616,6 +616,11 @@ type LocalOriginConverter = (
ChildSystemParachainAsSuperuser<ParaId, Origin>,
);

parameter_types! {
pub const BaseXcmWeight: Weight = 100_000;
pub const RocFee: (MultiLocation, u128) = (RocLocation::get(), 1 * CENTS);
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = Call;
Expand All @@ -625,6 +630,10 @@ impl xcm_executor::Config for XcmConfig {
type IsReserve = ();
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = ();
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type Trader = FixedRateOfConcreteFungible<RocFee>;
type ResponseHandler = ();
}

impl parachains_session_info::Config for Runtime {}
Expand Down
1 change: 1 addition & 0 deletions xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"

[dependencies]
parity-scale-codec = { version = "2.0.0", default-features = false, features = [ "derive" ] }
derivative = {version = "2.2.0", default-features = false, features = [ "use_core" ] }

[features]
default = ["std"]
Expand Down
74 changes: 74 additions & 0 deletions xcm/src/double_encoded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use alloc::vec::Vec;
use parity_scale_codec::{Encode, Decode};

#[derive(Encode, Decode)]
#[codec(encode_bound())]
#[codec(decode_bound())]
pub struct DoubleEncoded<T> {
encoded: Vec<u8>,
#[codec(skip)]
decoded: Option<T>,
}

impl<T> Clone for DoubleEncoded<T> {
fn clone(&self) -> Self { Self { encoded: self.encoded.clone(), decoded: None } }
}
impl<T> Eq for DoubleEncoded<T> {
}
impl<T> PartialEq for DoubleEncoded<T> {
fn eq(&self, other: &Self) -> bool { self.encoded.eq(&other.encoded) }
}
impl<T> core::fmt::Debug for DoubleEncoded<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.encoded.fmt(f) }
}

impl<T> From<Vec<u8>> for DoubleEncoded<T> {
fn from(encoded: Vec<u8>) -> Self {
Self { encoded, decoded: None }
}
}

impl<T> DoubleEncoded<T> {
pub fn into<S>(self) -> DoubleEncoded<S> { DoubleEncoded::from(self) }
pub fn from<S>(e: DoubleEncoded<S>) -> Self {
Self {
encoded: e.encoded,
decoded: None,
}
}
pub fn as_ref(&self) -> Option<&T> {
self.decoded.as_ref()
}
}

impl<T: Decode> DoubleEncoded<T> {
pub fn ensure_decoded(&mut self) -> Result<&T, ()> {
if self.decoded.is_none() {
self.decoded = T::decode(&mut &self.encoded[..]).ok();
}
self.decoded.as_ref().ok_or(())
}
pub fn take_decoded(&mut self) -> Result<T, ()> {
self.decoded.take().or_else(|| T::decode(&mut &self.encoded[..]).ok()).ok_or(())
}
pub fn try_into(mut self) -> Result<T, ()> {
self.ensure_decoded()?;
self.decoded.ok_or(())
}
}
25 changes: 22 additions & 3 deletions xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,32 @@
extern crate alloc;

use parity_scale_codec::{Encode, Decode};
use derivative::Derivative;

pub mod v0;

mod double_encoded;
pub use double_encoded::DoubleEncoded;

/// A single XCM message, together with its version code.
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub enum VersionedXcm {
V0(v0::Xcm),
#[derive(Derivative, Encode, Decode)]
#[derivative(Clone(bound=""), Eq(bound=""), PartialEq(bound=""), Debug(bound=""))]
#[codec(encode_bound())]
#[codec(decode_bound())]
pub enum VersionedXcm<Call> {
V0(v0::Xcm<Call>),
}

pub mod opaque {
pub mod v0 {
// Everything from v0
pub use crate::v0::*;
// Then override with the opaque types in v0
pub use crate::v0::opaque::{Xcm, Order};
}

/// The basic VersionedXcm type which just uses the `Vec<u8>` as an encoded call.
pub type VersionedXcm = super::VersionedXcm<()>;
}

/// A versioned multi-location, a relative location of a cross-consensus system identifier.
Expand Down
6 changes: 5 additions & 1 deletion xcm/src/v0/junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
/// Generally used when the context is a Polkadot Relay-chain.
///
/// There is also `Parachain` which can be used in tests to avoid the faffy `{ id: ... }` syntax. Production
/// code should use this.
// TODO: parity-scale-codec#262: Change to be `Parachain(#[codec(compact)] u32)`
Parachain { #[codec(compact)] id: u32 },
/// A 32-byte identifier for an account of a specific network that is respected as a sovereign endpoint within
/// the context.
Expand All @@ -64,7 +68,7 @@ pub enum Junction {
/// An instanced, indexed pallet that forms a constituent part of the context.
///
/// Generally used when the context is a Frame-based chain.
PalletInstance { id: u8 },
PalletInstance(u8),
/// A non-descript index within the context location.
///
/// Usage will vary widely owing to its generality.
Expand Down
Loading