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