Skip to content

flamenco/genesis: Address a bunch of genesis issues #4998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions src/app/ledger/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
}
}

if( FD_UNLIKELY( block_found!=0 ) ) {
FD_LOG_ERR(( "unable to seek to any slot" ));
}

/* Setup trash_hash */
uchar trash_hash_buf[32];
memset( trash_hash_buf, 0xFE, sizeof(trash_hash_buf) );
Expand All @@ -341,6 +337,16 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {

ulong block_slot = start_slot;
uchar aborted = 0U;

// set up to let us easily jump to the end of execution
do {

if( FD_UNLIKELY( block_found!=0 ) ) {
if( 0 == ledger_args->end_slot )
break; // special case just letting us do the genesis block
FD_LOG_ERR(( "unable to seek to any slot" ));
}

for( ulong slot = start_slot; slot<=ledger_args->end_slot && !aborted; ++slot ) {

ledger_args->slot_ctx->slot_bank.prev_slot = prev_slot;
Expand Down Expand Up @@ -573,6 +579,8 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
}
}

} while(0);

/* Throw an error if the blockstore wksp has a usage which exceeds the allowed
threshold. This likely indicates that a memory leak was introduced. */

Expand Down Expand Up @@ -615,8 +623,11 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
tps,
sec_per_slot ));

if ( slot_cnt == 0 ) {
FD_LOG_ERR(( "No slots replayed" ));
if( slot_cnt == 0 ) {
if( 0 != ledger_args->end_slot )
FD_LOG_ERR(( "No slots replayed" ));
else
FD_LOG_WARNING(( "No slots replayed" ));
}

args_cleanup( ledger_args );
Expand Down Expand Up @@ -647,7 +658,7 @@ allocator_setup( fd_wksp_t * wksp ) {
}

void
fd_ledger_main_setup( fd_ledger_args_t * args ) {
fd_ledger_capture_setup( fd_ledger_args_t * args ) {
fd_flamenco_boot( NULL, NULL );

/* Setup capture context */
Expand Down Expand Up @@ -691,6 +702,11 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) {
args->capture_ctx->dump_proto_start_slot = args->dump_proto_start_slot;
}
}
}

void
fd_ledger_main_setup( fd_ledger_args_t * args ) {
fd_flamenco_boot( NULL, NULL );

args->slot_ctx->snapshot_freq = args->snapshot_freq;
args->slot_ctx->incremental_freq = args->incremental_freq;
Expand Down Expand Up @@ -1318,12 +1334,14 @@ replay( fd_ledger_args_t * args ) {
}
}

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

fd_ledger_capture_setup( args );

if( args->genesis ) {
fd_runtime_read_genesis( args->slot_ctx, args->genesis, args->snapshot != NULL, NULL, args->runtime_spad );
fd_runtime_read_genesis( args->slot_ctx, args->genesis, args->snapshot != NULL, args->capture_ctx, args->runtime_spad );
}

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

fd_ledger_main_setup( args );

fd_blockstore_init( args->blockstore, -1, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, &args->slot_ctx->slot_bank );
Expand Down
34 changes: 22 additions & 12 deletions src/flamenco/runtime/fd_hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,30 +624,35 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
fd_lthash_zero( &lt_hashes[i] );
}

if( FD_LIKELY( tpool ) ){
ulong cnt_per_worker = task_data->info_sz / (wcnt-1UL);
if( FD_LIKELY( tpool ) ) {
ulong cnt_per_worker = (task_data->info_sz / (wcnt-1UL)) + 1UL;
for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
ulong start_idx = (worker_idx-1UL) * cnt_per_worker;
ulong end_idx = worker_idx!=wcnt-1 ? start_idx + cnt_per_worker - 1 : task_data->info_sz - 1;
if( start_idx >= task_data->info_sz ) {
wcnt = worker_idx;
break;
}
ulong end_idx = fd_ulong_sat_sub((worker_idx) * cnt_per_worker, 1UL);
if( end_idx >= task_data->info_sz )
end_idx = fd_ulong_sat_sub( task_data->info_sz, 1UL );;
fd_tpool_exec( tpool, worker_idx, fd_account_hash_task,
task_data, start_idx, end_idx,
&lt_hashes[worker_idx], 0UL, 0UL,
0UL, 0UL, worker_idx, 0UL, 0UL, 0UL );
task_data, start_idx, end_idx,
&lt_hashes[worker_idx], slot_ctx, 0UL,
0UL, 0UL, worker_idx, 0UL, 0UL, 0UL );
}

for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
fd_tpool_wait( tpool, worker_idx );
}

} else {
for( ulong i=0UL; i<task_data->info_sz; i++ ) {
fd_accounts_hash_task_info_t * task_info = &task_data->info[i];
fd_account_hash( slot_ctx->funk,
slot_ctx->funk_txn,
task_info,
&lt_hashes[ 0 ],
slot_ctx->slot_bank.slot,
&slot_ctx->epoch_ctx->features );
slot_ctx->funk_txn,
task_info,
&lt_hashes[ 0 ],
slot_ctx->slot_bank.slot,
&slot_ctx->epoch_ctx->features );
}
}

Expand Down Expand Up @@ -698,6 +703,11 @@ fd_hash_account( uchar hash[ static 32 ],
fd_blake3_fini_varlen( b3, lthash->bytes, FD_LTHASH_LEN_BYTES );
}

if (memcmp(pubkey, &fd_sysvar_clock_id, sizeof(fd_sysvar_clock_id)) == 0) {
FD_LOG_WARNING(( "sysvar_clock_id: %s", FD_BASE58_ENC_32_ALLOCA( hash ) ));
FD_LOG_WARNING(( "hi mom" ));
}

return hash;
}

Expand Down
29 changes: 29 additions & 0 deletions src/flamenco/runtime/fd_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3615,6 +3615,24 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx,

fd_sysvar_slot_history_update( slot_ctx, runtime_spad );

fd_runtime_update_leaders( slot_ctx, 0, runtime_spad );

fd_funk_t * funk = slot_ctx->funk;
fd_funk_txn_t * txn = slot_ctx->funk_txn;

/* Add all the genesis accounts into the rent fresh list */
for( fd_funk_rec_t const * rec = fd_funk_txn_first_rec( funk, txn );
NULL != rec;
rec = fd_funk_txn_next_rec( funk, rec ) ) {

if( !fd_funk_key_is_acc( rec->pair.key ) ) {
continue;
}

fd_funk_rec_key_t const * pubkey = rec->pair.key;
fd_runtime_register_new_fresh_account( slot_ctx, (fd_pubkey_t * const ) fd_type_pun_const(&pubkey->uc[0]) );
}

fd_runtime_freeze( slot_ctx, runtime_spad );

/* sort and update bank hash */
Expand Down Expand Up @@ -3657,6 +3675,17 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,

fd_epoch_bank_t * epoch_bank = fd_exec_epoch_ctx_epoch_bank( slot_ctx->epoch_ctx );

/* Allocate all the memory for the rent fresh accounts lists */
fd_slot_bank_t * slot_bank = &slot_ctx->slot_bank;
fd_rent_fresh_accounts_new( &slot_bank->rent_fresh_accounts );
slot_bank->rent_fresh_accounts.total_count = 0UL;
slot_bank->rent_fresh_accounts.fresh_accounts_len = FD_RENT_FRESH_ACCOUNTS_MAX;
slot_bank->rent_fresh_accounts.fresh_accounts = fd_spad_alloc(
runtime_spad,
FD_RENT_FRESH_ACCOUNT_ALIGN,
sizeof(fd_rent_fresh_account_t) * FD_RENT_FRESH_ACCOUNTS_MAX );
fd_memset( slot_bank->rent_fresh_accounts.fresh_accounts, 0, sizeof(fd_rent_fresh_account_t) * FD_RENT_FRESH_ACCOUNTS_MAX );

fd_genesis_solana_t * genesis_block;
fd_hash_t genesis_hash;

Expand Down
Loading