Skip to content

Commit

Permalink
[bridges/xcm] adapt paritytech/polkadot-sdk#2481 (XCM version check) +
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jan 29, 2024
1 parent 65debe9 commit 4d632f0
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 111 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

20 changes: 18 additions & 2 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToPolkadotXcmRouterInstance> for Runti
type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = xcm_config::bridging::to_polkadot::PolkadotNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;
type DestinationVersion = PolkadotXcm;

#[cfg(not(feature = "runtime-benchmarks"))]
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;
Expand Down Expand Up @@ -1535,11 +1536,26 @@ impl_runtime_apis! {
);
}

fn ensure_bridged_target_destination() -> MultiLocation {
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
);
xcm_config::bridging::to_polkadot::AssetHubPolkadot::get()
let bridged_asset_hub = xcm_config::bridging::to_polkadot::AssetHubPolkadot::get();
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridged_asset_hub),
XCM_VERSION,
).map_err(|e| {
log::error!(
"Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
RuntimeOrigin::root(),
bridged_asset_hub,
XCM_VERSION,
e
);
BenchmarkError::Stop("XcmVersion was not stored!")
})?;
Ok(bridged_asset_hub)
}
}

Expand Down
12 changes: 9 additions & 3 deletions system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use asset_hub_kusama_runtime::{
TrustBackedAssetsPalletLocation, XcmConfig,
},
AllPalletsWithoutSystem, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets,
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime,
RuntimeCall, RuntimeEvent, SessionKeys, ToPolkadotXcmRouterInstance, TrustBackedAssetsInstance,
XcmpQueue,
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem,
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys,
ToPolkadotXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
Expand Down Expand Up @@ -657,6 +657,12 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
);

fn bridging_to_asset_hub_polkadot() -> TestBridgingConfig {
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridging::to_polkadot::AssetHubPolkadot::get()),
XCM_VERSION,
)
.expect("version saved!");
TestBridgingConfig {
bridged_network: bridging::to_polkadot::PolkadotNetwork::get(),
local_bridge_hub_para_id: bridging::SiblingBridgeHubParaId::get(),
Expand Down
20 changes: 18 additions & 2 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToKusamaXcmRouterInstance> for Runtime
type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = xcm_config::bridging::to_kusama::KusamaNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;
type DestinationVersion = PolkadotXcm;

#[cfg(not(feature = "runtime-benchmarks"))]
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;
Expand Down Expand Up @@ -1420,11 +1421,26 @@ impl_runtime_apis! {
);
}

fn ensure_bridged_target_destination() -> MultiLocation {
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
);
xcm_config::bridging::to_kusama::AssetHubKusama::get()
let bridged_asset_hub = xcm_config::bridging::to_kusama::AssetHubKusama::get();
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridged_asset_hub),
XCM_VERSION,
).map_err(|e| {
log::error!(
"Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
RuntimeOrigin::root(),
bridged_asset_hub,
XCM_VERSION,
e
);
BenchmarkError::Stop("XcmVersion was not stored!")
})?;
Ok(bridged_asset_hub)
}
}

Expand Down
12 changes: 9 additions & 3 deletions system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use asset_hub_polkadot_runtime::{
TrustBackedAssetsPalletLocation, XcmConfig,
},
AllPalletsWithoutSystem, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets,
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime,
RuntimeCall, RuntimeEvent, SessionKeys, ToKusamaXcmRouterInstance, TrustBackedAssetsInstance,
XcmpQueue,
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem,
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys,
ToKusamaXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
Expand Down Expand Up @@ -683,6 +683,12 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
);

fn bridging_to_asset_hub_kusama() -> TestBridgingConfig {
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridging::to_kusama::AssetHubKusama::get()),
XCM_VERSION,
)
.expect("version saved!");
TestBridgingConfig {
bridged_network: bridging::to_kusama::KusamaNetwork::get(),
local_bridge_hub_para_id: bridging::SiblingBridgeHubParaId::get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use crate::{
weights,
xcm_config::{UniversalLocation, XcmRouter},
AccountId, Balance, Balances, BlockNumber, BridgePolkadotMessages, Runtime, RuntimeEvent,
RuntimeOrigin, XcmOverBridgeHubPolkadot,
AccountId, Balance, Balances, BlockNumber, BridgePolkadotMessages, PolkadotXcm, Runtime,
RuntimeEvent, RuntimeOrigin, XcmOverBridgeHubPolkadot,
};
use bp_messages::LaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
Expand All @@ -33,7 +33,7 @@ use bridge_runtime_common::{
},
messages_xcm_extension::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundSignedExtensionAdapter,
Expand Down Expand Up @@ -75,6 +75,11 @@ parameter_types! {
parameter_types! {
/// Polkadot Network identifier.
pub PolkadotGlobalConsensusNetwork: NetworkId = NetworkId::Polkadot;
/// Polkadot Network as `Location`.
pub PolkadotGlobalConsensusNetworkLocation: MultiLocation = MultiLocation {
parents: 2,
interior: X1(GlobalConsensus(PolkadotGlobalConsensusNetwork::get()))
};
/// Interior location (relative to this runtime) of the with-Polkadot messages pallet.
pub BridgeKusamaToPolkadotMessagesPalletInstance: InteriorMultiLocation = X1(
PalletInstance(<BridgePolkadotMessages as PalletInfoAccess>::index() as u8),
Expand All @@ -84,6 +89,14 @@ parameter_types! {
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();
/// Location of the bridged Polkadot Bridge Hub parachain.
pub BridgeHubPolkadotLocation: MultiLocation = MultiLocation {
parents: 2,
interior: X2(
GlobalConsensus(PolkadotGlobalConsensusNetwork::get()),
Parachain(<bp_bridge_hub_polkadot::BridgeHubPolkadot as bp_runtime::Parachain>::PARACHAIN_ID)
)
};

/// A route (XCM location and bridge lane) that the Kusama Asset Hub -> Polkadot Asset Hub
/// message is following.
Expand Down Expand Up @@ -257,9 +270,11 @@ impl XcmBlobHauler for ToBridgeHubPolkadotXcmBlobHauler {
pub type XcmOverBridgeHubPolkadotInstance = pallet_xcm_bridge_hub::Instance1;
impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubPolkadotInstance> for Runtime {
type UniversalLocation = UniversalLocation;
type BridgedNetworkId = PolkadotGlobalConsensusNetwork;
type BridgedNetwork = PolkadotGlobalConsensusNetworkLocation;
type BridgeMessagesPalletInstance = WithBridgeHubPolkadotMessagesInstance;
type MessageExportPrice = ();
type DestinationVersion =
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, BridgeHubPolkadotLocation>;
type Lanes = ActiveLanes;
type LanesSupport = ToBridgeHubPolkadotXcmBlobHauler;
}
Expand Down Expand Up @@ -418,5 +433,8 @@ mod tests {
bp_bridge_hub_kusama::WITH_BRIDGE_KUSAMA_TO_POLKADOT_MESSAGES_PALLET_INDEX
))
);

assert!(BridgeHubPolkadotLocation::get()
.starts_with(&PolkadotGlobalConsensusNetworkLocation::get()));
}
}
15 changes: 15 additions & 0 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,21 @@ impl_runtime_apis! {

fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
// save XCM version for remote bridge hub
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridge_to_polkadot_config::BridgeHubPolkadotLocation::get()),
XCM_VERSION,
).map_err(|e| {
log::error!(
"Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
RuntimeOrigin::root(),
bridge_to_polkadot_config::BridgeHubPolkadotLocation::get(),
XCM_VERSION,
e
);
BenchmarkError::Stop("XcmVersion was not stored!")
})?;
Ok(
(
bridge_to_polkadot_config::FromAssetHubKusamaToAssetHubPolkadotRoute::get().location,
Expand Down
Loading

0 comments on commit 4d632f0

Please sign in to comment.