Skip to content

Commit

Permalink
Extract darwinia-runtime (#32)
Browse files Browse the repository at this point in the history
* Skeleton

* XCM configs

* Bump toolchain

* Code cleaning part.1

* Code cleaning part.2

* Update SS58

* Rename

* Update token decimals

* Format

* Extract darwinia core primitives

* License

* Benchmarks

* Extract constants

* Docs

* CI part.1

* Adjust the runtime pallets structure (#29)

* frame-system

* pallet-timestamp

* pallet-authorship

* pallet-balances

* pallet-transaction-payment

* pallet-parachain-system

* pallet-parachain-info

* pallet-aura-ext

* pallet-xcmp-queue

* pallet-dmp-queue

* pallet-session

* pallet-aura

* pallet-collator-selection

* format

* deal ambiguous name

* fix compile

* clear imports

* update visibility for pallets

* add license for pallets

* update darwinia comments

* CI part.2

Signed-off-by: Xavier Lau <xavier@inv.cafe>

* CI part.3

* CI part.4

* Add missing features

* Case

* Setup build environment

* CI part.5

* init

* adjust structure & fix compile

* Move`type Barrier` out of `common` because of different runtimes may require different barriers

* Add required xcm barriers

* format

* remove redundant files

* format

* format

* try fix ci

* merge main

* fix ci

* Format

* remove unused dependencies

* format

* format

* format

* Format

Signed-off-by: Xavier Lau <xavier@inv.cafe>
Co-authored-by: Xavier Lau <xavier@inv.cafe>
  • Loading branch information
jiguantong and AurevoirXavier authored Nov 15, 2022
1 parent 56b31f8 commit 4e5fac1
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Check
run: |
unset RUSTC_WRAPPER
subalfred check features runtime
subalfred check features runtime/darwinia
runtime-checks:
name: Task check runtime
Expand Down
47 changes: 24 additions & 23 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ panic = "unwind"
members = [
"core/*",
"node",
"runtime",
"runtime/*",
]
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cumulus-relay-chain-interface = { git = "https://github.com/paritytech
cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.30" }

# darwinia
darwinia-runtime = { path = "../runtime" }
darwinia-runtime = { path = "../runtime/darwinia" }
dc-primitives = { path = "../core/primitives" }

# frontier
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub fn run() -> Result<()> {
// TODO: https://github.com/darwinia-network/darwinia-2.0/issues/35
Some(Subcommand::FrontierDb(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
runner.sync_run(|_config| {
// let PartialComponents { client, other, .. } = service::new_partial(&config,
// &cli)?; let frontier_backend = other.2;
// cmd.run::<_, Block>(client, frontier_backend)
Expand Down
27 changes: 27 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Darwinia Common Runtime"
edition = "2021"
homepage = "https://darwinia.network/"
license = "GPL-3.0"
name = "darwinia-common-runtime"
readme = "README.md"
repository = "https://github.com/darwinia-network/darwinia"
version = "6.0.0"

[dependencies]
# polkadot
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" }
# substrate
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }

[features]
default = ["std"]
std = [
# polkadot
"xcm/std",
"xcm-executor/std",
# substrate
"frame-support/std",
]
21 changes: 21 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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_attr(not(feature = "std"), no_std)]

pub mod xcm_barrier;
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
use core::marker::PhantomData;
// polkadot
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::*;
use xcm_executor::traits::ShouldExecute;
// substrate
use frame_support::{log, traits::Everything};
use frame_support::log;

frame_support::match_types! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
};
pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(_) }
};
}

//TODO: move DenyThenTry to polkadot's xcm module.
Expand Down Expand Up @@ -96,13 +99,3 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
Ok(())
}
}

pub type Barrier = DenyThenTry<
DenyReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// ^^^ Parent and its exec plurality get free execution
),
>;
8 changes: 4 additions & 4 deletions runtime/Cargo.toml → runtime/darwinia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ parachain-info = { default-features = false, git = "https://git
cumulus-pallet-session-benchmarking = { optional = true, default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" }

# darwinia
dc-primitives = { default-features = false, path = "../core/primitives" }
darwinia-common-runtime = { default-features = false, path = "../common" }
dc-primitives = { default-features = false, path = "../../core/primitives" }

# frontier
fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" }
Expand Down Expand Up @@ -88,9 +89,7 @@ frame-system-benchmarking = { optional = true, default-features = false, git = "
frame-try-runtime = { optional = true, default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }

[features]
default = [
"std",
]
default = ["std"]
std = [
# crates.io
"codec/std",
Expand All @@ -111,6 +110,7 @@ std = [
"cumulus-pallet-session-benchmarking?/std",

# darwinia
"darwinia-common-runtime/std",
"dc-primitives/std",

# frontier
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions runtime/src/lib.rs → runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ pub use pallets::*;

mod weights;

mod xcm_config;
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;

// crates.io
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ pub use evm::*;

mod base_fee;
pub use base_fee::*;

mod polkadot_xcm;
pub use polkadot_xcm::*;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

mod barrier;
use barrier::Barrier;

// darwinia
use crate::*;
use darwinia_common_runtime::xcm_barrier::*;
// polkadot
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
Expand Down Expand Up @@ -81,6 +79,20 @@ pub type XcmOriginToTransactDispatchOrigin = (
XcmPassthrough<RuntimeOrigin>,
);

pub type Barrier = DenyThenTry<
DenyReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
>;

frame_support::parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const MaxInstructions: u32 = 100;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4e5fac1

Please sign in to comment.