Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Align BridgeHub runtimes with other SP runtimes + reused test for tel…
Browse files Browse the repository at this point in the history
…eport 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>
  • Loading branch information
bkontur and joepetrowski committed Apr 24, 2023
1 parent 8615ac8 commit 2c1dd4f
Show file tree
Hide file tree
Showing 28 changed files with 312 additions and 87 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 2 additions & 4 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions parachains/runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion parachains/runtimes/assets/statemine/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 2 additions & 1 deletion parachains/runtimes/assets/statemine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion parachains/runtimes/assets/statemint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 2 additions & 1 deletion parachains/runtimes/assets/statemint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
18 changes: 10 additions & 8 deletions parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
>(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion parachains/runtimes/assets/westmint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 2 additions & 1 deletion parachains/runtimes/assets/westmint/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
5 changes: 3 additions & 2 deletions parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 4 additions & 8 deletions parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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>;
Expand Down
21 changes: 10 additions & 11 deletions parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 } |
Expand Down Expand Up @@ -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>,
),
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 2c1dd4f

Please sign in to comment.