polkadot_node_network_protocol/request_response/
v1.rs1use codec::{Decode, Encode};
20
21use polkadot_node_primitives::{
22 AvailableData, DisputeMessage, ErasureChunk, PoV, Proof, UncheckedDisputeMessage,
23};
24use polkadot_primitives::{
25 CandidateHash, CandidateReceiptV2 as CandidateReceipt, Hash, HeadData, Id as ParaId,
26 ValidatorIndex,
27};
28
29use super::{IsRequest, Protocol};
30
31#[derive(Debug, Copy, Clone, Encode, Decode)]
33pub struct ChunkFetchingRequest {
34 pub candidate_hash: CandidateHash,
36 pub index: ValidatorIndex,
39}
40
41#[derive(Debug, Clone, Encode, Decode)]
43pub enum ChunkFetchingResponse {
44 #[codec(index = 0)]
46 Chunk(ChunkResponse),
47 #[codec(index = 1)]
49 NoSuchChunk,
50}
51
52impl From<Option<ChunkResponse>> for ChunkFetchingResponse {
53 fn from(x: Option<ChunkResponse>) -> Self {
54 match x {
55 Some(c) => ChunkFetchingResponse::Chunk(c),
56 None => ChunkFetchingResponse::NoSuchChunk,
57 }
58 }
59}
60
61impl From<ChunkFetchingResponse> for Option<ChunkResponse> {
62 fn from(x: ChunkFetchingResponse) -> Self {
63 match x {
64 ChunkFetchingResponse::Chunk(c) => Some(c),
65 ChunkFetchingResponse::NoSuchChunk => None,
66 }
67 }
68}
69
70#[derive(Debug, Clone, Encode, Decode)]
77pub struct ChunkResponse {
78 pub chunk: Vec<u8>,
80 pub proof: Proof,
82}
83
84impl From<ErasureChunk> for ChunkResponse {
85 fn from(ErasureChunk { chunk, index: _, proof }: ErasureChunk) -> Self {
86 ChunkResponse { chunk, proof }
87 }
88}
89
90impl ChunkResponse {
91 pub fn recombine_into_chunk(self, req: &ChunkFetchingRequest) -> ErasureChunk {
93 ErasureChunk { chunk: self.chunk, proof: self.proof, index: req.index.into() }
94 }
95}
96
97impl IsRequest for ChunkFetchingRequest {
98 type Response = ChunkFetchingResponse;
99 const PROTOCOL: Protocol = Protocol::ChunkFetchingV1;
100}
101
102#[derive(Debug, Clone, Encode, Decode)]
104pub struct CollationFetchingRequest {
105 pub relay_parent: Hash,
107 pub para_id: ParaId,
109}
110
111#[derive(Debug, Clone, Encode, Decode)]
113pub enum CollationFetchingResponse {
114 #[codec(index = 0)]
116 Collation(CandidateReceipt, PoV),
117
118 #[codec(index = 1)]
120 CollationWithParentHeadData {
121 receipt: CandidateReceipt,
123 pov: PoV,
125 parent_head_data: HeadData,
128 },
129}
130
131impl IsRequest for CollationFetchingRequest {
132 type Response = CollationFetchingResponse;
133 const PROTOCOL: Protocol = Protocol::CollationFetchingV1;
134}
135
136#[derive(Debug, Clone, Encode, Decode)]
138pub struct PoVFetchingRequest {
139 pub candidate_hash: CandidateHash,
141}
142
143#[derive(Debug, Clone, Encode, Decode)]
145pub enum PoVFetchingResponse {
146 #[codec(index = 0)]
148 PoV(PoV),
149 #[codec(index = 1)]
151 NoSuchPoV,
152}
153
154impl IsRequest for PoVFetchingRequest {
155 type Response = PoVFetchingResponse;
156 const PROTOCOL: Protocol = Protocol::PoVFetchingV1;
157}
158
159#[derive(Debug, Clone, Encode, Decode)]
161pub struct AvailableDataFetchingRequest {
162 pub candidate_hash: CandidateHash,
164}
165
166#[derive(Debug, Clone, Encode, Decode)]
168pub enum AvailableDataFetchingResponse {
169 #[codec(index = 0)]
171 AvailableData(AvailableData),
172 #[codec(index = 1)]
174 NoSuchData,
175}
176
177impl From<Option<AvailableData>> for AvailableDataFetchingResponse {
178 fn from(x: Option<AvailableData>) -> Self {
179 match x {
180 Some(data) => AvailableDataFetchingResponse::AvailableData(data),
181 None => AvailableDataFetchingResponse::NoSuchData,
182 }
183 }
184}
185
186impl IsRequest for AvailableDataFetchingRequest {
187 type Response = AvailableDataFetchingResponse;
188 const PROTOCOL: Protocol = Protocol::AvailableDataFetchingV1;
189}
190
191#[derive(Clone, Encode, Decode, Debug)]
195pub struct DisputeRequest(pub UncheckedDisputeMessage);
196
197impl From<DisputeMessage> for DisputeRequest {
198 fn from(msg: DisputeMessage) -> Self {
199 Self(msg.into())
200 }
201}
202
203#[derive(Encode, Decode, Debug, PartialEq, Eq)]
205pub enum DisputeResponse {
206 #[codec(index = 0)]
208 Confirmed,
209}
210
211impl IsRequest for DisputeRequest {
212 type Response = DisputeResponse;
213 const PROTOCOL: Protocol = Protocol::DisputeSendingV1;
214}