Skip to content

Commit 5c983e6

Browse files
committed
refactor(reasm): change reasm (fka chainer) to key FECs by merkle root
fd_reasm (formerly fd_fec_chainer) now keys all FEC sets by merkle root. Every FEC set's parent is determined from the chained merkle root tied to every FEC set.
1 parent 2f4ff84 commit 5c983e6

File tree

20 files changed

+1289
-1418
lines changed

20 files changed

+1289
-1418
lines changed

src/app/firedancer-dev/commands/backtest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "../../../disco/metrics/fd_metrics.h"
2424
#include "../../../util/pod/fd_pod_format.h"
2525
#include "../../../discof/replay/fd_replay_notif.h"
26-
#include "../../../discof/repair/fd_fec_chainer.h"
26+
#include "../../../discof/repair/fd_reasm.h"
2727
#include "../../../flamenco/runtime/fd_runtime_public.h" /* FD_RUNTIME_PUBLIC_ACCOUNT_UPDATE_MSG_MTU */
2828
#include "../main.h"
2929

@@ -109,7 +109,7 @@ backtest_topo( config_t * config ) {
109109
batches from the CLI-specified source (eg. RocksDB). */
110110

111111
fd_topob_wksp( topo, "repair_repla" );
112-
fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_fec_out_t), 1UL );
112+
fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_reasm_fec_t), 1UL );
113113
fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "repair_repla", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
114114
fd_topob_tile_out( topo, "back", 0UL, "repair_repla", 0UL );
115115

src/app/firedancer-dev/commands/repair.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ repair_topo( config_t * config ) {
132132

133133
/**/ fd_topob_link( topo, "repair_net", "net_repair", config->net.ingress_buffer_size, FD_NET_MTU, 1UL );
134134
/**/ fd_topob_link( topo, "repair_sign", "repair_sign", 128UL, 2048UL, 1UL );
135-
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_repair", "shred_repair", pending_fec_shreds_depth, FD_SHRED_REPAIR_MTU, 2UL /* at most 2 msgs per after_frag */ );
135+
FOR(shred_tile_cnt) fd_topob_link( topo, "shred_repair", "shred_repair", pending_fec_shreds_depth, FD_SHRED_REPAIR_MTU, 2UL );
136136

137137
FOR(shred_tile_cnt) fd_topob_link( topo, "repair_shred", "shred_repair", pending_fec_shreds_depth, sizeof(fd_ed25519_sig_t), 1UL );
138138
/**/ fd_topob_link( topo, "sign_repair", "sign_repair", 128UL, 64UL, 1UL );
139-
/**/ fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_fec_out_t), 1UL );
139+
/**/ fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_reasm_fec_t), 1UL );
140140
/**/ fd_topob_link( topo, "poh_shred", "poh_shred", 16384UL, USHORT_MAX, 1UL );
141141

142-
/**/ fd_topob_link( topo, "send_txns", "send_txns", 128UL, FD_TXN_MTU, 1UL );
142+
/**/ fd_topob_link( topo, "send_txns", "send_txns", 128UL, FD_TXN_MTU, 1UL );
143143

144144
ushort parsed_tile_to_cpu[ FD_TILE_MAX ];
145145
/* Unassigned tiles will be floating, unless auto topology is enabled. */

src/app/firedancer/topology.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "topology.h"
22

3-
#include "../../discof/repair/fd_fec_chainer.h"
3+
#include "../../choreo/fd_choreo_base.h"
4+
#include "../../discof/repair/fd_reasm.h"
45
#include "../../discof/replay/fd_replay_notif.h"
56
#include "../../disco/net/fd_net_tile.h"
67
#include "../../disco/quic/fd_tpu.h"
@@ -244,7 +245,8 @@ fd_topo_initialize( config_t * config ) {
244245
fd_topob_wksp( topo, "gossip_repai" );
245246
fd_topob_wksp( topo, "gossip_verif" );
246247
fd_topob_wksp( topo, "gossip_tower" );
247-
fd_topob_wksp( topo, "replay_tower" );
248+
fd_topob_wksp( topo, "replay_out" );
249+
fd_topob_wksp( topo, "root_out" );
248250

249251
fd_topob_wksp( topo, "repair_sign" );
250252
fd_topob_wksp( topo, "sign_repair" );
@@ -337,8 +339,8 @@ fd_topo_initialize( config_t * config ) {
337339
338340
/**/ fd_topob_link( topo, "gossip_verif", "gossip_verif", config->tiles.verify.receive_buffer_size, FD_TPU_RAW_MTU, 1UL );
339341
/**/ fd_topob_link( topo, "gossip_tower", "gossip_tower", 128UL, FD_TPU_MTU, 1UL );
340-
/**/ fd_topob_link( topo, "replay_tower", "replay_tower", 128UL, 65536UL, 1UL );
341-
/**/ fd_topob_link( topo, "tower_replay", "replay_tower", 128UL, 0, 1UL );
342+
/**/ fd_topob_link( topo, "replay_out", "replay_out", 128UL, sizeof(fd_replay_out_t), 1UL );
343+
/**/ fd_topob_link( topo, "root_out", "root_out", 128UL, sizeof(fd_block_id_t), 1UL );
342344
343345
/**/ fd_topob_link( topo, "crds_shred", "crds_shred", 128UL, 8UL + 40200UL * 38UL, 1UL );
344346
/**/ fd_topob_link( topo, "gossip_repai", "gossip_repai", 128UL, 40200UL * 38UL, 1UL );
@@ -353,7 +355,7 @@ fd_topo_initialize( config_t * config ) {
353355

354356
FOR(shred_tile_cnt) fd_topob_link( topo, "repair_shred", "shred_repair", pending_fec_shreds_depth, sizeof(fd_ed25519_sig_t), 1UL );
355357
/**/ fd_topob_link( topo, "sign_repair", "sign_repair", 128UL, 64UL, 1UL );
356-
/**/ fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_fec_out_t), 1UL );
358+
/**/ fd_topob_link( topo, "repair_repla", "repair_repla", 65536UL, sizeof(fd_reasm_fec_t), 1UL );
357359
/**/ fd_topob_link( topo, "poh_shred", "poh_shred", 16384UL, USHORT_MAX, 1UL );
358360
/**/ fd_topob_link( topo, "poh_pack", "replay_poh", 128UL, sizeof(fd_became_leader_t) , 1UL );
359361
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 );
@@ -525,7 +527,6 @@ fd_topo_initialize( config_t * config ) {
525527

526528
for( ulong i=0UL; i<exec_tile_cnt; i++ ) {
527529
fd_topo_obj_t * exec_fseq_obj = fd_topob_obj( topo, "fseq", "exec_fseq" );
528-
fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "exec", i ) ], exec_fseq_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
529530
fd_topob_tile_uses( topo, replay_tile, exec_fseq_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
530531
FD_TEST( fd_pod_insertf_ulong( topo->props, exec_fseq_obj->id, "exec_fseq.%lu", i ) );
531532
}
@@ -637,10 +638,9 @@ fd_topo_initialize( config_t * config ) {
637638

638639
/**/ fd_topob_tile_out( topo, "repair", 0UL, "repair_net", 0UL );
639640

640-
/**/ fd_topob_tile_in( topo, "tower", 0UL, "metric_in", "gossip_tower", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
641-
/**/ fd_topob_tile_in( topo, "tower", 0UL, "metric_in", "replay_tower", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
642-
643-
/**/ fd_topob_tile_out( topo, "tower", 0UL, "tower_replay", 0UL );
641+
/**/ fd_topob_tile_in ( topo, "tower", 0UL, "metric_in", "gossip_tower", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
642+
/**/ fd_topob_tile_in ( topo, "tower", 0UL, "metric_in", "replay_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
643+
/**/ fd_topob_tile_out( topo, "tower", 0UL, "root_out", 0UL );
644644
/**/ fd_topob_tile_out( topo, "tower", 0UL, "tower_send", 0UL );
645645

646646
/* Sign links don't need to be reliable because they are synchronous,
@@ -669,12 +669,13 @@ fd_topo_initialize( config_t * config ) {
669669
FOR(net_tile_cnt) fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "net_repair", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
670670
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "gossip_repai", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
671671
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "stake_out", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
672+
fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "snap_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
672673
FOR(shred_tile_cnt) fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "shred_repair", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
673674
674-
/**/ fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "repair_repla", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
675+
/**/ fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "repair_repla", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
675676
/**/ fd_topob_tile_out( topo, "replay", 0UL, "stake_out", 0UL );
676-
/**/ fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "tower_replay", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
677-
/**/ fd_topob_tile_out( topo, "replay", 0UL, "replay_tower", 0UL );
677+
/**/ fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "root_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
678+
/**/ fd_topob_tile_out( topo, "replay", 0UL, "replay_out", 0UL );
678679
FOR(bank_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_poh", i );
679680
FOR(exec_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_exec", i ); /* TODO check order in fd_replay.c macros*/
680681

@@ -704,9 +705,9 @@ fd_topo_initialize( config_t * config ) {
704705

705706
fd_topob_tile_out( topo, "poh", 0UL, "poh_pack", 0UL );
706707

707-
/**/ fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "repair_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
708+
/**/ fd_topob_tile_in ( topo, "sign", 0UL, "metric_in", "repair_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
708709
/**/ fd_topob_tile_out( topo, "repair", 0UL, "repair_sign", 0UL );
709-
/**/ fd_topob_tile_in( topo, "repair", 0UL, "metric_in", "sign_repair", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
710+
/**/ fd_topob_tile_in ( topo, "repair", 0UL, "metric_in", "sign_repair", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
710711
/**/ fd_topob_tile_out( topo, "repair", 0UL, "repair_repla", 0UL );
711712
FOR(shred_tile_cnt) fd_topob_tile_out( topo, "repair", 0UL, "repair_shred", i );
712713
/**/ fd_topob_tile_out( topo, "sign", 0UL, "sign_repair", 0UL );

src/choreo/fd_choreo_base.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
#define FD_SLOT_PUBKEY_HASH(key,seed) FD_SLOT_HASH_HASH(key,seed)
3333
/* clang-format on */
3434

35+
/* The block_id is the merkle root of the last FEC set for a slot. This
36+
is guaranteed to be unique (practically speaking, the probability of
37+
collision before sun burns out is negligibly miniscule).
38+
39+
This is used as the identifier for a block (hence "block_id") because
40+
unlike the slot number, if a leader equivocates (ie. produces
41+
multiple blocks for the same slot), the block_id will remain unique
42+
unlike the slot. */
43+
44+
typedef uchar fd_block_id_t[ 32UL ];
45+
3546
typedef fd_slot_hash_t fd_slot_pubkey_t;
3647

3748
#endif /* HEADER_fd_src_choreo_fd_choreo_base_h */

src/disco/fd_disco_base.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../tango/fd_tango.h"
55
#include "../ballet/shred/fd_shred.h"
66
#include "../ballet/txn/fd_txn.h"
7-
7+
#include "../flamenco/types/fd_types_custom.h"
88
#include "../util/wksp/fd_wksp_private.h"
99

1010
#define DST_PROTO_OUTGOING (0UL)
@@ -66,6 +66,14 @@ FD_STATIC_ASSERT( FD_SHRED_REPAIR_MTU == 120 , update FD_SHRED_REPAIR_MTU );
6666
#define FD_NETMUX_SIG_MIN_HDR_SZ ( 42UL) /* The default header size, which means no vlan tags and no IP options. */
6767
#define FD_NETMUX_SIG_IGNORE_HDR_SZ (102UL) /* Outside the allowable range, but still fits in 4 bits when compressed */
6868

69+
struct fd_replay_out {
70+
fd_hash_t block_id; /* block id (last FEC set's merkle root) of the slot received from replay */
71+
fd_hash_t parent_block_id; /* parent block id of the slot received from replay */
72+
fd_hash_t bank_hash; /* bank hash of the slot received from replay */
73+
fd_hash_t block_hash; /* last microblock header hash of slot received from replay */
74+
};
75+
typedef struct fd_replay_out fd_replay_out_t;
76+
6977
FD_PROTOTYPES_BEGIN
7078

7179
/* hdr_sz is the total size of network headers, including eth, ip, udp.

src/disco/store/fd_store.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
partial order. Any given fork will be delivered in-order, but
6464
concurrent forks can be delivered in arbitrary order. Another way to
6565
phrase this is a parent FEC set will always be delivered before the
66-
child (see fd_fec_chainer).
66+
child (see fd_reasm).
6767
6868
CONCURRENCY
6969
@@ -188,7 +188,7 @@ struct __attribute__((aligned(FD_STORE_ALIGN))) fd_store_fec {
188188

189189
/* Pointers */
190190

191-
ulong next; /* reserved for internal use by fd_pool, fd_map_chain, orphan list */
191+
ulong next; /* reserved for internal use by fd_pool, fd_map_chain */
192192
ulong parent; /* pool idx of the parent */
193193
ulong child; /* pool idx of the left-child */
194194
ulong sibling; /* pool idx of the right-sibling */

src/discof/backtest/fd_backtest_tile.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "../../disco/store/fd_store.h"
99
#include "../../disco/topo/fd_topo.h"
1010
#include "../../discof/fd_discof.h"
11-
#include "../../discof/repair/fd_fec_chainer.h"
11+
#include "../../discof/repair/fd_reasm.h"
1212
#include "../../discof/replay/fd_replay_notif.h"
1313
#include "../../flamenco/runtime/fd_rocksdb.h"
1414
#include "../../util/pod/fd_pod_format.h"
@@ -406,21 +406,23 @@ after_credit_rocksdb( ctx_t * ctx,
406406

407407
ctx->prev_mr = mr;
408408

409-
fd_fec_out_t out = {
410-
.err = FD_FEC_CHAINER_SUCCESS,
411-
.merkle_root = mr,
409+
fd_hash_t cmr;
410+
memcpy( cmr.uc, (uchar const *)prev + fd_shred_chain_off( prev->variant ), sizeof(fd_hash_t) );
411+
fd_reasm_fec_t out = {
412+
.key = mr,
413+
.cmr = cmr,
412414
.slot = prev->slot,
413415
.parent_off = prev->data.parent_off,
414416
.fec_set_idx = prev->fec_set_idx,
415-
.data_cnt = (ushort)(prev->idx + 1 - prev->fec_set_idx),
417+
.data_cnt = (ushort)( prev->idx + 1 - prev->fec_set_idx ),
416418
.data_complete = !!( prev->data.flags & FD_SHRED_DATA_FLAG_DATA_COMPLETE ),
417419
.slot_complete = !!( prev->data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE )
418420
};
419421
ulong sig = out.slot << 32 | out.fec_set_idx;
420422
ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
421-
memcpy( fd_chunk_to_laddr( ctx->replay_out_mem, ctx->replay_out_chunk ), &out, sizeof(fd_fec_out_t) );
422-
fd_stem_publish( stem, REPLAY_OUT_IDX, sig, ctx->replay_out_chunk, sizeof(fd_fec_out_t), 0, 0, tspub );
423-
ctx->replay_out_chunk = fd_dcache_compact_next( ctx->replay_out_chunk, sizeof(fd_fec_out_t), ctx->replay_out_chunk0, ctx->replay_out_wmark );
423+
memcpy( fd_chunk_to_laddr( ctx->replay_out_mem, ctx->replay_out_chunk ), &out, sizeof(fd_reasm_fec_t) );
424+
fd_stem_publish( stem, REPLAY_OUT_IDX, sig, ctx->replay_out_chunk, sizeof(fd_reasm_fec_t), 0, 0, tspub );
425+
ctx->replay_out_chunk = fd_dcache_compact_next( ctx->replay_out_chunk, sizeof(fd_reasm_fec_t), ctx->replay_out_chunk0, ctx->replay_out_wmark );
424426
ctx->curr = curr;
425427
*charge_busy = 1;
426428

@@ -499,13 +501,13 @@ shredcap_notify_one_fec( ctx_t * ctx, fd_stem_context_t * stem ) {
499501
off += fec->data_sz;
500502
fd_store_exrel( ctx->store );
501503

502-
fd_fec_out_t * out = (fd_fec_out_t *)(slice_buf + off);
503-
off += sizeof(fd_fec_out_t);
504+
fd_reasm_fec_t * out = (fd_reasm_fec_t *)(slice_buf + off);
505+
off += sizeof(fd_reasm_fec_t);
504506

505507
ulong sig = out->slot << 32 | out->fec_set_idx;
506508
ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
507-
fd_stem_publish( stem, REPLAY_OUT_IDX, sig, ctx->replay_out_chunk, sizeof(fd_fec_out_t), 0, 0, tspub );
508-
ctx->replay_out_chunk = fd_dcache_compact_next( ctx->replay_out_chunk, sizeof(fd_fec_out_t), ctx->replay_out_chunk0, ctx->replay_out_wmark );
509+
fd_stem_publish( stem, REPLAY_OUT_IDX, sig, ctx->replay_out_chunk, sizeof(fd_reasm_fec_t), 0, 0, tspub );
510+
ctx->replay_out_chunk = fd_dcache_compact_next( ctx->replay_out_chunk, sizeof(fd_reasm_fec_t), ctx->replay_out_chunk0, ctx->replay_out_wmark );
509511

510512
break;
511513

0 commit comments

Comments
 (0)