Line data Source code
1 : #ifndef HEADER_fd_src_choreo_rotor_fd_rotor_serde_h
2 : #define HEADER_fd_src_choreo_rotor_fd_rotor_serde_h
3 :
4 : #include "../fd_choreo_base.h"
5 : #include "../../ballet/ed25519/fd_ed25519.h"
6 : #include "../../ballet/shred/fd_shred.h"
7 :
8 : /* FD_ROTOR_PROOF_MAX bounds a merkle proof in a response: 63 entries,
9 : enough for u64::MAX FEC sets. */
10 :
11 : #define FD_ROTOR_PROOF_MAX (63UL*FD_SHRED_MERKLE_NODE_SZ)
12 :
13 : struct fd_rotor_pong {
14 : fd_hash_t hash;
15 : };
16 : typedef struct fd_rotor_pong fd_rotor_pong_t;
17 :
18 : struct fd_rotor_shred {
19 : ulong slot;
20 : ulong shred_idx;
21 : };
22 : typedef struct fd_rotor_shred fd_rotor_shred_t;
23 :
24 : struct fd_rotor_highest_shred {
25 : ulong slot;
26 : ulong shred_idx;
27 : };
28 : typedef struct fd_rotor_highest_shred fd_rotor_highest_shred_t;
29 :
30 : struct fd_rotor_orphan {
31 : ulong slot;
32 : };
33 : typedef struct fd_rotor_orphan fd_rotor_orphan_t;
34 :
35 : struct fd_rotor_parent_fec_set_count {
36 : ulong slot;
37 : fd_hash_t block_id;
38 : };
39 : typedef struct fd_rotor_parent_fec_set_count fd_rotor_parent_fec_set_count_t;
40 :
41 : struct fd_rotor_fec_set_root {
42 : ulong slot;
43 : fd_hash_t block_id;
44 : uint fec_set_idx;
45 : };
46 : typedef struct fd_rotor_fec_set_root fd_rotor_fec_set_root_t;
47 :
48 : struct fd_rotor_shred_for_block_id {
49 : ulong slot;
50 : uint shred_idx;
51 : fd_hash_t block_id;
52 : };
53 : typedef struct fd_rotor_shred_for_block_id fd_rotor_shred_for_block_id_t;
54 :
55 0 : #define FD_ROTOR_SERDE_TAG_PONG (7U)
56 0 : #define FD_ROTOR_SERDE_TAG_WINDOW_INDEX (8U)
57 0 : #define FD_ROTOR_SERDE_TAG_HIGHEST_WINDOW_INDEX (9U)
58 0 : #define FD_ROTOR_SERDE_TAG_ORPHAN (10U)
59 0 : #define FD_ROTOR_SERDE_TAG_PARENT_AND_FEC_SET_COUNT (12U)
60 0 : #define FD_ROTOR_SERDE_TAG_FEC_SET_ROOT (13U)
61 0 : #define FD_ROTOR_SERDE_TAG_WINDOW_INDEX_FOR_BLOCK_ID (14U)
62 :
63 : /* RepairResponse, and BlockIdRepairResponse */
64 :
65 0 : #define FD_ROTOR_SERDE_TAG_PING (0U)
66 0 : #define FD_ROTOR_SERDE_TAG_PARENT_FEC_SET_COUNT_RES (0U)
67 0 : #define FD_ROTOR_SERDE_TAG_FEC_SET_ROOT_RES (1U)
68 : #define FD_ROTOR_SERDE_TAG_BLOCK_ID_PING (2U)
69 :
70 0 : #define FD_ROTOR_PONG_SER_SZ ( sizeof(uint) /* tag */ + \
71 0 : sizeof(fd_pubkey_t) /* from */ + \
72 0 : sizeof(fd_hash_t) /* hash */ + \
73 0 : FD_ED25519_SIG_SZ /* signature */ )
74 :
75 : #define FD_ROTOR_HEADER_SER_SZ ( sizeof(uint) /* tag */ + \
76 : FD_ED25519_SIG_SZ /* signature */ + \
77 : sizeof(fd_pubkey_t) /* sender */ + \
78 : sizeof(fd_pubkey_t) /* recipient */ + \
79 : sizeof(ulong) /* timestamp */ + \
80 : sizeof(uint) /* nonce */ )
81 :
82 : #define FD_ROTOR_WINDOW_INDEX_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(ulong) /* shred_index */ )
83 : #define FD_ROTOR_HIGHEST_WINDOW_INDEX_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(ulong) /* shred_index */ )
84 : #define FD_ROTOR_ORPHAN_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ )
85 : #define FD_ROTOR_PARENT_AND_FEC_SET_COUNT_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(fd_hash_t) /* block_id */ )
86 : #define FD_ROTOR_FEC_SET_ROOT_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(fd_hash_t) /* block_id */ + sizeof(uint) /* fec_set_index */ )
87 : #define FD_ROTOR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ ( FD_ROTOR_HEADER_SER_SZ + sizeof(ulong) /* slot */ + sizeof(uint) /* shred_index */ + sizeof(fd_hash_t) /* block_id */ )
88 :
89 : #define FD_ROTOR_SER_MAX FD_ROTOR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ
90 :
91 : #define FD_ROTOR_PING_DE_SZ ( sizeof(uint) /* tag */ + \
92 : sizeof(fd_pubkey_t) /* from */ + \
93 : sizeof(fd_hash_t) /* token */ + \
94 : FD_ED25519_SIG_SZ /* signature */ )
95 :
96 : #define FD_ROTOR_SIG_SER_MAX ( FD_ROTOR_SER_MAX - FD_ED25519_SIG_SZ )
97 :
98 : FD_PROTOTYPES_BEGIN
99 :
100 : /* signature, sender, recipient, timestamp and nonce (signature and
101 : from for a pong) are attached at send time and are not part of the
102 : request structs. Each ser returns the bytes written. */
103 :
104 : ulong
105 : fd_rotor_pong_ser( fd_rotor_pong_t const * self,
106 : fd_ed25519_sig_t const signature,
107 : fd_pubkey_t const * from,
108 : uchar buf[ static FD_ROTOR_PONG_SER_SZ ] );
109 :
110 : /* fd_rotor_req_sig_ser writes the signing preimage of the serialized
111 : request in buf to out and returns its size. Not for a pong, whose
112 : preimage is "SOLANA_PING_PONG" and the ping's token. */
113 :
114 : ulong
115 : fd_rotor_req_sig_ser( uchar const * buf,
116 : ulong buf_sz,
117 : uchar out[ static FD_ROTOR_SIG_SER_MAX ] );
118 :
119 : ulong
120 : fd_rotor_req_window_index_ser( fd_rotor_shred_t const * self,
121 : fd_ed25519_sig_t const signature,
122 : fd_pubkey_t const * sender,
123 : fd_pubkey_t const * recipient,
124 : ulong timestamp,
125 : uint nonce,
126 : uchar buf[ static FD_ROTOR_WINDOW_INDEX_SER_SZ ] );
127 :
128 : ulong
129 : fd_rotor_req_highest_window_index_ser( fd_rotor_highest_shred_t const * self,
130 : fd_ed25519_sig_t const signature,
131 : fd_pubkey_t const * sender,
132 : fd_pubkey_t const * recipient,
133 : ulong timestamp,
134 : uint nonce,
135 : uchar buf[ static FD_ROTOR_HIGHEST_WINDOW_INDEX_SER_SZ ] );
136 :
137 : ulong
138 : fd_rotor_req_orphan_ser( fd_rotor_orphan_t const * self,
139 : fd_ed25519_sig_t const signature,
140 : fd_pubkey_t const * sender,
141 : fd_pubkey_t const * recipient,
142 : ulong timestamp,
143 : uint nonce,
144 : uchar buf[ static FD_ROTOR_ORPHAN_SER_SZ ] );
145 :
146 : ulong
147 : fd_rotor_req_parent_and_fec_set_count_ser( fd_rotor_parent_fec_set_count_t const * self,
148 : fd_ed25519_sig_t const signature,
149 : fd_pubkey_t const * sender,
150 : fd_pubkey_t const * recipient,
151 : ulong timestamp,
152 : uint nonce,
153 : uchar buf[ static FD_ROTOR_PARENT_AND_FEC_SET_COUNT_SER_SZ ] );
154 :
155 : ulong
156 : fd_rotor_req_fec_set_root_ser( fd_rotor_fec_set_root_t const * self,
157 : fd_ed25519_sig_t const signature,
158 : fd_pubkey_t const * sender,
159 : fd_pubkey_t const * recipient,
160 : ulong timestamp,
161 : uint nonce,
162 : uchar buf[ static FD_ROTOR_FEC_SET_ROOT_SER_SZ ] );
163 :
164 : ulong
165 : fd_rotor_req_window_index_for_block_id_ser( fd_rotor_shred_for_block_id_t const * self,
166 : fd_ed25519_sig_t const signature,
167 : fd_pubkey_t const * sender,
168 : fd_pubkey_t const * recipient,
169 : ulong timestamp,
170 : uint nonce,
171 : uchar buf[ static FD_ROTOR_WINDOW_INDEX_FOR_BLOCK_ID_SER_SZ ] );
172 :
173 : ulong
174 : fd_rotor_ping_de( uchar const * buf,
175 : ulong buf_sz,
176 : fd_pubkey_t * from,
177 : fd_hash_t * token,
178 : fd_ed25519_sig_t signature );
179 :
180 : ulong
181 : fd_rotor_block_id_ping_de( uchar const * buf,
182 : ulong buf_sz,
183 : fd_pubkey_t * from,
184 : fd_hash_t * token,
185 : fd_ed25519_sig_t signature );
186 :
187 : ulong
188 : fd_rotor_res_parent_fec_set_count_de( uchar const * buf,
189 : ulong buf_sz,
190 : uint * fec_set_cnt,
191 : ulong * parent_slot,
192 : fd_hash_t * parent_block_id,
193 : uchar proof[ static FD_ROTOR_PROOF_MAX ],
194 : ulong * proof_sz,
195 : uint * nonce );
196 :
197 : ulong
198 : fd_rotor_res_fec_set_root_de( uchar const * buf,
199 : ulong buf_sz,
200 : uchar fec_set_root[ static FD_SHRED_MERKLE_NODE_SZ ],
201 : uchar proof[ static FD_ROTOR_PROOF_MAX ],
202 : ulong * proof_sz,
203 : uint * nonce );
204 :
205 : /* fd_rotor_res_parent_fec_set_count_verify and
206 : fd_rotor_res_fec_set_root_verify check a decoded response's proof
207 : against block_id, the block the request named. fec_set_idx and
208 : fec_set_cnt are the requested FEC set index and the block's FEC set
209 : count. Return 0 if it verifies, -1 otherwise. */
210 :
211 : int
212 : fd_rotor_res_parent_fec_set_count_verify( uint fec_set_cnt,
213 : ulong parent_slot,
214 : fd_hash_t const * parent_block_id,
215 : uchar const * proof,
216 : ulong proof_sz,
217 : fd_hash_t const * block_id );
218 :
219 : int
220 : fd_rotor_res_fec_set_root_verify( uchar const fec_set_root[ static FD_SHRED_MERKLE_NODE_SZ ],
221 : uchar const * proof,
222 : ulong proof_sz,
223 : fd_hash_t const * block_id,
224 : uint fec_set_idx,
225 : uint fec_set_cnt );
226 :
227 : FD_PROTOTYPES_END
228 :
229 : #endif /* HEADER_fd_src_choreo_rotor_fd_rotor_serde_h */
|