Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Message router for LCMP & XCMP #141

Merged
merged 37 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0eb70fc
init message router pallet
jiguantong Aug 19, 2022
7142955
Add xcm exec config
jiguantong Aug 23, 2022
cb615d3
route xcm to moonbeam
jiguantong Oct 12, 2022
b1d54dd
Add message router for pangolin-parachain
jiguantong Aug 24, 2022
6e77a49
extend remote xcm
jiguantong Aug 25, 2022
7f8eaae
format
jiguantong Aug 29, 2022
28744de
update weight for message router
jiguantong Aug 30, 2022
52b1a49
format
jiguantong Aug 30, 2022
02ca129
extend DescendOrigin for remote xcm
jiguantong Aug 30, 2022
8886020
Add parachain & relay chain runtime mock
jiguantong Oct 12, 2022
4b559c2
format
jiguantong Sep 1, 2022
52912a5
Add descendOrigin barrier & allow moonbeam
jiguantong Sep 2, 2022
b26217e
Support AccountKey20Derive
jiguantong Oct 12, 2022
f9e61f1
Companion for PureStake/moonbeam#1791
jiguantong Sep 8, 2022
c6fbfbf
use default weight for bridge_messages
jiguantong Sep 14, 2022
1fc3005
add comments
jiguantong Sep 22, 2022
73dd3d9
Add message router for crab parachain
jiguantong Sep 22, 2022
6592059
Add message router for darwinia parachain
jiguantong Sep 22, 2022
f4bc4ce
format
jiguantong Sep 22, 2022
1f4b3cc
remove mock
jiguantong Sep 22, 2022
40fd856
add comment for barrier
jiguantong Sep 23, 2022
82640a8
Allow `DescendOrigin` for Astar
jiguantong Sep 27, 2022
0bf60b9
Support alpha bridge
jiguantong Oct 12, 2022
f98182e
format
jiguantong Oct 1, 2022
2a2a530
Fix compile after rebase
jiguantong Oct 12, 2022
5b9054f
fix pangolin parachain alpha bridge
jiguantong Oct 13, 2022
e83111c
Adapt to multiple targets
jiguantong Oct 17, 2022
bfac62d
add xcm fee limit
jiguantong Oct 18, 2022
d6c38a9
Revert "add xcm fee limit"
jiguantong Oct 18, 2022
de25437
update comment
jiguantong Oct 18, 2022
c5b60ed
remove useless config and sort
jiguantong Oct 19, 2022
4d48709
add comments
jiguantong Oct 19, 2022
3af655e
update comment
jiguantong Oct 19, 2022
0b76522
account_u8 to raw_account
jiguantong Oct 19, 2022
63db32d
sp-io
jiguantong Oct 20, 2022
630fcb6
Support astar network router
jiguantong Oct 24, 2022
434e379
dont need `reverse` of `AccountKey20Derive`
jiguantong Oct 25, 2022
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
59 changes: 40 additions & 19 deletions Cargo.lock

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

16 changes: 13 additions & 3 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ frame-system = { default-features = false, git = "https://github.c
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
# polkadot
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
polkadot-runtime-parachains = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
xcm-builder = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27" }

[dev-dependencies]
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
jiguantong marked this conversation as resolved.
Show resolved Hide resolved

[features]
default = ["std"]
Expand Down Expand Up @@ -73,7 +78,12 @@ std = [
"sp-runtime/std",
"sp-std/std",
# polkadot
"pallet-xcm/std",
"polkadot-core-primitives/std",
"polkadot-parachain/std",
"polkadot-runtime-parachains/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
]

Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod helixbridge;
pub mod message_router;
pub mod remote_governance;
pub mod xcm_config;

Expand Down
78 changes: 78 additions & 0 deletions runtime/common/src/message_router/barriers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia 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.
//
// Darwinia 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 Darwinia. If not, see <https://www.gnu.org/licenses/>.

//! Various implementations for `ShouldExecute`.

use frame_support::{ensure, log, traits::Contains, weights::Weight};
use sp_std::{marker::PhantomData, result::Result};
use xcm::latest::{Instruction::*, MultiLocation, WeightLimit::*, Xcm};
use xcm_executor::traits::ShouldExecute;

/// Allows execution from `origin` if it is contained in `T` (i.e. `T::Contains(origin)`) taking
/// payments into account.
///
/// Only allows for `TeleportAsset`, `WithdrawAsset`, `ClaimAsset` and `ReserveAssetDeposit` XCMs
/// because they are the only ones that place assets in the Holding Register to pay for execution.
/// Copy from https://github.com/paritytech/polkadot/blob/release-v0.9.26/xcm/xcm-builder/src/barriers.rs#L53
/// Allow `DescendOrigin` as the first instruction to specify the payment account
pub struct AllowDescendOriginPaidExecutionFrom<T>(PhantomData<T>);
impl<T: Contains<MultiLocation>> ShouldExecute for AllowDescendOriginPaidExecutionFrom<T> {
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
log::trace!(
target: "xcm::barriers",
"AllowDescendOriginPaidExecutionFrom origin: {:?}, message: {:?}, max_weight: {:?}, weight_credit: {:?}",
origin, message, max_weight, _weight_credit,
);
ensure!(T::contains(origin), ());
let mut iter = message.0.iter_mut();
let i = iter.next().ok_or(())?;
// Modified: Only allows `DescendOrigin` as the first instruction
match i {
DescendOrigin(_) => (),
_ => return Err(()),
}
let i = iter.next().ok_or(())?;
match i {
ReceiveTeleportedAsset(..)
| WithdrawAsset(..)
| ReserveAssetDeposited(..)
| ClaimAsset { .. } => (),
_ => return Err(()),
}
let mut i = iter.next().ok_or(())?;
while let ClearOrigin = i {
i = iter.next().ok_or(())?;
}
match i {
BuyExecution { weight_limit: Limited(ref mut weight), .. } if *weight >= max_weight => {
*weight = max_weight;
Ok(())
},
BuyExecution { ref mut weight_limit, .. } if weight_limit == &Unlimited => {
*weight_limit = Limited(max_weight);
Ok(())
},
_ => Err(()),
}
}
}
51 changes: 51 additions & 0 deletions runtime/common/src/message_router/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia 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.
//
// Darwinia 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 Darwinia. If not, see <https://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

// --- paritytech ---
use frame_benchmarking::{account, benchmarks};
use frame_support::{assert_ok, traits::Get};
use frame_system::RawOrigin;
use sp_std::{boxed::Box, vec};
use xcm::{latest::prelude::*, VersionedXcm::V2};
// --- darwinia ---
use crate::message_router::{Call, Config, Pallet};
use dc_primitives::COIN;

benchmarks! {
set_target_xcm_exec_config {
let target_location = T::MoonbeamLocation::get();
let local_asset_units_per_second: u128 = 14719736222326895902025_u128;
}:_(RawOrigin::Root, target_location.clone(), local_asset_units_per_second)
verify {
assert_eq!(Pallet::<T>::target_xcm_exec_config(target_location), Some(local_asset_units_per_second));
}

forward_to_moonbeam {
let target_location = T::MoonbeamLocation::get();
let local_asset_units_per_second: u128 = 14719736222326895902025_u128;
assert_ok!(Pallet::<T>::set_target_xcm_exec_config(RawOrigin::Root.into(), target_location.clone(), local_asset_units_per_second));
let xcm = Xcm(vec![
DescendOrigin(X1(AccountKey20 {
network: Any,
key: [0u8;20].into()
})),
]);
}:_(RawOrigin::Root, Box::new(V2(xcm)))
}
Loading