Skip to content

Commit

Permalink
Add XCM pallet to template runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Mar 16, 2023
1 parent dd03b0c commit 5bc6b39
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 27 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# ignore vscode settings
.vscode

# Custom Polkadot-js apps types
pallets/did/src/custom_types.json
# DIP template
dip-template/res
dip-template/scripts

**/__pycache__
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion dip-template/nodes/dip-receiver/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

const PARA_ID: u32 = 2_000;
const PARA_ID: u32 = 2_001;

pub type ChainSpec = GenericChainSpec<GenesisConfig, Extensions>;
type AccountPublic = <Signature as Verify>::Signer;
Expand Down Expand Up @@ -99,6 +99,7 @@ fn testnet_genesis(
},
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: Default::default(),
did_lookup: Default::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions dip-template/nodes/dip-receiver/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Cli::native_runtime_version(chain_spec)
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}

Expand Down
1 change: 1 addition & 0 deletions dip-template/nodes/dip-sender/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn testnet_genesis(
},
aura: Default::default(),
aura_ext: Default::default(),
polkadot_xcm: Default::default(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions dip-template/nodes/dip-sender/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Cli::native_runtime_version(chain_spec)
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}

Expand Down
1 change: 1 addition & 0 deletions dip-template/res/dev-receiver.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0000000000000000000000000000000000000000000000000000000000000000008e9ad81250d805804e7e08d6b17634f44ee511da822c3259323654eea0feca3003170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
1 change: 1 addition & 0 deletions dip-template/res/dev-receiver.wasm

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dip-template/res/dev-sender.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x00000000000000000000000000000000000000000000000000000000000000000007336d65abf689f4897b226f6d6a45a9943e53314ec0160767cdeb6d774a686a03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
1 change: 1 addition & 0 deletions dip-template/res/dev-sender.wasm

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion dip-template/runtimes/dip-receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-transaction-pool.workspace = true
sp-version.workspace = true

# Polkadot
pallet-xcm.workspace = true
xcm.workspace = true
xcm-builder.workspace = true
xcm-executor.workspace = true
Expand Down Expand Up @@ -97,6 +98,7 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"pallet-xcm/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
Expand All @@ -116,5 +118,6 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-dip-receiver/runtime-benchmarks",
"xcm-builder/runtime-benchmarks"
"xcm-builder/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
]
3 changes: 2 additions & 1 deletion dip-template/runtimes/dip-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ construct_runtime!(
// XCM
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
DmpQueue: cumulus_pallet_dmp_queue = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
PolkadotXcm: pallet_xcm = 32,
CumulusXcm: cumulus_pallet_xcm = 33,

// DID lookup
DidLookup: pallet_did_lookup = 40,
Expand Down
45 changes: 42 additions & 3 deletions dip-template/runtimes/dip-receiver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ use frame_support::{
weights::{IdentityFee, Weight},
};
use frame_system::EnsureRoot;
use pallet_xcm::TestWeightInfo;
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
AllowTopLevelPaidExecutionFrom, CurrencyAdapter, FixedWeightBounds, IsConcrete, SiblingParachainAsNative,
SiblingParachainConvertsVia, UsingComponents,
AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, IsConcrete,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedToAccountId32, UsingComponents,
};
use xcm_executor::XcmExecutor;

Expand All @@ -37,7 +38,7 @@ use crate::{
};

parameter_types! {
pub const HereLocation: MultiLocation = MultiLocation::here();
pub HereLocation: MultiLocation = MultiLocation::here();
pub UnitWeightCost: Weight = Weight::from_ref_time(1_000);
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
Expand Down Expand Up @@ -104,6 +105,44 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
}

const MAX_INSTRUCTIONS: u32 = 100;

parameter_types! {
pub RelayNetwork: Option<NetworkId> = None;
}
#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

pub type XcmPalletToRemoteLocationConverter = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

impl pallet_xcm::Config for Runtime {
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;

type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, XcmPalletToRemoteLocationConverter>;
type MaxLockers = ConstU32<8>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, XcmPalletToRemoteLocationConverter>;
type SovereignAccountOf = ();
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, ConstU32<MAX_INSTRUCTIONS>>;
type WeightInfo = TestWeightInfo;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmReserveTransferFilter = Nothing;
type XcmRouter = XcmRouter;
type XcmTeleportFilter = Nothing;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
}

impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
Expand Down
5 changes: 5 additions & 0 deletions dip-template/runtimes/dip-sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-transaction-pool.workspace = true
sp-version.workspace = true

# Polkadot
pallet-xcm.workspace = true
xcm.workspace = true
xcm-builder.workspace = true
xcm-executor.workspace = true
Expand All @@ -56,6 +57,7 @@ xcm-executor.workspace = true
cumulus-pallet-aura-ext.workspace = true
cumulus-pallet-dmp-queue.workspace = true
cumulus-pallet-parachain-system.workspace = true
cumulus-pallet-xcm.workspace = true
cumulus-pallet-xcmp-queue.workspace = true
cumulus-primitives-core.workspace = true
cumulus-primitives-timestamp.workspace = true
Expand Down Expand Up @@ -96,12 +98,14 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"pallet-xcm/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-core/std",
"cumulus-primitives-timestamp/std",
Expand All @@ -114,5 +118,6 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-dip-sender/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks"
]
2 changes: 2 additions & 0 deletions dip-template/runtimes/dip-sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ construct_runtime!(
// XCM
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
DmpQueue: cumulus_pallet_dmp_queue = 31,
PolkadotXcm: pallet_xcm = 32,
CumulusXcm: cumulus_pallet_xcm = 33,

// DID
Did: did = 40,
Expand Down
50 changes: 47 additions & 3 deletions dip-template/runtimes/dip-sender/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ use frame_support::{
weights::{IdentityFee, Weight},
};
use frame_system::EnsureRoot;
use pallet_xcm::TestWeightInfo;
use xcm::latest::prelude::*;
use xcm_builder::{FixedWeightBounds, UsingComponents};
use xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, SignedToAccountId32, UsingComponents};
use xcm_executor::XcmExecutor;

use crate::{
AccountId, AllPalletsWithSystem, Balance, Balances, ParachainInfo, ParachainSystem, Runtime, RuntimeCall,
RuntimeEvent, XcmpQueue,
RuntimeEvent, RuntimeOrigin, XcmpQueue,
};

parameter_types! {
pub UnitWeightCost: Weight = Weight::from_ref_time(1_000);
pub HereLocation: MultiLocation = Junctions::Here.into();
pub UnitWeightCost: Weight = Weight::from_ref_time(1_000);
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

Expand Down Expand Up @@ -84,3 +85,46 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}

const MAX_INSTRUCTIONS: u32 = 100;

parameter_types! {
pub RelayNetwork: Option<NetworkId> = None;
}
#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

pub type XcmPalletToRemoteLocationConverter = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

impl pallet_xcm::Config for Runtime {
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;

type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, XcmPalletToRemoteLocationConverter>;
type MaxLockers = ConstU32<8>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, XcmPalletToRemoteLocationConverter>;
type SovereignAccountOf = ();
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, ConstU32<MAX_INSTRUCTIONS>>;
type WeightInfo = TestWeightInfo;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmReserveTransferFilter = Nothing;
type XcmRouter = XcmRouter;
type XcmTeleportFilter = Nothing;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
}

impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
4 changes: 4 additions & 0 deletions dip-template/scripts/export-genesis-receiver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

/home/antonio/Developer/kilt-node/target/debug/dip-receiver-node-template export-genesis-state --chain dev /home/antonio/Developer/kilt-node/dip-template/res/dev-receiver.hex
/home/antonio/Developer/kilt-node/target/debug/dip-receiver-node-template export-genesis-wasm --chain dev /home/antonio/Developer/kilt-node/dip-template/res/dev-receiver.wasm
4 changes: 4 additions & 0 deletions dip-template/scripts/export-genesis-sender.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

/home/antonio/Developer/kilt-node/target/debug/dip-sender-node-template export-genesis-state --chain dev /home/antonio/Developer/kilt-node/dip-template/res/dev-sender.hex
/home/antonio/Developer/kilt-node/target/debug/dip-sender-node-template export-genesis-wasm --chain dev /home/antonio/Developer/kilt-node/dip-template/res/dev-sender.wasm
12 changes: 6 additions & 6 deletions dip-template/scripts/start-parachain-receiver-alice.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env sh

/home/antonio/Developer/kilt-node/target/debug/dip-node-template \
--alice --collator --base-path /tmp/para/receiver/alice \
--force-authoring --chain dev-receiver --port 40060 \
--ws-port 50060 --execution wasm \
-- \
--chain ../res/rococo-local-0.9.38.raw.json --execution wasm \
/home/antonio/Developer/kilt-node/target/debug/dip-receiver-node-template \
--alice --collator --base-path /tmp/para/receiver/alice \
--force-authoring --chain dev --port 40060 \
--ws-port 50060 --execution wasm \
-- \
--chain ../res/rococo-local-0.9.38.raw.json --execution wasm \
--port 40600 --ws-port 50600
12 changes: 6 additions & 6 deletions dip-template/scripts/start-parachain-sender-alice.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env sh

/home/antonio/Developer/kilt-node/target/debug/dip-node-template \
--alice --collator --base-path /tmp/para/sender/alice \
--force-authoring --chain dev-sender --port 40010 \
--ws-port 50010 --execution wasm \
-- \
--chain ../res/rococo-local-0.9.38.raw.json --execution wasm \
/home/antonio/Developer/kilt-node/target/debug/dip-sender-node-template \
--alice --collator --base-path /tmp/para/sender/alice \
--force-authoring --chain dev --port 40010 \
--ws-port 50010 --execution wasm \
-- \
--chain ../res/rococo-local-0.9.38.raw.json --execution wasm \
--port 40100 --ws-port 50100

0 comments on commit 5bc6b39

Please sign in to comment.