Skip to content

Commit ce3676a

Browse files
committed
feat(shred,repair): shred publish to repair
1 parent 59f097b commit ce3676a

File tree

6 files changed

+204
-203
lines changed

6 files changed

+204
-203
lines changed

src/app/fdctl/topos/fd_firedancer.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fd_topo_initialize( config_t * config ) {
172172
fd_topob_wksp( topo, "dedup_pack" );
173173

174174
fd_topob_wksp( topo, "shred_storei" );
175-
fd_topob_wksp( topo, "shred_replay" );
175+
fd_topob_wksp( topo, "shred_repair" );
176176
fd_topob_wksp( topo, "stake_out" );
177177

178178
fd_topob_wksp( topo, "poh_shred" );
@@ -246,6 +246,8 @@ fd_topo_initialize( config_t * config ) {
246246

247247
#define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
248248

249+
ulong pending_fec_shreds_depth = fd_ulong_min( fd_ulong_pow2_up( config->tiles.shred.max_pending_shred_sets * FD_REEDSOL_DATA_SHREDS_MAX ), USHORT_MAX + 1 /* dcache max */ );
250+
249251
/* topo, link_name, wksp_name, depth, mtu, burst */
250252
FOR(quic_tile_cnt) fd_topob_link( topo, "quic_net", "net_quic", config->tiles.net.send_buffer_size, FD_NET_MTU, 1UL );
251253
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_net", "net_shred", config->tiles.net.send_buffer_size, FD_NET_MTU, 1UL );
@@ -259,7 +261,6 @@ fd_topo_initialize( config_t * config ) {
259261

260262
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_sign", "shred_sign", 128UL, 32UL, 1UL );
261263
FOR(shred_tile_cnt) fd_topob_link( topo, "sign_shred", "sign_shred", 128UL, 64UL, 1UL );
262-
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_replay", "shred_replay", 128UL, 128UL, config->tiles.shred.max_pending_shred_sets );
263264
264265
/**/ fd_topob_link( topo, "gossip_sign", "gossip_sign", 128UL, 2048UL, 1UL );
265266
/**/ fd_topob_link( topo, "sign_gossip", "sign_gossip", 128UL, 64UL, 1UL );
@@ -280,6 +281,7 @@ fd_topo_initialize( config_t * config ) {
280281
/**/ fd_topob_link( topo, "repair_store", "repair_store", 1024UL*1024UL, FD_SHRED_MAX_SZ, 128UL );
281282
/**/ fd_topob_link( topo, "repair_net", "net_repair", config->tiles.net.send_buffer_size, FD_NET_MTU, 1UL );
282283
/**/ fd_topob_link( topo, "repair_sign", "repair_sign", 128UL, 2048UL, 1UL );
284+
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_repair", "shred_repair", pending_fec_shreds_depth, FD_SHRED_REPAIR_MTU, config->tiles.shred.max_pending_shred_sets );
283285
/**/ fd_topob_link( topo, "sign_repair", "sign_repair", 128UL, 64UL, 1UL );
284286
/**/ fd_topob_link( topo, "store_replay", "store_replay", 128UL, (4096UL*sizeof(fd_txn_p_t))+sizeof(ulong)+sizeof(fd_hash_t), 16UL );
285287
FOR(bank_tile_cnt) fd_topob_link( topo, "replay_poh", "replay_poh", 128UL, (4096UL*sizeof(fd_txn_p_t))+sizeof(fd_microblock_trailer_t), 1UL );
@@ -503,7 +505,7 @@ fd_topo_initialize( config_t * config ) {
503505
/**/ fd_topob_tile_in( topo, "shred", i, "metric_in", "sign_shred", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
504506
/**/ fd_topob_tile_out( topo, "sign", 0UL, "sign_shred", i );
505507
}
506-
FOR(shred_tile_cnt) fd_topob_tile_out( topo, "shred", i, "shred_replay", i );
508+
FOR(shred_tile_cnt) fd_topob_tile_out( topo, "shred", i, "shred_repair", i );
507509

508510
FOR(net_tile_cnt) fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "net_gossip", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
509511
/**/ fd_topob_tile_out( topo, "gossip", 0UL, "gossip_net", 0UL );
@@ -523,15 +525,17 @@ fd_topo_initialize( config_t * config ) {
523525
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "gossip_repai", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
524526
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "stake_out", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
525527
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "store_repair", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
528+
FOR(shred_tile_cnt) fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "shred_repair", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
526529
/**/ fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "store_replay", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
527530
/**/ fd_topob_tile_out( topo, "replay", 0UL, "stake_out", 0UL );
528531
/**/ fd_topob_tile_out( topo, "replay", 0UL, "replay_notif", 0UL );
529532
/**/ fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "pack_replay", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
530533
/**/ fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "batch_replay", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
531534
/**/ fd_topob_tile_out( topo, "replay", 0UL, "replay_voter", 0UL );
532535
FOR(bank_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_poh", i );
533-
FOR(exec_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_exec", i ); /* TODO check order in fd_replay.c macros*/
534-
FOR(shred_tile_cnt) fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "shred_replay", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
536+
537+
538+
FOR(exec_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_exec", i ); /* TODO check order in fd_replay.c macros*/
535539

536540
FOR(exec_tile_cnt) fd_topob_tile_in( topo, "exec", i, "metric_in", "replay_exec", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
537541

src/ballet/bmtree/fd_bmtree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ static uchar const fd_bmtree_node_prefix[32UL] __attribute__((aligned(32))) = "\
149149
struct __attribute__((packed)) fd_bmtree_node {
150150
uchar hash[ 32 ]; /* Last bytes may not be meaningful */
151151
};
152-
153152
typedef struct fd_bmtree_node fd_bmtree_node_t;
154153

154+
FD_STATIC_ASSERT( sizeof(fd_bmtree_node_t) == 32, update FD_SHRED_MERKLE_ROOT_SZ );
155+
155156
/* bmtree_hash_leaf computes `SHA-256(prefix|data), where prefix is the
156157
first prefix_sz bytes of fd_bmtree_leaf_prefix. prefix_sz is
157158
typically FD_BMTREE_LONG_PREFIX_SZ or FD_BMTREE_SHORT_PREFIX_SZ.

src/disco/fd_disco_base.h

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,32 @@
2828
/* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP
2929
headers that can go in or out of the net tile. 2048 is the maximum
3030
XSK entry size, so this value follows naturally. */
31+
3132
#define FD_NET_MTU (2048UL)
3233

3334
/* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU.
3435
3536
This is minimum MTU of IPv6 packet - IPv6 header - UDP header
3637
1280 - 40 - 8 */
38+
3739
#define FD_TPU_MTU (1232UL)
3840

3941
/* FD_GOSSIP_MTU is the max sz of a gossip packet which is the same as
4042
above. */
43+
4144
#define FD_GOSSIP_MTU (FD_TPU_MTU)
4245

4346
/* FD_SHRED_STORE_MTU is the size of an fd_shred34_t (statically
4447
asserted in fd_shred_tile.c). */
48+
4549
#define FD_SHRED_STORE_MTU (41792UL)
4650

51+
/* FD_SHRED_REPAIR_MTU the size of a coding shred header + size of a
52+
merkle root. */
53+
54+
#define FD_SHRED_REPAIR_MTU (FD_SHRED_CODE_HEADER_SZ + FD_SHRED_MERKLE_ROOT_SZ)
55+
FD_STATIC_ASSERT( FD_SHRED_REPAIR_MTU == 121 , update FD_SHRED_REPAIR_MTU );
56+
4757
#define FD_NETMUX_SIG_MIN_HDR_SZ ( 42UL) /* The default header size, which means no vlan tags and no IP options. */
4858
#define FD_NETMUX_SIG_IGNORE_HDR_SZ (102UL) /* Outside the allowable range, but still fits in 4 bits when compressed */
4959

@@ -123,29 +133,60 @@ fd_disco_replay_old_sig( ulong slot,
123133
FD_FN_CONST static inline ulong fd_disco_replay_old_sig_flags( ulong sig ) { return (sig & 0xFFUL); }
124134
FD_FN_CONST static inline ulong fd_disco_replay_old_sig_slot( ulong sig ) { return (sig >> 8); }
125135

136+
/* fd_disco_shred_repair_sig constructs a sig for the shred_repair link.
137+
The encoded fields vary depending on the type of the sig. The
138+
diagram below describes the encoding.
139+
140+
type (1) | is_code or data_completes (1) | slot (32) | fec_set_idx (15) | shred_idx or data_cnt or parent_off (15)
141+
[63] | [62] | [30, 61] | [15, 29] | [0, 14]
142+
143+
The first bit of the sig is the sig type. The next 32 bits describe
144+
the slot number and 15 bits after that the fec_set_idx, regardless of
145+
the sig type. Note if the bits are saturated caller MUST ignore the
146+
value extracted from the sig (ie. UINT_MAX for slot and 2^15 - 1 for
147+
fec_set_idx).
148+
149+
The second bit and last 15 bits vary in interpretation depending on
150+
the sig type:
151+
152+
When type is 0, the sig describes a shred header. In this case, the
153+
second bit describes whether it is a coding shred (is_code) and the
154+
last 15 bits either describe a shred_idx if it's a data shred
155+
(is_code = 0) or the data_cnt if it's a coding shred (is_code = 1).
156+
157+
When type is 1, the sig describes a completed FEC set. In this case,
158+
the second bit describes whether the FEC set completes the entry
159+
batch, which will be true if the last data shred in the FEC set is
160+
marked with a DATA_COMPLETES flag (FIXME this is not invariant in the
161+
protocol yet). This implies the FEC set is the last one in the entry
162+
batch. The last 15 bits describe the parent slot's offset
163+
(parent_off) from the FEC set's slot. */
164+
126165
FD_FN_CONST static inline ulong
127-
fd_disco_shred_replay_sig( ulong slot,
128-
uint shred_idx,
129-
uint fec_set_idx,
130-
int is_code,
131-
int completes ) {
132-
133-
/* | 32 LSB of slot | 15 LSB of shred_idx | 15 LSB of fec_idx | 1 bit of shred data/code type | 1 bit if shred completes the fec set |
134-
| slot[32,63] | shred_idx[17,32] | fec_idx[2,16] | is_parity[1] | is_complete[0] | */
135-
136-
ulong slot_ul = fd_ulong_min( (ulong)slot, (ulong)UINT_MAX );
137-
ulong shred_idx_ul = fd_ulong_min( (ulong)shred_idx, (ulong)FD_SHRED_MAX_PER_SLOT );
138-
ulong fec_set_idx_ul = fd_ulong_min( (ulong)fec_set_idx, (ulong)FD_SHRED_MAX_PER_SLOT );
139-
ulong is_code_ul = (ulong)is_code;
140-
ulong completes_ul = (ulong)completes;
141-
return slot_ul << 32 | shred_idx_ul << 17 | fec_set_idx_ul << 2 | is_code_ul << 1 | completes_ul;
166+
fd_disco_shred_repair_sig( int type, int is_code_or_data_completes, ulong slot, uint fec_set_idx, uint shred_idx_or_data_cnt_or_parent_off ) {
167+
ulong type_ul = (ulong)type;
168+
ulong is_code_or_data_completes_ul = (ulong)is_code_or_data_completes;
169+
ulong slot_ul = fd_ulong_min( (ulong)slot, (ulong)UINT_MAX );
170+
ulong fec_set_idx_ul = fd_ulong_min( (ulong)fec_set_idx, (ulong)FD_SHRED_MAX_PER_SLOT );
171+
ulong shred_idx_or_data_cnt_or_parent_off_ul = fd_ulong_min( (ulong)shred_idx_or_data_cnt_or_parent_off, (ulong)FD_SHRED_MAX_PER_SLOT );
172+
return type_ul << 63 | is_code_or_data_completes_ul << 62 | slot_ul << 30 | fec_set_idx_ul << 15 | shred_idx_or_data_cnt_or_parent_off_ul;
142173
}
143174

144-
FD_FN_CONST static inline ulong fd_disco_shred_replay_sig_slot ( ulong sig ) { return fd_ulong_extract ( sig, 32, 63 ); }
145-
FD_FN_CONST static inline uint fd_disco_shred_replay_sig_shred_idx ( ulong sig ) { return (uint)fd_ulong_extract ( sig, 17, 31 ); }
146-
FD_FN_CONST static inline uint fd_disco_shred_replay_sig_fec_set_idx( ulong sig ) { return (uint)fd_ulong_extract ( sig, 2, 16 ); }
147-
FD_FN_CONST static inline int fd_disco_shred_replay_sig_is_code ( ulong sig ) { return fd_ulong_extract_bit( sig, 1 ); }
148-
FD_FN_CONST static inline int fd_disco_shred_replay_sig_completes ( ulong sig ) { return fd_ulong_extract_bit( sig, 0 ); }
175+
#define FD_DISCO_SHRED_REPAIR_SIG_TYPE_HDR (0)
176+
#define FD_DISCO_SHRED_REPAIR_SIG_TYPE_FEC (1)
177+
178+
/* fd_disco_shred_repair_sig_{...} are accessors for the fields encoded
179+
in the sig described above. */
180+
181+
FD_FN_CONST static inline int fd_disco_shred_repair_sig_type ( ulong sig ) { return fd_ulong_extract_bit( sig, 63 ); }
182+
FD_FN_CONST static inline int fd_disco_shred_repair_sig_is_code ( ulong sig ) { return fd_ulong_extract_bit( sig, 62 ); } /* type 0 */
183+
FD_FN_CONST static inline int fd_disco_shred_repair_sig_data_completes( ulong sig ) { return fd_ulong_extract_bit( sig, 62 ); } /* type 1 */
184+
FD_FN_CONST static inline ulong fd_disco_shred_repair_sig_slot ( ulong sig ) { return fd_ulong_extract ( sig, 30, 61 ); }
185+
FD_FN_CONST static inline uint fd_disco_shred_repair_sig_fec_set_idx ( ulong sig ) { return (uint)fd_ulong_extract ( sig, 15, 29 ); }
186+
FD_FN_CONST static inline uint fd_disco_shred_repair_sig_shred_idx ( ulong sig ) { return (uint)fd_ulong_extract_lsb( sig, 15 ); } /* type 0, is_code 0 */
187+
FD_FN_CONST static inline uint fd_disco_shred_repair_sig_data_cnt ( ulong sig ) { return (uint)fd_ulong_extract_lsb( sig, 15 ); } /* type 0, is_code 1 */
188+
FD_FN_CONST static inline uint fd_disco_shred_repair_sig_parent_off ( ulong sig ) { return (uint)fd_ulong_extract_lsb( sig, 15 ); } /* type 1 */
189+
149190

150191
FD_FN_PURE static inline ulong
151192
fd_disco_compact_chunk0( void * wksp ) {

0 commit comments

Comments
 (0)