moonriver_runtime/
bridge_config.rs1extern crate alloc;
18
19use crate::xcm_config::{SelfLocation, UniversalLocation};
20use crate::{
21 moonriver_weights, Balances, BridgePolkadotMessages, BridgeXcmOverMoonbeam, MessageQueue,
22 PolkadotXcm, Runtime, RuntimeEvent, RuntimeHoldReason,
23};
24use alloc::collections::btree_set::BTreeSet;
25use bp_moonriver::bp_polkadot;
26use bp_parachains::SingleParaStoredHeaderDataBuilder;
27use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;
28use frame_support::pallet_prelude::PalletInfoAccess;
29use frame_support::traits::{Contains, Everything};
30use frame_support::{parameter_types, traits::ConstU32};
31use frame_system::{EnsureNever, EnsureRoot};
32use moonbeam_core_primitives::{AccountId, Balance};
33use moonbeam_runtime_common::bridge::{CongestionManager, LocalBlobDispatcher};
34use pallet_xcm_bridge::XcmAsPlainPayload;
35use polkadot_parachain::primitives::Sibling;
36use xcm::latest::{InteriorLocation, Junction, Location, NetworkId};
37use xcm::prelude::{GlobalConsensus, PalletInstance};
38use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia};
39
40parameter_types! {
41 pub BridgeKusamaToPolkadotMessagesPalletInstance: InteriorLocation = [PalletInstance(<BridgePolkadotMessages as PalletInfoAccess>::index() as u8)].into();
42 pub PolkadotGlobalConsensusNetwork: NetworkId = NetworkId::Polkadot;
43 pub PolkadotGlobalConsensusNetworkLocation: Location = Location::new(
44 2,
45 [GlobalConsensus(PolkadotGlobalConsensusNetwork::get())]
46 );
47
48 pub const RelayChainHeadersToKeep: u32 = 1024;
49 pub const ParachainHeadsToKeep: u32 = 64;
50
51 pub const PolkadotBridgeParachainPalletName: &'static str = bp_polkadot::PARAS_PALLET_NAME;
52 pub const MaxPolkadotParaHeadDataSize: u32 = bp_polkadot::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
53
54 pub UniversalAliases: BTreeSet<(Location, Junction)> = BTreeSet::from_iter(
56 alloc::vec![
57 (SelfLocation::get(), GlobalConsensus(PolkadotGlobalConsensusNetwork::get()))
60 ]
61 );
62
63 pub storage BridgeDeposit: Balance = 0;
64}
65
66impl Contains<(Location, Junction)> for UniversalAliases {
67 fn contains(alias: &(Location, Junction)) -> bool {
68 UniversalAliases::get().contains(alias)
69 }
70}
71
72pub type BridgeGrandpaPolkadotInstance = pallet_bridge_grandpa::Instance1;
74impl pallet_bridge_grandpa::Config<BridgeGrandpaPolkadotInstance> for Runtime {
75 type RuntimeEvent = RuntimeEvent;
76 type BridgedChain = bp_polkadot::Polkadot;
77 type MaxFreeHeadersPerBlock = ConstU32<4>;
78 type FreeHeadersInterval = ConstU32<5>;
79 type HeadersToKeep = RelayChainHeadersToKeep;
80 type WeightInfo = moonriver_weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
81}
82
83pub type BridgeMoonbeamInstance = pallet_bridge_parachains::Instance1;
85impl pallet_bridge_parachains::Config<BridgeMoonbeamInstance> for Runtime {
86 type RuntimeEvent = RuntimeEvent;
87 type BridgesGrandpaPalletInstance = BridgeGrandpaPolkadotInstance;
88 type ParasPalletName = PolkadotBridgeParachainPalletName;
89 type ParaStoredHeaderDataBuilder = SingleParaStoredHeaderDataBuilder<bp_moonbeam::Moonbeam>;
90 type HeadsToKeep = ParachainHeadsToKeep;
91 type MaxParaHeadDataSize = MaxPolkadotParaHeadDataSize;
92 type OnNewHead = ();
93 type WeightInfo = moonriver_weights::pallet_bridge_parachains::WeightInfo<Runtime>;
94}
95
96pub type WithPolkadotMessagesInstance = pallet_bridge_messages::Instance1;
98impl pallet_bridge_messages::Config<WithPolkadotMessagesInstance> for Runtime {
99 type RuntimeEvent = RuntimeEvent;
100
101 type ThisChain = bp_moonriver::Moonriver;
102 type BridgedChain = bp_moonbeam::Moonbeam;
103 type BridgedHeaderChain = pallet_bridge_parachains::ParachainHeaders<
104 Runtime,
105 BridgeMoonbeamInstance,
106 bp_moonbeam::Moonbeam,
107 >;
108
109 type OutboundPayload = XcmAsPlainPayload;
110 type InboundPayload = XcmAsPlainPayload;
111 type LaneId = bp_moonriver::LaneId;
112
113 type DeliveryPayments = ();
114 type DeliveryConfirmationPayments = (); type MessageDispatch = BridgeXcmOverMoonbeam;
117 type OnMessagesDelivered = BridgeXcmOverMoonbeam;
118 type WeightInfo = moonriver_weights::pallet_bridge_messages::WeightInfo<Runtime>;
119}
120
121pub type XcmOverPolkadotInstance = pallet_xcm_bridge::Instance1;
124impl pallet_xcm_bridge::Config<XcmOverPolkadotInstance> for Runtime {
125 type RuntimeEvent = RuntimeEvent;
126
127 type UniversalLocation = UniversalLocation;
128 type BridgedNetwork = PolkadotGlobalConsensusNetworkLocation;
129 type BridgeMessagesPalletInstance = WithPolkadotMessagesInstance;
130 type MessageExportPrice = ();
131 type DestinationVersion =
132 XcmVersionOfDestAndRemoteBridge<PolkadotXcm, bp_moonbeam::GlobalConsensusLocation>;
133
134 type ForceOrigin = EnsureRoot<AccountId>;
135 type OpenBridgeOrigin = EnsureNever<Location>;
137 type BridgeOriginAccountIdConverter = (
139 ParentIsPreset<AccountId>,
140 SiblingParachainConvertsVia<Sibling, AccountId>,
141 );
142
143 type BridgeDeposit = BridgeDeposit;
144 type Currency = Balances;
145 type RuntimeHoldReason = RuntimeHoldReason;
146 type AllowWithoutBridgeDeposit = Everything;
148 type LocalXcmChannelManager = CongestionManager<Runtime>;
149 type BlobDispatcher = LocalBlobDispatcher<
152 MessageQueue,
153 UniversalLocation,
154 BridgeKusamaToPolkadotMessagesPalletInstance,
155 >;
156}
157
158#[cfg(feature = "runtime-benchmarks")]
159pub mod benchmarking {
160 use crate::bridge_config::PolkadotGlobalConsensusNetwork;
161 use crate::Runtime;
162 use bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof;
163 use bp_messages::target_chain::FromBridgedChainMessagesProof;
164 use pallet_bridge_messages::LaneIdOf;
165 use xcm::latest::{InteriorLocation, Location, NetworkId};
166 use xcm::prelude::{GlobalConsensus, Parachain};
167
168 pub type FromMoonbeamMessagesProof<MI> =
170 FromBridgedChainMessagesProof<bp_moonriver::Hash, LaneIdOf<Runtime, MI>>;
171 pub type ToMoonbeamMessagesDeliveryProof<MI> =
173 FromBridgedChainMessagesDeliveryProof<bp_moonriver::Hash, LaneIdOf<Runtime, MI>>;
174
175 pub(crate) fn open_bridge_for_benchmarks<R, XBHI, C>(
176 with: pallet_xcm_bridge::LaneIdOf<R, XBHI>,
177 sibling_para_id: u32,
178 ) -> InteriorLocation
179 where
180 R: pallet_xcm_bridge::Config<XBHI>,
181 XBHI: 'static,
182 C: xcm_executor::traits::ConvertLocation<
183 bp_runtime::AccountIdOf<pallet_xcm_bridge::ThisChainOf<R, XBHI>>,
184 >,
185 {
186 use alloc::boxed::Box;
187 use pallet_xcm_bridge::{Bridge, BridgeId, BridgeState};
188 use sp_runtime::traits::Zero;
189 use xcm::VersionedInteriorLocation;
190
191 let lane_id = with;
193 let sibling_parachain = Location::new(1, [Parachain(sibling_para_id)]);
194 let universal_source = [
195 GlobalConsensus(NetworkId::Kusama),
196 Parachain(sibling_para_id),
197 ]
198 .into();
199 let universal_destination = [
200 GlobalConsensus(PolkadotGlobalConsensusNetwork::get()),
201 Parachain(<bp_moonbeam::Moonbeam as bp_runtime::Parachain>::PARACHAIN_ID),
202 ]
203 .into();
204 let bridge_id = BridgeId::new(&universal_source, &universal_destination);
205
206 pallet_xcm_bridge::Bridges::<R, XBHI>::insert(
208 bridge_id,
209 Bridge {
210 bridge_origin_relative_location: Box::new(sibling_parachain.clone().into()),
211 bridge_origin_universal_location: Box::new(VersionedInteriorLocation::from(
212 universal_source.clone(),
213 )),
214 bridge_destination_universal_location: Box::new(VersionedInteriorLocation::from(
215 universal_destination,
216 )),
217 state: BridgeState::Opened,
218 bridge_owner_account: C::convert_location(&sibling_parachain)
219 .expect("valid AccountId"),
220 deposit: Zero::zero(),
221 lane_id,
222 },
223 );
224 pallet_xcm_bridge::LaneToBridge::<R, XBHI>::insert(lane_id, bridge_id);
225
226 universal_source
227 }
228}