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/// The per-parachain state of the backing system, including
54/// state-machine constraints and candidates pending availability.
55#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
56pub struct BackingState<H = Hash, N = BlockNumber> {
57 /// The state-machine constraints of the parachain.
58 pub constraints: Constraints<N>,
59 /// The candidates pending availability. These should be ordered, i.e. they should form
60 /// a sub-chain, where the first candidate builds on top of the required parent of the
61 /// constraints and each subsequent builds on top of the previous head-data.
62 pub pending_availability: Vec<CandidatePendingAvailability<H, N>>,
63}
64
65impl<H: Copy> From<BackingState<H>> for crate::v8::async_backing::BackingState<H> {
66 fn from(value: BackingState<H>) -> Self {
67 Self {
68 constraints: value.constraints,
69 pending_availability: value
70 .pending_availability
71 .into_iter()
72 .map(|candidate| candidate.into())
73 .collect::<Vec<_>>(),
74 }
75 }
76}