Skip to content

Commit

Permalink
feat(system-parachains/bridge-hubs): Configure BH Kusama
Browse files Browse the repository at this point in the history
- Bridges V2 refactoring backport and pallet_bridge_messages simplifications (SDK #4935)
- [bridges-v2] Permissionless lanes (SDK #4949)
- add possibility to inject non-authorities session-keys in genesis (SDK #5078)
- Transfer Polkadot-native assets to Ethereum (SDK #5546)
- [stable2049] Backport #5546 (SDK #5710)
- `XcmFeeToAccount` -> `SendXcmFeeToAccount`
- [bh polkadot] minor: replace `DOLLARS` with `UNITS` on `BridgeDeposit` storage type
  • Loading branch information
pandres95 committed Oct 21, 2024
1 parent 460ea9a commit 2639ad6
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub fn genesis() -> Storage {
)
})
.collect(),
// TODO: Any keys to add here?
non_authority_keys: vec![],
},
polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
1 change: 1 addition & 0 deletions system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ bridge-hub-test-utils = { workspace = true }
bridge-runtime-common = { features = [
"integrity-test",
], workspace = true, default-features = true }
pallet-bridge-relayers = { workspace = true, features = ["integrity-test"] }
sp-keyring = { workspace = true }
static_assertions = { workspace = true }
parachains-runtimes-test-utils = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ use frame_support::{
dispatch::DispatchClass,
sp_runtime::{MultiAddress, MultiSigner},
};
use sp_runtime::{FixedPointNumber, FixedU128, RuntimeDebug, Saturating};
use sp_runtime::{FixedPointNumber, FixedU128, RuntimeDebug, Saturating, StateVersion};

/// BridgeHubKusama parachain.
#[derive(RuntimeDebug)]
pub struct BridgeHubKusama;

impl Chain for BridgeHubKusama {
const ID: ChainId = *b"bhks";
const STATE_VERSION: StateVersion = StateVersion::V1;

type BlockNumber = BlockNumber;
type Hash = Hash;
Expand Down Expand Up @@ -93,7 +94,7 @@ pub const WITH_BRIDGE_HUB_KUSAMA_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
pub const WITH_BRIDGE_KUSAMA_TO_POLKADOT_MESSAGES_PALLET_INDEX: u8 = 53;

decl_bridge_finality_runtime_apis!(bridge_hub_kusama);
decl_bridge_messages_runtime_apis!(bridge_hub_kusama);
decl_bridge_messages_runtime_apis!(bridge_hub_kusama, LegacyLaneId);

frame_support::parameter_types! {
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Kusama
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,29 @@ use crate::{
weights,
xcm_config::{UniversalLocation, XcmRouter},
AccountId, Balance, Balances, BlockNumber, BridgePolkadotMessages, PolkadotXcm, Runtime,
RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, XcmOverBridgeHubPolkadot,
RuntimeEvent, RuntimeHoldReason, XcmOverBridgeHubPolkadot,
};
use bp_messages::{LaneId, LegacyLaneId};
use bp_messages::LegacyLaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::Chain;
use bridge_runtime_common::{
extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundSignedExtensionAdapter,
RefundableMessagesLane, RefundableParachain,
},
messages,
messages::{
source::{FromBridgedChainMessagesDeliveryProof, TargetHeaderChainAdapter},
target::{FromBridgedChainMessagesProof, SourceHeaderChainAdapter},
MessageBridge, ThisChainWithMessages, UnderlyingChainProvider,
},
messages_xcm_extension::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
};
use bp_runtime::{Chain, UnderlyingChainProvider};
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;
use frame_support::{parameter_types, traits::PalletInfoAccess};
use frame_system::{EnsureNever, EnsureRoot};
use kusama_runtime_constants as constants;
use pallet_bridge_messages::LaneIdOf;
use pallet_bridge_relayers::extension::{
BridgeRelayersSignedExtension, WithMessagesExtensionConfig,
};
use pallet_xcm_bridge_hub::XcmAsPlainPayload;
use parachains_common::xcm_config::{AllSiblingSystemParachains, RelayOrOtherSystemParachains};
use polkadot_parachain_primitives::primitives::Sibling;
use sp_runtime::{traits::ConstU32, RuntimeDebug};
use xcm::latest::prelude::*;
use xcm_builder::{BridgeBlobDispatcher, ParentIsPreset, SiblingParachainConvertsVia};

/// 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]);
pub const XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT: LegacyLaneId =
LegacyLaneId([0, 0, 0, 1]);

// Parameters that may be changed by the governance.
parameter_types! {
Expand Down Expand Up @@ -96,27 +87,9 @@ parameter_types! {
].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(Parachain(AssetHubKusamaParaId::get().into()).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
pub const AssetHubKusamaToAssetHubPolkadotMessagesLane: LegacyLaneId
= 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, InteriorLocation))> = sp_std::vec![
(
FromAssetHubKusamaToAssetHubPolkadotRoute::get(),
(PolkadotGlobalConsensusNetwork::get(), Parachain(AssetHubPolkadotParaId::get().into()).into())
)
];
}

// Parameters, used by bridge transport code.
Expand Down Expand Up @@ -160,11 +133,17 @@ parameter_types! {
pub PriorityBoostPerParachainHeader: u64 = 920_224_664_224_664;
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;

// TODO: What's the correct value?
pub storage BridgeDeposit: Balance = 10 * DOLLARS;
pub storage BridgeDeposit: Balance = constants::currency::UNITS;
}

/// Dispatches received XCM messages from other bridge
pub type FromPolkadotMessageBlobDispatcher = BridgeBlobDispatcher<
XcmRouter,
UniversalLocation,
BridgeKusamaToPolkadotMessagesPalletInstance,
>;

/// Add GRANDPA bridge pallet to track Polkadot relay chain.
pub type BridgeGrandpaPolkadotInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<BridgeGrandpaPolkadotInstance> for Runtime {
Expand Down Expand Up @@ -193,8 +172,11 @@ impl pallet_bridge_parachains::Config<BridgeParachainPolkadotInstance> for Runti
impl pallet_bridge_relayers::Config 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 @@ -213,59 +195,26 @@ impl pallet_bridge_messages::Config<WithBridgeHubPolkadotMessagesInstance> for R
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_bridge_messages::WeightInfo<Runtime>;

type InboundPayload = XcmAsPlainPayload;
type OutboundPayload = XcmAsPlainPayload;
type DeliveryPayments = ();

type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithBridgeHubPolkadotMessagesInstance,
DeliveryRewardInBalance,
>;
type MessageDispatch = XcmBlobMessageDispatch<
FromPolkadotMessageBlobDispatcher,
Self::WeightInfo,
cumulus_pallet_xcmp_queue::bridging::OutXcmpChannelStatusProvider<
AssetHubKusamaParaId,
Runtime,
>,
>;
type OnMessagesDelivered = OnMessagesDeliveredFromPolkadot;

type ThisChain = BridgeHubKusama;
type BridgedChain = BridgeHubPolkadot;
type ThisChain = bp_bridge_hub_kusama::BridgeHubKusama;
type BridgedChain = bp_bridge_hub_polkadot::BridgeHubPolkadot;
type BridgedHeaderChain = pallet_bridge_parachains::ParachainHeaders<
Runtime,
BridgeParachainPolkadotInstance,
bp_bridge_hub_polkadot::BridgeHubPolkadot,
>;
type LaneId = LegacyLaneId;
}

/// Proof of messages, coming from Polkadot.
pub type FromPolkadotBridgeHubMessagesProof =
FromBridgedChainMessagesProof<bp_bridge_hub_polkadot::Hash>;
/// Messages delivery proof for Kusama Bridge Hub -> Polkadot Bridge Hub messages.
pub type ToPolkadotBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_polkadot::Hash>;

/// Dispatches received XCM messages from Polkadot BridgeHub.
type FromPolkadotMessageBlobDispatcher = BridgeBlobDispatcher<
XcmRouter,
UniversalLocation,
BridgeKusamaToPolkadotMessagesPalletInstance,
>;

/// Export XCM messages to be relayed to the other side
pub type ToBridgeHubPolkadotHaulBlobExporter = XcmOverBridgeHubPolkadot;
pub struct ToBridgeHubPolkadotXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubPolkadotXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithBridgeHubPolkadotMessagesInstance;
type OutboundPayload = XcmAsPlainPayload;
type InboundPayload = XcmAsPlainPayload;
type LaneId = LegacyLaneId;

type ToSourceChainSender = XcmRouter;
type CongestedMessage = bp_asset_hub_kusama::CongestedMessage;
type UncongestedMessage = bp_asset_hub_kusama::UncongestedMessage;
type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithBridgeHubPolkadotMessagesInstance,
DeliveryRewardInBalance,
>;
type MessageDispatch = XcmOverBridgeHubPolkadot;
type OnMessagesDelivered = XcmOverBridgeHubPolkadot;
}

/// Add support for the export and dispatch of XCM programs.
Expand All @@ -276,7 +225,9 @@ impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubPolkadotInstance> for Runtime
type UniversalLocation = UniversalLocation;
type BridgedNetwork = PolkadotGlobalConsensusNetworkLocation;
type BridgeMessagesPalletInstance = WithBridgeHubPolkadotMessagesInstance;

// `MessageExportPrice` is simply propagated to the inner `xcm_builder::HaulBlobExporter`, and
// we do not need or want to add any additional price for exporting here, as it is already
// covered by the measured weight of the `ExportMessage` instruction.
type MessageExportPrice = ();
type DestinationVersion =
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, BridgeHubPolkadotLocation>;
Expand All @@ -295,34 +246,12 @@ impl pallet_xcm_bridge_hub::Config<XcmOverBridgeHubPolkadotInstance> for Runtime
type AllowWithoutBridgeDeposit =
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>;

// TODO: (bridges-v2) - add `LocalXcmChannelManager` impl - https://github.com/paritytech/parity-bridges-common/issues/3047
// TODO: @acatangiu (bridges-v2) - add `LocalXcmChannelManager` impl - https://github.com/paritytech/parity-bridges-common/issues/3047
// @acatangiu
type LocalXcmChannelManager = ();
type BlobDispatcher = FromPolkadotMessageBlobDispatcher;
}

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

/// Messaging Bridge configuration for BridgeHubKusama -> BridgeHubPolkadot
pub struct WithBridgeHubPolkadotMessageBridge;
impl MessageBridge for WithBridgeHubPolkadotMessageBridge {
const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
bp_bridge_hub_kusama::WITH_BRIDGE_HUB_KUSAMA_MESSAGES_PALLET_NAME;
type ThisChain = BridgeHubKusama;
type BridgedChain = BridgeHubPolkadot;
type BridgedHeaderChain = pallet_bridge_parachains::ParachainHeaders<
Runtime,
BridgeParachainPolkadotInstance,
bp_bridge_hub_polkadot::BridgeHubPolkadot,
>;
}

/// Maximal outbound payload size of BridgeHubKusama -> BridgeHubPolkadot messages.
pub type ToBridgeHubPolkadotMaximalOutboundPayloadSize =
messages::source::FromThisChainMaximalOutboundPayloadSize<WithBridgeHubPolkadotMessageBridge>;

/// BridgeHubPolkadot chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct BridgeHubPolkadot;
Expand All @@ -331,8 +260,6 @@ impl UnderlyingChainProvider for BridgeHubPolkadot {
type Chain = bp_bridge_hub_polkadot::BridgeHubPolkadot;
}

impl messages::BridgedChainWithMessages for BridgeHubPolkadot {}

/// BridgeHubKusama chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct BridgeHubKusama;
Expand All @@ -341,38 +268,30 @@ impl UnderlyingChainProvider for BridgeHubKusama {
type Chain = bp_bridge_hub_kusama::BridgeHubKusama;
}

impl ThisChainWithMessages for BridgeHubKusama {
type RuntimeOrigin = RuntimeOrigin;
}
pub type RelayersForLegacyLaneIdsMessagesInstance = ();

/// Signed extension that refunds relayers that are delivering messages from the Polkadot parachain.
pub type RefundBridgeHubPolkadotMessages = RefundSignedExtensionAdapter<
RefundBridgedParachainMessages<
pub type OnBridgeHubPolkadotRefundBridgeHubKusamaMessages = BridgeRelayersSignedExtension<
Runtime,
WithMessagesExtensionConfig<
StrOnBridgeHubPolkadotRefundBridgeHubKusamaMessages,
Runtime,
RefundableParachain<
BridgeParachainPolkadotInstance,
bp_bridge_hub_polkadot::BridgeHubPolkadot,
>,
RefundableMessagesLane<
WithBridgeHubPolkadotMessagesInstance,
AssetHubKusamaToAssetHubPolkadotMessagesLane,
>,
ActualFeeRefund<Runtime>,
WithBridgeHubPolkadotMessagesInstance,
RelayersForLegacyLaneIdsMessagesInstance,
PriorityBoostPerMessage,
StrRefundBridgeHubPolkadotMessages,
>,
LaneIdOf<Runtime, WithBridgeHubPolkadotMessagesInstance>,
>;
bp_runtime::generate_static_str_provider!(RefundBridgeHubPolkadotMessages);
bp_runtime::generate_static_str_provider!(OnBridgeHubPolkadotRefundBridgeHubKusamaMessages);

#[cfg(test)]
mod tests {
use super::*;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
assert_complete_bridge_constants, check_message_lane_weights,
AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants,
AssertCompleteBridgeConstants,
assert_complete_with_parachain_bridge_constants, check_message_lane_weights,
AssertChainConstants, AssertCompleteBridgeConstants,
},
};

Expand Down Expand Up @@ -411,11 +330,11 @@ mod tests {
runtime: Runtime,
with_bridged_chain_grandpa_instance: BridgeGrandpaPolkadotInstance,
with_bridged_chain_messages_instance: WithBridgeHubPolkadotMessagesInstance,
this_chain: bp_kusama::Kusama,
bridged_chain: bp_polkadot::Polkadot,
this_chain: bp_bridge_hub_kusama::BridgeHubKusama,
bridged_chain: bp_bridge_hub_polkadot::BridgeHubPolkadot,
);

assert_complete_bridge_constants::<
assert_complete_with_parachain_bridge_constants::<
Runtime,
BridgeGrandpaPolkadotInstance,
WithBridgeHubPolkadotMessagesInstance,
Expand All @@ -427,19 +346,19 @@ mod tests {
},
});

bridge_runtime_common::extensions::priority_calculator::per_relay_header::ensure_priority_boost_is_sane::<
pallet_bridge_relayers::extension::per_relay_header::ensure_priority_boost_is_sane::<
Runtime,
BridgeGrandpaPolkadotInstance,
PriorityBoostPerRelayHeader,
>(FEE_BOOST_PER_RELAY_HEADER);

bridge_runtime_common::extensions::priority_calculator::per_parachain_header::ensure_priority_boost_is_sane::<
pallet_bridge_relayers::extension::per_parachain_header::ensure_priority_boost_is_sane::<
Runtime,
RefundableParachain<WithBridgeHubPolkadotMessagesInstance, BridgeHubPolkadot>,
PriorityBoostPerParachainHeader,
>(FEE_BOOST_PER_PARACHAIN_HEADER);

bridge_runtime_common::extensions::priority_calculator::per_message::ensure_priority_boost_is_sane::<
pallet_bridge_relayers::extension::per_message::ensure_priority_boost_is_sane::<
Runtime,
WithBridgeHubPolkadotMessagesInstance,
PriorityBoostPerMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ fn bridge_hub_kusama_genesis(
)
})
.collect(),
// TODO: Any keys to add here?
non_authority_keys: vec![],
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down
Loading

0 comments on commit 2639ad6

Please sign in to comment.