Skip to content
Merged
68 changes: 41 additions & 27 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

//! Everything required to serve Millau <-> Rialto messages.

use crate::{RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
use crate::{RialtoGrandpaInstance, Runtime, RuntimeOrigin, WithRialtoMessagesInstance};

use bp_messages::LaneId;
use bridge_runtime_common::{
messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
},
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
use xcm::latest::prelude::*;
use xcm_builder::HaulBlobExporter;

/// Default lane that is used to send messages to Rialto.
pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
Expand All @@ -48,7 +52,7 @@ pub type ToRialtoMessageVerifier =
messages::source::FromThisChainMessageVerifier<WithRialtoMessageBridge>;

/// Message payload for Rialto -> Millau messages.
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload<RuntimeCall>;
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload;

/// Messages proof for Rialto -> Millau messages.
pub type FromRialtoMessagesProof = messages::target::FromBridgedChainMessagesProof<bp_rialto::Hash>;
Expand All @@ -58,12 +62,13 @@ pub type ToRialtoMessagesDeliveryProof =
messages::source::FromBridgedChainMessagesDeliveryProof<bp_rialto::Hash>;

/// Call-dispatch based message dispatch for Rialto -> Millau messages.
pub type FromRialtoMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
WithRialtoMessageBridge,
xcm_executor::XcmExecutor<crate::xcm_config::XcmConfig>,
crate::xcm_config::XcmWeigher,
WeightCredit,
>;
pub type FromRialtoMessageDispatch =
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
bp_millau::Millau,
bp_rialto::Rialto,
crate::xcm_config::OnMillauBlobDispatcher,
bridge_runtime_common::messages_xcm_extension::XcmRouterWeigher<crate::DbWeight>,
>;

/// Maximal outbound payload size of Millau -> Rialto messages.
pub type ToRialtoMaximalOutboundPayloadSize =
Expand All @@ -74,8 +79,6 @@ pub type ToRialtoMaximalOutboundPayloadSize =
pub struct WithRialtoMessageBridge;

impl MessageBridge for WithRialtoMessageBridge {
const THIS_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
const BRIDGED_CHAIN_ID: ChainId = RIALTO_CHAIN_ID;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;

type ThisChain = Millau;
Expand All @@ -94,15 +97,6 @@ impl messages::UnderlyingChainProvider for Millau {

impl messages::ThisChainWithMessages for Millau {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;

fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
MessageNonce::MAX
}
}

/// Rialto chain from message lane point of view.
Expand All @@ -117,9 +111,29 @@ impl messages::UnderlyingChainProvider for Rialto {
type Chain = bp_rialto::Rialto;
}

impl messages::BridgedChainWithMessages for Rialto {
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
impl messages::BridgedChainWithMessages for Rialto {}

/// Export XCM messages to be relayed to Rialto.
pub type ToRialtoBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToRialtoXcmBlobHauler>,
crate::xcm_config::RialtoNetwork,
(),
>;

/// To-Rialto XCM hauler.
pub struct ToRialtoXcmBlobHauler;

impl XcmBlobHauler for ToRialtoXcmBlobHauler {
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
type MessageSenderOrigin = RuntimeOrigin;

fn message_sender_origin() -> RuntimeOrigin {
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
.into()
}

fn xcm_lane() -> LaneId {
XCM_LANE
}
}

Expand Down
70 changes: 43 additions & 27 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@

//! Everything required to serve Millau <-> RialtoParachain messages.

use crate::{Runtime, RuntimeCall, RuntimeOrigin, WithRialtoParachainsInstance};
use crate::{
Runtime, RuntimeOrigin, WithRialtoParachainMessagesInstance, WithRialtoParachainsInstance,
};

use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bridge_runtime_common::messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
use bp_messages::LaneId;
use bridge_runtime_common::{
messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
},
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
use xcm::latest::prelude::*;
use xcm_builder::HaulBlobExporter;

/// Default lane that is used to send messages to Rialto parachain.
pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
Expand All @@ -48,16 +54,16 @@ pub type ToRialtoParachainMessageVerifier =
messages::source::FromThisChainMessageVerifier<WithRialtoParachainMessageBridge>;

/// Message payload for RialtoParachain -> Millau messages.
pub type FromRialtoParachainMessagePayload =
messages::target::FromBridgedChainMessagePayload<RuntimeCall>;
pub type FromRialtoParachainMessagePayload = messages::target::FromBridgedChainMessagePayload;

/// Call-dispatch based message dispatch for RialtoParachain -> Millau messages.
pub type FromRialtoParachainMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
WithRialtoParachainMessageBridge,
xcm_executor::XcmExecutor<crate::xcm_config::XcmConfig>,
crate::xcm_config::XcmWeigher,
WeightCredit,
>;
pub type FromRialtoParachainMessageDispatch =
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
bp_millau::Millau,
bp_rialto::Rialto,
crate::xcm_config::OnMillauBlobDispatcher,
bridge_runtime_common::messages_xcm_extension::XcmRouterWeigher<crate::DbWeight>,
>;

/// Maximal outbound payload size of Millau -> RialtoParachain messages.
pub type ToRialtoParachainMaximalOutboundPayloadSize =
Expand All @@ -68,8 +74,6 @@ pub type ToRialtoParachainMaximalOutboundPayloadSize =
pub struct WithRialtoParachainMessageBridge;

impl MessageBridge for WithRialtoParachainMessageBridge {
const THIS_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
const BRIDGED_CHAIN_ID: ChainId = RIALTO_PARACHAIN_CHAIN_ID;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;

type ThisChain = Millau;
Expand All @@ -90,16 +94,7 @@ impl messages::UnderlyingChainProvider for Millau {
}

impl messages::ThisChainWithMessages for Millau {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;

fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
true
}

fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
MessageNonce::MAX
}
}

/// RialtoParachain chain from message lane point of view.
Expand All @@ -116,8 +111,29 @@ impl messages::UnderlyingChainProvider for RialtoParachain {
type Chain = bp_rialto_parachain::RialtoParachain;
}

impl messages::BridgedChainWithMessages for RialtoParachain {
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
impl messages::BridgedChainWithMessages for RialtoParachain {}

/// Export XCM messages to be relayed to Rialto.
pub type ToRialtoParachainBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToRialtoParachainXcmBlobHauler>,
crate::xcm_config::RialtoParachainNetwork,
(),
>;

/// To-RialtoParachain XCM hauler.
pub struct ToRialtoParachainXcmBlobHauler;

impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
type MessageSender =
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;
type MessageSenderOrigin = RuntimeOrigin;

fn message_sender_origin() -> RuntimeOrigin {
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
.into()
}

fn xcm_lane() -> LaneId {
XCM_LANE
}
}
Loading