referrerpolicy=no-referrer-when-downgrade

polkadot_primitives/vstaging/
async_backing.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot 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// Polkadot 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 Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use super::*;
18
19use alloc::vec::Vec;
20use codec::{Decode, Encode};
21use scale_info::TypeInfo;
22use sp_core::RuntimeDebug;
23
24/// A candidate pending availability.
25#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
26pub struct CandidatePendingAvailability<H = Hash, N = BlockNumber> {
27	/// The hash of the candidate.
28	pub candidate_hash: CandidateHash,
29	/// The candidate's descriptor.
30	pub descriptor: CandidateDescriptorV2<H>,
31	/// The commitments of the candidate.
32	pub commitments: CandidateCommitments,
33	/// The candidate's relay parent's number.
34	pub relay_parent_number: N,
35	/// The maximum Proof-of-Validity size allowed, in bytes.
36	pub max_pov_size: u32,
37}
38
39impl<H: Copy> From<CandidatePendingAvailability<H>>
40	for crate::v8::async_backing::CandidatePendingAvailability<H>
41{
42	fn from(value: CandidatePendingAvailability<H>) -> Self {
43		Self {
44			candidate_hash: value.candidate_hash,
45			descriptor: value.descriptor.into(),
46			commitments: value.commitments,
47			relay_parent_number: value.relay_parent_number,
48			max_pov_size: value.max_pov_size,
49		}
50	}
51}
52
53/// Constraints on the actions that can be taken by a new parachain
54/// block. These limitations are implicitly associated with some particular
55/// parachain, which should be apparent from usage.
56#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
57pub struct Constraints<N = BlockNumber> {
58	/// The minimum relay-parent number accepted under these constraints.
59	pub min_relay_parent_number: N,
60	/// The maximum Proof-of-Validity size allowed, in bytes.
61	pub max_pov_size: u32,
62	/// The maximum new validation code size allowed, in bytes.
63	pub max_code_size: u32,
64	/// The maximum head-data size, in bytes.
65	pub max_head_data_size: u32,
66	/// The amount of UMP messages remaining.
67	pub ump_remaining: u32,
68	/// The amount of UMP bytes remaining.
69	pub ump_remaining_bytes: u32,
70	/// The maximum number of UMP messages allowed per candidate.
71	pub max_ump_num_per_candidate: u32,
72	/// Remaining DMP queue. Only includes sent-at block numbers.
73	pub dmp_remaining_messages: Vec<N>,
74	/// The limitations of all registered inbound HRMP channels.
75	pub hrmp_inbound: InboundHrmpLimitations<N>,
76	/// The limitations of all registered outbound HRMP channels.
77	pub hrmp_channels_out: Vec<(Id, OutboundHrmpChannelLimitations)>,
78	/// The maximum number of HRMP messages allowed per candidate.
79	pub max_hrmp_num_per_candidate: u32,
80	/// The required parent head-data of the parachain.
81	pub required_parent: HeadData,
82	/// The expected validation-code-hash of this parachain.
83	pub validation_code_hash: ValidationCodeHash,
84	/// The code upgrade restriction signal as-of this parachain.
85	pub upgrade_restriction: Option<UpgradeRestriction>,
86	/// The future validation code hash, if any, and at what relay-parent
87	/// number the upgrade would be minimally applied.
88	pub future_validation_code: Option<(N, ValidationCodeHash)>,
89}
90
91/// The per-parachain state of the backing system, including
92/// state-machine constraints and candidates pending availability.
93#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
94pub struct BackingState<H = Hash, N = BlockNumber> {
95	/// The state-machine constraints of the parachain.
96	pub constraints: crate::async_backing::Constraints<N>,
97	/// The candidates pending availability. These should be ordered, i.e. they should form
98	/// a sub-chain, where the first candidate builds on top of the required parent of the
99	/// constraints and each subsequent builds on top of the previous head-data.
100	pub pending_availability: Vec<CandidatePendingAvailability<H, N>>,
101}
102
103impl<H: Copy> From<BackingState<H>> for crate::v8::async_backing::BackingState<H> {
104	fn from(value: BackingState<H>) -> Self {
105		Self {
106			constraints: value.constraints,
107			pending_availability: value
108				.pending_availability
109				.into_iter()
110				.map(|candidate| candidate.into())
111				.collect::<Vec<_>>(),
112		}
113	}
114}