Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur authored and claravanstaden committed Feb 5, 2024
1 parent 074d900 commit a1fa8d9
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 975 deletions.
464 changes: 3 additions & 461 deletions system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs

Large diffs are not rendered by default.

464 changes: 3 additions & 461 deletions system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bp-asset-hub-polkadot = { path = "../../asset-hubs/asset-hub-polkadot/primitives
bp-bridge-hub-kusama = { path = "./primitives", default-features = false}
bp-bridge-hub-polkadot = { path = "../bridge-hub-polkadot/primitives", default-features = false}
kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false}
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}

# Substrate
frame-benchmarking = { default-features = false, optional = true, version = "27.0.0" }
Expand Down Expand Up @@ -97,6 +98,7 @@ pallet-bridge-grandpa = { default-features = false , version = "0.6.0" }
pallet-bridge-messages = { default-features = false , version = "0.6.0" }
pallet-bridge-parachains = { default-features = false , version = "0.6.0" }
pallet-bridge-relayers = { default-features = false , version = "0.6.0" }
pallet-xcm-bridge-hub = { default-features = false , version = "0.1.0" }

# Bridges
bp-header-chain = { default-features = false , version = "0.4.0" }
Expand Down Expand Up @@ -184,12 +186,14 @@ 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",
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"polkadot-runtime-constants/std",
"scale-info/std",
"serde",
"snowbridge-beacon-primitives/std",
Expand Down Expand Up @@ -247,6 +251,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",
Expand Down Expand Up @@ -288,6 +293,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
weights,
xcm_config::{UniversalLocation, XcmRouter},
AccountId, Balance, Balances, BlockNumber, BridgePolkadotMessages, Runtime, RuntimeEvent,
RuntimeOrigin,
RuntimeOrigin, XcmOverBridgeHubPolkadot,
};
use bp_messages::LaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
Expand Down Expand Up @@ -48,7 +48,7 @@ use xcm::{
latest::prelude::*,
prelude::{InteriorMultiLocation, NetworkId},
};
use xcm_builder::{BridgeBlobDispatcher, HaulBlobExporter};
use xcm_builder::BridgeBlobDispatcher;

/// Lane identifier, used to connect Kusama Asset Hub and Polkadot Asset Hub.
pub const XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT: LaneId = LaneId([0, 0, 0, 1]);
Expand Down Expand Up @@ -82,12 +82,30 @@ parameter_types! {

/// Identifier of the sibling Kusama Asset Hub parachain.
pub AssetHubKusamaParaId: cumulus_primitives_core::ParaId = kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into();
/// Identifier of the bridged Polkadot Asset Hub parachain.
pub AssetHubPolkadotParaId: cumulus_primitives_core::ParaId = polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into();

/// A route (XCM location and bridge lane) that the Kusama Asset Hub -> Polkadot Asset Hub
/// message is following.
pub FromAssetHubKusamaToAssetHubPolkadotRoute: SenderAndLane = SenderAndLane::new(
ParentThen(X1(Parachain(AssetHubKusamaParaId::get().into()))).into(),
XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT,
);

/// Lane identifier, used to connect Kusama Asset Hub and Polkadot Asset Hub.
pub const AssetHubKusamaToAssetHubPolkadotMessagesLane: bp_messages::LaneId
= XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT;
/// All active lanes that the current bridge supports.
pub ActiveOutboundLanesToBridgeHubPolkadot: &'static [bp_messages::LaneId]
= &[XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT];

/// Lanes
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
(
FromAssetHubKusamaToAssetHubPolkadotRoute::get(),
(PolkadotGlobalConsensusNetwork::get(), X1(Parachain(AssetHubPolkadotParaId::get().into())))
)
];
}

// Parameters, used by bridge transport code.
Expand Down Expand Up @@ -120,13 +138,6 @@ parameter_types! {
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_polkadot::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;

/// Lane identifier, used to connect Kusama Asset Hub and Polkadot Asset Hub.
pub const AssetHubKusamaToAssetHubPolkadotMessagesLane: bp_messages::LaneId
= XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT;
/// All active lanes that the current bridge supports.
pub ActiveOutboundLanesToBridgeHubPolkadot: &'static [bp_messages::LaneId]
= &[XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT];

/// Reserve identifier, used by the `pallet_bridge_relayers` to hold funds of registered relayer.
pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
/// Minimal period of relayer registration. Roughly, it is the 1 hour of real time.
Expand Down Expand Up @@ -231,24 +242,30 @@ type FromPolkadotMessageBlobDispatcher = BridgeBlobDispatcher<
>;

/// Export XCM messages to be relayed to the other side
pub type ToBridgeHubPolkadotHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubPolkadotXcmBlobHauler>,
PolkadotGlobalConsensusNetwork,
(),
>;
pub type ToBridgeHubPolkadotHaulBlobExporter = XcmOverBridgeHubPolkadot;
pub struct ToBridgeHubPolkadotXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubPolkadotXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithBridgeHubPolkadotMessagesInstance;
type SenderAndLane = FromAssetHubKusamaToAssetHubPolkadotRoute;

type ToSourceChainSender = XcmRouter;
type CongestedMessage = bp_asset_hub_kusama::CongestedMessage;
type UncongestedMessage = bp_asset_hub_kusama::UncongestedMessage;
}

/// Add support for the export and dispatch of XCM programs.
pub type XcmOverBridgeHubPolkadotInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubPolkadotInstance> for Runtime {
type UniversalLocation = UniversalLocation;
type BridgedNetworkId = PolkadotGlobalConsensusNetwork;
type BridgeMessagesPalletInstance = WithBridgeHubPolkadotMessagesInstance;
type MessageExportPrice = ();
type Lanes = ActiveLanes;
type LanesSupport = ToBridgeHubPolkadotXcmBlobHauler;
}

/// On messages delivered callback.
type OnMessagesDeliveredFromPolkadot = XcmBlobHaulerAdapter<ToBridgeHubPolkadotXcmBlobHauler>;
type OnMessagesDeliveredFromPolkadot = XcmBlobHaulerAdapter<ToBridgeHubPolkadotXcmBlobHauler, ActiveLanes>;

/// Messaging Bridge configuration for BridgeHubKusama -> BridgeHubPolkadot
pub struct WithBridgeHubPolkadotMessageBridge;
Expand Down
13 changes: 9 additions & 4 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,17 +674,16 @@ construct_runtime!(
// Pallets that may be used by all bridges.
BridgeRelayers: pallet_bridge_relayers = 50,

//// todo add message queue pallet
// Polkadot bridge pallets.
BridgePolkadotGrandpa: pallet_bridge_grandpa::<Instance1> = 51,
BridgePolkadotParachains: pallet_bridge_parachains::<Instance1> = 52,
BridgePolkadotMessages: pallet_bridge_messages::<Instance1> = 53,
XcmOverBridgeHubPolkadot: pallet_xcm_bridge_hub::<Instance1> = 54,

EthereumInboundQueue: snowbridge_inbound_queue = 80,
EthereumOutboundQueue: snowbridge_outbound_queue = 81,
EthereumBeaconClient: snowbridge_ethereum_beacon_client = 82,
EthereumSystem: snowbridge_system = 83,


}
);

Expand Down Expand Up @@ -1142,7 +1141,13 @@ impl_runtime_apis! {

fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
Ok((KsmRelayLocation::get(), NetworkId::Polkadot, X1(Parachain(1000))))
Ok(
(
bridge_to_polkadot_config::FromAssetHubKusamaToAssetHubPolkadotRoute::get().location,
NetworkId::Polkadot,
X1(Parachain(bridge_to_polkadot_config::AssetHubPolkadotParaId::get().into()))
)
)
}

fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
Expand Down
10 changes: 2 additions & 8 deletions system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use bp_polkadot_core::Signature;
use bridge_hub_kusama_runtime::{
bridge_to_polkadot_config::{
BridgeGrandpaPolkadotInstance, BridgeHubPolkadotChainId, BridgeParachainPolkadotInstance,
AssetHubPolkadotParaId, BridgeGrandpaPolkadotInstance, BridgeHubPolkadotChainId, BridgeParachainPolkadotInstance,
DeliveryRewardInBalance, PolkadotGlobalConsensusNetwork, RefundBridgeHubPolkadotMessages,
RequiredStakeForStakeAndSlash, WithBridgeHubPolkadotMessageBridge,
WithBridgeHubPolkadotMessagesInstance, XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT,
Expand Down Expand Up @@ -115,12 +115,6 @@ bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
_ => None,
}
}),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
_ => None,
}
}),
1002
);

Expand Down Expand Up @@ -189,7 +183,7 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() {
_ => None,
}
}),
|| ExportMessage { network: Polkadot, destination: X1(Parachain(4321)), xcm: Xcm(vec![]) },
|| ExportMessage { network: Polkadot, destination: X1(Parachain(AssetHubPolkadotParaId::get().into())), xcm: Xcm(vec![]) },
XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT,
Some((KsmRelayLocation::get(), ExistentialDeposit::get()).into()),
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
Expand Down
6 changes: 6 additions & 0 deletions system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bp-asset-hub-kusama = { path = "../../asset-hubs/asset-hub-kusama/primitives", d
bp-asset-hub-polkadot = { path = "../../asset-hubs/asset-hub-polkadot/primitives", default-features = false}
bp-bridge-hub-kusama = { path = "../bridge-hub-kusama/primitives", default-features = false}
bp-bridge-hub-polkadot = { path = "../bridge-hub-polkadot/primitives", default-features = false}
kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false}
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}

# Substrate
Expand Down Expand Up @@ -97,6 +98,7 @@ pallet-bridge-grandpa = { default-features = false , version = "0.6.0" }
pallet-bridge-messages = { default-features = false , version = "0.6.0" }
pallet-bridge-parachains = { default-features = false , version = "0.6.0" }
pallet-bridge-relayers = { default-features = false , version = "0.6.0" }
pallet-xcm-bridge-hub = { default-features = false , version = "0.1.0" }

# Bridges
bp-header-chain = { default-features = false , version = "0.4.0" }
Expand Down Expand Up @@ -166,6 +168,7 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"kusama-runtime-constants/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
Expand All @@ -182,6 +185,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",
Expand Down Expand Up @@ -246,6 +250,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",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
Expand Down Expand Up @@ -286,6 +291,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
weights,
xcm_config::{UniversalLocation, XcmRouter},
AccountId, Balance, Balances, BlockNumber, BridgeKusamaMessages, Runtime, RuntimeEvent,
RuntimeOrigin,
RuntimeOrigin, XcmOverBridgeHubKusama,
};
use bp_messages::LaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
Expand Down Expand Up @@ -48,7 +48,7 @@ use xcm::{
latest::prelude::*,
prelude::{InteriorMultiLocation, NetworkId},
};
use xcm_builder::{BridgeBlobDispatcher, HaulBlobExporter};
use xcm_builder::BridgeBlobDispatcher;

/// Lane identifier, used to connect Polkadot Asset Hub and Kusama Asset Hub.
pub const XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA: LaneId = LaneId([0, 0, 0, 1]);
Expand Down Expand Up @@ -82,12 +82,30 @@ parameter_types! {

/// Identifier of the sibling Polkadot Asset Hub parachain.
pub AssetHubPolkadotParaId: cumulus_primitives_core::ParaId = polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into();
/// Identifier of the bridged Kusama Asset Hub parachain.
pub AssetHubKusamaParaId: cumulus_primitives_core::ParaId = kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into();

/// A route (XCM location and bridge lane) that the Polkadot Asset Hub -> Kusama Asset Hub
/// message is following.
pub FromAssetHubPolkadotToAssetHubKusamaRoute: SenderAndLane = SenderAndLane::new(
ParentThen(X1(Parachain(AssetHubPolkadotParaId::get().into()))).into(),
XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA,
);

/// Lane identifier, used to connect Polkadot Asset Hub and Kusama Asset Hub.
pub const AssetHubPolkadotToAssetHubKusamaMessagesLane: bp_messages::LaneId
= XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA;
/// All active lanes that the current bridge supports.
pub ActiveOutboundLanesToBridgeHubKusama: &'static [bp_messages::LaneId]
= &[XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA];

/// Lanes
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
(
FromAssetHubPolkadotToAssetHubKusamaRoute::get(),
(KusamaGlobalConsensusNetwork::get(), X1(Parachain(AssetHubKusamaParaId::get().into())))
)
];
}

// Parameters, used by bridge transport code.
Expand Down Expand Up @@ -120,13 +138,6 @@ parameter_types! {
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_kusama::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;

/// Lane identifier, used to connect Polkadot Asset Hub and Kusama Asset Hub.
pub const AssetHubPolkadotToAssetHubKusamaMessagesLane: bp_messages::LaneId
= XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA;
/// All active lanes that the current bridge supports.
pub ActiveOutboundLanesToBridgeHubKusama: &'static [bp_messages::LaneId]
= &[XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA];

/// Reserve identifier, used by the `pallet_bridge_relayers` to hold funds of registered relayer.
pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
/// Minimal period of relayer registration. Roughly, it is the 1 hour of real time.
Expand Down Expand Up @@ -231,24 +242,30 @@ type FromKusamaMessageBlobDispatcher = BridgeBlobDispatcher<
>;

/// Export XCM messages to be relayed to the other side
pub type ToBridgeHubKusamaHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubKusamaXcmBlobHauler>,
KusamaGlobalConsensusNetwork,
(),
>;
pub type ToBridgeHubKusamaHaulBlobExporter = XcmOverBridgeHubKusama;
pub struct ToBridgeHubKusamaXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubKusamaXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithBridgeHubKusamaMessagesInstance;
type SenderAndLane = FromAssetHubPolkadotToAssetHubKusamaRoute;

type ToSourceChainSender = XcmRouter;
type CongestedMessage = bp_asset_hub_polkadot::CongestedMessage;
type UncongestedMessage = bp_asset_hub_polkadot::UncongestedMessage;
}

/// Add support for the export and dispatch of XCM programs.
pub type XcmOverBridgeHubKusamaInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubKusamaInstance> for Runtime {
type UniversalLocation = UniversalLocation;
type BridgedNetworkId = KusamaGlobalConsensusNetwork;
type BridgeMessagesPalletInstance = WithBridgeHubKusamaMessagesInstance;
type MessageExportPrice = ();
type Lanes = ActiveLanes;
type LanesSupport = ToBridgeHubKusamaXcmBlobHauler;
}

/// On messages delivered callback.
type OnMessagesDeliveredFromKusama = XcmBlobHaulerAdapter<ToBridgeHubKusamaXcmBlobHauler>;
type OnMessagesDeliveredFromKusama = XcmBlobHaulerAdapter<ToBridgeHubKusamaXcmBlobHauler, ActiveLanes>;

/// Messaging Bridge configuration for BridgeHubPolkadot -> BridgeHubKusama
pub struct WithBridgeHubKusamaMessageBridge;
Expand Down
9 changes: 8 additions & 1 deletion system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ construct_runtime!(
BridgeKusamaGrandpa: pallet_bridge_grandpa::<Instance1> = 51,
BridgeKusamaParachains: pallet_bridge_parachains::<Instance1> = 52,
BridgeKusamaMessages: pallet_bridge_messages::<Instance1> = 53,
XcmOverBridgeHubKusama: pallet_xcm_bridge_hub::<Instance1> = 54,

EthereumInboundQueue: snowbridge_inbound_queue = 80,
EthereumOutboundQueue: snowbridge_outbound_queue = 81,
Expand Down Expand Up @@ -1139,7 +1140,13 @@ impl_runtime_apis! {

fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
Ok((DotRelayLocation::get(), NetworkId::Kusama, X1(Parachain(1000))))
Ok(
(
bridge_to_kusama_config::FromAssetHubPolkadotToAssetHubKusamaRoute::get().location,
NetworkId::Kusama,
X1(Parachain(bridge_to_kusama_config::AssetHubKusamaParaId::get().into()))
)
)
}

fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
Expand Down
Loading

0 comments on commit a1fa8d9

Please sign in to comment.