1
// Copyright 2025 Moonbeam foundation
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam 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
// Moonbeam 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 Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! # Moonriver bridge primitives
18

            
19
#![cfg_attr(not(feature = "std"), no_std)]
20

            
21
pub use bp_bridge_hub_cumulus::{
22
	BlockLength, BlockWeights, Hasher, Nonce, SignedBlock, AVERAGE_BLOCK_INTERVAL,
23
	MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
24
};
25
use bp_messages::{ChainWithMessages, MessageNonce};
26

            
27
pub use moonbeam_core_primitives::{AccountId, Balance, BlockNumber, Hash, Header, Signature};
28

            
29
use bp_runtime::{
30
	decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
31
};
32
use frame_support::{dispatch::DispatchClass, weights::Weight};
33
use sp_runtime::StateVersion;
34
use xcm::latest::prelude::{Junction, Location, NetworkId};
35

            
36
/// Identifier of Moonriver parachain in the Kusama relay chain.
37
pub const PARACHAIN_ID: u32 = 2023;
38

            
39
/// Bridge lane identifier.
40
pub type LaneId = bp_messages::HashedLaneId;
41

            
42
/// Moonriver parachain.
43
pub struct Moonriver;
44

            
45
impl Chain for Moonriver {
46
	const ID: ChainId = *b"mnrv";
47

            
48
	type BlockNumber = BlockNumber;
49
	type Hash = Hash;
50
	type Hasher = Hasher;
51
	type Header = Header;
52

            
53
	type AccountId = AccountId;
54
	type Balance = Balance;
55
	type Nonce = Nonce;
56
	type Signature = Signature;
57

            
58
	const STATE_VERSION: StateVersion = StateVersion::V1;
59

            
60
21
	fn max_extrinsic_size() -> u32 {
61
21
		*BlockLength::get().max.get(DispatchClass::Normal)
62
21
	}
63

            
64
	fn max_extrinsic_weight() -> Weight {
65
		BlockWeights::get()
66
			.get(DispatchClass::Normal)
67
			.max_extrinsic
68
			.unwrap_or(Weight::MAX)
69
	}
70
}
71

            
72
impl Parachain for Moonriver {
73
	const PARACHAIN_ID: u32 = PARACHAIN_ID;
74
	const MAX_HEADER_SIZE: u32 = 4_096;
75
}
76

            
77
impl ChainWithMessages for Moonriver {
78
	const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
79
		WITH_MOONRIVER_KUSAMA_MESSAGES_PALLET_NAME;
80

            
81
	const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
82
		MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
83
	const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
84
		MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
85
}
86

            
87
/// Name of the With-MoonriverKusama messages pallet instance that is deployed at bridged chains.
88
pub const WITH_MOONRIVER_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages";
89

            
90
decl_bridge_finality_runtime_apis!(moonriver_kusama);
91
decl_bridge_messages_runtime_apis!(moonriver_kusama, LaneId);
92

            
93
frame_support::parameter_types! {
94
	pub GlobalConsensusLocation: Location = Location::new(
95
		2,
96
		[
97
			Junction::GlobalConsensus(NetworkId::Kusama),
98
			Junction::Parachain(Moonriver::PARACHAIN_ID)
99
		]
100
	);
101
}
102

            
103
/// Bridging primitives describing the Polkadot relay chain, which we need for the other side.
104
/// Same approach as in https://github.com/polkadot-fellows/runtimes/pull/627
105
pub mod bp_polkadot {
106
	use super::{decl_bridge_finality_runtime_apis, Chain, ChainId, StateVersion, Weight};
107
	use bp_header_chain::ChainWithGrandpa;
108
	pub use bp_polkadot_core::*;
109

            
110
	/// Polkadot Chain
111
	pub struct Polkadot;
112

            
113
	impl Chain for Polkadot {
114
		const ID: ChainId = *b"pdot";
115

            
116
		type BlockNumber = BlockNumber;
117
		type Hash = Hash;
118
		type Hasher = Hasher;
119
		type Header = Header;
120

            
121
		type AccountId = AccountId;
122
		type Balance = Balance;
123
		type Nonce = Nonce;
124
		type Signature = Signature;
125

            
126
		const STATE_VERSION: StateVersion = StateVersion::V0;
127

            
128
		fn max_extrinsic_size() -> u32 {
129
			max_extrinsic_size()
130
		}
131

            
132
		fn max_extrinsic_weight() -> Weight {
133
			max_extrinsic_weight()
134
		}
135
	}
136

            
137
	impl ChainWithGrandpa for Polkadot {
138
		const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_POLKADOT_GRANDPA_PALLET_NAME;
139
		const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
140
		const REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY: u32 =
141
			REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY;
142
		const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
143
		const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
144
	}
145

            
146
	/// Name of the parachains pallet in the Polkadot runtime.
147
	pub const PARAS_PALLET_NAME: &str = "Paras";
148
	/// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains.
149
	pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa";
150
	/// Name of the With-Polkadot parachains pallet instance that is deployed at bridged chains.
151
	pub const WITH_POLKADOT_BRIDGE_PARACHAINS_PALLET_NAME: &str = "BridgePolkadotParachains";
152

            
153
	/// Maximal size of encoded `bp_parachains::ParaStoredHeaderData` structure among all Polkadot
154
	/// parachains.
155
	///
156
	/// It includes the block number and state root, so it shall be near 40 bytes, but let's have
157
	/// some reserve.
158
	pub const MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE: u32 = 128;
159

            
160
	decl_bridge_finality_runtime_apis!(polkadot, grandpa);
161
}