[BridgeHub] Setup wococo bridge grandpa/parachain pallets

This commit is contained in:
Branislav Kontur
2022-08-02 11:54:35 +02:00
parent e48282b840
commit 170c908a9f
7 changed files with 524 additions and 87 deletions
Generated
+283
View File
@@ -713,10 +713,288 @@ dependencies = [
"thiserror", "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]] [[package]]
name = "bridge-hub-rococo-runtime" name = "bridge-hub-rococo-runtime"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bp-polkadot-core 0.1.0",
"bp-rococo 0.1.0",
"bp-wococo 0.1.0",
"cumulus-pallet-aura-ext", "cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue", "cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system",
@@ -9013,6 +9291,11 @@ source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-
dependencies = [ dependencies = [
"beefy-merkle-tree", "beefy-merkle-tree",
"beefy-primitives", "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-benchmarking",
"frame-executive", "frame-executive",
"frame-support", "frame-support",
+9
View File
@@ -1,5 +1,14 @@
[workspace] [workspace]
members = [ 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/cli",
"client/consensus/aura", "client/consensus/aura",
"client/consensus/common", "client/consensus/common",
+4
View File
@@ -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. 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 👑
[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). [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).
+18
View File
@@ -38,6 +38,7 @@ ls -lrt ~/local_bridge_testing/bin/polkadot-parachain
### Run Rococo BridgeHub parachain ### Run Rococo BridgeHub parachain
#### Generate spec + genesis + wasm (paraId=1013) #### 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 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-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 ~/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 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.
@@ -66,6 +66,16 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default-
pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false }
parachain-info = { path = "../../../../parachains/pallets/parachain-info", 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] [features]
default = [ default = [
"std", "std",
@@ -50,6 +50,7 @@ use frame_support::{
}, },
PalletId, PalletId,
}; };
use frame_support::traits::IsInVec;
use frame_system::{ use frame_system::{
limits::{BlockLength, BlockWeights}, limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureRoot,
@@ -58,6 +59,8 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill}; pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};
use bp_polkadot_core::parachains::ParaId;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage; pub use sp_runtime::BuildStorage;
@@ -114,6 +117,8 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>, frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>, frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
// TODO: do we need?
// BridgeRejectObsoleteHeadersAndMessages,
); );
/// Unchecked extrinsic type as expected by this runtime. /// Unchecked extrinsic type as expected by this runtime.
@@ -367,7 +372,8 @@ parameter_types! {
} }
impl pallet_transaction_payment::Config for Runtime { impl pallet_transaction_payment::Config for Runtime {
type Event = Event; // TODO: hacked
// type Event = Event;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>; type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type WeightToFee = WeightToFee; type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>; type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
@@ -405,6 +411,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ControllerOrigin = EnsureRoot<AccountId>; type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type WeightInfo = (); type WeightInfo = ();
type PriceForSiblingDelivery = ();
} }
impl cumulus_pallet_dmp_queue::Config for Runtime { impl cumulus_pallet_dmp_queue::Config for Runtime {
@@ -467,6 +474,37 @@ impl pallet_collator_selection::Config for Runtime {
type WeightInfo = (); 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<ParaId> = (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<GetTenFirstParachains>;
type HeadsToKeep = ParachainHeadsToKeep;
}
// Create the runtime by composing the FRAME pallets that were previously configured. // Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!( construct_runtime!(
pub enum Runtime where pub enum Runtime where
@@ -484,7 +522,9 @@ construct_runtime!(
// Monetary stuff. // Monetary stuff.
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10, Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 11, // TODO: hacked
// TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 11,
TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 11,
// Collator support. The order of these 4 are important and shall not change. // Collator support. The order of these 4 are important and shall not change.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, Authorship: pallet_authorship::{Pallet, Call, Storage} = 20,
@@ -498,6 +538,10 @@ construct_runtime!(
PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin, Config} = 31, PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin, Config} = 31,
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 32, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 32,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 33, DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 33,
// Bridge pallets
BridgeWococoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
BridgeWococoParachains: pallet_bridge_parachains::{Pallet, Call, Storage},
} }
); );
@@ -1,5 +1,5 @@
use super::{ use super::{
AccountId, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, AccountId, Balance, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
WeightToFee, XcmpQueue, WeightToFee, XcmpQueue,
}; };
use core::marker::PhantomData; use core::marker::PhantomData;
@@ -8,13 +8,14 @@ use frame_support::{
traits::{Everything, Nothing}, traits::{Everything, Nothing},
weights::Weight, weights::Weight,
}; };
use frame_support::weights::IdentityFee;
use pallet_xcm::XcmPassthrough; use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling; use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor; use polkadot_runtime_common::impls::ToAuthor;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
use xcm_builder::{ use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, UsingComponents,
@@ -23,9 +24,11 @@ use xcm_executor::{traits::ShouldExecute, XcmExecutor};
parameter_types! { parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent(); 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 RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).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 /// 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. // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: Weight = 1_000_000_000; pub UnitWeightCost: Weight = 1_000_000_000;
pub const MaxInstructions: u32 = 100; pub const MaxInstructions: u32 = 100;
pub MaxAssetsIntoHolding: u32 = 64;
} }
match_types! { match_types! {
@@ -89,97 +93,140 @@ match_types! {
} }
//TODO: move DenyThenTry to polkadot's xcm module. //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. // /// 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. // /// If it passes the Deny, and matches one of the Allow cases then it is let through.
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>) // pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
where // where
Deny: ShouldExecute, // Deny: ShouldExecute,
Allow: ShouldExecute; // Allow: ShouldExecute;
//
impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow> // impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
where // where
Deny: ShouldExecute, // Deny: ShouldExecute,
Allow: ShouldExecute, // Allow: ShouldExecute,
{ // {
fn should_execute<Call>( // fn should_execute<Call>(
origin: &MultiLocation, // origin: &MultiLocation,
message: &mut Xcm<Call>, // message: &mut Xcm<Call>,
max_weight: Weight, // max_weight: Weight,
weight_credit: &mut Weight, // weight_credit: &mut Weight,
) -> Result<(), ()> { // ) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?; // Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit) // Allow::should_execute(origin, message, max_weight, weight_credit)
} // }
} // }
// TODO: hacked
// See issue #5233 // See issue #5233
pub struct DenyReserveTransferToRelayChain; // pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain { // impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<Call>( // fn should_execute<Call>(
origin: &MultiLocation, // origin: &MultiLocation,
message: &mut Xcm<Call>, // message: &mut Xcm<Call>,
_max_weight: Weight, // _max_weight: Weight,
_weight_credit: &mut Weight, // _weight_credit: &mut Weight,
) -> Result<(), ()> { // ) -> Result<(), ()> {
if message.0.iter().any(|inst| { // if message.0.iter().any(|inst| {
matches!( // matches!(
inst, // inst,
InitiateReserveWithdraw { // InitiateReserveWithdraw {
reserve: MultiLocation { parents: 1, interior: Here }, // reserve: MultiLocation { parents: 1, interior: Here },
.. // ..
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } | // } | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
TransferReserveAsset { // TransferReserveAsset {
dest: MultiLocation { parents: 1, interior: Here }, // dest: MultiLocation { parents: 1, interior: Here },
.. // ..
} // }
) // )
}) { // }) {
return Err(()) // Deny // 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` match_types! {
// should not allow this, but we just log it here. pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {
if matches!(origin, MultiLocation { parents: 1, interior: Here }) && MultiLocation { parents: 1, interior: Here } |
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. })) MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }
{ };
log::warn!(
target: "xcm::barriers",
"Unexpected ReserveAssetDeposited from the Relay Chain",
);
}
// Permit everything else
Ok(())
}
} }
pub type Barrier = DenyThenTry< // TOOD: hacked
DenyReserveTransferToRelayChain, // pub type Barrier = DenyThenTry<
( // DenyReserveTransferToRelayChain,
TakeWeightCredit, // (
AllowTopLevelPaidExecutionFrom<Everything>, // TakeWeightCredit,
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>, // AllowTopLevelPaidExecutionFrom<Everything>,
// ^^^ Parent and its exec plurality get free execution // AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
), // // ^^^ Parent and its exec plurality get free execution
>; // ),
// >;
pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
// ^^^ Parent & its unit plurality gets free execution
);
/// XCM weigher type.
pub type XcmWeigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
// 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<Ancestry>;
// type Barrier = Barrier;
// type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
// type Trader =
// UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
// type ResponseHandler = PolkadotXcm;
// type AssetTrap = PolkadotXcm;
// type AssetClaims = PolkadotXcm;
// type SubscriptionService = PolkadotXcm;
// }
pub struct XcmConfig; pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig { impl xcm_executor::Config for XcmConfig {
type Call = Call; type Call = Call;
type XcmSender = XcmRouter; type XcmSender = XcmRouter;
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor; type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin; type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset; type IsReserve = NativeAsset;
type IsTeleporter = (); // Teleporting is disabled. type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of UNIT
type LocationInverter = LocationInverter<Ancestry>; type UniversalLocation = UniversalLocation;
type Barrier = Barrier; type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>; type Weigher = XcmWeigher;
type Trader = type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;
UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = PolkadotXcm; type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm; type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm; type AssetClaims = PolkadotXcm;
type SubscriptionService = 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. /// No local origins on this chain are allowed to dispatch XCM sends/executions.
@@ -189,30 +236,52 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
/// queues. /// queues.
pub type XcmRouter = ( pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain: // Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>, cumulus_primitives_utility::ParentAsUmp<ParachainSystem, (), ()>,
// ..and XCMP to communicate with the sibling chains. // ..and XCMP to communicate with the sibling chains.
XcmpQueue, XcmpQueue,
); );
// TODO: hacked
// impl pallet_xcm::Config for Runtime {
// type Event = Event;
// type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
// type XcmRouter = XcmRouter;
// type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
// type XcmExecuteFilter = Nothing;
// // ^ Disable dispatchable execute on the XCM pallet.
// // Needs to be `Everything` for local testing.
// type XcmExecutor = XcmExecutor<XcmConfig>;
// type XcmTeleportFilter = Everything;
// type XcmReserveTransferFilter = Nothing;
// type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
// type LocationInverter = LocationInverter<Ancestry>;
// 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 { impl pallet_xcm::Config for Runtime {
type Event = Event; type Event = Event;
type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>; type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter; type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>; type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing; type XcmExecuteFilter = Everything;
// ^ Disable dispatchable execute on the XCM pallet.
// Needs to be `Everything` for local testing.
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything; type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>; type Weigher = XcmWeigher;
type LocationInverter = LocationInverter<Ancestry>;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; 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 { impl cumulus_pallet_xcm::Config for Runtime {