Align BridgeHub runtimes with other SP runtimes + reused test for teleport native tokens + some nits (#2449)

* Align BridgeHub runtimes with other SP runtimes

* Reused `teleports_for_native_asset_works` test to all bridge-hub runtime

* Fix import vs doc

* Removed unnecessery deps

* DealWithFees + ToAuthor->ToStakingPot for BH according to the other runtimes

* Update parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Update parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Update parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Align all desc

* Extract runtime_para_id for test

* Fix test

---------

Co-authored-by: parity-processbot <>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
Branislav Kontur
2023-04-24 15:43:16 +02:00
committed by GitHub
parent 8615ac834c
commit 2c1dd4f017
28 changed files with 312 additions and 87 deletions
Generated
+10 -3
View File
@@ -761,6 +761,7 @@ dependencies = [
name = "bridge-hub-kusama-runtime"
version = "0.1.0"
dependencies = [
"bridge-hub-test-utils",
"cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
@@ -786,7 +787,6 @@ dependencies = [
"pallet-collator-selection",
"pallet-multisig",
"pallet-session",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
@@ -824,6 +824,7 @@ dependencies = [
name = "bridge-hub-polkadot-runtime"
version = "0.1.0"
dependencies = [
"bridge-hub-test-utils",
"cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
@@ -848,7 +849,6 @@ dependencies = [
"pallet-collator-selection",
"pallet-multisig",
"pallet-session",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
@@ -887,6 +887,7 @@ dependencies = [
name = "bridge-hub-rococo-runtime"
version = "0.1.0"
dependencies = [
"bridge-hub-test-utils",
"cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
@@ -911,7 +912,6 @@ dependencies = [
"pallet-collator-selection",
"pallet-multisig",
"pallet-session",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
@@ -946,6 +946,13 @@ dependencies = [
"xcm-executor",
]
[[package]]
name = "bridge-hub-test-utils"
version = "0.1.0"
dependencies = [
"asset-test-utils",
]
[[package]]
name = "bs58"
version = "0.4.0"
+1 -1
View File
@@ -123,7 +123,7 @@ for `release-parachains-v0.9.270`
5. Clone `it/release-<version>-fast-sudo` from Polkadot
In case the branch does not exists (it is a manual process): cherry pick paritytech/polkadot@791c8b8 and run
`find . -type f -name "*.toml" -print0 | xargs -0 sed -i '' -e 's/polkadot-vX.X.X/polkadot-v<version>/g'`
6. `cargo build --release features --fast-runtime`
6. `cargo build --release --features fast-runtime`
7. Copy `./target/polkadot` into `./bin` (in Cumulus)
8. Run the tests:
- Statemint: `yarn zombienet-test -c ./examples/statemint/config.toml -t ./examples/statemint`
@@ -22,9 +22,7 @@ use cumulus_primitives_core::{
};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use polkadot_parachain::primitives::{
HeadData, RelayChainBlockNumber, ValidationParams, ValidationResult,
};
use polkadot_parachain::primitives::{HeadData, RelayChainBlockNumber, ValidationResult};
use codec::Encode;
@@ -238,7 +236,7 @@ where
.expect("Could not find `set_validation_data` inherent")
}
/// Validate the given [`PersistedValidationData`] against the [`ValidationParams`].
/// Validate the given [`PersistedValidationData`] against the [`MemoryOptimizedValidationParams`].
fn validate_validation_data(
validation_data: &PersistedValidationData,
relay_parent_number: RelayChainBlockNumber,
@@ -28,6 +28,9 @@ pub mod constants;
mod weights;
pub mod xcm_config;
use assets_common::{
foreign_creators::ForeignCreators, matching::FromSiblingParachain, MultiLocationForAssetId,
};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
@@ -74,9 +77,6 @@ use xcm_config::{
pub use sp_runtime::BuildStorage;
// Polkadot imports
use assets_common::{
foreign_creators::ForeignCreators, matching::FromSiblingParachain, MultiLocationForAssetId,
};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use xcm::latest::BodyId;
@@ -356,7 +356,7 @@ pub type Barrier = DenyThenTry<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its plurality (i.e. governance bodies) gets free execution.
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
@@ -492,7 +492,8 @@ asset_test_utils::include_teleports_for_native_asset_works!(
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
})
}),
1000
);
asset_test_utils::include_teleports_for_foreign_assets_works!(
@@ -259,7 +259,7 @@ pub type Barrier = DenyThenTry<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent, its plurality (i.e. governance bodies) and Fellows plurality gets free execution.
// Parent, its pluralities (i.e. governance bodies), and the Fellows plurality get free execution.
AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, FellowsPlurality)>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
@@ -470,7 +470,8 @@ asset_test_utils::include_teleports_for_native_asset_works!(
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
})
}),
1000
);
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
@@ -78,6 +78,7 @@ pub fn teleports_for_native_asset_works<
unwrap_xcmp_queue_event: Box<
dyn Fn(Vec<u8>) -> Option<cumulus_pallet_xcmp_queue::Event<Runtime>>,
>,
runtime_para_id: u32,
) where
Runtime: frame_system::Config
+ pallet_balances::Config
@@ -102,7 +103,6 @@ pub fn teleports_for_native_asset_works<
Call = cumulus_pallet_parachain_system::Call<Runtime>,
>,
{
let runtime_para_id = 1000;
ExtBuilder::<Runtime>::default()
.with_collators(collator_session_keys.collators())
.with_session_keys(collator_session_keys.session_keys())
@@ -273,14 +273,15 @@ macro_rules! include_teleports_for_native_asset_works(
$collator_session_key:expr,
$existential_deposit:expr,
$unwrap_pallet_xcm_event:expr,
$unwrap_xcmp_queue_event:expr
$unwrap_xcmp_queue_event:expr,
$runtime_para_id:expr
) => {
#[test]
fn teleports_for_native_asset_works() {
const BOB: [u8; 32] = [2u8; 32];
let target_account = parachains_common::AccountId::from(BOB);
asset_test_utils::test_cases::teleports_for_native_asset_works::<
$crate::test_cases::teleports_for_native_asset_works::<
$runtime,
$xcm_config,
$checking_account,
@@ -291,7 +292,8 @@ macro_rules! include_teleports_for_native_asset_works(
$existential_deposit,
target_account,
$unwrap_pallet_xcm_event,
$unwrap_xcmp_queue_event
$unwrap_xcmp_queue_event,
$runtime_para_id
)
}
}
@@ -598,7 +600,7 @@ macro_rules! include_teleports_for_foreign_assets_works(
const SOME_ASSET_OWNER: [u8; 32] = [5u8; 32];
let asset_owner = parachains_common::AccountId::from(SOME_ASSET_OWNER);
asset_test_utils::test_cases::teleports_for_foreign_assets_works::<
$crate::test_cases::teleports_for_foreign_assets_works::<
$runtime,
$xcm_config,
$checking_account,
@@ -715,7 +717,7 @@ macro_rules! include_asset_transactor_transfer_with_local_consensus_currency_wor
const BOB: [u8; 32] = [2u8; 32];
let target_account = parachains_common::AccountId::from(BOB);
asset_test_utils::test_cases::asset_transactor_transfer_with_local_consensus_currency_works::<
$crate::test_cases::asset_transactor_transfer_with_local_consensus_currency_works::<
$runtime,
$xcm_config
>(
@@ -969,7 +971,7 @@ macro_rules! include_asset_transactor_transfer_with_pallet_assets_instance_works
const CHARLIE: [u8; 32] = [3u8; 32];
let charlie_account = parachains_common::AccountId::from(CHARLIE);
asset_test_utils::test_cases::asset_transactor_transfer_with_pallet_assets_instance_works::<
$crate::test_cases::asset_transactor_transfer_with_pallet_assets_instance_works::<
$runtime,
$xcm_config,
$assets_pallet_instance,
@@ -1297,7 +1299,7 @@ macro_rules! include_create_and_manage_foreign_assets_for_local_consensus_parach
const BOB: [u8; 32] = [2u8; 32];
let bob_account = parachains_common::AccountId::from(BOB);
asset_test_utils::test_cases::create_and_manage_foreign_assets_for_local_consensus_parachain_assets_works::<
$crate::test_cases::create_and_manage_foreign_assets_for_local_consensus_parachain_assets_works::<
$runtime,
$xcm_config,
$weight_to_fee,
@@ -354,7 +354,7 @@ pub type Barrier = DenyThenTry<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent or its plurality (i.e. governance bodies) gets free execution.
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
@@ -497,7 +497,8 @@ asset_test_utils::include_teleports_for_native_asset_works!(
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
})
}),
1000
);
asset_test_utils::include_teleports_for_foreign_assets_works!(
@@ -29,7 +29,6 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -72,6 +71,9 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { path = "../../../../parachains/pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../../parachains/common", default-features = false }
[dev-dependencies]
bridge-hub-test-utils = { path = "../test-utils"}
[features]
default = [
"std",
@@ -100,7 +102,6 @@ std = [
"pallet-collator-selection/std",
"pallet-multisig/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
@@ -64,15 +64,15 @@ use xcm_config::{
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
// Polkadot imports
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use parachains_common::{
opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
impls::DealWithFees, opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
// XCM Imports
use xcm::latest::prelude::BodyId;
use xcm_executor::XcmExecutor;
@@ -143,11 +143,6 @@ pub fn native_version() -> NativeVersion {
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
// the lazy contract deletion.
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
@@ -264,7 +259,8 @@ parameter_types! {
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OnChargeTransaction =
pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
@@ -24,11 +24,11 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::xcm_config::{
ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry,
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry},
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -96,17 +96,16 @@ pub type XcmOriginToTransactDispatchOrigin = (
// transaction from the Root origin.
ParentAsSuperuser<RuntimeOrigin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
// `RuntimeOrigin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<RuntimeOrigin>,
);
match_types! {
// TODO: map gov2 origins here - after merge https://github.com/paritytech/cumulus/pull/1895
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
};
pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
@@ -165,10 +164,10 @@ pub type Barrier = DenyThenTry<
AllowKnownQueryResponses<PolkadotXcm>,
WithComputedOrigin<
(
// Allow anything to pay for execution.
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
@@ -197,7 +196,7 @@ impl xcm_executor::Config for XcmConfig {
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, KsmRelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
UsingComponents<WeightToFee, KsmRelayLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
@@ -0,0 +1,56 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use bridge_hub_kusama_runtime::{
constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit,
ParachainSystem, PolkadotXcm, Runtime, RuntimeEvent, SessionKeys,
};
use codec::Decode;
use frame_support::parameter_types;
use parachains_common::{AccountId, AuraId};
const ALICE: [u8; 32] = [1u8; 32];
parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
XcmConfig,
CheckingAccount,
WeightToFee,
ParachainSystem,
bridge_hub_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
_ => None,
}
}),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
}),
1002
);
@@ -29,7 +29,6 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -72,6 +71,9 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { path = "../../../../parachains/pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../../parachains/common", default-features = false }
[dev-dependencies]
bridge-hub-test-utils = { path = "../test-utils"}
[features]
default = [
"std",
@@ -100,7 +102,6 @@ std = [
"pallet-collator-selection/std",
"pallet-multisig/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
@@ -70,7 +70,7 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use parachains_common::{
opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
impls::DealWithFees, opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
// XCM Imports
@@ -143,11 +143,6 @@ pub fn native_version() -> NativeVersion {
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
// the lazy contract deletion.
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
@@ -264,7 +259,8 @@ parameter_types! {
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OnChargeTransaction =
pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
@@ -24,11 +24,11 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::xcm_config::{
ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry,
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry},
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -96,22 +96,24 @@ pub type XcmOriginToTransactDispatchOrigin = (
// transaction from the Root origin.
ParentAsSuperuser<RuntimeOrigin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
// `RuntimeOrigin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<RuntimeOrigin>,
);
match_types! {
// TODO: map gov2 origins here - after merge https://github.com/paritytech/cumulus/pull/1895
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
};
pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(_) }
};
pub type FellowsPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) }
};
}
/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
/// account for proof size weights.
@@ -165,10 +167,10 @@ pub type Barrier = DenyThenTry<
AllowKnownQueryResponses<PolkadotXcm>,
WithComputedOrigin<
(
// Allow anything to pay for execution.
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Parent, its pluralities (i.e. governance bodies), and the Fellows plurality get free execution.
AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, FellowsPlurality)>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
@@ -197,7 +199,7 @@ impl xcm_executor::Config for XcmConfig {
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, DotRelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
UsingComponents<WeightToFee, DotRelayLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
@@ -0,0 +1,56 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use bridge_hub_polkadot_runtime::{
constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit,
ParachainSystem, PolkadotXcm, Runtime, RuntimeEvent, SessionKeys,
};
use codec::Decode;
use frame_support::parameter_types;
use parachains_common::{AccountId, AuraId};
const ALICE: [u8; 32] = [1u8; 32];
parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
XcmConfig,
CheckingAccount,
WeightToFee,
ParachainSystem,
bridge_hub_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
_ => None,
}
}),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
}),
1002
);
@@ -29,7 +29,6 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
@@ -72,6 +71,9 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { path = "../../../../parachains/pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../../parachains/common", default-features = false }
[dev-dependencies]
bridge-hub-test-utils = { path = "../test-utils"}
[features]
default = [
"std",
@@ -99,7 +101,6 @@ std = [
"pallet-collator-selection/std",
"pallet-multisig/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
@@ -73,7 +73,7 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
// XCM Imports
use parachains_common::{
opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
impls::DealWithFees, opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use xcm_executor::XcmExecutor;
@@ -209,11 +209,6 @@ pub fn native_version() -> NativeVersion {
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
// the lazy contract deletion.
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
@@ -331,7 +326,8 @@ parameter_types! {
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OnChargeTransaction =
pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees<Runtime>>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
@@ -24,11 +24,11 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::xcm_config::{
ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry,
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry},
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
@@ -94,16 +94,16 @@ pub type XcmOriginToTransactDispatchOrigin = (
// transaction from the Root origin.
ParentAsSuperuser<RuntimeOrigin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
// `RuntimeOrigin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<RuntimeOrigin>,
);
match_types! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
};
pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
@@ -163,10 +163,10 @@ pub type Barrier = DenyThenTry<
AllowKnownQueryResponses<PolkadotXcm>,
WithComputedOrigin<
(
// Allow anything to pay for execution.
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
@@ -195,7 +195,7 @@ impl xcm_executor::Config for XcmConfig {
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
@@ -0,0 +1,56 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub use bridge_hub_rococo_runtime::{
constants::fee::WeightToFee, xcm_config::XcmConfig, Balances, ExistentialDeposit,
ParachainSystem, PolkadotXcm, Runtime, RuntimeEvent, SessionKeys,
};
use codec::Decode;
use frame_support::parameter_types;
use parachains_common::{AccountId, AuraId};
const ALICE: [u8; 32] = [1u8; 32];
parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
XcmConfig,
CheckingAccount,
WeightToFee,
ParachainSystem,
bridge_hub_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
_ => None,
}
}),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
}),
1013
);
@@ -0,0 +1,17 @@
[package]
name = "bridge-hub-test-utils"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
description = "Utils for BridgeHub testing"
[dependencies]
# Cumulus
asset-test-utils = { path = "../../assets/test-utils"}
[features]
default = [ "std" ]
std = [
"asset-test-utils/std",
]
@@ -0,0 +1,18 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
pub mod test_cases;
pub use test_cases::CollatorSessionKeys;
@@ -0,0 +1,20 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! Module contains predefined test-case scenarios for `Runtime` with bridging capabilities.
// Re-export test_cases from assets
pub use asset_test_utils::{include_teleports_for_native_asset_works, CollatorSessionKeys};
@@ -204,7 +204,7 @@ pub type Barrier = DenyThenTry<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its plurality (i.e. governance bodies) gets free execution.
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
@@ -129,7 +129,7 @@ pub type Barrier = DenyThenTry<
(
// If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its plurality (i.e. governance bodies) gets free execution.
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,