polkadot_primitives/v8/
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
17//! Asynchronous backing primitives.
18
19use super::*;
20
21use alloc::vec::Vec;
22use codec::{Decode, Encode};
23use scale_info::TypeInfo;
24use sp_core::RuntimeDebug;
25
26/// Candidate's acceptance limitations for asynchronous backing per relay parent.
27#[derive(
28	RuntimeDebug,
29	Copy,
30	Clone,
31	PartialEq,
32	Encode,
33	Decode,
34	TypeInfo,
35	serde::Serialize,
36	serde::Deserialize,
37)]
38
39pub struct AsyncBackingParams {
40	/// The maximum number of para blocks between the para head in a relay parent
41	/// and a new candidate. Restricts nodes from building arbitrary long chains
42	/// and spamming other validators.
43	///
44	/// When async backing is disabled, the only valid value is 0.
45	pub max_candidate_depth: u32,
46	/// How many ancestors of a relay parent are allowed to build candidates on top
47	/// of.
48	///
49	/// When async backing is disabled, the only valid value is 0.
50	pub allowed_ancestry_len: u32,
51}
52
53/// Constraints on inbound HRMP channels.
54#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
55pub struct InboundHrmpLimitations<N = BlockNumber> {
56	/// An exhaustive set of all valid watermarks, sorted ascending.
57	///
58	/// It's only expected to contain block numbers at which messages were
59	/// previously sent to a para, excluding most recent head.
60	pub valid_watermarks: Vec<N>,
61}
62
63/// Constraints on outbound HRMP channels.
64#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
65pub struct OutboundHrmpChannelLimitations {
66	/// The maximum bytes that can be written to the channel.
67	pub bytes_remaining: u32,
68	/// The maximum messages that can be written to the channel.
69	pub messages_remaining: u32,
70}
71
72/// Constraints on the actions that can be taken by a new parachain
73/// block. These limitations are implicitly associated with some particular
74/// parachain, which should be apparent from usage.
75#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
76pub struct Constraints<N = BlockNumber> {
77	/// The minimum relay-parent number accepted under these constraints.
78	pub min_relay_parent_number: N,
79	/// The maximum Proof-of-Validity size allowed, in bytes.
80	pub max_pov_size: u32,
81	/// The maximum new validation code size allowed, in bytes.
82	pub max_code_size: u32,
83	/// The amount of UMP messages remaining.
84	pub ump_remaining: u32,
85	/// The amount of UMP bytes remaining.
86	pub ump_remaining_bytes: u32,
87	/// The maximum number of UMP messages allowed per candidate.
88	pub max_ump_num_per_candidate: u32,
89	/// Remaining DMP queue. Only includes sent-at block numbers.
90	pub dmp_remaining_messages: Vec<N>,
91	/// The limitations of all registered inbound HRMP channels.
92	pub hrmp_inbound: InboundHrmpLimitations<N>,
93	/// The limitations of all registered outbound HRMP channels.
94	pub hrmp_channels_out: Vec<(Id, OutboundHrmpChannelLimitations)>,
95	/// The maximum number of HRMP messages allowed per candidate.
96	pub max_hrmp_num_per_candidate: u32,
97	/// The required parent head-data of the parachain.
98	pub required_parent: HeadData,
99	/// The expected validation-code-hash of this parachain.
100	pub validation_code_hash: ValidationCodeHash,
101	/// The code upgrade restriction signal as-of this parachain.
102	pub upgrade_restriction: Option<UpgradeRestriction>,
103	/// The future validation code hash, if any, and at what relay-parent
104	/// number the upgrade would be minimally applied.
105	pub future_validation_code: Option<(N, ValidationCodeHash)>,
106}
107
108/// A candidate pending availability.
109#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
110pub struct CandidatePendingAvailability<H = Hash, N = BlockNumber> {
111	/// The hash of the candidate.
112	pub candidate_hash: CandidateHash,
113	/// The candidate's descriptor.
114	pub descriptor: CandidateDescriptor<H>,
115	/// The commitments of the candidate.
116	pub commitments: CandidateCommitments,
117	/// The candidate's relay parent's number.
118	pub relay_parent_number: N,
119	/// The maximum Proof-of-Validity size allowed, in bytes.
120	pub max_pov_size: u32,
121}
122
123/// The per-parachain state of the backing system, including
124/// state-machine constraints and candidates pending availability.
125#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
126pub struct BackingState<H = Hash, N = BlockNumber> {
127	/// The state-machine constraints of the parachain.
128	pub constraints: Constraints<N>,
129	/// The candidates pending availability. These should be ordered, i.e. they should form
130	/// a sub-chain, where the first candidate builds on top of the required parent of the
131	/// constraints and each subsequent builds on top of the previous head-data.
132	pub pending_availability: Vec<CandidatePendingAvailability<H, N>>,
133}