Skip to content

Commit 4e38549

Browse files
asdf
1 parent 08ebe62 commit 4e38549

14 files changed

+191
-136
lines changed

src/flamenco/rewards/fd_rewards.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
695695
ulong exec_spad_cnt,
696696
fd_spad_t * runtime_spad ) {
697697
/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
698+
698699
fd_stake_history_t const * stake_history = fd_sysvar_cache_stake_history( slot_ctx->sysvar_cache );
699700
if( FD_UNLIKELY( !stake_history ) ) {
700701
FD_LOG_ERR(( "StakeHistory sysvar is missing from sysvar cache" ));

src/flamenco/runtime/context/fd_exec_slot_ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fd_exec_slot_ctx_new( void * mem,
2525
fd_exec_slot_ctx_t * self = (fd_exec_slot_ctx_t *)mem;
2626
fd_slot_bank_new( &self->slot_bank );
2727

28-
self->sysvar_cache = fd_sysvar_cache_new( fd_spad_alloc( runtime_spad, fd_sysvar_cache_align(), fd_sysvar_cache_footprint() ) );
28+
self->sysvar_cache = fd_sysvar_cache_new( fd_spad_alloc( runtime_spad, fd_sysvar_cache_align(), fd_sysvar_cache_footprint() ), fd_wksp_containing( runtime_spad ) );
2929

3030
FD_COMPILER_MFENCE();
3131
self->magic = FD_EXEC_SLOT_CTX_MAGIC;

src/flamenco/runtime/fd_runtime.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ fd_runtime_sysvar_cache_load( fd_exec_slot_ctx_t * slot_ctx,
224224
fd_sysvar_cache_restore( slot_ctx->sysvar_cache,
225225
slot_ctx->funk,
226226
slot_ctx->funk_txn,
227-
runtime_spad,
228-
slot_ctx->runtime_wksp );
227+
runtime_spad );
229228

230229
return FD_RUNTIME_EXECUTE_SUCCESS;
231230
}
@@ -531,6 +530,9 @@ fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
531530

532531
FD_LOG_DEBUG(( "fd_runtime_freeze: capitalization %lu ", slot_ctx->slot_bank.capitalization));
533532
slot_ctx->slot_bank.collected_rent = 0;
533+
534+
fd_sysvar_cache_invalidate( slot_ctx->sysvar_cache );
535+
FD_TEST( slot_ctx->sysvar_cache->has_clock==0 );
534536
}
535537

536538
#define FD_RENT_EXEMPT (-1L)
@@ -990,7 +992,7 @@ fd_runtime_block_sysvar_update_pre_execute( fd_exec_slot_ctx_t * slot_ctx,
990992
double clock_update_time_ms = (double)clock_update_time * 1e-6;
991993
FD_LOG_INFO(( "clock updated - slot: %lu, elapsed: %6.6f ms", slot_ctx->slot_bank.slot, clock_update_time_ms ));
992994
if( !FD_FEATURE_ACTIVE( slot_ctx->slot_bank.slot, slot_ctx->epoch_ctx->features, disable_fees_sysvar ) ) {
993-
fd_sysvar_fees_update(slot_ctx);
995+
fd_sysvar_fees_update( slot_ctx );
994996
}
995997
// It has to go into the current txn previous info but is not in slot 0
996998
if( slot_ctx->slot_bank.slot != 0 ) {

src/flamenco/runtime/program/fd_address_lookup_table_program.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,21 @@ extend_lookup_table( fd_exec_instr_ctx_t * ctx,
678678
}
679679

680680
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L290 */
681-
fd_sol_sysvar_clock_t clock[1];
682-
if( FD_UNLIKELY( !fd_sysvar_clock_read( clock,
683-
ctx->txn_ctx->sysvar_cache,
684-
ctx->txn_ctx->funk,
685-
ctx->txn_ctx->funk_txn ) ) )
681+
// fd_sol_sysvar_clock_t clock[1];
682+
// if( FD_UNLIKELY( !fd_sysvar_clock_read( clock,
683+
// ctx->txn_ctx->sysvar_cache,
684+
// ctx->txn_ctx->funk,
685+
// ctx->txn_ctx->funk_txn,
686+
// NULL ) ) )
687+
// return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
688+
689+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
690+
ctx->txn_ctx->funk,
691+
ctx->txn_ctx->funk_txn,
692+
ctx->txn_ctx->spad );
693+
if( FD_UNLIKELY( !clock ) ) {
686694
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
695+
}
687696

688697
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L291-L299 */
689698
if( clock->slot!=state->meta.last_extended_slot ) {
@@ -874,11 +883,11 @@ deactivate_lookup_table( fd_exec_instr_ctx_t * ctx ) {
874883
}
875884

876885
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L380 */
877-
fd_sol_sysvar_clock_t clock[1];
878-
if( FD_UNLIKELY( !fd_sysvar_clock_read( clock,
879-
ctx->txn_ctx->sysvar_cache,
880-
ctx->txn_ctx->funk,
881-
ctx->txn_ctx->funk_txn ) ) ) {
886+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
887+
ctx->txn_ctx->funk,
888+
ctx->txn_ctx->funk_txn,
889+
ctx->txn_ctx->spad );
890+
if( FD_UNLIKELY( !clock ) ) {
882891
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
883892
}
884893

@@ -996,11 +1005,11 @@ close_lookup_table( fd_exec_instr_ctx_t * ctx ) {
9961005
}
9971006

9981007
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L437 */
999-
fd_sol_sysvar_clock_t clock[1];
1000-
if( FD_UNLIKELY( !fd_sysvar_clock_read( clock,
1001-
ctx->txn_ctx->sysvar_cache,
1002-
ctx->txn_ctx->funk,
1003-
ctx->txn_ctx->funk_txn ) ) ) {
1008+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( ctx->txn_ctx->sysvar_cache,
1009+
ctx->txn_ctx->funk,
1010+
ctx->txn_ctx->funk_txn,
1011+
ctx->txn_ctx->spad );
1012+
if( FD_UNLIKELY( !clock ) ) {
10041013
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
10051014
}
10061015

src/flamenco/runtime/program/fd_bpf_loader_program.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,20 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
794794
return err;
795795
}
796796

797-
fd_sol_sysvar_clock_t clock = {0};
798-
if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
799-
instr_ctx->txn_ctx->sysvar_cache,
800-
instr_ctx->txn_ctx->funk,
801-
instr_ctx->txn_ctx->funk_txn ) ) ) {
797+
// fd_sol_sysvar_clock_t clock = {0};
798+
// if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
799+
// instr_ctx->txn_ctx->sysvar_cache,
800+
// instr_ctx->txn_ctx->funk,
801+
// instr_ctx->txn_ctx->funk_txn,
802+
// NULL ) ) ) {
803+
// return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
804+
// }
805+
806+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
807+
instr_ctx->txn_ctx->funk,
808+
instr_ctx->txn_ctx->funk_txn,
809+
instr_ctx->txn_ctx->spad );
810+
if( FD_UNLIKELY( !clock ) ) {
802811
return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
803812
}
804813

@@ -1036,7 +1045,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
10361045
fd_bpf_upgradeable_loader_state_t programdata_loader_state = {
10371046
.discriminant = fd_bpf_upgradeable_loader_state_enum_program_data,
10381047
.inner.program_data = {
1039-
.slot = clock.slot,
1048+
.slot = clock->slot,
10401049
.upgrade_authority_address = (fd_pubkey_t *)authority_key,
10411050
},
10421051
};
@@ -1227,7 +1236,6 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
12271236

12281237
ulong programdata_data_offset = PROGRAMDATA_METADATA_SIZE;
12291238
fd_bpf_upgradeable_loader_state_t * programdata_state = NULL;
1230-
fd_sol_sysvar_clock_t clock = {0};
12311239
ulong programdata_balance_required = 0UL;
12321240

12331241
/* https://github.com/anza-xyz/agave/blob/v2.1.4/programs/bpf_loader/src/lib.rs#L778-L779 */
@@ -1251,15 +1259,16 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
12511259
return err;
12521260
}
12531261

1254-
if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
1255-
instr_ctx->txn_ctx->sysvar_cache,
1256-
instr_ctx->txn_ctx->funk,
1257-
instr_ctx->txn_ctx->funk_txn ) ) ) {
1262+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
1263+
instr_ctx->txn_ctx->funk,
1264+
instr_ctx->txn_ctx->funk_txn,
1265+
instr_ctx->txn_ctx->spad );
1266+
if( FD_UNLIKELY( !clock ) ) {
12581267
return FD_EXECUTOR_INSTR_ERR_GENERIC_ERR;
12591268
}
12601269

12611270
if( fd_bpf_upgradeable_loader_state_is_program_data( programdata_state ) ) {
1262-
if( FD_UNLIKELY( clock.slot==programdata_state->inner.program_data.slot ) ) {
1271+
if( FD_UNLIKELY( clock->slot==programdata_state->inner.program_data.slot ) ) {
12631272
fd_log_collector_msg_literal( instr_ctx, "Program was deployed in this block already" );
12641273
return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
12651274
}
@@ -1309,7 +1318,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
13091318
/* Update the ProgramData account, record the upgraded data, and zero the rest in a local scope */
13101319
do {
13111320
programdata_state->discriminant = fd_bpf_upgradeable_loader_state_enum_program_data;
1312-
programdata_state->inner.program_data.slot = clock.slot;
1321+
programdata_state->inner.program_data.slot = clock->slot;
13131322
programdata_state->inner.program_data.upgrade_authority_address = (fd_pubkey_t *)authority_key;
13141323
err = fd_bpf_loader_v3_program_set_state( &programdata, programdata_state );
13151324
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
@@ -1663,14 +1672,14 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
16631672
fd_log_collector_msg_literal( instr_ctx, "Program account not owned by loader" );
16641673
return FD_EXECUTOR_INSTR_ERR_INCORRECT_PROGRAM_ID;
16651674
}
1666-
fd_sol_sysvar_clock_t clock = {0};
1667-
if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
1668-
instr_ctx->txn_ctx->sysvar_cache,
1669-
instr_ctx->txn_ctx->funk,
1670-
instr_ctx->txn_ctx->funk_txn ) ) ) {
1675+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
1676+
instr_ctx->txn_ctx->funk,
1677+
instr_ctx->txn_ctx->funk_txn,
1678+
instr_ctx->txn_ctx->spad );
1679+
if( FD_UNLIKELY( !clock ) ) {
16711680
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
16721681
}
1673-
if( FD_UNLIKELY( clock.slot==close_account_state->inner.program_data.slot ) ) {
1682+
if( FD_UNLIKELY( clock->slot==close_account_state->inner.program_data.slot ) ) {
16741683
fd_log_collector_msg_literal( instr_ctx,"Program was deployed in this block already" );
16751684
return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
16761685
}
@@ -1787,22 +1796,21 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
17871796
return FD_EXECUTOR_INSTR_ERR_INVALID_REALLOC;
17881797
}
17891798

1790-
fd_sol_sysvar_clock_t clock = {0};
1791-
if( FD_UNLIKELY( !fd_sysvar_clock_read( &clock,
1792-
instr_ctx->txn_ctx->sysvar_cache,
1793-
instr_ctx->txn_ctx->funk,
1794-
instr_ctx->txn_ctx->funk_txn ) ) ) {
1799+
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( instr_ctx->txn_ctx->sysvar_cache,
1800+
instr_ctx->txn_ctx->funk,
1801+
instr_ctx->txn_ctx->funk_txn,
1802+
instr_ctx->txn_ctx->spad );
1803+
if( FD_UNLIKELY( !clock ) ) {
17951804
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
17961805
}
17971806

1798-
17991807
fd_pubkey_t * upgrade_authority_address = NULL;
18001808
fd_bpf_upgradeable_loader_state_t * programdata_state = fd_bpf_loader_program_get_state( programdata_account.acct, spad, &err );
18011809
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
18021810
return err;
18031811
}
18041812
if( fd_bpf_upgradeable_loader_state_is_program_data( programdata_state ) ) {
1805-
if( FD_UNLIKELY( clock.slot==programdata_state->inner.program_data.slot ) ) {
1813+
if( FD_UNLIKELY( clock->slot==programdata_state->inner.program_data.slot ) ) {
18061814
fd_log_collector_msg_literal( instr_ctx, "Program was extended in this block already" );
18071815
return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
18081816
}
@@ -1916,7 +1924,7 @@ process_loader_upgradeable_instruction( fd_exec_instr_ctx_t * instr_ctx ) {
19161924
FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( instr_ctx, 0UL, &programdata_account );
19171925

19181926
programdata_state->discriminant = fd_bpf_upgradeable_loader_state_enum_program_data;
1919-
programdata_state->inner.program_data.slot = clock.slot;
1927+
programdata_state->inner.program_data.slot = clock->slot;
19201928
programdata_state->inner.program_data.upgrade_authority_address = upgrade_authority_address;
19211929

19221930
err = fd_bpf_loader_v3_program_set_state( &programdata_account, programdata_state );

src/flamenco/runtime/program/fd_stake_program.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,10 +2550,9 @@ fd_stake_program_execute( fd_exec_instr_ctx_t * ctx ) {
25502550

25512551
/* The EpochRewards sysvar only exists after partitioned epoch rewards is activated.
25522552
If the sysvar exists, check the `active` field */
2553-
fd_sysvar_epoch_rewards_t const * rewards = fd_sysvar_cache_epoch_rewards( ctx->txn_ctx->sysvar_cache );
2554-
int epoch_rewards_active = (NULL != rewards) ? rewards->active : false;
2553+
int epoch_rewards_active = (ctx->txn_ctx->sysvar_cache->has_epoch_rewards) ? fd_sysvar_cache_epoch_rewards( ctx->txn_ctx->sysvar_cache )->active : 0;
25552554

2556-
if (epoch_rewards_active && instruction->discriminant!=fd_stake_instruction_enum_get_minimum_delegation) {
2555+
if( epoch_rewards_active && instruction->discriminant!=fd_stake_instruction_enum_get_minimum_delegation ) {
25572556
ctx->txn_ctx->custom_err = FD_STAKE_ERR_EPOCH_REWARDS_ACTIVE;
25582557
return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
25592558
}

0 commit comments

Comments
 (0)