Skip to content

Commit 5a80173

Browse files
committed
fixes to get fd bench to boot
1 parent 5cea668 commit 5a80173

File tree

10 files changed

+120
-19
lines changed

10 files changed

+120
-19
lines changed

src/app/fdctl/config/default.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ name = "fd1"
3131
# 1. The `SUDO_USER`, `LOGNAME`, `USER`, `LNAME`, or `USERNAME`
3232
# environment variables are checked in this order, and if one of
3333
# them is set that user is used
34-
# 2. The `/proc/self/loginid` file is used to determine the UID, and
34+
# 2. The `/proc/self/loginuid` file is used to determine the UID, and
3535
# the username is looked up in nss (the name service switch).
3636
#
3737
# This means if running as sudo, the user will be the terminal user

src/app/firedancer-dev/main.c

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ extern fd_topo_run_tile_t fd_tile_archiver_feeder;
9292
extern fd_topo_run_tile_t fd_tile_archiver_writer;
9393
extern fd_topo_run_tile_t fd_tile_archiver_playback;
9494

95+
extern fd_topo_run_tile_t fd_tile_bencho;
96+
extern fd_topo_run_tile_t fd_tile_benchg;
97+
extern fd_topo_run_tile_t fd_tile_benchs;
98+
9599
fd_topo_run_tile_t * TILES[] = {
96100
&fd_tile_net,
97101
&fd_tile_netlnk,
@@ -122,6 +126,9 @@ fd_topo_run_tile_t * TILES[] = {
122126
&fd_tile_archiver_feeder,
123127
&fd_tile_archiver_writer,
124128
&fd_tile_archiver_playback,
129+
&fd_tile_bencho,
130+
&fd_tile_benchg,
131+
&fd_tile_benchs,
125132
NULL,
126133
};
127134

src/app/ledger/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ ingest( fd_ledger_args_t * args ) {
11301130
}
11311131

11321132
if( args->genesis ) {
1133-
fd_runtime_read_genesis( slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->tpool, args->runtime_spad );
1133+
fd_runtime_read_genesis( slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad );
11341134
}
11351135

11361136
if( !args->snapshot && (args->restore_funk != NULL || args->restore != NULL) ) {
@@ -1320,7 +1320,7 @@ replay( fd_ledger_args_t * args ) {
13201320
}
13211321

13221322
if( args->genesis ) {
1323-
fd_runtime_read_genesis( args->slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->tpool, args->runtime_spad );
1323+
fd_runtime_read_genesis( args->slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad );
13241324
}
13251325

13261326
FD_LOG_NOTICE(( "Used memory in spad after loading in snapshot %lu", args->runtime_spad->mem_used ));

src/discof/replay/fd_replay_tile.c

+38-8
Original file line numberDiff line numberDiff line change
@@ -2089,8 +2089,7 @@ read_snapshot( void * _ctx,
20892089
/* Funk already has a snapshot loaded */
20902090
fd_runtime_recover_banks( ctx->slot_ctx, 1, 1, ctx->runtime_spad );
20912091
base_slot = ctx->slot_ctx->slot_bank.slot;
2092-
publish_stake_weights( ctx, stem, ctx->slot_ctx );
2093-
fd_fseq_update( ctx->published_wmark, ctx->slot_ctx->slot_bank.slot );
2092+
kickoff_repair_orphans( ctx, stem );
20942093
} else {
20952094

20962095
/* If we have an incremental snapshot try to prefetch the snapshot slot
@@ -2342,13 +2341,17 @@ init_snapshot( fd_replay_tile_ctx_t * ctx,
23422341
ctx->genesis,
23432342
is_snapshot,
23442343
ctx->capture_ctx,
2345-
NULL,
23462344
ctx->runtime_spad );
2347-
fd_blockstore_init( ctx->slot_ctx->blockstore,
2348-
ctx->blockstore_fd,
2349-
FD_BLOCKSTORE_ARCHIVE_MIN_SIZE,
2350-
&ctx->slot_ctx->slot_bank );
2351-
2345+
if( !is_snapshot ) {
2346+
/* read_snapshot calls kickoff_repair_orphans which calls init_blockstore.
2347+
Thus we need to call init_blockstore here if snapshot isn't read.
2348+
We call this after fd_runtime_read_genesis, which sets up the
2349+
slot_bank needed in blockstore_init */
2350+
fd_blockstore_init( ctx->slot_ctx->blockstore,
2351+
ctx->blockstore_fd,
2352+
FD_BLOCKSTORE_ARCHIVE_MIN_SIZE,
2353+
&ctx->slot_ctx->slot_bank );
2354+
}
23522355
ctx->epoch_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
23532356
ctx->epoch_ctx->runtime_public = ctx->runtime_public;
23542357
init_after_snapshot( ctx, stem );
@@ -2367,6 +2370,33 @@ init_snapshot( fd_replay_tile_ctx_t * ctx,
23672370

23682371
send_exec_epoch_msg( ctx, stem, ctx->slot_ctx );
23692372

2373+
/* Publish slot notifs */
2374+
ulong curr_slot = ctx->curr_slot;
2375+
ulong block_entry_height = 0;
2376+
2377+
if( is_snapshot ){
2378+
for(;;){
2379+
fd_block_map_query_t query[1] = { 0 };
2380+
int err = fd_block_map_query_try( ctx->blockstore->block_map, &curr_slot, NULL, query, 0 );
2381+
fd_block_info_t * block_info = fd_block_map_query_ele( query );
2382+
if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) FD_LOG_ERR(( "Failed to query blockstore for slot %lu", curr_slot ));
2383+
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) {
2384+
FD_LOG_WARNING(( "Waiting for block map query for slot %lu", curr_slot ));
2385+
continue;
2386+
};
2387+
block_entry_height = block_info->block_height;
2388+
if( FD_UNLIKELY( fd_block_map_query_test( query ) == FD_MAP_SUCCESS ) ) break;
2389+
}
2390+
} else {
2391+
/* Block after genesis has a height of 1.
2392+
TODO: We should be able to query slot 1 block_map entry to get this
2393+
(using the above for loop), but blockstore/fork setup on genesis is
2394+
broken for now. */
2395+
block_entry_height = 1UL;
2396+
}
2397+
2398+
publish_slot_notifications( ctx, stem, fork, block_entry_height, curr_slot );
2399+
23702400

23712401
FD_TEST( ctx->slot_ctx );
23722402
}

src/flamenco/runtime/fd_blockstore.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ fd_blockstore_new( void * shmem,
6666
memset( blocks, 0, sizeof(fd_block_info_t) * block_max );
6767
FD_TEST( fd_block_map_new ( block_map, block_max, lock_cnt, BLOCK_INFO_PROBE_CNT, seed ) );
6868

69+
/* Caller is in charge of freeing map_slot_para element store set.
70+
We need to explicitly do this since blocks is memset to 0, which
71+
is not a "freed" state in map_slot_para (slot 0 is a valid key). */
72+
fd_block_info_t * blocks_ = (fd_block_info_t *)blocks;
73+
for( ulong i=0UL; i<block_max; i++ ) {
74+
fd_block_map_private_ele_free( NULL, /* Not needed, avoids a join on block_map */
75+
&blocks_[i] );
76+
}
77+
6978
blockstore_shmem->block_idx_gaddr = fd_wksp_gaddr( wksp, fd_block_idx_join( fd_block_idx_new( block_idx, lg_idx_max ) ) );
7079
blockstore_shmem->slot_deque_gaddr = fd_wksp_gaddr( wksp, fd_slot_deque_join (fd_slot_deque_new( slot_deque, block_max ) ) );
7180
blockstore_shmem->txn_map_gaddr = fd_wksp_gaddr( wksp, fd_txn_map_join (fd_txn_map_new( txn_map, txn_max, seed ) ) );
@@ -1201,7 +1210,10 @@ fd_blockstore_block_height_update( fd_blockstore_t * blockstore, ulong slot, ulo
12011210
// TODO make nonblocking
12021211
int err = fd_block_map_prepare( blockstore->block_map, &slot, NULL, query, FD_MAP_FLAG_BLOCKING );
12031212
fd_block_info_t * block_info = fd_block_map_query_ele( query );
1204-
if( FD_UNLIKELY( err || block_info->slot != slot ) ) return;
1213+
if( FD_UNLIKELY( err || block_info->slot != slot ) ) {
1214+
fd_block_map_cancel( query );
1215+
return;
1216+
};
12051217
block_info->block_height = height;
12061218
fd_block_map_publish( query );
12071219
}

src/flamenco/runtime/fd_blockstore.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ typedef struct fd_block_info fd_block_info_t;
330330
#define MAP_NAME fd_block_map
331331
#define MAP_ELE_T fd_block_info_t
332332
#define MAP_KEY slot
333-
#define MAP_ELE_IS_FREE(ctx, ele) ((ele)->slot == 0)
334-
#define MAP_ELE_FREE(ctx, ele) ((ele)->slot = 0)
333+
#define MAP_ELE_IS_FREE(ctx, ele) ((ele)->slot == ULONG_MAX)
334+
#define MAP_ELE_FREE(ctx, ele) ((ele)->slot = ULONG_MAX)
335+
#define MAP_ELE_MOVE(ctx,dst,src) do { MAP_ELE_T * _src = (src); (*(dst)) = *_src; _src->MAP_KEY = (MAP_KEY_T)ULONG_MAX; } while(0)
335336
#define MAP_KEY_HASH(key, seed) (void)(seed), (*(key))
336337
#include "../../util/tmpl/fd_map_slot_para.c"
337338

@@ -370,6 +371,7 @@ typedef struct fd_block_idx fd_block_idx_t;
370371
#define MAP_T fd_block_idx_t
371372
#define MAP_KEY slot
372373
#define MAP_KEY_HASH(key) ((uint)(key)) /* finalized slots are guaranteed to be unique so perfect hashing */
374+
#define MAP_KEY_INVAL(k) (k == ULONG_MAX)
373375
#include "../../util/tmpl/fd_map_dynamic.c"
374376

375377
struct fd_txn_key {

src/flamenco/runtime/fd_hashes.c

+40
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,46 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
649649
runtime_spad );
650650
}
651651

652+
int
653+
fd_update_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
654+
fd_capture_ctx_t * capture_ctx,
655+
fd_hash_t * hash,
656+
ulong signature_cnt,
657+
fd_spad_t * runtime_spad ) {
658+
659+
/* Collect list of changed accounts to be added to bank hash */
660+
fd_accounts_hash_task_data_t * task_data = fd_spad_alloc( runtime_spad,
661+
alignof(fd_accounts_hash_task_data_t),
662+
sizeof(fd_accounts_hash_task_data_t) );
663+
664+
fd_collect_modified_accounts( slot_ctx, task_data, runtime_spad );
665+
666+
fd_lthash_value_t * lt_hash = fd_spad_alloc( runtime_spad,
667+
FD_LTHASH_VALUE_ALIGN,
668+
FD_LTHASH_VALUE_FOOTPRINT );
669+
fd_lthash_zero( lt_hash );
670+
671+
for( ulong i=0UL; i<task_data->info_sz; i++ ) {
672+
fd_accounts_hash_task_info_t * task_info = &task_data->info[i];
673+
fd_account_hash( slot_ctx->funk,
674+
slot_ctx->funk_txn,
675+
task_info,
676+
lt_hash,
677+
slot_ctx->slot_bank.slot,
678+
&slot_ctx->epoch_ctx->features );
679+
}
680+
681+
return fd_update_hash_bank_exec_hash( slot_ctx,
682+
hash,
683+
capture_ctx,
684+
task_data,
685+
1UL,
686+
lt_hash,
687+
1UL,
688+
signature_cnt,
689+
runtime_spad );
690+
}
691+
652692
void const *
653693
fd_hash_account( uchar hash[ static 32 ],
654694
fd_lthash_value_t * lthash,

src/flamenco/runtime/fd_hashes.h

+9
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
110110
fd_tpool_t * tpool,
111111
fd_spad_t * runtime_spad );
112112

113+
/* Single threaded version of fd_update_hash_bank_tpool
114+
TODO: Use parallel execution APIs in fd_runtime_public */
115+
int
116+
fd_update_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
117+
fd_capture_ctx_t * capture_ctx,
118+
fd_hash_t * hash,
119+
ulong signature_cnt,
120+
fd_spad_t * runtime_spad );
121+
113122
/* fd_hash_account is the method to compute the account
114123
hash. It includes the following content:
115124
- lamports

src/flamenco/runtime/fd_runtime.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,6 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
36323632
static int
36333633
fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx,
36343634
fd_capture_ctx_t * capture_ctx,
3635-
fd_tpool_t * tpool,
36363635
fd_spad_t * runtime_spad ) {
36373636
ulong hashcnt_per_slot = slot_ctx->epoch_ctx->epoch_bank.hashes_per_tick * slot_ctx->epoch_ctx->epoch_bank.ticks_per_slot;
36383637
while( hashcnt_per_slot-- ) {
@@ -3654,7 +3653,11 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx,
36543653
fd_runtime_freeze( slot_ctx, runtime_spad );
36553654

36563655
/* sort and update bank hash */
3657-
int result = fd_update_hash_bank_tpool( slot_ctx, capture_ctx, &slot_ctx->slot_bank.banks_hash, slot_ctx->signature_cnt, tpool,runtime_spad );
3656+
int result = fd_update_hash_bank( slot_ctx,
3657+
capture_ctx,
3658+
&slot_ctx->slot_bank.banks_hash,
3659+
slot_ctx->signature_cnt,
3660+
runtime_spad );
36583661
if( FD_UNLIKELY( result != FD_EXECUTOR_INSTR_SUCCESS ) ) {
36593662
FD_LOG_ERR(( "Failed to update bank hash with error=%d", result ));
36603663
}
@@ -3671,7 +3674,6 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
36713674
char const * genesis_filepath,
36723675
uchar is_snapshot,
36733676
fd_capture_ctx_t * capture_ctx,
3674-
fd_tpool_t * tpool,
36753677
fd_spad_t * runtime_spad ) {
36763678

36773679
if( strlen( genesis_filepath ) == 0 ) {
@@ -3764,7 +3766,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
37643766

37653767
slot_ctx->slot_bank.slot = 0UL;
37663768

3767-
int err = fd_runtime_process_genesis_block( slot_ctx, capture_ctx, tpool, runtime_spad );
3769+
int err = fd_runtime_process_genesis_block( slot_ctx, capture_ctx, runtime_spad );
37683770
if( FD_UNLIKELY( err ) ) {
37693771
FD_LOG_ERR(( "Genesis slot 0 execute failed with error %d", err ));
37703772
}

src/flamenco/runtime/fd_runtime.h

-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
669669
char const * genesis_filepath,
670670
uchar is_snapshot,
671671
fd_capture_ctx_t * capture_ctx,
672-
fd_tpool_t * tpool,
673672
fd_spad_t * spad );
674673

675674
FD_PROTOTYPES_END

0 commit comments

Comments
 (0)