referrerpolicy=no-referrer-when-downgrade

polkadot_node_network_protocol/request_response/
v2.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//! Requests and responses as sent over the wire for the individual protocols.
18
19use codec::{Decode, Encode};
20
21use polkadot_node_primitives::ErasureChunk;
22use polkadot_primitives::{
23	CandidateHash, CommittedCandidateReceiptV2 as CommittedCandidateReceipt, Hash, Id as ParaId,
24	PersistedValidationData, UncheckedSignedStatement, ValidatorIndex,
25};
26
27use super::{v1, IsRequest, Protocol};
28use crate::v3::StatementFilter;
29
30/// Request a candidate with statements.
31#[derive(Debug, Clone, Encode, Decode)]
32pub struct AttestedCandidateRequest {
33	/// Hash of the candidate we want to request.
34	pub candidate_hash: CandidateHash,
35	/// Statement filter with 'OR' semantics, indicating which validators
36	/// not to send statements for.
37	///
38	/// The filter must have exactly the minimum size required to
39	/// fit all validators from the backing group.
40	///
41	/// The response may not contain any statements masked out by this mask.
42	pub mask: StatementFilter,
43}
44
45/// Response to an `AttestedCandidateRequest`.
46#[derive(Debug, Clone, Encode, Decode)]
47pub struct AttestedCandidateResponse {
48	/// The candidate receipt, with commitments.
49	pub candidate_receipt: CommittedCandidateReceipt,
50	/// The [`PersistedValidationData`] corresponding to the candidate.
51	pub persisted_validation_data: PersistedValidationData,
52	/// All known statements about the candidate, in compact form,
53	/// omitting `Seconded` statements which were intended to be masked
54	/// out.
55	pub statements: Vec<UncheckedSignedStatement>,
56}
57
58impl IsRequest for AttestedCandidateRequest {
59	type Response = AttestedCandidateResponse;
60	const PROTOCOL: Protocol = Protocol::AttestedCandidateV2;
61}
62
63/// Responses as sent by collators.
64pub type CollationFetchingResponse = super::v1::CollationFetchingResponse;
65
66/// Request the advertised collation at that relay-parent.
67#[derive(Debug, Clone, Encode, Decode)]
68pub struct CollationFetchingRequest {
69	/// Relay parent collation is built on top of.
70	pub relay_parent: Hash,
71	/// The `ParaId` of the collation.
72	pub para_id: ParaId,
73	/// Candidate hash.
74	pub candidate_hash: CandidateHash,
75}
76
77impl IsRequest for CollationFetchingRequest {
78	// The response is the same as for V1.
79	type Response = CollationFetchingResponse;
80	const PROTOCOL: Protocol = Protocol::CollationFetchingV2;
81}
82
83/// Request an availability chunk.
84#[derive(Debug, Copy, Clone, Encode, Decode)]
85pub struct ChunkFetchingRequest {
86	/// Hash of candidate we want a chunk for.
87	pub candidate_hash: CandidateHash,
88	/// The validator index we are requesting from. This may not be identical to the index of the
89	/// chunk we'll receive. It's up to the caller to decide whether they need to validate they got
90	/// the chunk they were expecting.
91	pub index: ValidatorIndex,
92}
93
94/// Receive a requested erasure chunk.
95#[derive(Debug, Clone, Encode, Decode)]
96pub enum ChunkFetchingResponse {
97	/// The requested chunk data.
98	#[codec(index = 0)]
99	Chunk(ErasureChunk),
100	/// Node was not in possession of the requested chunk.
101	#[codec(index = 1)]
102	NoSuchChunk,
103}
104
105impl From<Option<ErasureChunk>> for ChunkFetchingResponse {
106	fn from(x: Option<ErasureChunk>) -> Self {
107		match x {
108			Some(c) => ChunkFetchingResponse::Chunk(c),
109			None => ChunkFetchingResponse::NoSuchChunk,
110		}
111	}
112}
113
114impl From<ChunkFetchingResponse> for Option<ErasureChunk> {
115	fn from(x: ChunkFetchingResponse) -> Self {
116		match x {
117			ChunkFetchingResponse::Chunk(c) => Some(c),
118			ChunkFetchingResponse::NoSuchChunk => None,
119		}
120	}
121}
122
123impl From<v1::ChunkFetchingRequest> for ChunkFetchingRequest {
124	fn from(v1::ChunkFetchingRequest { candidate_hash, index }: v1::ChunkFetchingRequest) -> Self {
125		Self { candidate_hash, index }
126	}
127}
128
129impl From<ChunkFetchingRequest> for v1::ChunkFetchingRequest {
130	fn from(ChunkFetchingRequest { candidate_hash, index }: ChunkFetchingRequest) -> Self {
131		Self { candidate_hash, index }
132	}
133}
134
135impl IsRequest for ChunkFetchingRequest {
136	type Response = ChunkFetchingResponse;
137	const PROTOCOL: Protocol = Protocol::ChunkFetchingV2;
138}