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
//! # Moonbeam 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
use bp_runtime::{
28
	decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
29
};
30
use frame_support::{dispatch::DispatchClass, weights::Weight};
31
pub use moonbeam_core_primitives::{AccountId, Balance, BlockNumber, Hash, Header, Signature};
32
use sp_runtime::StateVersion;
33
use xcm::latest::prelude::{Junction, Location, NetworkId};
34

            
35
/// Bridge lane identifier.
36
pub type LaneId = bp_messages::HashedLaneId;
37

            
38
/// Moonbeam parachain.
39
pub struct Moonbeam;
40

            
41
impl Chain for Moonbeam {
42
	const ID: ChainId = *b"mnbm";
43

            
44
	type BlockNumber = BlockNumber;
45
	type Hash = Hash;
46
	type Hasher = Hasher;
47
	type Header = Header;
48

            
49
	type AccountId = AccountId;
50
	type Balance = Balance;
51
	type Nonce = Nonce;
52
	type Signature = Signature;
53

            
54
	const STATE_VERSION: StateVersion = StateVersion::V1;
55

            
56
14
	fn max_extrinsic_size() -> u32 {
57
14
		*BlockLength::get().max.get(DispatchClass::Normal)
58
14
	}
59

            
60
	fn max_extrinsic_weight() -> Weight {
61
		BlockWeights::get()
62
			.get(DispatchClass::Normal)
63
			.max_extrinsic
64
			.unwrap_or(Weight::MAX)
65
	}
66
}
67

            
68
impl Parachain for Moonbeam {
69
	const PARACHAIN_ID: u32 = PARACHAIN_ID;
70
	const MAX_HEADER_SIZE: u32 = 4_096;
71
}
72

            
73
impl ChainWithMessages for Moonbeam {
74
	const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
75
		WITH_MOONBEAM_POLKADOT_MESSAGES_PALLET_NAME;
76

            
77
	const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
78
		MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
79
	const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
80
		MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
81
}
82

            
83
/// Identifier of Moonbeam parachain in the Polkadot relay chain.
84
pub const PARACHAIN_ID: u32 = 2004;
85

            
86
/// Name of the With-MoonbeamPolkadot messages pallet instance that is deployed at bridged chains.
87
pub const WITH_MOONBEAM_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages";
88

            
89
decl_bridge_finality_runtime_apis!(moonbeam_polkadot);
90
decl_bridge_messages_runtime_apis!(moonbeam_polkadot, LaneId);
91

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