From 170c908a9f44529f7e806d5b65a7ce3290d04cce Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 2 Aug 2022 11:54:35 +0200 Subject: [PATCH] [BridgeHub] Setup wococo bridge grandpa/parachain pallets --- Cargo.lock | 283 ++++++++++++++++++ Cargo.toml | 9 + README.md | 4 + parachains/runtimes/bridge-hubs/README.md | 18 ++ .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 10 + .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 48 ++- .../bridge-hub-rococo/src/xcm_config.rs | 239 +++++++++------ 7 files changed, 524 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74fe22a8dc..8edcc339e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -713,10 +713,288 @@ dependencies = [ "thiserror", ] +[[package]] +name = "bp-header-chain" +version = "0.1.0" +dependencies = [ + "assert_matches", + "bp-runtime 0.1.0", + "bp-test-utils 0.1.0", + "finality-grandpa", + "frame-support", + "hex", + "hex-literal", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-finality-grandpa", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-header-chain" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "finality-grandpa", + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-finality-grandpa", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-message-dispatch" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "frame-support", + "parity-scale-codec", + "scale-info", + "sp-std", +] + +[[package]] +name = "bp-messages" +version = "0.1.0" +dependencies = [ + "bitvec", + "bp-runtime 0.1.0", + "frame-support", + "frame-system", + "hex", + "hex-literal", + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-std", +] + +[[package]] +name = "bp-messages" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bitvec", + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-std", +] + +[[package]] +name = "bp-parachains" +version = "0.1.0" +dependencies = [ + "bp-polkadot-core 0.1.0", + "bp-runtime 0.1.0", + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", +] + +[[package]] +name = "bp-polkadot-core" +version = "0.1.0" +dependencies = [ + "bp-messages 0.1.0", + "bp-runtime 0.1.0", + "frame-support", + "frame-system", + "hex", + "parity-scale-codec", + "parity-util-mem", + "scale-info", + "serde", + "sp-api", + "sp-core", + "sp-runtime", + "sp-std", + "sp-version", +] + +[[package]] +name = "bp-polkadot-core" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-messages 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-runtime", + "sp-std", + "sp-version", +] + +[[package]] +name = "bp-relayers" +version = "0.1.0" +dependencies = [ + "frame-support", + "hex", + "hex-literal", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-rococo" +version = "0.1.0" +dependencies = [ + "bp-messages 0.1.0", + "bp-polkadot-core 0.1.0", + "bp-runtime 0.1.0", + "frame-support", + "parity-scale-codec", + "smallvec", + "sp-api", + "sp-runtime", + "sp-std", + "sp-version", +] + +[[package]] +name = "bp-rococo" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-messages 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-polkadot-core 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "frame-support", + "parity-scale-codec", + "smallvec", + "sp-api", + "sp-runtime", + "sp-std", + "sp-version", +] + +[[package]] +name = "bp-runtime" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "hash-db", + "hex-literal", + "num-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", +] + +[[package]] +name = "bp-runtime" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "frame-support", + "hash-db", + "num-traits", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", +] + +[[package]] +name = "bp-test-utils" +version = "0.1.0" +dependencies = [ + "bp-header-chain 0.1.0", + "ed25519-dalek", + "finality-grandpa", + "parity-scale-codec", + "sp-application-crypto", + "sp-finality-grandpa", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-test-utils" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-header-chain 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "ed25519-dalek", + "finality-grandpa", + "parity-scale-codec", + "sp-application-crypto", + "sp-finality-grandpa", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-wococo" +version = "0.1.0" +dependencies = [ + "bp-messages 0.1.0", + "bp-polkadot-core 0.1.0", + "bp-rococo 0.1.0", + "bp-runtime 0.1.0", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-wococo" +version = "0.1.0" +source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#81128ab75395e256ae8ef50994d46101d0e67cea" +dependencies = [ + "bp-messages 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-polkadot-core 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-rococo 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + [[package]] name = "bridge-hub-rococo-runtime" version = "0.1.0" dependencies = [ + "bp-polkadot-core 0.1.0", + "bp-rococo 0.1.0", + "bp-wococo 0.1.0", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -9013,6 +9291,11 @@ source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm- dependencies = [ "beefy-merkle-tree", "beefy-primitives", + "bp-messages 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-rococo 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-runtime 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bp-wococo 0.1.0 (git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges)", + "bridge-runtime-common", "frame-benchmarking", "frame-executive", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index b2d34b8e3f..4ba7acb605 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,14 @@ [workspace] members = [ + "bridges/modules/grandpa", + "bridges/modules/messages", + "bridges/modules/parachains", + "bridges/modules/relayers", + "bridges/modules/shift-session-manager", + "bridges/primitives/polkadot-core", + "bridges/primitives/runtime", + "bridges/primitives/chain-rococo", + "bridges/primitives/chain-wococo", "client/cli", "client/consensus/aura", "client/consensus/common", diff --git a/README.md b/README.md index 7ac6ca2e51..852b493ed6 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ See [the `contracts-rococo` readme](parachains/runtimes/contracts/contracts-roco See [the `bridge-hubs` readme](parachains/runtimes/bridge-hubs/README.md) for details. +**_Important:_** + +BridgeHub stuff uses external dependencies from repo `https://github.com/paritytech/parity-bridges-common.git`, which are mirrored to `./bridges` directory with `git subtree` feature. + ## Rococo 👑 [Rococo](https://polkadot.js.org/apps/?rpc=wss://rococo-rpc.polkadot.io) is becoming a [Community Parachain Testbed](https://polkadot.network/blog/rococo-revamp-becoming-a-community-parachain-testbed/) for parachain teams in the Polkadot ecosystem. It supports multiple parachains with the differentiation of long-term connections and recurring short-term connections, to see which parachains are currently connected and how long they will be connected for [see here](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frococo-rpc.polkadot.io#/parachains). diff --git a/parachains/runtimes/bridge-hubs/README.md b/parachains/runtimes/bridge-hubs/README.md index 9f89d42e2d..30832db75c 100644 --- a/parachains/runtimes/bridge-hubs/README.md +++ b/parachains/runtimes/bridge-hubs/README.md @@ -38,6 +38,7 @@ ls -lrt ~/local_bridge_testing/bin/polkadot-parachain ### Run Rococo BridgeHub parachain #### Generate spec + genesis + wasm (paraId=1013) ``` +rm ~/local_bridge_testing/bridge-hub-rococo-local-raw.json ~/local_bridge_testing/bin/polkadot-parachain build-spec --chain bridge-hub-rococo-local --raw --disable-default-bootnode > ~/local_bridge_testing/bridge-hub-rococo-local-raw.json ~/local_bridge_testing/bin/polkadot-parachain export-genesis-state --chain ~/local_bridge_testing/bridge-hub-rococo-local-raw.json > ~/local_bridge_testing/bridge-hub-rococo-local-genesis ~/local_bridge_testing/bin/polkadot-parachain export-genesis-wasm --chain ~/local_bridge_testing/bridge-hub-rococo-local-raw.json > ~/local_bridge_testing/bridge-hub-rococo-local-genesis-wasm @@ -63,3 +64,20 @@ https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer ``` https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/parachains ``` + + +## Git subtree `./bridges` + +Add Bridges repo as a local remote and synchronize it with latest `master` from bridges repo: +``` +git remote add -f bridges git@github.com:paritytech/parity-bridges-common.git +# (ran just only first time, when subtree was initialized) +# git subtree add --prefix=bridges bridges master --squash +git subtree pull --prefix=bridges bridges master --squash +```` +We use `--squash` to avoid adding individual commits and rather squashing them +all into one. + +Now we use `master` branch, but in future, it could change to some release branch/tag. + +Original `./bridges/Cargo.toml` was renamed to `./bridges/Cargo.toml_removed_for_bridges_subtree_feature` to avoid confusion for `Cargo` having multiple workspaces. diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 2bf9f9867c..4ebdf07060 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -66,6 +66,16 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../../parachains/pallets/parachain-info", default-features = false } +# Bridges +bp-polkadot-core = { path = "../../../../bridges/primitives/polkadot-core", default-features = false } +bp-rococo = { path = "../../../../bridges/primitives/chain-rococo", default-features = false } +bp-wococo = { path = "../../../../bridges/primitives/chain-wococo", default-features = false } +pallet-bridge-grandpa = { path = "../../../../bridges/modules/grandpa", default-features = false } +pallet-bridge-messages = { path = "../../../../bridges/modules/messages", default-features = false } +pallet-bridge-parachains = { path = "../../../../bridges/modules/parachains", default-features = false } +pallet-bridge-relayers = { path = "../../../../bridges/modules/relayers", default-features = false } +pallet-shift-session-manager = { path = "../../../../bridges/modules/shift-session-manager", default-features = false } + [features] default = [ "std", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 9076081c28..7fe076ee29 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -50,6 +50,7 @@ use frame_support::{ }, PalletId, }; +use frame_support::traits::IsInVec; use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, @@ -58,6 +59,8 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; +use bp_polkadot_core::parachains::ParaId; + #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -114,6 +117,8 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + // TODO: do we need? + // BridgeRejectObsoleteHeadersAndMessages, ); /// Unchecked extrinsic type as expected by this runtime. @@ -367,7 +372,8 @@ parameter_types! { } impl pallet_transaction_payment::Config for Runtime { - type Event = Event; + // TODO: hacked + // type Event = Event; type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier; @@ -405,6 +411,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -467,6 +474,37 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = (); } +/// Add bridge pallets (GPA) +parameter_types! { + pub const MaxRequests: u32 = 50; + pub const HeadersToKeep: u32 = 1024; +} + +/// Add granda bridge pallet to track Wococo relay chain +pub type WococoGrandpaInstance = (); +impl pallet_bridge_grandpa::Config for Runtime { + type BridgedChain = bp_wococo::Wococo; + type MaxRequests = MaxRequests; + type HeadersToKeep = HeadersToKeep; + type WeightInfo = (); +} + +pub const PARAS_PALLET_NAME: &str = "WococoBridgeHubParachain"; +parameter_types! { + pub const ParachainHeadsToKeep: u32 = 50; + pub const ParasPalletName: &'static str = PARAS_PALLET_NAME; + pub GetTenFirstParachains: Vec = (0..10).map(ParaId).collect(); +} + +/// Add parachain bridge pallet to track Wococo bridge hub parachain +impl pallet_bridge_parachains::Config for Runtime { + type WeightInfo = (); + type BridgesGrandpaPalletInstance = WococoGrandpaInstance; + type ParasPalletName = ParasPalletName; + type TrackedParachains = IsInVec; + type HeadsToKeep = ParachainHeadsToKeep; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -484,7 +522,9 @@ construct_runtime!( // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, - TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, + // TODO: hacked + // TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 11, // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, @@ -498,6 +538,10 @@ construct_runtime!( PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin, Config} = 31, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, + + // Bridge pallets + BridgeWococoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, + BridgeWococoParachains: pallet_bridge_parachains::{Pallet, Call, Storage}, } ); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 2ec84d1887..28a8600d2e 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -1,5 +1,5 @@ use super::{ - AccountId, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, + AccountId, Balance, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, WeightToFee, XcmpQueue, }; use core::marker::PhantomData; @@ -8,13 +8,14 @@ use frame_support::{ traits::{Everything, Nothing}, weights::Weight, }; +use frame_support::weights::IdentityFee; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset, + EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, @@ -23,9 +24,11 @@ use xcm_executor::{traits::ShouldExecute, XcmExecutor}; parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Any; + // TODO: hack: hardcoded Polkadot? + pub const RelayNetwork: NetworkId = NetworkId::Rococo; pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into())); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -79,6 +82,7 @@ parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. pub UnitWeightCost: Weight = 1_000_000_000; pub const MaxInstructions: u32 = 100; + pub MaxAssetsIntoHolding: u32 = 64; } match_types! { @@ -89,97 +93,140 @@ match_types! { } //TODO: move DenyThenTry to polkadot's xcm module. -/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. -/// If it passes the Deny, and matches one of the Allow cases then it is let through. -pub struct DenyThenTry(PhantomData, PhantomData) -where - Deny: ShouldExecute, - Allow: ShouldExecute; - -impl ShouldExecute for DenyThenTry -where - Deny: ShouldExecute, - Allow: ShouldExecute, -{ - fn should_execute( - origin: &MultiLocation, - message: &mut Xcm, - max_weight: Weight, - weight_credit: &mut Weight, - ) -> Result<(), ()> { - Deny::should_execute(origin, message, max_weight, weight_credit)?; - Allow::should_execute(origin, message, max_weight, weight_credit) - } -} +// /// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. +// /// If it passes the Deny, and matches one of the Allow cases then it is let through. +// pub struct DenyThenTry(PhantomData, PhantomData) +// where +// Deny: ShouldExecute, +// Allow: ShouldExecute; +// +// impl ShouldExecute for DenyThenTry +// where +// Deny: ShouldExecute, +// Allow: ShouldExecute, +// { +// fn should_execute( +// origin: &MultiLocation, +// message: &mut Xcm, +// max_weight: Weight, +// weight_credit: &mut Weight, +// ) -> Result<(), ()> { +// Deny::should_execute(origin, message, max_weight, weight_credit)?; +// Allow::should_execute(origin, message, max_weight, weight_credit) +// } +// } +// TODO: hacked // See issue #5233 -pub struct DenyReserveTransferToRelayChain; -impl ShouldExecute for DenyReserveTransferToRelayChain { - fn should_execute( - origin: &MultiLocation, - message: &mut Xcm, - _max_weight: Weight, - _weight_credit: &mut Weight, - ) -> Result<(), ()> { - if message.0.iter().any(|inst| { - matches!( - inst, - InitiateReserveWithdraw { - reserve: MultiLocation { parents: 1, interior: Here }, - .. - } | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } | - TransferReserveAsset { - dest: MultiLocation { parents: 1, interior: Here }, - .. - } - ) - }) { - return Err(()) // Deny - } +// pub struct DenyReserveTransferToRelayChain; +// impl ShouldExecute for DenyReserveTransferToRelayChain { +// fn should_execute( +// origin: &MultiLocation, +// message: &mut Xcm, +// _max_weight: Weight, +// _weight_credit: &mut Weight, +// ) -> Result<(), ()> { +// if message.0.iter().any(|inst| { +// matches!( +// inst, +// InitiateReserveWithdraw { +// reserve: MultiLocation { parents: 1, interior: Here }, +// .. +// } | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } | +// TransferReserveAsset { +// dest: MultiLocation { parents: 1, interior: Here }, +// .. +// } +// ) +// }) { +// return Err(()) // Deny +// } +// +// // An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve` +// // should not allow this, but we just log it here. +// if matches!(origin, MultiLocation { parents: 1, interior: Here }) && +// message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. })) +// { +// log::warn!( +// target: "xcm::barriers", +// "Unexpected ReserveAssetDeposited from the Relay Chain", +// ); +// } +// // Permit everything else +// Ok(()) +// } +// } - // An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve` - // should not allow this, but we just log it here. - if matches!(origin, MultiLocation { parents: 1, interior: Here }) && - message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. })) - { - log::warn!( - target: "xcm::barriers", - "Unexpected ReserveAssetDeposited from the Relay Chain", - ); - } - // Permit everything else - Ok(()) - } +match_types! { + pub type ParentOrParentsUnitPlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) } + }; } -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - AllowUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), ->; +// TOOD: hacked +// pub type Barrier = DenyThenTry< +// DenyReserveTransferToRelayChain, +// ( +// TakeWeightCredit, +// AllowTopLevelPaidExecutionFrom, +// AllowUnpaidExecutionFrom, +// // ^^^ Parent and its exec plurality get free execution +// ), +// >; +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + AllowUnpaidExecutionFrom, + // ^^^ Parent & its unit plurality gets free execution +); +/// XCM weigher type. +pub type XcmWeigher = FixedWeightBounds; + +// TODO: hacked +// pub struct XcmConfig; +// impl xcm_executor::Config for XcmConfig { +// type Call = Call; +// type XcmSender = XcmRouter; +// // How to withdraw and deposit an asset. +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = XcmOriginToTransactDispatchOrigin; +// type IsReserve = NativeAsset; +// type IsTeleporter = (); // Teleporting is disabled. +// type LocationInverter = LocationInverter; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = +// UsingComponents>; +// type ResponseHandler = PolkadotXcm; +// type AssetTrap = PolkadotXcm; +// type AssetClaims = PolkadotXcm; +// type SubscriptionService = PolkadotXcm; +// } pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type Call = Call; type XcmSender = XcmRouter; - // How to withdraw and deposit an asset. type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToTransactDispatchOrigin; type IsReserve = NativeAsset; - type IsTeleporter = (); // Teleporting is disabled. - type LocationInverter = LocationInverter; + type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of UNIT + type UniversalLocation = UniversalLocation; type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = - UsingComponents>; + type Weigher = XcmWeigher; + type Trader = UsingComponents, RelayLocation, AccountId, Balances, ()>; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -189,30 +236,52 @@ pub type LocalOriginToLocation = SignedToAccountId32, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, ); +// TODO: hacked +// impl pallet_xcm::Config for Runtime { +// type Event = Event; +// type SendXcmOrigin = EnsureXcmOrigin; +// type XcmRouter = XcmRouter; +// type ExecuteXcmOrigin = EnsureXcmOrigin; +// type XcmExecuteFilter = Nothing; +// // ^ Disable dispatchable execute on the XCM pallet. +// // Needs to be `Everything` for local testing. +// type XcmExecutor = XcmExecutor; +// type XcmTeleportFilter = Everything; +// type XcmReserveTransferFilter = Nothing; +// type Weigher = FixedWeightBounds; +// type LocationInverter = LocationInverter; +// type Origin = Origin; +// type Call = Call; +// +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// // ^ Override for AdvertisedXcmVersion default +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// } impl pallet_xcm::Config for Runtime { type Event = Event; type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = XcmRouter; type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - // ^ Disable dispatchable execute on the XCM pallet. - // Needs to be `Everything` for local testing. + type XcmExecuteFilter = Everything; type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Nothing; - type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; + type XcmReserveTransferFilter = Everything; + type Weigher = XcmWeigher; type Origin = Origin; type Call = Call; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - // ^ Override for AdvertisedXcmVersion default type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = frame_support::traits::ConstU32<8>; + type UniversalLocation = UniversalLocation; } impl cumulus_pallet_xcm::Config for Runtime {