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