Skip to content

Commit

Permalink
WIP: fix signed extensions and refund
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jul 17, 2024
1 parent d5b88a8 commit 52d5cb6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@
//! are reusing Polkadot Bulletin chain primitives everywhere here.

use crate::{
weights, xcm_config::UniversalLocation, BridgeRococoBulletinGrandpa,
BridgeRococoBulletinMessages, PolkadotXcm, Runtime, RuntimeEvent, XcmOverRococoBulletin,
XcmRouter,
weights, xcm_config::UniversalLocation, AccountId, Balance, Balances,
BridgeRococoBulletinGrandpa, BridgeRococoBulletinMessages, PolkadotXcm, Runtime, RuntimeEvent,
RuntimeHoldReason, XcmOverRococoBulletin, XcmRouter,
};
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof, LaneId,
};
use bp_runtime::Chain;
use bridge_runtime_common::{
extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedMessages, RefundSignedExtensionAdapter,
RefundableMessagesLane,
},
messages_xcm_extension::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
};
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;

use frame_support::{parameter_types, traits::PalletInfoAccess};
use frame_system::EnsureRoot;
use pallet_bridge_relayers::extension::{
BridgeRelayersSignedExtension, WithMessagesExtensionConfig,
};
use pallet_xcm::EnsureXcm;
use pallet_xcm_bridge_hub::XcmAsPlainPayload;
use parachains_common::xcm_config::ParentRelayOrSiblingParachains;
use polkadot_parachain_primitives::primitives::Sibling;
use testnet_parachains_constants::rococo::currency::UNITS as ROC;
use xcm::{
latest::prelude::*,
prelude::{InteriorLocation, NetworkId},
};
use xcm_builder::BridgeBlobDispatcher;
use xcm_builder::{BridgeBlobDispatcher, ParentIsPreset, SiblingParachainConvertsVia};

parameter_types! {
/// Bridge specific chain (network) identifier of the Rococo Bulletin Chain.
Expand All @@ -61,12 +61,6 @@ parameter_types! {
2,
[GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get())]
);
/// All active lanes that the current bridge supports.
pub ActiveOutboundLanesToRococoBulletin: &'static [bp_messages::LaneId]
= &[XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN];
/// Lane identifier, used to connect Rococo People and Rococo Bulletin chain.
pub const RococoPeopleToRococoBulletinMessagesLane: bp_messages::LaneId
= XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN;

// see the `FEE_BOOST_PER_RELAY_HEADER` constant get the meaning of this value
pub PriorityBoostPerRelayHeader: u64 = 58_014_163_614_163;
Expand All @@ -78,26 +72,8 @@ parameter_types! {
/// meaning of this value.
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;

/// Identifier of the sibling Rococo People parachain.
pub RococoPeopleParaId: cumulus_primitives_core::ParaId = rococo_runtime_constants::system_parachain::PEOPLE_ID.into();
/// A route (XCM location and bridge lane) that the Rococo People Chain -> Rococo Bulletin Chain
/// message is following.
pub FromRococoPeopleToRococoBulletinRoute: SenderAndLane = SenderAndLane::new(
ParentThen(Parachain(RococoPeopleParaId::get().into()).into()).into(),
XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN,
);
/// All active routes and their destinations.
pub ActiveLanes: alloc::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = alloc::vec![
(
FromRococoPeopleToRococoBulletinRoute::get(),
(RococoBulletinGlobalConsensusNetwork::get(), Here)
)
];

/// XCM message that is never sent.
pub NeverSentMessage: Option<Xcm<()>> = None;
pub storage BridgeDeposit: Balance = 5 * ROC;
}
pub const XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN: LaneId = LaneId([0, 0, 0, 0]);

/// Proof of messages, coming from Rococo Bulletin chain.
pub type FromRococoBulletinMessagesProof =
Expand All @@ -113,34 +89,15 @@ type FromRococoBulletinMessageBlobDispatcher = BridgeBlobDispatcher<
BridgeRococoToRococoBulletinMessagesPalletInstance,
>;

/// Export XCM messages to be relayed to the other side
pub type ToRococoBulletinHaulBlobExporter = XcmOverRococoBulletin;

pub struct ToRococoBulletinXcmBlobHauler;
impl XcmBlobHauler for ToRococoBulletinXcmBlobHauler {
type Runtime = Runtime;
type MessagesInstance = WithRococoBulletinMessagesInstance;
type ToSourceChainSender = XcmRouter;
type CongestedMessage = NeverSentMessage;
type UncongestedMessage = NeverSentMessage;
}

/// On messages delivered callback.
type OnMessagesDeliveredFromRococoBulletin =
XcmBlobHaulerAdapter<ToRococoBulletinXcmBlobHauler, ActiveLanes>;

/// Signed extension that refunds relayers that are delivering messages from the Rococo Bulletin
/// chain.
pub type OnBridgeHubRococoRefundRococoBulletinMessages = RefundSignedExtensionAdapter<
RefundBridgedMessages<
pub type OnBridgeHubRococoRefundRococoBulletinMessages = BridgeRelayersSignedExtension<
Runtime,
WithMessagesExtensionConfig<
StrOnBridgeHubRococoRefundRococoBulletinMessages,
Runtime,
RefundableMessagesLane<
WithRococoBulletinMessagesInstance,
RococoPeopleToRococoBulletinMessagesLane,
>,
ActualFeeRefund<Runtime>,
WithRococoBulletinMessagesInstance,
PriorityBoostPerMessage,
StrOnBridgeHubRococoRefundRococoBulletinMessages,
>,
>;
bp_runtime::generate_static_str_provider!(OnBridgeHubRococoRefundRococoBulletinMessages);
Expand All @@ -156,31 +113,43 @@ impl pallet_bridge_messages::Config<WithRococoBulletinMessagesInstance> for Runt
type BridgedChain = bp_polkadot_bulletin::PolkadotBulletin;
type BridgedHeaderChain = BridgeRococoBulletinGrandpa;

type ActiveOutboundLanes = ActiveOutboundLanesToRococoBulletin;

type OutboundPayload = XcmAsPlainPayload;

type InboundPayload = XcmAsPlainPayload;
type DeliveryPayments = ();

type DeliveryConfirmationPayments = ();

type MessageDispatch =
XcmBlobMessageDispatch<FromRococoBulletinMessageBlobDispatcher, Self::WeightInfo, ()>;
type OnMessagesDelivered = OnMessagesDeliveredFromRococoBulletin;
type MessageDispatch = XcmOverRococoBulletin;
type OnMessagesDelivered = XcmOverRococoBulletin;
}

/// Add support for the export and dispatch of XCM programs.
pub type XcmOverPolkadotBulletinInstance = pallet_xcm_bridge_hub::Instance2;
impl pallet_xcm_bridge_hub::Config<XcmOverPolkadotBulletinInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;

type UniversalLocation = UniversalLocation;
type BridgedNetwork = RococoBulletinGlobalConsensusNetworkLocation;
type BridgeMessagesPalletInstance = WithRococoBulletinMessagesInstance;

type MessageExportPrice = ();
type DestinationVersion =
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, RococoBulletinGlobalConsensusNetworkLocation>;
type Lanes = ActiveLanes;
type LanesSupport = ToRococoBulletinXcmBlobHauler;

type AdminOrigin = EnsureRoot<AccountId>;
// Only allow calls from relay chains and sibling parachains to directly open the bridge.
type OpenBridgeOrigin = EnsureXcm<ParentRelayOrSiblingParachains>;
// Converter aligned with `OpenBridgeOrigin`.
type BridgeOriginAccountIdConverter =
(ParentIsPreset<AccountId>, SiblingParachainConvertsVia<Sibling, AccountId>);

type BridgeDeposit = BridgeDeposit;
type Currency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;

type LocalXcmChannelManager = ();
type BlobDispatcher = FromRococoBulletinMessageBlobDispatcher;
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ use bp_messages::{
};
use bp_runtime::Chain;
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;
use bridge_runtime_common::extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedMessages, RefundSignedExtensionAdapter, RefundableMessagesLane,
};
use pallet_xcm_bridge_hub::XcmAsPlainPayload;

use codec::Encode;
use frame_support::{parameter_types, traits::PalletInfoAccess};
use frame_system::EnsureRoot;
use pallet_bridge_relayers::extension::{
BridgeRelayersSignedExtension, WithMessagesExtensionConfig,
};
use pallet_xcm::EnsureXcm;
use parachains_common::xcm_config::ParentRelayOrSiblingParachains;
use polkadot_parachain_primitives::primitives::Sibling;
Expand All @@ -62,10 +62,9 @@ parameter_types! {
// 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();

// TODO:(bridges-v2) - check with `LocalXcmChannelManager` if we need - FAIL-CI
pub CongestedMessage: Xcm<()> = build_congestion_message(true).into();
// TODO:(bridges-v2) - check with `LocalXcmChannelManager` if we need - FAIL-CI
pub UncongestedMessage: Xcm<()> = build_congestion_message(false).into();

pub BridgeHubWestendLocation: Location = Location::new(
Expand All @@ -79,6 +78,7 @@ parameter_types! {
pub storage BridgeDeposit: Balance = 5 * ROC;
}

// TODO:(bridges-v2) - check with `LocalXcmChannelManager` if we need - FAIL-CI
fn build_congestion_message<Call>(is_congested: bool) -> alloc::vec::Vec<Instruction<Call>> {
alloc::vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Expand Down Expand Up @@ -110,16 +110,13 @@ type FromWestendMessageBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, UniversalLocation, BridgeRococoToWestendMessagesPalletInstance>;

/// Signed extension that refunds relayers that are delivering messages from the Westend parachain.
pub type OnBridgeHubRococoRefundBridgeHubWestendMessages = RefundSignedExtensionAdapter<
RefundBridgedMessages<
pub type OnBridgeHubRococoRefundBridgeHubWestendMessages = BridgeRelayersSignedExtension<
Runtime,
WithMessagesExtensionConfig<
StrOnBridgeHubRococoRefundBridgeHubWestendMessages,
Runtime,
RefundableMessagesLane<
WithBridgeHubWestendMessagesInstance,
AssetHubRococoToAssetHubWestendMessagesLane,
>,
ActualFeeRefund<Runtime>,
WithBridgeHubWestendMessagesInstance,
PriorityBoostPerMessage,
StrOnBridgeHubRococoRefundBridgeHubWestendMessages,
>,
>;
bp_runtime::generate_static_str_provider!(OnBridgeHubRococoRefundBridgeHubWestendMessages);
Expand Down
Loading

0 comments on commit 52d5cb6

Please sign in to comment.