referrerpolicy=no-referrer-when-downgrade

bp_asset_hub_rococo/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Module with configuration which reflects AssetHubRococo runtime setup.
17
18#![cfg_attr(not(feature = "std"), no_std)]
19
20extern crate alloc;
21
22use codec::{Decode, Encode};
23use scale_info::TypeInfo;
24
25pub use bp_bridge_hub_cumulus::*;
26use bp_messages::*;
27use bp_runtime::{
28	decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
29};
30pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
31use frame_support::{
32	dispatch::DispatchClass,
33	sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion},
34};
35use testnet_parachains_constants::rococo::currency::UNITS;
36use xcm::latest::prelude::*;
37
38/// `AssetHubRococo` Runtime `Call` enum.
39///
40/// The enum represents a subset of possible `Call`s we can send to `AssetHubRococo` chain.
41/// Ideally this code would be auto-generated from metadata, because we want to
42/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
43///
44/// All entries here (like pretty much in the entire file) must be kept in sync with
45/// `AssetHubRococo` `construct_runtime`, so that we maintain SCALE-compatibility.
46#[allow(clippy::large_enum_variant)]
47#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
48pub enum Call {
49	/// `ToWestendXcmRouter` bridge pallet.
50	#[codec(index = 45)]
51	ToWestendXcmRouter(XcmBridgeHubRouterCall),
52}
53
54frame_support::parameter_types! {
55	/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
56	pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
57	/// Should match the `AssetDeposit` of the `ForeignAssets` pallet on Asset Hub.
58	pub const CreateForeignAssetDeposit: u128 = UNITS / 10;
59}
60
61/// Builds an (un)congestion XCM program with the `report_bridge_status` call for
62/// `ToWestendXcmRouter`.
63pub fn build_congestion_message<RuntimeCall>(
64	bridge_id: sp_core::H256,
65	is_congested: bool,
66) -> alloc::vec::Vec<Instruction<RuntimeCall>> {
67	alloc::vec![
68		UnpaidExecution { weight_limit: Unlimited, check_origin: None },
69		Transact {
70			origin_kind: OriginKind::Xcm,
71			fallback_max_weight: Some(XcmBridgeHubRouterTransactCallMaxWeight::get()),
72			call: Call::ToWestendXcmRouter(XcmBridgeHubRouterCall::report_bridge_status {
73				bridge_id,
74				is_congested,
75			})
76			.encode()
77			.into(),
78		},
79		ExpectTransactStatus(MaybeErrorCode::Success),
80	]
81}
82
83/// Identifier of AssetHubRococo in the Rococo relay chain.
84pub const ASSET_HUB_ROCOCO_PARACHAIN_ID: u32 = 1000;
85
86/// AssetHubRococo parachain.
87#[derive(RuntimeDebug)]
88
89pub struct AssetHubRococo;
90
91impl Chain for AssetHubRococo {
92	const ID: ChainId = *b"ahro";
93
94	type BlockNumber = BlockNumber;
95	type Hash = Hash;
96	type Hasher = Hasher;
97	type Header = Header;
98
99	type AccountId = AccountId;
100	type Balance = Balance;
101	type Nonce = Nonce;
102	type Signature = Signature;
103
104	const STATE_VERSION: StateVersion = StateVersion::V1;
105
106	fn max_extrinsic_size() -> u32 {
107		*BlockLength::get().max.get(DispatchClass::Normal)
108	}
109
110	fn max_extrinsic_weight() -> Weight {
111		BlockWeightsForAsyncBacking::get()
112			.get(DispatchClass::Normal)
113			.max_extrinsic
114			.unwrap_or(Weight::MAX)
115	}
116}
117
118impl Parachain for AssetHubRococo {
119	const PARACHAIN_ID: u32 = ASSET_HUB_ROCOCO_PARACHAIN_ID;
120	const MAX_HEADER_SIZE: u32 = MAX_ASSET_HUB_HEADER_SIZE;
121}
122
123/// Describing permissionless lanes instance
124impl ChainWithMessages for AssetHubRococo {
125	const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
126		WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME;
127
128	const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
129		MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
130	const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
131		MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
132}
133
134/// Public key of the chain account that may be used to verify signatures.
135pub type AccountSigner = MultiSigner;
136
137/// The address format for describing accounts.
138pub type Address = MultiAddress<AccountId, ()>;
139
140/// Name of the With-AssetHubRococo messages pallet instance that is deployed at bridged chains.
141pub const WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";
142
143/// Name of the With-AssetHubRococo bridge-relayers pallet instance that is deployed at bridged
144/// chains.
145pub const WITH_ASSET_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
146
147/// Pallet index of `BridgeWestendMessages: pallet_bridge_messages::<Instance1>`.
148pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 62;
149
150decl_bridge_finality_runtime_apis!(asset_hub_rococo);
151decl_bridge_messages_runtime_apis!(asset_hub_rococo, HashedLaneId);