Skip to content

Commit

Permalink
sysvar_cache: missing cache checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpsiegel authored and topointon-jump committed Oct 23, 2024
1 parent a992d2b commit 7ed0381
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dump/test-vectors/syscall/fixtures/vm/addacbadf20289ee6160b20fd96759b6ac9531c7_2482561.fix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0eab22c4ad17e86cddeafe336bd257f45a02ab11
aedb1f0036bc7ee4f6d562fe038072fc79586f5f
12 changes: 9 additions & 3 deletions src/flamenco/runtime/sysvar/fd_sysvar_epoch_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ fd_sysvar_epoch_rewards_read(
fd_sysvar_epoch_rewards_t * result,
fd_exec_slot_ctx_t * slot_ctx
) {
fd_sysvar_epoch_rewards_t const * ret = fd_sysvar_cache_epoch_rewards( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_sysvar_epoch_rewards_t));
return result;
}

FD_BORROWED_ACCOUNT_DECL(acc);
int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_epoch_rewards_id, acc );
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) {
Expand Down Expand Up @@ -75,7 +81,7 @@ fd_sysvar_epoch_rewards_set_inactive(
} else {
FD_TEST( epoch_rewards->total_rewards == epoch_rewards->distributed_rewards );
}


epoch_rewards->active = 0;

Expand Down Expand Up @@ -105,10 +111,10 @@ fd_sysvar_epoch_rewards_init(
.distributed_rewards = distributed_rewards,
.active = 1
};

/* On clusters where partitioned_epoch_rewards_superfeature is enabled, we should use point_value.rewards.
On other clusters, including those where enable_partitioned_epoch_reward is enabled, we should use total_rewards.
https://github.com/anza-xyz/agave/blob/b9c9ecccbb05d9da774d600bdbef2cf210c57fa8/runtime/src/bank/partitioned_epoch_rewards/sysvar.rs#L36-L43 */
if ( FD_LIKELY( FD_FEATURE_ACTIVE( slot_ctx, partitioned_epoch_rewards_superfeature ) ) ) {
epoch_rewards.total_rewards = point_value.rewards;
Expand Down
7 changes: 6 additions & 1 deletion src/flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ write_epoch_schedule( fd_exec_slot_ctx_t * slot_ctx,
fd_epoch_schedule_t *
fd_sysvar_epoch_schedule_read( fd_epoch_schedule_t * result,
fd_exec_slot_ctx_t * slot_ctx ) {
fd_epoch_schedule_t const * ret = fd_sysvar_cache_epoch_schedule( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_epoch_schedule_t));
return result;
}

FD_BORROWED_ACCOUNT_DECL(acc);
int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_epoch_schedule_id, acc );
Expand Down Expand Up @@ -99,7 +104,7 @@ fd_epoch_slot0( fd_epoch_schedule_t const * schedule,
}

return fd_ulong_sat_add(
fd_ulong_sat_mul(
fd_ulong_sat_mul(
fd_ulong_sat_sub(
epoch,
schedule->first_normal_epoch),
Expand Down
5 changes: 5 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_fees.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ write_fees( fd_exec_slot_ctx_t* slot_ctx, fd_sysvar_fees_t* fees ) {
fd_sysvar_fees_t *
fd_sysvar_fees_read( fd_sysvar_fees_t * result,
fd_exec_slot_ctx_t * slot_ctx ) {
fd_sysvar_fees_t const * ret = fd_sysvar_cache_fees( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_sysvar_fees_t));
return result;
}

FD_BORROWED_ACCOUNT_DECL(acc);
int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_fees_id, acc );
Expand Down
5 changes: 5 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_last_restart_slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ) {
fd_sol_sysvar_last_restart_slot_t *
fd_sysvar_last_restart_slot_read( fd_sol_sysvar_last_restart_slot_t * result,
fd_exec_slot_ctx_t const * slot_ctx ) {
fd_sol_sysvar_last_restart_slot_t const * ret = fd_sysvar_cache_last_restart_slot( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_sol_sysvar_last_restart_slot_t));
return result;
}

FD_BORROWED_ACCOUNT_DECL(acc);
int err = fd_acc_mgr_view(slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_last_restart_slot_id, acc);
Expand Down
6 changes: 6 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_rent.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ fd_rent_t *
fd_sysvar_rent_read( fd_rent_t * result,
fd_exec_slot_ctx_t * slot_ctx ) {

fd_rent_t const * ret = fd_sysvar_cache_rent( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_rent_t));
return result;
}

FD_BORROWED_ACCOUNT_DECL(rent_rec);

int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_rent_id, rent_rec );
Expand Down
5 changes: 5 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ fd_sysvar_slot_hashes_update( fd_exec_slot_ctx_t * slot_ctx ) {
fd_slot_hashes_t *
fd_sysvar_slot_hashes_read( fd_slot_hashes_t * result,
fd_exec_slot_ctx_t * slot_ctx ) {
fd_slot_hashes_t const * ret = fd_sysvar_cache_slot_hashes( slot_ctx->sysvar_cache );
if( FD_UNLIKELY( NULL != ret ) ) {
fd_memcpy(result, ret, sizeof(fd_slot_hashes_t));
return result;
}

// FD_LOG_INFO(( "SysvarS1otHashes111111111111111111111111111 at slot %lu: " FD_LOG_HEX16_FMT, slot_ctx->slot_bank.slot, FD_LOG_HEX16_FMT_ARGS( metadata.hash ) ));

Expand Down
4 changes: 2 additions & 2 deletions src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx ) {

int
fd_sysvar_slot_history_read( fd_exec_slot_ctx_t * slot_ctx,
fd_valloc_t valloc,
fd_valloc_t valloc,
fd_slot_history_t * out_history) {
/* Set current_slot, and update next_slot */

Expand All @@ -137,7 +137,7 @@ fd_sysvar_slot_history_read( fd_exec_slot_ctx_t * slot_ctx,
ctx.valloc = valloc;
if( fd_slot_history_decode( out_history, &ctx ) )
FD_LOG_ERR(("fd_slot_history_decode failed"));

return 0;
}

Expand Down
1 change: 0 additions & 1 deletion src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fd_stake_history_t *
fd_sysvar_stake_history_read( fd_stake_history_t * result,
fd_exec_slot_ctx_t * slot_ctx,
fd_valloc_t * valloc ) {

FD_BORROWED_ACCOUNT_DECL(stake_rec);
int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_stake_history_id, stake_rec);
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) )
Expand Down

0 comments on commit 7ed0381

Please sign in to comment.