referrerpolicy=no-referrer-when-downgrade

bp_asset_hub_westend/
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 AssetHubWestend runtime setup.
17
18#![cfg_attr(not(feature = "std"), no_std)]
19
20extern crate alloc;
21
22pub use bp_bridge_hub_cumulus::*;
23use bp_messages::*;
24use bp_runtime::{
25	decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
26};
27pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
28use codec::{Decode, Encode};
29use frame_support::{
30	dispatch::DispatchClass,
31	sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion},
32};
33use scale_info::TypeInfo;
34use testnet_parachains_constants::westend::currency::UNITS;
35use xcm::latest::prelude::*;
36
37/// `AssetHubWestend` Runtime `Call` enum.
38///
39/// The enum represents a subset of possible `Call`s we can send to `AssetHubWestend` chain.
40/// Ideally this code would be auto-generated from metadata, because we want to
41/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
42///
43/// All entries here (like pretty much in the entire file) must be kept in sync with
44/// `AssetHubWestend` `construct_runtime`, so that we maintain SCALE-compatibility.
45#[allow(clippy::large_enum_variant)]
46#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
47pub enum Call {
48	/// `ToRococoXcmRouter` bridge pallet.
49	#[codec(index = 34)]
50	ToRococoXcmRouter(XcmBridgeHubRouterCall),
51}
52
53frame_support::parameter_types! {
54	/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
55	pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
56
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/// `ToRococoXcmRouter`.
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::ToRococoXcmRouter(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 AssetHubWestend in the Westend relay chain.
84pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000;
85
86/// AssetHubWestend parachain.
87#[derive(RuntimeDebug)]
88pub struct AssetHubWestend;
89
90impl Chain for AssetHubWestend {
91	const ID: ChainId = *b"ahwd";
92
93	type BlockNumber = BlockNumber;
94	type Hash = Hash;
95	type Hasher = Hasher;
96	type Header = Header;
97
98	type AccountId = AccountId;
99	type Balance = Balance;
100	type Nonce = Nonce;
101	type Signature = Signature;
102
103	const STATE_VERSION: StateVersion = StateVersion::V1;
104
105	fn max_extrinsic_size() -> u32 {
106		*BlockLength::get().max.get(DispatchClass::Normal)
107	}
108
109	fn max_extrinsic_weight() -> Weight {
110		BlockWeightsForAsyncBacking::get()
111			.get(DispatchClass::Normal)
112			.max_extrinsic
113			.unwrap_or(Weight::MAX)
114	}
115}
116
117impl Parachain for AssetHubWestend {
118	const PARACHAIN_ID: u32 = ASSET_HUB_WESTEND_PARACHAIN_ID;
119	const MAX_HEADER_SIZE: u32 = MAX_ASSET_HUB_HEADER_SIZE;
120}
121
122/// Describing permissionless lanes instance
123impl ChainWithMessages for AssetHubWestend {
124	const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
125		WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME;
126
127	const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
128		MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
129	const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
130		MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
131}
132
133/// Public key of the chain account that may be used to verify signatures.
134pub type AccountSigner = MultiSigner;
135
136/// The address format for describing accounts.
137pub type Address = MultiAddress<AccountId, ()>;
138
139/// Name of the With-AssetHubWestend messages pallet instance that is deployed at bridged chains.
140pub const WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME: &str = "BridgeWestendMessages";
141
142/// Name of the With-AssetHubWestend bridge-relayers pallet instance that is deployed at bridged
143/// chains.
144pub const WITH_ASSET_HUB_WESTEND_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
145
146/// Pallet index of `BridgeRococoMessages: pallet_bridge_messages::<Instance1>`.
147pub const WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 63;
148
149decl_bridge_finality_runtime_apis!(asset_hub_westend);
150decl_bridge_messages_runtime_apis!(asset_hub_westend, HashedLaneId);