bridge_hub_rococo_runtime/
bridge_common_config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
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 frame_support::{parameter_types, traits::ConstU32};
27
28parameter_types! {
29	pub const RelayChainHeadersToKeep: u32 = 1024;
30	pub const ParachainHeadsToKeep: u32 = 64;
31
32	pub const WestendBridgeParachainPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
33	pub const MaxWestendParaHeadDataSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
34
35	pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000;
36	pub const RelayerStakeLease: u32 = 8;
37	pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
38
39	pub storage DeliveryRewardInBalance: u64 = 1_000_000;
40}
41
42/// Add GRANDPA bridge pallet to track Westend relay chain.
43pub type BridgeGrandpaWestendInstance = pallet_bridge_grandpa::Instance3;
44impl pallet_bridge_grandpa::Config<BridgeGrandpaWestendInstance> for Runtime {
45	type RuntimeEvent = RuntimeEvent;
46	type BridgedChain = bp_westend::Westend;
47	type MaxFreeHeadersPerBlock = ConstU32<4>;
48	type FreeHeadersInterval = ConstU32<5>;
49	type HeadersToKeep = RelayChainHeadersToKeep;
50	type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
51}
52
53/// Add parachain bridge pallet to track Westend BridgeHub parachain
54pub type BridgeParachainWestendInstance = pallet_bridge_parachains::Instance3;
55impl pallet_bridge_parachains::Config<BridgeParachainWestendInstance> for Runtime {
56	type RuntimeEvent = RuntimeEvent;
57	type WeightInfo = weights::pallet_bridge_parachains::WeightInfo<Runtime>;
58	type BridgesGrandpaPalletInstance = BridgeGrandpaWestendInstance;
59	type ParasPalletName = WestendBridgeParachainPalletName;
60	type ParaStoredHeaderDataBuilder =
61		SingleParaStoredHeaderDataBuilder<bp_bridge_hub_westend::BridgeHubWestend>;
62	type HeadsToKeep = ParachainHeadsToKeep;
63	type MaxParaHeadDataSize = MaxWestendParaHeadDataSize;
64}
65
66/// Allows collect and claim rewards for relayers
67pub type RelayersForLegacyLaneIdsMessagesInstance = ();
68impl pallet_bridge_relayers::Config<RelayersForLegacyLaneIdsMessagesInstance> for Runtime {
69	type RuntimeEvent = RuntimeEvent;
70	type Reward = Balance;
71	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
72		pallet_balances::Pallet<Runtime>,
73		AccountId,
74		Self::LaneId,
75	>;
76	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
77		AccountId,
78		BlockNumber,
79		Balances,
80		RelayerStakeReserveId,
81		RequiredStakeForStakeAndSlash,
82		RelayerStakeLease,
83	>;
84	type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
85	type LaneId = bp_messages::LegacyLaneId;
86}
87
88/// Allows collect and claim rewards for relayers
89pub type RelayersForPermissionlessLanesInstance = pallet_bridge_relayers::Instance2;
90impl pallet_bridge_relayers::Config<RelayersForPermissionlessLanesInstance> for Runtime {
91	type RuntimeEvent = RuntimeEvent;
92	type Reward = Balance;
93	type PaymentProcedure = bp_relayers::PayRewardFromAccount<
94		pallet_balances::Pallet<Runtime>,
95		AccountId,
96		Self::LaneId,
97	>;
98	type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
99		AccountId,
100		BlockNumber,
101		Balances,
102		RelayerStakeReserveId,
103		RequiredStakeForStakeAndSlash,
104		RelayerStakeLease,
105	>;
106	type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
107	type LaneId = bp_messages::HashedLaneId;
108}
109
110/// Add GRANDPA bridge pallet to track Rococo Bulletin chain.
111pub type BridgeGrandpaRococoBulletinInstance = pallet_bridge_grandpa::Instance4;
112impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoBulletinInstance> for Runtime {
113	type RuntimeEvent = RuntimeEvent;
114	type BridgedChain = bp_polkadot_bulletin::PolkadotBulletin;
115	type MaxFreeHeadersPerBlock = ConstU32<4>;
116	type FreeHeadersInterval = ConstU32<5>;
117	type HeadersToKeep = RelayChainHeadersToKeep;
118	// Technically this is incorrect - we have two pallet instances and ideally we shall
119	// benchmark every instance separately. But the benchmarking engine has a flaw - it
120	// messes with components. E.g. in Kusama maximal validators count is 1024 and in
121	// Bulletin chain it is 100. But benchmarking engine runs Bulletin benchmarks using
122	// components range, computed for Kusama => it causes an error.
123	//
124	// In practice, however, GRANDPA pallet works the same way for all bridged chains, so
125	// weights are also the same for both bridges.
126	type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
127}