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
@@ -98,6 +98,7 @@ pallet-bridge-grandpa = { path = "../../../../../bridges/modules/grandpa", defau
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-xcm-bridge-hub = { path = "../../../../../bridges/modules/xcm-bridge-hub", default-features = false }
bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false }
[dev-dependencies]
@@ -156,6 +157,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm-bridge-hub/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
@@ -207,6 +209,7 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm-bridge-hub/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
@@ -239,6 +242,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm-bridge-hub/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
@@ -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> {
@@ -191,7 +191,7 @@ mod bridge_hub_rococo_tests {
_ => None,
}
}),
|| ExportMessage { network: Westend, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) },
|| ExportMessage { network: Westend, destination: X1(Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into())), xcm: Xcm(vec![]) },
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
Some((TokenLocation::get(), ExistentialDeposit::get()).into()),
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
@@ -74,6 +74,7 @@ parachain-info = { package = "staging-parachain-info", path = "../../../pallets/
parachains-common = { path = "../../../common", default-features = false }
# Bridges
bp-asset-hub-rococo = { path = "../../../../../bridges/primitives/chain-asset-hub-rococo", default-features = false }
bp-asset-hub-westend = { path = "../../../../../bridges/primitives/chain-asset-hub-westend", default-features = false }
bp-bridge-hub-rococo = { path = "../../../../../bridges/primitives/chain-bridge-hub-rococo", default-features = false }
bp-bridge-hub-westend = { path = "../../../../../bridges/primitives/chain-bridge-hub-westend", default-features = false }
@@ -89,6 +90,7 @@ pallet-bridge-grandpa = { path = "../../../../../bridges/modules/grandpa", defau
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-xcm-bridge-hub = { path = "../../../../../bridges/modules/xcm-bridge-hub", default-features = false }
bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false }
[dev-dependencies]
@@ -100,6 +102,7 @@ sp-keyring = { path = "../../../../../substrate/primitives/keyring" }
[features]
default = ["std"]
std = [
"bp-asset-hub-rococo/std",
"bp-asset-hub-westend/std",
"bp-bridge-hub-rococo/std",
"bp-bridge-hub-westend/std",
@@ -144,6 +147,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm-bridge-hub/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
@@ -195,6 +199,7 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm-bridge-hub/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
@@ -227,6 +232,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm-bridge-hub/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
@@ -17,8 +17,9 @@
//! Bridge definitions used on BridgeHub with the Westend flavor.
use crate::{
bridge_common_config::DeliveryRewardInBalance, weights, AccountId, BridgeRococoMessages,
ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin, XcmRouter,
bridge_common_config::DeliveryRewardInBalance, weights, xcm_config::UniversalLocation,
AccountId, BridgeRococoMessages, Runtime, RuntimeEvent, RuntimeOrigin, XcmOverBridgeHubRococo,
XcmRouter,
};
use bp_messages::LaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
@@ -48,7 +49,7 @@ use xcm::{
latest::prelude::*,
prelude::{InteriorMultiLocation, NetworkId},
};
use xcm_builder::{BridgeBlobDispatcher, HaulBlobExporter};
use xcm_builder::BridgeBlobDispatcher;
parameter_types! {
pub const RelayChainHeadersToKeep: u32 = 1024;
@@ -62,23 +63,29 @@ parameter_types! {
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_westend::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const BridgeHubRococoChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID;
pub BridgeHubWestendUniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(Westend), Parachain(ParachainInfo::parachain_id().into()));
pub BridgeWestendToRococoMessagesPalletInstance: InteriorMultiLocation = X1(PalletInstance(<BridgeRococoMessages as PalletInfoAccess>::index() as u8));
pub RococoGlobalConsensusNetwork: NetworkId = NetworkId::Rococo;
pub ActiveOutboundLanesToBridgeHubRococo: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO];
pub const AssetHubWestendToAssetHubRococoMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO;
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;
pub AssetHubWestendParaId: cumulus_primitives_core::ParaId = bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID.into();
pub AssetHubRococoParaId: cumulus_primitives_core::ParaId = bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID.into();
// Lanes
pub ActiveOutboundLanesToBridgeHubRococo: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO];
pub const AssetHubWestendToAssetHubRococoMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO;
pub FromAssetHubWestendToAssetHubRococoRoute: SenderAndLane = SenderAndLane::new(
ParentThen(X1(Parachain(AssetHubWestendParaId::get().into()))).into(),
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
);
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
(
FromAssetHubWestendToAssetHubRococoRoute::get(),
(RococoGlobalConsensusNetwork::get(), X1(Parachain(AssetHubRococoParaId::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_WESTEND_TO_ASSET_HUB_ROCOCO: LaneId = LaneId([0, 0, 0, 2]);
@@ -110,23 +117,16 @@ pub type ToRococoBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_rococo::Hash>;
/// Dispatches received XCM messages from other bridge
type FromRococoMessageBlobDispatcher = BridgeBlobDispatcher<
XcmRouter,
BridgeHubWestendUniversalLocation,
BridgeWestendToRococoMessagesPalletInstance,
>;
type FromRococoMessageBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, UniversalLocation, BridgeWestendToRococoMessagesPalletInstance>;
/// Export XCM messages to be relayed to the other side
pub type ToBridgeHubRococoHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubRococoXcmBlobHauler>,
RococoGlobalConsensusNetwork,
(),
>;
pub type ToBridgeHubRococoHaulBlobExporter = XcmOverBridgeHubRococo;
pub struct ToBridgeHubRococoXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubRococoXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithBridgeHubRococoMessagesInstance;
type SenderAndLane = FromAssetHubWestendToAssetHubRococoRoute;
type ToSourceChainSender = XcmRouter;
type CongestedMessage = CongestedMessage;
@@ -134,7 +134,7 @@ impl XcmBlobHauler for ToBridgeHubRococoXcmBlobHauler {
}
/// On messages delivered callback.
type OnMessagesDelivered = XcmBlobHaulerAdapter<ToBridgeHubRococoXcmBlobHauler>;
type OnMessagesDelivered = XcmBlobHaulerAdapter<ToBridgeHubRococoXcmBlobHauler, ActiveLanes>;
/// Messaging Bridge configuration for BridgeHubWestend -> BridgeHubRococo
pub struct WithBridgeHubRococoMessageBridge;
@@ -256,6 +256,17 @@ impl pallet_bridge_messages::Config<WithBridgeHubRococoMessagesInstance> for Run
type OnMessagesDelivered = OnMessagesDelivered;
}
/// Add support for the export and dispatch of XCM programs.
pub type XcmOverBridgeHubRococoInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubRococoInstance> for Runtime {
type UniversalLocation = UniversalLocation;
type BridgedNetworkId = RococoGlobalConsensusNetwork;
type BridgeMessagesPalletInstance = WithBridgeHubRococoMessagesInstance;
type MessageExportPrice = ();
type Lanes = ActiveLanes;
type LanesSupport = ToBridgeHubRococoXcmBlobHauler;
}
#[cfg(test)]
mod tests {
use super::*;
@@ -488,6 +488,7 @@ construct_runtime!(
BridgeRococoGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 42,
BridgeRococoParachains: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage, Event<T>} = 43,
BridgeRococoMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 44,
XcmOverBridgeHubRococo: pallet_xcm_bridge_hub::<Instance1>::{Pallet} = 45,
// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
@@ -921,7 +922,13 @@ impl_runtime_apis! {
fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
Ok((WestendLocation::get(), NetworkId::Rococo, X1(Parachain(100))))
Ok(
(
bridge_to_rococo_config::FromAssetHubWestendToAssetHubRococoRoute::get().location,
NetworkId::Rococo,
X1(Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into()))
)
)
}
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
@@ -179,7 +179,7 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() {
_ => None,
}
}),
|| ExportMessage { network: Rococo, destination: X1(Parachain(4321)), xcm: Xcm(vec![]) },
|| ExportMessage { network: Rococo, destination: X1(Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into())), xcm: Xcm(vec![]) },
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
Some((WestendLocation::get(), ExistentialDeposit::get()).into()),
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
@@ -1457,9 +1457,9 @@ pub mod test_data {
);
// to compute proper cost of GRANDPA call, let's add some dummy bytes to header, so that the
// `submit_finality_proof` call size would be close to maximal expected (and refundable)
let expected_bytes_in_grandpa_call = BridgedRelayChain::AVERAGE_HEADER_SIZE_IN_JUSTIFICATION
let expected_bytes_in_grandpa_call = BridgedRelayChain::AVERAGE_HEADER_SIZE
.saturating_mul(BridgedRelayChain::REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY)
.saturating_add(BridgedRelayChain::MAX_HEADER_SIZE)
.saturating_add(BridgedRelayChain::MAX_MANDATORY_HEADER_SIZE)
as usize;
let extra_bytes_required =
expected_bytes_in_grandpa_call.saturating_sub(relay_chain_header.encoded_size());