bridge_hub_rococo_runtime/
bridge_common_config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Bridge definitions that can be used by multiple BridgeHub flavors.
18//! All configurations here should be dedicated to a single chain; in other words, we don't need two
19//! chains for a single pallet configuration.
20//!
21//! For example, the messaging pallet needs to know the sending and receiving chains, but the
22//! GRANDPA tracking pallet only needs to be aware of one chain.
23
24use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent};
25use bp_parachains::SingleParaStoredHeaderDataBuilder;
26use bp_relayers::RewardsAccountParams;
27use frame_support::{parameter_types, traits::ConstU32};
28
29parameter_types! {
30	pub const RelayChainHeadersToKeep: u32 = 1024;
31	pub const ParachainHeadsToKeep: u32 = 64;
32
33	pub const WestendBridgeParachainPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
34	pub const MaxWestendParaHeadDataSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
35
36	pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000;
37	pub const RelayerStakeLease: u32 = 8;
38	pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
39
40	pub storage DeliveryRewardInBalance: u64 = 1_000_000;
41}
42
43/// Add GRANDPA bridge pallet to track Westend relay chain.
44pub type BridgeGrandpaWestendInstance = pallet_bridge_grandpa::Instance3;
45impl pallet_bridge_grandpa::Config<BridgeGrandpaWestendInstance> for Runtime {
46	type RuntimeEvent = RuntimeEvent;
47	type BridgedChain = bp_westend::Westend;
48	type MaxFreeHeadersPerBlock = ConstU32<4>;
49	type FreeHeadersInterval = ConstU32<5>;
50	type HeadersToKeep = RelayChainHeadersToKeep;
51	type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
52}
53
54/// Add parachain bridge pallet to track Westend BridgeHub parachain
55pub type BridgeParachainWestendInstance = pallet_bridge_parachains::Instance3;
56impl pallet_bridge_parachains::Config<BridgeParachainWestendInstance> for Runtime {
57	type RuntimeEvent = RuntimeEvent;
58	type WeightInfo = weights::pallet_bridge_parachains::WeightInfo<Runtime>;
59	type BridgesGrandpaPalletInstance = BridgeGrandpaWestendInstance;
60	type ParasPalletName = WestendBridgeParachainPalletName;
61	type ParaStoredHeaderDataBuilder =
62		SingleParaStoredHeaderDataBuilder<bp_bridge_hub_westend::BridgeHubWestend>;
63	type HeadsToKeep = ParachainHeadsToKeep;
64	type MaxParaHeadDataSize = MaxWestendParaHeadDataSize;
65}
66
67/// Allows collect and claim rewards for relayers
68pub type RelayersForLegacyLaneIdsMessagesInstance = ();
69impl pallet_bridge_relayers::Config<RelayersForLegacyLaneIdsMessagesInstance> for Runtime {
70	type RuntimeEvent = RuntimeEvent;
71	type RewardBalance = Balance;
72	type Reward = RewardsAccountParams<bp_messages::LegacyLaneId>;
73	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
74		pallet_balances::Pallet<Runtime>,
75		AccountId,
76		bp_messages::LegacyLaneId,
77		Self::RewardBalance,
78	>;
79	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
80		AccountId,
81		BlockNumber,
82		Balances,
83		RelayerStakeReserveId,
84		RequiredStakeForStakeAndSlash,
85		RelayerStakeLease,
86	>;
87	type Balance = Balance;
88	type WeightInfo = weights::pallet_bridge_relayers_legacy::WeightInfo<Runtime>;
89}
90
91/// Allows collect and claim rewards for relayers
92pub type RelayersForPermissionlessLanesInstance = pallet_bridge_relayers::Instance2;
93impl pallet_bridge_relayers::Config<RelayersForPermissionlessLanesInstance> for Runtime {
94	type RuntimeEvent = RuntimeEvent;
95	type RewardBalance = Balance;
96	type Reward = RewardsAccountParams<bp_messages::HashedLaneId>;
97	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
98		pallet_balances::Pallet<Runtime>,
99		AccountId,
100		bp_messages::HashedLaneId,
101		Self::RewardBalance,
102	>;
103	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
104		AccountId,
105		BlockNumber,
106		Balances,
107		RelayerStakeReserveId,
108		RequiredStakeForStakeAndSlash,
109		RelayerStakeLease,
110	>;
111	type Balance = Balance;
112	type WeightInfo = weights::pallet_bridge_relayers_permissionless_lanes::WeightInfo<Runtime>;
113}
114
115/// Add GRANDPA bridge pallet to track Rococo Bulletin chain.
116pub type BridgeGrandpaRococoBulletinInstance = pallet_bridge_grandpa::Instance4;
117impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoBulletinInstance> for Runtime {
118	type RuntimeEvent = RuntimeEvent;
119	type BridgedChain = bp_polkadot_bulletin::PolkadotBulletin;
120	type MaxFreeHeadersPerBlock = ConstU32<4>;
121	type FreeHeadersInterval = ConstU32<5>;
122	type HeadersToKeep = RelayChainHeadersToKeep;
123	// Technically this is incorrect - we have two pallet instances and ideally we shall
124	// benchmark every instance separately. But the benchmarking engine has a flaw - it
125	// messes with components. E.g. in Kusama maximal validators count is 1024 and in
126	// Bulletin chain it is 100. But benchmarking engine runs Bulletin benchmarks using
127	// components range, computed for Kusama => it causes an error.
128	//
129	// In practice, however, GRANDPA pallet works the same way for all bridged chains, so
130	// weights are also the same for both bridges.
131	type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
132}