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
18
	fn max_extrinsic_size() -> u32 {
61
18
		*BlockLength::get().max.get(DispatchClass::Normal)
62
18
	}
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
}