Line data Source code
1 : #ifndef HEADER_fd_src_disco_repair_fd_repair_serde_h
2 : #define HEADER_fd_src_disco_repair_fd_repair_serde_h
3 :
4 : #include "../../flamenco/fd_flamenco_base.h"
5 : #include "../../ballet/ed25519/fd_ed25519.h"
6 : #include "../../ballet/shred/fd_shred.h"
7 : #include "../../disco/shred/fd_fec_set.h"
8 :
9 : /* FD_REPAIR_PROOF_MAX bounds a merkle proof in a response: 63 entries,
10 : enough for u64::MAX FEC sets. */
11 :
12 : #define FD_REPAIR_PROOF_MAX (63UL*FD_SHRED_MERKLE_NODE_SZ)
13 :
14 : struct fd_repair_pong {
15 : fd_hash_t hash;
16 : };
17 : typedef struct fd_repair_pong fd_repair_pong_t;
18 :
19 : struct fd_repair_shred {
20 : ulong slot;
21 : ulong shred_idx;
22 : };
23 : typedef struct fd_repair_shred fd_repair_shred_t;
24 :
25 : struct fd_repair_highest_shred {
26 : ulong slot;
27 : ulong shred_idx;
28 : };
29 : typedef struct fd_repair_highest_shred fd_repair_highest_shred_t;
30 :
31 : struct fd_repair_orphan {
32 : ulong slot;
33 : };
34 : typedef struct fd_repair_orphan fd_repair_orphan_t;
35 :
36 : struct fd_repair_parent_fec_set_count {
37 : ulong slot;
38 : fd_hash_t block_id;
39 : };
40 : typedef struct fd_repair_parent_fec_set_count fd_repair_parent_fec_set_count_t;
41 :
42 : struct fd_repair_fec_set_root {
43 : ulong slot;
44 : fd_hash_t block_id;
45 : uint fec_set_idx;
46 : };
47 : typedef struct fd_repair_fec_set_root fd_repair_fec_set_root_t;
48 :
49 : struct fd_repair_shred_for_block_id {
50 : ulong slot;
51 : uint shred_idx;
52 : fd_hash_t block_id;
53 : };
54 : typedef struct fd_repair_shred_for_block_id fd_repair_shred_for_block_id_t;
55 :
56 0 : #define FD_REPAIR_SERDE_TAG_PONG (7U)
57 0 : #define FD_REPAIR_SERDE_TAG_WINDOW_INDEX (8U)
58 0 : #define FD_REPAIR_SERDE_TAG_HIGHEST_WINDOW_INDEX (9U)
59 0 : #define FD_REPAIR_SERDE_TAG_ORPHAN (10U)
60 0 : #define FD_REPAIR_SERDE_TAG_ANCESTOR_HASHES (11U)
61 0 : #define FD_REPAIR_SERDE_TAG_PARENT_AND_FEC_SET_COUNT (12U)
62 0 : #define FD_REPAIR_SERDE_TAG_FEC_SET_ROOT (13U)
63 0 : #define FD_REPAIR_SERDE_TAG_WINDOW_INDEX_FOR_BLOCK_ID (14U)
64 :
65 : /* RepairResponse, and BlockIdRepairResponse */
66 :
67 0 : #define FD_REPAIR_SERDE_TAG_PING (0U)
68 0 : #define FD_REPAIR_SERDE_TAG_PARENT_FEC_SET_COUNT_RES (0U)
69 0 : #define FD_REPAIR_SERDE_TAG_FEC_SET_ROOT_RES (1U)
70 : #define FD_REPAIR_SERDE_TAG_BLOCK_ID_PING (2U)
71 :
72 0 : #define FD_REPAIR_PONG_SER_SZ ( sizeof(uint) /* tag */ + \
73 0 : sizeof(fd_pubkey_t) /* from */ + \
74 0 : sizeof(fd_hash_t) /* hash */ + \
75 0 : FD_ED25519_SIG_SZ /* signature */ )
76 :
77 0 : #define FD_REPAIR_HEADER_SER_SZ ( sizeof(uint) /* tag */ + \
78 0 : FD_ED25519_SIG_SZ /* signature */ + \
79 0 : sizeof(fd_pubkey_t) /* sender */ + \
80 0 : sizeof(fd_pubkey_t) /* recipient */ + \
81 0 : sizeof(ulong) /* timestamp */ + \
82 0 : sizeof(uint) /* nonce */ )
83 :
84 : #define FD_REPAIR_WINDOW_INDEX_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(ulong) /* shred_index */ )
85 : #define FD_REPAIR_HIGHEST_WINDOW_INDEX_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(ulong) /* shred_index */ )
86 : #define FD_REPAIR_ORPHAN_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ )
87 : #define FD_REPAIR_PARENT_AND_FEC_SET_COUNT_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(fd_hash_t) /* block_id */ )
88 : #define FD_REPAIR_FEC_SET_ROOT_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(fd_hash_t) /* block_id */ + sizeof(uint) /* fec_set_index */ )
89 0 : #define FD_REPAIR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ ( FD_REPAIR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(uint) /* shred_index */ + sizeof(fd_hash_t) /* block_id */ )
90 :
91 0 : #define FD_REPAIR_SER_MAX FD_REPAIR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ
92 :
93 : #define FD_REPAIR_PING_DE_SZ ( sizeof(uint) /* tag */ + \
94 : sizeof(fd_pubkey_t) /* from */ + \
95 : sizeof(fd_hash_t) /* token */ + \
96 : FD_ED25519_SIG_SZ /* signature */ )
97 :
98 0 : #define FD_REPAIR_SIG_SER_MAX ( FD_REPAIR_SER_MAX - FD_ED25519_SIG_SZ )
99 :
100 : /* FD_REPAIR_RES_DE_MAX bounds the size of a block id metadata response
101 : the shred tiles forward to repair and rserve serializes into: a parent
102 : and FEC set count response whose proof has a node for each layer of
103 : the largest block any configuration allows. Shred responses are
104 : always larger. */
105 :
106 0 : #define FD_REPAIR_RES_DE_MAX ( sizeof(uint) /* tag */ + \
107 0 : sizeof(uint) /* fec_set_count */ + \
108 0 : sizeof(ulong) /* parent_slot */ + \
109 0 : sizeof(fd_hash_t) /* parent_block_id */ + \
110 0 : sizeof(ulong) /* proof_sz */ + \
111 0 : (1UL+(63UL-(ulong)__builtin_clzl( FD_SHRED_BLK_MAX_RAISED/FD_FEC_SHRED_CNT )))*FD_SHRED_MERKLE_NODE_SZ /* proof */ + \
112 0 : sizeof(uint) /* nonce */ )
113 :
114 : FD_STATIC_ASSERT( FD_REPAIR_RES_DE_MAX<FD_SHRED_MIN_SZ, repair_res_de_max );
115 :
116 : /* FD_REPAIR_NET_FRAME_MAX bounds a forwarded repair frame: the largest
117 : Ethernet, IP and UDP header a netmux sig encodes, plus the payload. */
118 :
119 0 : #define FD_REPAIR_NET_FRAME_MAX (42UL+4UL*15UL+FD_REPAIR_RES_DE_MAX)
120 :
121 : FD_PROTOTYPES_BEGIN
122 :
123 : /* signature, sender, recipient, timestamp and nonce (signature and
124 : from for a pong) are attached at send time and are not part of the
125 : request structs. Each ser returns the bytes written. */
126 :
127 : ulong
128 : fd_repair_pong_ser( fd_repair_pong_t const * self,
129 : fd_ed25519_sig_t const signature,
130 : fd_pubkey_t const * from,
131 : uchar buf[ static FD_REPAIR_PONG_SER_SZ ] );
132 :
133 : /* fd_repair_req_sig_ser writes the signing preimage of the serialized
134 : request in buf to out and returns its size. Not for a pong, whose
135 : preimage is "SOLANA_PING_PONG" and the ping's token. */
136 :
137 : ulong
138 : fd_repair_req_sig_ser( uchar const * buf,
139 : ulong buf_sz,
140 : uchar out[ static FD_REPAIR_SIG_SER_MAX ] );
141 :
142 : ulong
143 : fd_repair_req_window_index_ser( fd_repair_shred_t const * self,
144 : fd_ed25519_sig_t const signature,
145 : fd_pubkey_t const * sender,
146 : fd_pubkey_t const * recipient,
147 : ulong timestamp,
148 : uint nonce,
149 : uchar buf[ static FD_REPAIR_WINDOW_INDEX_SER_SZ ] );
150 :
151 : ulong
152 : fd_repair_req_highest_window_index_ser( fd_repair_highest_shred_t const * self,
153 : fd_ed25519_sig_t const signature,
154 : fd_pubkey_t const * sender,
155 : fd_pubkey_t const * recipient,
156 : ulong timestamp,
157 : uint nonce,
158 : uchar buf[ static FD_REPAIR_HIGHEST_WINDOW_INDEX_SER_SZ ] );
159 :
160 : ulong
161 : fd_repair_req_orphan_ser( fd_repair_orphan_t const * self,
162 : fd_ed25519_sig_t const signature,
163 : fd_pubkey_t const * sender,
164 : fd_pubkey_t const * recipient,
165 : ulong timestamp,
166 : uint nonce,
167 : uchar buf[ static FD_REPAIR_ORPHAN_SER_SZ ] );
168 :
169 : ulong
170 : fd_repair_req_parent_and_fec_set_count_ser( fd_repair_parent_fec_set_count_t const * self,
171 : fd_ed25519_sig_t const signature,
172 : fd_pubkey_t const * sender,
173 : fd_pubkey_t const * recipient,
174 : ulong timestamp,
175 : uint nonce,
176 : uchar buf[ static FD_REPAIR_PARENT_AND_FEC_SET_COUNT_SER_SZ ] );
177 :
178 : ulong
179 : fd_repair_req_fec_set_root_ser( fd_repair_fec_set_root_t const * self,
180 : fd_ed25519_sig_t const signature,
181 : fd_pubkey_t const * sender,
182 : fd_pubkey_t const * recipient,
183 : ulong timestamp,
184 : uint nonce,
185 : uchar buf[ static FD_REPAIR_FEC_SET_ROOT_SER_SZ ] );
186 :
187 : ulong
188 : fd_repair_req_window_index_for_block_id_ser( fd_repair_shred_for_block_id_t const * self,
189 : fd_ed25519_sig_t const signature,
190 : fd_pubkey_t const * sender,
191 : fd_pubkey_t const * recipient,
192 : ulong timestamp,
193 : uint nonce,
194 : uchar buf[ static FD_REPAIR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ ] );
195 :
196 : /* Each request de reads a request of its kind from buf and returns
197 : the bytes read, 0 if buf does not start with one. Does not verify
198 : the signature. */
199 :
200 : ulong
201 : fd_repair_req_window_index_de( uchar const * buf,
202 : ulong buf_sz,
203 : fd_repair_shred_t * self,
204 : fd_ed25519_sig_t signature,
205 : fd_pubkey_t * sender,
206 : fd_pubkey_t * recipient,
207 : ulong * timestamp,
208 : uint * nonce );
209 :
210 : ulong
211 : fd_repair_req_highest_window_index_de( uchar const * buf,
212 : ulong buf_sz,
213 : fd_repair_highest_shred_t * self,
214 : fd_ed25519_sig_t signature,
215 : fd_pubkey_t * sender,
216 : fd_pubkey_t * recipient,
217 : ulong * timestamp,
218 : uint * nonce );
219 :
220 : ulong
221 : fd_repair_req_orphan_de( uchar const * buf,
222 : ulong buf_sz,
223 : fd_repair_orphan_t * self,
224 : fd_ed25519_sig_t signature,
225 : fd_pubkey_t * sender,
226 : fd_pubkey_t * recipient,
227 : ulong * timestamp,
228 : uint * nonce );
229 :
230 : ulong
231 : fd_repair_req_parent_and_fec_set_count_de( uchar const * buf,
232 : ulong buf_sz,
233 : fd_repair_parent_fec_set_count_t * self,
234 : fd_ed25519_sig_t signature,
235 : fd_pubkey_t * sender,
236 : fd_pubkey_t * recipient,
237 : ulong * timestamp,
238 : uint * nonce );
239 :
240 : ulong
241 : fd_repair_req_fec_set_root_de( uchar const * buf,
242 : ulong buf_sz,
243 : fd_repair_fec_set_root_t * self,
244 : fd_ed25519_sig_t signature,
245 : fd_pubkey_t * sender,
246 : fd_pubkey_t * recipient,
247 : ulong * timestamp,
248 : uint * nonce );
249 :
250 : ulong
251 : fd_repair_req_window_index_for_block_id_de( uchar const * buf,
252 : ulong buf_sz,
253 : fd_repair_shred_for_block_id_t * self,
254 : fd_ed25519_sig_t signature,
255 : fd_pubkey_t * sender,
256 : fd_pubkey_t * recipient,
257 : ulong * timestamp,
258 : uint * nonce );
259 :
260 : ulong
261 : fd_repair_pong_de( uchar const * buf,
262 : ulong buf_sz,
263 : fd_repair_pong_t * self,
264 : fd_ed25519_sig_t signature,
265 : fd_pubkey_t * from );
266 :
267 : ulong
268 : fd_repair_ping_ser( fd_pubkey_t const * from,
269 : fd_hash_t const * token,
270 : fd_ed25519_sig_t const signature,
271 : uchar buf[ static FD_REPAIR_PING_DE_SZ ] );
272 :
273 : ulong
274 : fd_repair_block_id_ping_ser( fd_pubkey_t const * from,
275 : fd_hash_t const * token,
276 : fd_ed25519_sig_t const signature,
277 : uchar buf[ static FD_REPAIR_PING_DE_SZ ] );
278 :
279 : /* fd_repair_res_parent_fec_set_count_ser and fd_repair_res_fec_set_root_ser
280 : write a response, proof_sz bytes of proof included, and return the
281 : bytes written, 0 if it does not fit in buf_sz. */
282 :
283 : ulong
284 : fd_repair_res_parent_fec_set_count_ser( uint fec_set_cnt,
285 : ulong parent_slot,
286 : fd_hash_t const * parent_block_id,
287 : uchar const * proof,
288 : ulong proof_sz,
289 : uint nonce,
290 : uchar * buf,
291 : ulong buf_sz );
292 :
293 : ulong
294 : fd_repair_res_fec_set_root_ser( uchar const fec_set_root[ static FD_SHRED_MERKLE_NODE_SZ ],
295 : uchar const * proof,
296 : ulong proof_sz,
297 : uint nonce,
298 : uchar * buf,
299 : ulong buf_sz );
300 :
301 : ulong
302 : fd_repair_ping_de( uchar const * buf,
303 : ulong buf_sz,
304 : fd_pubkey_t * from,
305 : fd_hash_t * token,
306 : fd_ed25519_sig_t signature );
307 :
308 : ulong
309 : fd_repair_block_id_ping_de( uchar const * buf,
310 : ulong buf_sz,
311 : fd_pubkey_t * from,
312 : fd_hash_t * token,
313 : fd_ed25519_sig_t signature );
314 :
315 : ulong
316 : fd_repair_res_parent_fec_set_count_de( uchar const * buf,
317 : ulong buf_sz,
318 : uint * fec_set_cnt,
319 : ulong * parent_slot,
320 : fd_hash_t * parent_block_id,
321 : uchar proof[ static FD_REPAIR_PROOF_MAX ],
322 : ulong * proof_sz,
323 : uint * nonce );
324 :
325 : ulong
326 : fd_repair_res_fec_set_root_de( uchar const * buf,
327 : ulong buf_sz,
328 : uchar fec_set_root[ static FD_SHRED_MERKLE_NODE_SZ ],
329 : uchar proof[ static FD_REPAIR_PROOF_MAX ],
330 : ulong * proof_sz,
331 : uint * nonce );
332 :
333 : /* fd_repair_res_parent_fec_set_count_verify and
334 : fd_repair_res_fec_set_root_verify check a decoded response's proof
335 : against block_id, the block the request named. fec_set_idx and
336 : fec_set_cnt are the requested FEC set index and the block's FEC set
337 : count. Return 0 if it verifies, -1 otherwise. */
338 :
339 : int
340 : fd_repair_res_parent_fec_set_count_verify( uint fec_set_cnt,
341 : ulong parent_slot,
342 : fd_hash_t const * parent_block_id,
343 : uchar const * proof,
344 : ulong proof_sz,
345 : fd_hash_t const * block_id );
346 :
347 : int
348 : fd_repair_res_fec_set_root_verify( uchar const fec_set_root[ static FD_SHRED_MERKLE_NODE_SZ ],
349 : uchar const * proof,
350 : ulong proof_sz,
351 : fd_hash_t const * block_id,
352 : uint fec_set_idx,
353 : uint fec_set_cnt );
354 :
355 : FD_PROTOTYPES_END
356 :
357 : #endif /* HEADER_fd_src_disco_repair_fd_repair_serde_h */
|