Branislav Kontur
2023-12-06 18:05:05 +01:00
committed by GitHub
parent e7651cf41b
commit be500fc202
33 changed files with 1057 additions and 232 deletions
@@ -18,8 +18,10 @@
use crate::{
bridge_common_config::{BridgeParachainWestendInstance, DeliveryRewardInBalance},
weights, AccountId, BridgeWestendMessages, ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin,
XcmRouter,
weights,
xcm_config::UniversalLocation,
AccountId, BridgeWestendMessages, Runtime, RuntimeEvent, RuntimeOrigin,
XcmOverBridgeHubWestend, XcmRouter,
};
use bp_messages::LaneId;
use bridge_runtime_common::{
@@ -46,7 +48,7 @@ use xcm::{
latest::prelude::*,
prelude::{InteriorMultiLocation, NetworkId},
};
use xcm_builder::{BridgeBlobDispatcher, HaulBlobExporter};
use xcm_builder::BridgeBlobDispatcher;
parameter_types! {
pub const MaxUnrewardedRelayerEntriesAtInboundLane: bp_messages::MessageNonce =
@@ -55,23 +57,28 @@ parameter_types! {
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const BridgeHubWestendChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_WESTEND_CHAIN_ID;
pub BridgeRococoToWestendMessagesPalletInstance: InteriorMultiLocation = X1(PalletInstance(<BridgeWestendMessages as PalletInfoAccess>::index() as u8));
pub BridgeHubRococoUniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(Rococo), Parachain(ParachainInfo::parachain_id().into()));
pub WestendGlobalConsensusNetwork: NetworkId = NetworkId::Westend;
pub ActiveOutboundLanesToBridgeHubWestend: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND];
pub const AssetHubRococoToAssetHubWestendMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND;
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;
pub AssetHubRococoParaId: cumulus_primitives_core::ParaId = bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID.into();
pub AssetHubWestendParaId: cumulus_primitives_core::ParaId = bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID.into();
// Lanes
pub ActiveOutboundLanesToBridgeHubWestend: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND];
pub const AssetHubRococoToAssetHubWestendMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND;
pub FromAssetHubRococoToAssetHubWestendRoute: SenderAndLane = SenderAndLane::new(
ParentThen(X1(Parachain(AssetHubRococoParaId::get().into()))).into(),
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
);
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
(
FromAssetHubRococoToAssetHubWestendRoute::get(),
(WestendGlobalConsensusNetwork::get(), X1(Parachain(AssetHubWestendParaId::get().into())))
)
];
pub CongestedMessage: Xcm<()> = build_congestion_message(true).into();
pub UncongestedMessage: Xcm<()> = build_congestion_message(false).into();
}
pub const XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND: LaneId = LaneId([0, 0, 0, 2]);
@@ -103,23 +110,16 @@ pub type ToWestendBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_westend::Hash>;
/// Dispatches received XCM messages from other bridge
type FromWestendMessageBlobDispatcher = BridgeBlobDispatcher<
XcmRouter,
BridgeHubRococoUniversalLocation,
BridgeRococoToWestendMessagesPalletInstance,
>;
type FromWestendMessageBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, UniversalLocation, BridgeRococoToWestendMessagesPalletInstance>;
/// Export XCM messages to be relayed to the other side
pub type ToBridgeHubWestendHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubWestendXcmBlobHauler>,
WestendGlobalConsensusNetwork,
(),
>;
pub type ToBridgeHubWestendHaulBlobExporter = XcmOverBridgeHubWestend;
pub struct ToBridgeHubWestendXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubWestendXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithBridgeHubWestendMessagesInstance;
type SenderAndLane = FromAssetHubRococoToAssetHubWestendRoute;
type ToSourceChainSender = XcmRouter;
type CongestedMessage = CongestedMessage;
@@ -127,7 +127,8 @@ impl XcmBlobHauler for ToBridgeHubWestendXcmBlobHauler {
}
/// On messages delivered callback.
type OnMessagesDeliveredFromWestend = XcmBlobHaulerAdapter<ToBridgeHubWestendXcmBlobHauler>;
type OnMessagesDeliveredFromWestend =
XcmBlobHaulerAdapter<ToBridgeHubWestendXcmBlobHauler, ActiveLanes>;
/// Messaging Bridge configuration for BridgeHubRococo -> BridgeHubWestend
pub struct WithBridgeHubWestendMessageBridge;
@@ -229,6 +230,17 @@ impl pallet_bridge_messages::Config<WithBridgeHubWestendMessagesInstance> for Ru
type OnMessagesDelivered = OnMessagesDeliveredFromWestend;
}
/// Add support for the export and dispatch of XCM programs.
pub type XcmOverBridgeHubWestendInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubWestendInstance> for Runtime {
type UniversalLocation = UniversalLocation;
type BridgedNetworkId = WestendGlobalConsensusNetwork;
type BridgeMessagesPalletInstance = WithBridgeHubWestendMessagesInstance;
type MessageExportPrice = ();
type Lanes = ActiveLanes;
type LanesSupport = ToBridgeHubWestendXcmBlobHauler;
}
#[cfg(test)]
mod tests {
use super::*;
@@ -500,6 +500,8 @@ construct_runtime!(
BridgeRelayers: pallet_bridge_relayers::{Pallet, Call, Storage, Event<T>} = 47,
XcmOverBridgeHubWestend: pallet_xcm_bridge_hub::<Instance1>::{Pallet} = 52,
// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>} = 250,
@@ -931,7 +933,13 @@ impl_runtime_apis! {
fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
Ok((TokenLocation::get(), NetworkId::Westend, X1(Parachain(100))))
Ok(
(
bridge_to_westend_config::FromAssetHubRococoToAssetHubWestendRoute::get().location,
NetworkId::Westend,
X1(Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into()))
)
)
}
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {