referrerpolicy=no-referrer-when-downgrade

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	type OnNewHead = ();
66}
67
68/// Allows collect and claim rewards for relayers
69pub type RelayersForLegacyLaneIdsMessagesInstance = ();
70impl pallet_bridge_relayers::Config<RelayersForLegacyLaneIdsMessagesInstance> for Runtime {
71	type RuntimeEvent = RuntimeEvent;
72	type RewardBalance = Balance;
73	type Reward = RewardsAccountParams<bp_messages::LegacyLaneId>;
74	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
75		pallet_balances::Pallet<Runtime>,
76		AccountId,
77		bp_messages::LegacyLaneId,
78		Self::RewardBalance,
79	>;
80	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
81		AccountId,
82		BlockNumber,
83		Balances,
84		RelayerStakeReserveId,
85		RequiredStakeForStakeAndSlash,
86		RelayerStakeLease,
87	>;
88	type Balance = Balance;
89	type WeightInfo = weights::pallet_bridge_relayers_legacy::WeightInfo<Runtime>;
90}
91
92/// Allows collect and claim rewards for relayers
93pub type RelayersForPermissionlessLanesInstance = pallet_bridge_relayers::Instance2;
94impl pallet_bridge_relayers::Config<RelayersForPermissionlessLanesInstance> for Runtime {
95	type RuntimeEvent = RuntimeEvent;
96	type RewardBalance = Balance;
97	type Reward = RewardsAccountParams<bp_messages::HashedLaneId>;
98	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
99		pallet_balances::Pallet<Runtime>,
100		AccountId,
101		bp_messages::HashedLaneId,
102		Self::RewardBalance,
103	>;
104	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
105		AccountId,
106		BlockNumber,
107		Balances,
108		RelayerStakeReserveId,
109		RequiredStakeForStakeAndSlash,
110		RelayerStakeLease,
111	>;
112	type Balance = Balance;
113	type WeightInfo = weights::pallet_bridge_relayers_permissionless_lanes::WeightInfo<Runtime>;
114}
115
116/// Add GRANDPA bridge pallet to track Rococo Bulletin chain.
117pub type BridgeGrandpaRococoBulletinInstance = pallet_bridge_grandpa::Instance4;
118impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoBulletinInstance> for Runtime {
119	type RuntimeEvent = RuntimeEvent;
120	type BridgedChain = bp_polkadot_bulletin::PolkadotBulletin;
121	type MaxFreeHeadersPerBlock = ConstU32<4>;
122	type FreeHeadersInterval = ConstU32<5>;
123	type HeadersToKeep = RelayChainHeadersToKeep;
124	// Technically this is incorrect - we have two pallet instances and ideally we shall
125	// benchmark every instance separately. But the benchmarking engine has a flaw - it
126	// messes with components. E.g. in Kusama maximal validators count is 1024 and in
127	// Bulletin chain it is 100. But benchmarking engine runs Bulletin benchmarks using
128	// components range, computed for Kusama => it causes an error.
129	//
130	// In practice, however, GRANDPA pallet works the same way for all bridged chains, so
131	// weights are also the same for both bridges.
132	type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
133}