Skip to content
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

flamenco: implement verify_ticks #3829

Merged
merged 1 commit into from
Jan 8, 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
35 changes: 28 additions & 7 deletions src/app/fdctl/run/tiles/fd_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,16 +998,20 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
FD_TEST( fork == child );

// fork is advancing
FD_LOG_NOTICE(( "new block execution - slowt: %lu, parent_slot: %lu", curr_slot, ctx->parent_slot ));
FD_LOG_NOTICE(( "new block execution - slot: %lu, parent_slot: %lu", curr_slot, ctx->parent_slot ));
fd_epoch_bank_t * epoch_bank = fd_exec_epoch_ctx_epoch_bank( fork->slot_ctx.epoch_ctx );

/* if it is an epoch boundary, push out stake weights */
if( fork->slot_ctx.slot_bank.slot != 0 ) {
is_new_epoch_in_new_block = (int)fd_runtime_is_epoch_boundary( epoch_bank, fork->slot_ctx.slot_bank.slot, fork->slot_ctx.slot_bank.prev_slot );
}

fork->slot_ctx.slot_bank.prev_slot = fork->slot_ctx.slot_bank.slot;
fork->slot_ctx.slot_bank.slot = curr_slot;
fork->slot_ctx.slot_bank.prev_slot = fork->slot_ctx.slot_bank.slot;
fork->slot_ctx.slot_bank.slot = curr_slot;
fork->slot_ctx.slot_bank.tick_height = fork->slot_ctx.slot_bank.max_tick_height;
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( epoch_bank->ticks_per_slot, curr_slot, &fork->slot_ctx.slot_bank.max_tick_height ) ) ) {
FD_LOG_ERR(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", curr_slot, epoch_bank->ticks_per_slot ));
}
fork->slot_ctx.enable_exec_recording = ctx->tx_metadata_storage;

if( fd_runtime_is_epoch_boundary( epoch_bank, fork->slot_ctx.slot_bank.slot, fork->slot_ctx.slot_bank.prev_slot ) ) {
Expand All @@ -1025,7 +1029,9 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
fd_exec_epoch_ctx_from_prev( epoch_fork->epoch_ctx, prev_epoch_ctx );
fork->slot_ctx.epoch_ctx = epoch_fork->epoch_ctx;
}

fork->slot_ctx.status_cache = ctx->status_cache;

fd_funk_txn_xid_t xid = { 0 };

if( flags & REPLAY_FLAG_PACKED_MICROBLOCK ) {
Expand All @@ -1039,6 +1045,25 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
fork->slot_ctx.funk_txn = fd_funk_txn_prepare(ctx->funk, fork->slot_ctx.funk_txn, &xid, 1);
fd_funk_end_write( ctx->funk );

if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_block_pre_execute_process_new_epoch( &fork->slot_ctx ) ) ) {
FD_LOG_ERR(( "couldn't process new epoch" ));
}

fd_blockstore_start_read( ctx->blockstore );
fd_block_t * block = fd_blockstore_block_query( ctx->blockstore, curr_slot );
fd_blockstore_end_read( ctx->blockstore );
ulong tick_res = fd_runtime_block_verify_ticks(
fd_blockstore_block_micro_laddr( ctx->blockstore, block ),
block->micros_cnt,
fd_blockstore_block_data_laddr( ctx->blockstore, block ),
fork->slot_ctx.slot_bank.tick_height,
fork->slot_ctx.slot_bank.max_tick_height,
fork->slot_ctx.epoch_ctx->epoch_bank.hashes_per_tick
);
if( FD_UNLIKELY( tick_res != FD_BLOCK_OK ) ) {
FD_LOG_WARNING(( "failed to verify ticks res %lu slot %lu prev_slot %lu", tick_res, curr_slot, fork->slot_ctx.slot_bank.prev_slot ));
}

int res = fd_runtime_block_execute_prepare( &fork->slot_ctx );
if( res != FD_RUNTIME_EXECUTE_SUCCESS ) {
FD_LOG_ERR(( "block prep execute failed" ));
Expand Down Expand Up @@ -1250,10 +1275,6 @@ after_frag( fd_replay_tile_ctx_t * ctx,
fd_blockstore_end_read( ctx->blockstore );
fork->slot_ctx.block = block_;

/* TODO:FIXME: This needs to be unhacked. */
fork->slot_ctx.slot_bank.max_tick_height += 64UL * (curr_slot - ctx->parent_slot);
fork->slot_ctx.slot_bank.tick_height += 64UL * (curr_slot - ctx->parent_slot);

int res = fd_runtime_block_execute_finalize_tpool( &fork->slot_ctx, ctx->capture_ctx, block_info, ctx->tpool );

if( res != FD_RUNTIME_EXECUTE_SUCCESS ) {
Expand Down
11 changes: 5 additions & 6 deletions src/app/ledger/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,15 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
fd_blockstore_end_read( blockstore );
if( blk == NULL ) {
FD_LOG_WARNING(( "failed to read slot %lu", slot ));
/* TODO: This is currently a hack because ticks are not correctly
computed or handled in the runtime. It is neceesary to update ticks
for skipped slots for snapshot creation. */
ledger_args->slot_ctx->slot_bank.tick_height += 64UL;
ledger_args->slot_ctx->slot_bank.max_tick_height += 64UL;

continue;
}
ledger_args->slot_ctx->block = blk;

ledger_args->slot_ctx->slot_bank.tick_height = ledger_args->slot_ctx->slot_bank.max_tick_height;
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ledger_args->epoch_ctx->epoch_bank.ticks_per_slot, slot, &ledger_args->slot_ctx->slot_bank.max_tick_height ) ) ) {
FD_LOG_ERR(( "couldn't compute max tick height slot %lu ticks_per_slot %lu", slot, ledger_args->epoch_ctx->epoch_bank.ticks_per_slot ));
}

if( ledger_args->slot_ctx->root_slot%ledger_args->snapshot_freq==0UL && !ledger_args->is_snapshotting ) {

ledger_args->is_snapshotting = 1;
Expand Down
2 changes: 0 additions & 2 deletions src/flamenco/runtime/context/fd_exec_slot_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ struct __attribute__((aligned(8UL))) fd_exec_slot_ctx {
fd_txncache_t * status_cache;
fd_slot_history_t slot_history[1];

ulong tick_count;

int enable_exec_recording; /* Enable/disable execution metadata
recording, e.g. txn logs. Analogue
of Agave's ExecutionRecordingConfig. */
Expand Down
7 changes: 6 additions & 1 deletion src/flamenco/runtime/fd_blockstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct fd_block {
ulong shreds_cnt;
ulong batch_gaddr; /* list of fd_block_entry_batch_t */
ulong batch_cnt;
ulong micros_gaddr; /* ptr to the list of fd_blockstore_micro_t */
ulong micros_gaddr; /* ptr to the list of fd_block_micro_t */
ulong micros_cnt;
ulong txns_gaddr; /* ptr to the list of fd_block_txn_t */
ulong txns_cnt;
Expand Down Expand Up @@ -572,6 +572,11 @@ fd_blockstore_block_batch_laddr( fd_blockstore_t * blockstore, fd_block_t * bloc
return fd_wksp_laddr_fast( fd_blockstore_wksp( blockstore ), block->batch_gaddr );
}

FD_FN_PURE static inline fd_block_micro_t *
fd_blockstore_block_micro_laddr( fd_blockstore_t * blockstore, fd_block_t * block ) {
return fd_wksp_laddr_fast( fd_blockstore_wksp( blockstore ), block->micros_gaddr );
}

/* fd_buf_shred_query queries the blockstore for shred at slot,
shred_idx. Returns a pointer to the shred or NULL if not in
blockstore. The returned pointer lifetime is until the shred is
Expand Down
Loading
Loading