Skip to content

Commit

Permalink
Adjust testnet runtimes to the latest vogue
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Sep 19, 2024
1 parent 71a2d80 commit 8f2ae83
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! GRANDPA tracking pallet only needs to be aware of one chain.
use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent};
use bp_messages::LegacyLaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use frame_support::{parameter_types, traits::ConstU32};

Expand Down Expand Up @@ -64,11 +65,15 @@ impl pallet_bridge_parachains::Config<BridgeParachainWestendInstance> for Runtim
}

/// Allows collect and claim rewards for relayers
impl pallet_bridge_relayers::Config for Runtime {
pub type RelayersForLegacyLaneIdsMessagesInstance = ();
impl pallet_bridge_relayers::Config<RelayersForLegacyLaneIdsMessagesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Reward = Balance;
type PaymentProcedure =
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type PaymentProcedure = bp_relayers::PayRewardFromAccount<
pallet_balances::Pallet<Runtime>,
AccountId,
Self::LaneId,
>;
type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
AccountId,
BlockNumber,
Expand All @@ -78,6 +83,7 @@ impl pallet_bridge_relayers::Config for Runtime {
RelayerStakeLease,
>;
type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
type LaneId = LegacyLaneId;
}

/// Add GRANDPA bridge pallet to track Rococo Bulletin chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ use crate::{
};
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof,
target_chain::FromBridgedChainMessagesProof, LegacyLaneId,
};
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;

use frame_support::{
parameter_types,
traits::{Equals, PalletInfoAccess},
};
use frame_system::EnsureRoot;
use frame_system::{EnsureNever, EnsureRoot};
use pallet_bridge_messages::LaneIdOf;
use pallet_bridge_relayers::extension::{
BridgeRelayersSignedExtension, WithMessagesExtensionConfig,
};
use pallet_xcm::EnsureXcm;
use pallet_xcm_bridge_hub::XcmAsPlainPayload;
use polkadot_parachain_primitives::primitives::Sibling;
use testnet_parachains_constants::rococo::currency::UNITS as ROC;
Expand Down Expand Up @@ -78,11 +78,11 @@ parameter_types! {
}

/// Proof of messages, coming from Rococo Bulletin chain.
pub type FromRococoBulletinMessagesProof =
FromBridgedChainMessagesProof<bp_polkadot_bulletin::Hash>;
pub type FromRococoBulletinMessagesProof<MI> =
FromBridgedChainMessagesProof<bp_polkadot_bulletin::Hash, LaneIdOf<Runtime, MI>>;
/// Messages delivery proof for Rococo Bridge Hub -> Rococo Bulletin messages.
pub type ToRococoBulletinMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_polkadot_bulletin::Hash>;
pub type ToRococoBulletinMessagesDeliveryProof<MI> =
FromBridgedChainMessagesDeliveryProof<bp_polkadot_bulletin::Hash, LaneIdOf<Runtime, MI>>;

/// Dispatches received XCM messages from other bridge.
type FromRococoBulletinMessageBlobDispatcher = BridgeBlobDispatcher<
Expand All @@ -101,6 +101,7 @@ pub type OnBridgeHubRococoRefundRococoBulletinMessages = BridgeRelayersSignedExt
WithRococoBulletinMessagesInstance,
PriorityBoostPerMessage,
>,
LaneIdOf<Runtime, WithRococoBulletinMessagesInstance>,
>;
bp_runtime::generate_static_str_provider!(OnBridgeHubRococoRefundRococoBulletinMessages);

Expand All @@ -116,10 +117,10 @@ impl pallet_bridge_messages::Config<WithRococoBulletinMessagesInstance> for Runt
type BridgedHeaderChain = BridgeRococoBulletinGrandpa;

type OutboundPayload = XcmAsPlainPayload;

type InboundPayload = XcmAsPlainPayload;
type DeliveryPayments = ();
type LaneId = LegacyLaneId;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = ();

type MessageDispatch = XcmOverRococoBulletin;
Expand All @@ -140,8 +141,8 @@ impl pallet_xcm_bridge_hub::Config<XcmOverPolkadotBulletinInstance> for Runtime
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, RococoBulletinGlobalConsensusNetworkLocation>;

type ForceOrigin = EnsureRoot<AccountId>;
// Only allow calls from sibling People parachain to directly open the bridge.
type OpenBridgeOrigin = EnsureXcm<Equals<PeopleRococoLocation>>;
// We don't want to allow creating bridges for this instance with `LegacyLaneId`.
type OpenBridgeOrigin = EnsureNever<Location>;
// Converter aligned with `OpenBridgeOrigin`.
type BridgeOriginAccountIdConverter =
(ParentIsPreset<AccountId>, SiblingParachainConvertsVia<Sibling, AccountId>);
Expand Down Expand Up @@ -230,14 +231,20 @@ mod tests {
}

#[cfg(feature = "runtime-benchmarks")]
pub(crate) fn open_bridge_for_benchmarks(
with: bp_messages::LaneId,
pub(crate) fn open_bridge_for_benchmarks<R, XBHI, C>(
with: pallet_xcm_bridge_hub::LaneIdOf<R, XBHI>,
sibling_para_id: u32,
) -> InteriorLocation {
) -> InteriorLocation
where
R: pallet_xcm_bridge_hub::Config<XBHI>,
XBHI: 'static,
C: xcm_executor::traits::ConvertLocation<
bp_runtime::AccountIdOf<pallet_xcm_bridge_hub::ThisChainOf<R, XBHI>>,
>,
{
use pallet_xcm_bridge_hub::{Bridge, BridgeId, BridgeState};
use sp_runtime::traits::Zero;
use xcm::VersionedInteriorLocation;
use xcm_executor::traits::ConvertLocation;

// insert bridge metadata
let lane_id = with;
Expand All @@ -248,7 +255,7 @@ pub(crate) fn open_bridge_for_benchmarks(
let bridge_id = BridgeId::new(&universal_source, &universal_destination);

// insert only bridge metadata, because the benchmarks create lanes
pallet_xcm_bridge_hub::Bridges::<Runtime, XcmOverPolkadotBulletinInstance>::insert(
pallet_xcm_bridge_hub::Bridges::<R, XBHI>::insert(
bridge_id,
Bridge {
bridge_origin_relative_location: alloc::boxed::Box::new(
Expand All @@ -261,30 +268,23 @@ pub(crate) fn open_bridge_for_benchmarks(
VersionedInteriorLocation::from(universal_destination),
),
state: BridgeState::Opened,
bridge_owner_account: crate::xcm_config::LocationToAccountId::convert_location(
&sibling_parachain,
)
.expect("valid AccountId"),
deposit: Balance::zero(),
bridge_owner_account: C::convert_location(&sibling_parachain).expect("valid AccountId"),
deposit: Zero::zero(),
lane_id,
},
);
pallet_xcm_bridge_hub::LaneToBridge::<Runtime, XcmOverPolkadotBulletinInstance>::insert(
lane_id, bridge_id,
);
pallet_xcm_bridge_hub::LaneToBridge::<R, XBHI>::insert(lane_id, bridge_id);

universal_source
}

/// Contains the migration for the PeopleRococo<>RococoBulletin bridge.
pub mod migration {
use super::*;
use bp_messages::LaneId;
use frame_support::traits::ConstBool;
use sp_runtime::Either;

parameter_types! {
pub RococoPeopleToRococoBulletinMessagesLane: LaneId = LaneId::from_inner(Either::Right([0, 0, 0, 0]));
pub RococoPeopleToRococoBulletinMessagesLane: LegacyLaneId = LegacyLaneId([0, 0, 0, 0]);
pub BulletinRococoLocation: InteriorLocation = [GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get())].into();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ use crate::{
};
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof,
target_chain::FromBridgedChainMessagesProof, LegacyLaneId,
};
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;
use pallet_xcm_bridge_hub::XcmAsPlainPayload;

use frame_support::{parameter_types, traits::PalletInfoAccess};
use frame_system::EnsureRoot;
use frame_system::{EnsureNever, EnsureRoot};
use pallet_bridge_messages::LaneIdOf;
use pallet_bridge_relayers::extension::{
BridgeRelayersSignedExtension, WithMessagesExtensionConfig,
};
use pallet_xcm::EnsureXcm;
use parachains_common::xcm_config::{
AllSiblingSystemParachains, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains,
};
use parachains_common::xcm_config::{AllSiblingSystemParachains, RelayOrOtherSystemParachains};
use polkadot_parachain_primitives::primitives::Sibling;
use testnet_parachains_constants::rococo::currency::UNITS as ROC;
use xcm::{
Expand Down Expand Up @@ -73,11 +71,11 @@ parameter_types! {
}

/// Proof of messages, coming from Westend.
pub type FromWestendBridgeHubMessagesProof =
FromBridgedChainMessagesProof<bp_bridge_hub_westend::Hash>;
pub type FromWestendBridgeHubMessagesProof<MI> =
FromBridgedChainMessagesProof<bp_bridge_hub_westend::Hash, LaneIdOf<Runtime, MI>>;
/// Messages delivery proof for Rococo Bridge Hub -> Westend Bridge Hub messages.
pub type ToWestendBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_westend::Hash>;
pub type ToWestendBridgeHubMessagesDeliveryProof<MI> =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_westend::Hash, LaneIdOf<Runtime, MI>>;

/// Dispatches received XCM messages from other bridge
type FromWestendMessageBlobDispatcher =
Expand All @@ -92,6 +90,7 @@ pub type OnBridgeHubRococoRefundBridgeHubWestendMessages = BridgeRelayersSignedE
WithBridgeHubWestendMessagesInstance,
PriorityBoostPerMessage,
>,
LaneIdOf<Runtime, WithBridgeHubWestendMessagesInstance>,
>;
bp_runtime::generate_static_str_provider!(OnBridgeHubRococoRefundBridgeHubWestendMessages);

Expand All @@ -110,10 +109,10 @@ impl pallet_bridge_messages::Config<WithBridgeHubWestendMessagesInstance> for Ru
>;

type OutboundPayload = XcmAsPlainPayload;

type InboundPayload = XcmAsPlainPayload;
type DeliveryPayments = ();
type LaneId = LegacyLaneId;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithBridgeHubWestendMessagesInstance,
Expand All @@ -124,7 +123,8 @@ impl pallet_bridge_messages::Config<WithBridgeHubWestendMessagesInstance> for Ru
type OnMessagesDelivered = XcmOverBridgeHubWestend;
}

/// Add support for the export and dispatch of XCM programs.
/// Add support for the export and dispatch of XCM programs withing
/// `WithBridgeHubWestendMessagesInstance`.
pub type XcmOverBridgeHubWestendInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubWestendInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -138,8 +138,8 @@ impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubWestendInstance> for Runtime
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, BridgeHubWestendLocation>;

type ForceOrigin = EnsureRoot<AccountId>;
// Only allow calls from relay chains and sibling parachains to directly open the bridge.
type OpenBridgeOrigin = EnsureXcm<ParentRelayOrSiblingParachains>;
// We don't want to allow creating bridges for this instance with `LegacyLaneId`.
type OpenBridgeOrigin = EnsureNever<Location>;
// Converter aligned with `OpenBridgeOrigin`.
type BridgeOriginAccountIdConverter =
(ParentIsPreset<AccountId>, SiblingParachainConvertsVia<Sibling, AccountId>);
Expand All @@ -157,14 +157,20 @@ impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubWestendInstance> for Runtime
}

#[cfg(feature = "runtime-benchmarks")]
pub(crate) fn open_bridge_for_benchmarks(
with: bp_messages::LaneId,
pub(crate) fn open_bridge_for_benchmarks<R, XBHI, C>(
with: pallet_xcm_bridge_hub::LaneIdOf<R, XBHI>,
sibling_para_id: u32,
) -> InteriorLocation {
) -> InteriorLocation
where
R: pallet_xcm_bridge_hub::Config<XBHI>,
XBHI: 'static,
C: xcm_executor::traits::ConvertLocation<
bp_runtime::AccountIdOf<pallet_xcm_bridge_hub::ThisChainOf<R, XBHI>>,
>,
{
use pallet_xcm_bridge_hub::{Bridge, BridgeId, BridgeState};
use sp_runtime::traits::Zero;
use xcm::VersionedInteriorLocation;
use xcm_executor::traits::ConvertLocation;

// insert bridge metadata
let lane_id = with;
Expand All @@ -174,7 +180,7 @@ pub(crate) fn open_bridge_for_benchmarks(
let bridge_id = BridgeId::new(&universal_source, &universal_destination);

// insert only bridge metadata, because the benchmarks create lanes
pallet_xcm_bridge_hub::Bridges::<Runtime, XcmOverBridgeHubWestendInstance>::insert(
pallet_xcm_bridge_hub::Bridges::<R, XBHI>::insert(
bridge_id,
Bridge {
bridge_origin_relative_location: alloc::boxed::Box::new(
Expand All @@ -187,17 +193,12 @@ pub(crate) fn open_bridge_for_benchmarks(
VersionedInteriorLocation::from(universal_destination),
),
state: BridgeState::Opened,
bridge_owner_account: crate::xcm_config::LocationToAccountId::convert_location(
&sibling_parachain,
)
.expect("valid AccountId"),
deposit: Balance::zero(),
bridge_owner_account: C::convert_location(&sibling_parachain).expect("valid AccountId"),
deposit: Zero::zero(),
lane_id,
},
);
pallet_xcm_bridge_hub::LaneToBridge::<Runtime, XcmOverBridgeHubWestendInstance>::insert(
lane_id, bridge_id,
);
pallet_xcm_bridge_hub::LaneToBridge::<R, XBHI>::insert(lane_id, bridge_id);

universal_source
}
Expand Down Expand Up @@ -297,12 +298,10 @@ mod tests {
/// Contains the migration for the AssetHubRococo<>AssetHubWestend bridge.
pub mod migration {
use super::*;
use bp_messages::LaneId;
use frame_support::traits::ConstBool;
use sp_runtime::Either;

parameter_types! {
pub AssetHubRococoToAssetHubWestendMessagesLane: LaneId = LaneId::from_inner(Either::Right([0, 0, 0, 2]));
pub AssetHubRococoToAssetHubWestendMessagesLane: LegacyLaneId = LegacyLaneId([0, 0, 0, 2]);
pub AssetHubRococoLocation: Location = Location::new(1, [Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)]);
pub AssetHubWestendUniversalLocation: InteriorLocation = [GlobalConsensus(WestendGlobalConsensusNetwork::get()), Parachain(bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID)].into();
}
Expand Down
Loading

0 comments on commit 8f2ae83

Please sign in to comment.