// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Parity Bridges Common. // Parity Bridges Common is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Parity Bridges Common is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . //! Everything required to serve Millau <-> RialtoParachain messages. use crate::{ Runtime, RuntimeOrigin, WithRialtoParachainMessagesInstance, WithRialtoParachainsInstance, }; use bp_messages::LaneId; use bridge_runtime_common::{ messages::{ self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge, }, messages_xcm_extension::{SenderAndLane, XcmBlobHauler, XcmBlobHaulerAdapter}, }; use frame_support::{parameter_types, weights::Weight}; use pallet_bridge_relayers::WeightInfoExt as _; use sp_runtime::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]); /// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual /// tests, confirming that we don't break encoding somewhere between. pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2); parameter_types! { /// Weight credit for our test messages. /// /// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge /// (it is prepended with `UniversalOrigin` instruction). pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE; /// Lane used by the with-RialtoParachain bridge. pub RialtoParachainSenderAndLane: SenderAndLane = SenderAndLane::new(Here.into(), XCM_LANE); /// Dummy message used in configuration. pub DummyXcmMessage: Xcm<()> = Xcm::new(); } /// Message payload for Millau -> RialtoParachain messages. pub type ToRialtoParachainMessagePayload = messages::source::FromThisChainMessagePayload; /// Message verifier for Millau -> RialtoParachain messages. pub type ToRialtoParachainMessageVerifier = messages::source::FromThisChainMessageVerifier; /// Message payload for RialtoParachain -> Millau messages. pub type FromRialtoParachainMessagePayload = messages::target::FromBridgedChainMessagePayload; /// Call-dispatch based message dispatch for RialtoParachain -> Millau messages. pub type FromRialtoParachainMessageDispatch = bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch< crate::xcm_config::OnMillauBlobDispatcher, (), (), >; /// Maximal outbound payload size of Millau -> RialtoParachain messages. pub type ToRialtoParachainMaximalOutboundPayloadSize = messages::source::FromThisChainMaximalOutboundPayloadSize; /// Millau <-> RialtoParachain message bridge. #[derive(RuntimeDebug, Clone, Copy)] pub struct WithRialtoParachainMessageBridge; impl MessageBridge for WithRialtoParachainMessageBridge { const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME; type ThisChain = Millau; type BridgedChain = RialtoParachain; type BridgedHeaderChain = pallet_bridge_parachains::ParachainHeaders< Runtime, WithRialtoParachainsInstance, bp_rialto_parachain::RialtoParachain, >; } /// Millau chain from message lane point of view. #[derive(RuntimeDebug, Clone, Copy)] pub struct Millau; impl messages::UnderlyingChainProvider for Millau { type Chain = bp_millau::Millau; } impl messages::ThisChainWithMessages for Millau { type RuntimeOrigin = RuntimeOrigin; } /// RialtoParachain chain from message lane point of view. #[derive(RuntimeDebug, Clone, Copy)] pub struct RialtoParachain; /// RialtoParachain as source header chain. pub type RialtoParachainAsSourceHeaderChain = SourceHeaderChainAdapter; /// RialtoParachain as target header chain. pub type RialtoParachainAsTargetHeaderChain = TargetHeaderChainAdapter; impl messages::UnderlyingChainProvider for RialtoParachain { type Chain = bp_rialto_parachain::RialtoParachain; } impl messages::BridgedChainWithMessages for RialtoParachain {} /// Export XCM messages to be relayed to Rialto. pub type ToRialtoParachainBlobExporter = HaulBlobExporter< XcmBlobHaulerAdapter, crate::xcm_config::RialtoParachainNetwork, (), >; /// To-RialtoParachain XCM hauler. pub struct ToRialtoParachainXcmBlobHauler; impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler { type Runtime = Runtime; type MessagesInstance = WithRialtoParachainMessagesInstance; type SenderAndLane = RialtoParachainSenderAndLane; type ToSourceChainSender = crate::xcm_config::XcmRouter; type CongestedMessage = DummyXcmMessage; type UncongestedMessage = DummyXcmMessage; } impl pallet_bridge_messages::WeightInfoExt for crate::weights::RialtoParachainMessagesWeightInfo { fn expected_extra_storage_proof_size() -> u32 { bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE } fn receive_messages_proof_overhead_from_runtime() -> Weight { pallet_bridge_relayers::weights::BridgeWeight::::receive_messages_proof_overhead_from_runtime() } fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight { pallet_bridge_relayers::weights::BridgeWeight::::receive_messages_delivery_proof_overhead_from_runtime() } } #[cfg(test)] mod tests { use super::*; use crate::{ PriorityBoostPerMessage, RialtoGrandpaInstance, Runtime, WithRialtoParachainMessagesInstance, }; use bridge_runtime_common::{ assert_complete_bridge_types, integrity::{ assert_complete_bridge_constants, check_message_lane_weights, AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants, AssertCompleteBridgeConstants, }, }; #[test] fn ensure_millau_message_lane_weights_are_correct() { check_message_lane_weights::( bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE, bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, true, ); } #[test] fn ensure_bridge_integrity() { assert_complete_bridge_types!( runtime: Runtime, with_bridged_chain_grandpa_instance: RialtoGrandpaInstance, with_bridged_chain_messages_instance: WithRialtoParachainMessagesInstance, bridge: WithRialtoParachainMessageBridge, this_chain: bp_millau::Millau, bridged_chain: bp_rialto::Rialto, ); assert_complete_bridge_constants::< Runtime, RialtoGrandpaInstance, WithRialtoParachainMessagesInstance, WithRialtoParachainMessageBridge, >(AssertCompleteBridgeConstants { this_chain_constants: AssertChainConstants { block_length: bp_millau::BlockLength::get(), block_weights: bp_millau::BlockWeights::get(), }, messages_pallet_constants: AssertBridgeMessagesPalletConstants { max_unrewarded_relayers_in_bridged_confirmation_tx: bp_rialto_parachain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, max_unconfirmed_messages_in_bridged_confirmation_tx: bp_rialto_parachain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, bridged_chain_id: bp_runtime::RIALTO_PARACHAIN_CHAIN_ID, }, pallet_names: AssertBridgePalletNames { with_this_chain_messages_pallet_name: bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME, with_bridged_chain_grandpa_pallet_name: bp_rialto::WITH_RIALTO_GRANDPA_PALLET_NAME, with_bridged_chain_messages_pallet_name: bp_rialto_parachain::WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME, }, }); bridge_runtime_common::priority_calculator::ensure_priority_boost_is_sane::< Runtime, WithRialtoParachainMessagesInstance, PriorityBoostPerMessage, >(1_000_000); } }