Add Basic XCM (#1934)

* basic setup

* fix compile

* add back xcmsink

* Update primitives.rs

* add downward xcm for sudo

* Update paras_sudo_wrapper.rs

* Update Cargo.lock

* some cleanups

* Add error log

Co-authored-by: Sergei Shulepov <sergei@parity.io>
This commit is contained in:
Shawn Tabrizi
2020-12-14 02:11:08 -08:00
committed by GitHub
parent a5fe710cc6
commit adaa63098b
7 changed files with 108 additions and 4 deletions
+2
View File
@@ -35,6 +35,7 @@ pallet-offences = { git = "https://github.com/paritytech/substrate", branch = "m
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
xcm = { package = "xcm", path = "../../xcm", default-features = false }
xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", default-features = false }
primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }
libsecp256k1 = { version = "0.3.5", default-features = false, optional = true }
@@ -84,6 +85,7 @@ std = [
"pallet-timestamp/std",
"pallet-vesting/std",
"xcm/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"libsecp256k1/hmac",
+36
View File
@@ -52,6 +52,42 @@ impl UmpSink for () {
}
}
/// A specific implementation of a UmpSink where messages are in the XCM format
/// and will be forwarded to the XCM Executor.
pub struct XcmSink<Config>(sp_std::marker::PhantomData<Config>);
impl<Config: xcm_executor::Config> UmpSink for XcmSink<Config> {
fn process_upward_message(origin: ParaId, msg: Vec<u8>) -> Weight {
use parity_scale_codec::Decode;
use xcm::VersionedXcm;
use xcm::v0::{Junction, MultiLocation, ExecuteXcm};
use xcm_executor::XcmExecutor;
let weight: Weight = 0;
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);
}
}
} else {
frame_support::debug::error!(
target: "xcm",
"Failed to decode versioned XCM from upward message.",
);
}
// 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).
weight
}
}
/// An error returned by [`check_upward_messages`] that indicates a violation of one of acceptance
/// criteria rules.
pub enum AcceptanceCheckErr {