Skip to content

Commit c40941b

Browse files
committed
wip
1 parent 9d0b414 commit c40941b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1093
-922
lines changed

src/disco/bundle/fd_bundle_crank.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "fd_bundle_crank.h"
22
#include "../../flamenco/runtime/fd_pubkey_utils.h"
3+
#if FD_HAS_AVX
4+
#include "../../util/simd/fd_avx.h"
5+
#endif
36

47
FD_STATIC_ASSERT( sizeof(fd_bundle_crank_tip_payment_config_t)==89UL, config_struct );
58

src/discof/replay/fd_exec.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ generate_stake_weight_msg( fd_exec_slot_ctx_t * slot_ctx,
2424
runtime_spad );
2525
fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank );
2626

27-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
27+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
2828

2929
stake_weight_msg->epoch = epoch;
30-
stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */
31-
stake_weight_msg->start_slot = fd_epoch_slot0( epoch_schedule, stake_weight_msg_out[0] ); /* start_slot */
32-
stake_weight_msg->slot_cnt = epoch_schedule->slots_per_epoch; /* slot_cnt */
33-
stake_weight_msg->excluded_stake = 0UL; /* excluded stake */
30+
stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */
31+
stake_weight_msg->start_slot = fd_epoch_slot0( &epoch_schedule, stake_weight_msg_out[0] ); /* start_slot */
32+
stake_weight_msg->slot_cnt = epoch_schedule.slots_per_epoch; /* slot_cnt */
33+
stake_weight_msg->excluded_stake = 0UL; /* excluded stake */
3434

3535
return 5*sizeof(ulong) + (stake_weight_idx * sizeof(fd_stake_weight_t));
3636
}

src/discof/replay/fd_replay_tile.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ static void
305305
publish_stake_weights( fd_replay_tile_ctx_t * ctx,
306306
fd_stem_context_t * stem,
307307
fd_exec_slot_ctx_t * slot_ctx ) {
308-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
308+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
309309

310310
fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( slot_ctx->bank );
311311
fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes );
312312

313313
if( epoch_stakes_root!=NULL ) {
314314
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem,
315315
ctx->stake_out->chunk );
316-
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, slot_ctx->slot );
316+
ulong epoch = fd_slot_to_leader_schedule_epoch( &epoch_schedule, slot_ctx->slot );
317317
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch - 1, stake_weights_msg );
318318
ulong stake_weights_sig = 4UL;
319319
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
@@ -328,8 +328,7 @@ publish_stake_weights( fd_replay_tile_ctx_t * ctx,
328328

329329
if( next_epoch_stakes_root!=NULL ) {
330330
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk );
331-
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule,
332-
slot_ctx->slot ); /* epoch */
331+
ulong epoch = fd_slot_to_leader_schedule_epoch( &epoch_schedule, slot_ctx->slot ); /* epoch */
333332
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch, stake_weights_msg );
334333
ulong stake_weights_sig = 4UL;
335334
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
@@ -1444,7 +1443,9 @@ read_snapshot( void * _ctx,
14441443
kickoff_repair_orphans( ctx, stem );
14451444
}
14461445

1446+
fd_epoch_schedule_t const epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( ctx->slot_ctx->sysvar_cache );
14471447
fd_runtime_update_leaders( ctx->slot_ctx->bank,
1448+
&epoch_schedule,
14481449
ctx->slot_ctx->slot,
14491450
ctx->runtime_spad );
14501451
}
@@ -1469,7 +1470,9 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx,
14691470
/* FIXME: This branch does not set up a new block exec ctx
14701471
properly. Needs to do whatever prepare_new_block_execution
14711472
does, but just hacking that in breaks stuff. */
1473+
fd_epoch_schedule_t const epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( ctx->slot_ctx->sysvar_cache );
14721474
fd_runtime_update_leaders( ctx->slot_ctx->bank,
1475+
&epoch_schedule,
14731476
ctx->slot_ctx->slot,
14741477
ctx->runtime_spad );
14751478

src/flamenco/rewards/fd_rewards.c

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ get_inflation_num_slots( fd_exec_slot_ctx_t * slot_ctx,
9494
/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank.rs#L2121 */
9595
static double
9696
slot_in_year_for_inflation( fd_exec_slot_ctx_t * slot_ctx ) {
97-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
98-
99-
ulong num_slots = get_inflation_num_slots( slot_ctx, epoch_schedule, slot_ctx->slot );
97+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
98+
ulong num_slots = get_inflation_num_slots( slot_ctx, &epoch_schedule, slot_ctx->slot );
10099
return (double)num_slots / (double)fd_bank_slots_per_year_get( slot_ctx->bank );
101100
}
102101

@@ -278,7 +277,8 @@ get_slots_in_epoch( ulong epoch,
278277
static double
279278
epoch_duration_in_years( fd_exec_slot_ctx_t * slot_ctx,
280279
ulong prev_epoch ) {
281-
ulong slots_in_epoch = get_slots_in_epoch( prev_epoch, fd_bank_epoch_schedule_query( slot_ctx->bank ) );
280+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
281+
ulong slots_in_epoch = get_slots_in_epoch( prev_epoch, &epoch_schedule );
282282
return (double)slots_in_epoch / (double)fd_bank_slots_per_year_get( slot_ctx->bank );
283283
}
284284

@@ -377,8 +377,7 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx,
377377
ulong rewards,
378378
fd_point_value_t * result,
379379
fd_tpool_t * tpool,
380-
fd_epoch_info_t * temp_info,
381-
fd_spad_t * runtime_spad ) {
380+
fd_epoch_info_t * temp_info ) {
382381

383382
uint128 points = 0;
384383
ulong minimum_stake_delegation = get_minimum_stake_delegation( slot_ctx );
@@ -387,13 +386,12 @@ calculate_reward_points_partitioned( fd_exec_slot_ctx_t * slot_ctx,
387386
int _err[1];
388387
ulong new_warmup_cooldown_rate_epoch_val = 0UL;
389388
ulong * new_warmup_cooldown_rate_epoch = &new_warmup_cooldown_rate_epoch_val;
390-
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot,
391-
slot_ctx->funk,
392-
slot_ctx->funk_txn,
393-
runtime_spad,
394-
fd_bank_features_query( slot_ctx->bank ),
395-
new_warmup_cooldown_rate_epoch,
396-
_err );
389+
int is_some = fd_new_warmup_cooldown_rate_epoch(
390+
slot_ctx->sysvar_cache,
391+
fd_bank_features_query( slot_ctx->bank ),
392+
slot_ctx->slot,
393+
new_warmup_cooldown_rate_epoch,
394+
_err );
397395
if( FD_UNLIKELY( !is_some ) ) {
398396
new_warmup_cooldown_rate_epoch = NULL;
399397
}
@@ -605,13 +603,12 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct
605603
int _err[1];
606604
ulong new_warmup_cooldown_rate_epoch_val = 0UL;
607605
ulong * new_warmup_cooldown_rate_epoch = &new_warmup_cooldown_rate_epoch_val;
608-
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot,
609-
slot_ctx->funk,
610-
slot_ctx->funk_txn,
611-
runtime_spad,
612-
fd_bank_features_query( slot_ctx->bank ),
613-
new_warmup_cooldown_rate_epoch,
614-
_err );
606+
int is_some = fd_new_warmup_cooldown_rate_epoch(
607+
slot_ctx->sysvar_cache,
608+
fd_bank_features_query( slot_ctx->bank ),
609+
slot_ctx->slot,
610+
new_warmup_cooldown_rate_epoch,
611+
_err );
615612
if( FD_UNLIKELY( !is_some ) ) {
616613
new_warmup_cooldown_rate_epoch = NULL;
617614
}
@@ -699,8 +696,10 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
699696
fd_spad_t * * exec_spads,
700697
ulong exec_spad_cnt,
701698
fd_spad_t * runtime_spad ) {
702-
/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
703-
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad );
699+
/* FIXME the reflinks here heavily diverged from upstream Agave */
700+
701+
/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
702+
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_join_const( slot_ctx->sysvar_cache );
704703
if( FD_UNLIKELY( !stake_history ) ) {
705704
FD_LOG_ERR(( "Unable to read and decode stake history sysvar" ));
706705
}
@@ -711,8 +710,7 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
711710
rewards,
712711
&result->point_value,
713712
tpool,
714-
temp_info,
715-
runtime_spad );
713+
temp_info );
716714

717715
/* Calculate the stake and vote rewards for each account */
718716
calculate_stake_vote_rewards( slot_ctx,
@@ -725,6 +723,8 @@ calculate_validator_rewards( fd_exec_slot_ctx_t * slot_ctx,
725723
exec_spads,
726724
exec_spad_cnt,
727725
runtime_spad );
726+
727+
fd_sysvar_stake_history_leave_const( slot_ctx->sysvar_cache, stake_history );
728728
}
729729

730730
/* Calculate the number of blocks required to distribute rewards to all stake accounts.
@@ -837,10 +837,10 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_
837837
runtime_spad );
838838

839839
fd_stake_reward_calculation_t * stake_reward_calculation = &validator_result->calculate_stake_vote_rewards_result.stake_reward_calculation;
840-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
841-
ulong num_partitions = get_reward_distribution_num_blocks( epoch_schedule,
842-
slot_ctx->slot,
843-
stake_reward_calculation->stake_rewards_len );
840+
fd_epoch_schedule_t const epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
841+
842+
ulong num_partitions = get_reward_distribution_num_blocks(
843+
&epoch_schedule, slot_ctx->slot, stake_reward_calculation->stake_rewards_len );
844844
hash_rewards_into_partitions( stake_reward_calculation,
845845
parent_blockhash,
846846
num_partitions,
@@ -1036,8 +1036,7 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx,
10361036
static void
10371037
distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * partition,
10381038
fd_stake_reward_t * pool,
1039-
fd_exec_slot_ctx_t * slot_ctx,
1040-
fd_spad_t * runtime_spad ) {
1039+
fd_exec_slot_ctx_t * slot_ctx ) {
10411040

10421041
ulong lamports_distributed = 0UL;
10431042
ulong lamports_burned = 0UL;
@@ -1059,8 +1058,7 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
10591058

10601059
/* Update the epoch rewards sysvar with the amount distributed and burnt */
10611060
fd_sysvar_epoch_rewards_distribute( slot_ctx,
1062-
lamports_distributed + lamports_burned,
1063-
runtime_spad );
1061+
lamports_distributed + lamports_burned );
10641062

10651063
FD_LOG_DEBUG(( "lamports burned: %lu, lamports distributed: %lu", lamports_burned, lamports_distributed ));
10661064

@@ -1071,15 +1069,7 @@ distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * pa
10711069
10721070
https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L42 */
10731071
void
1074-
fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
1075-
fd_tpool_t * tpool,
1076-
fd_spad_t * * exec_spads,
1077-
ulong exec_spad_cnt,
1078-
fd_spad_t * runtime_spad ) {
1079-
1080-
(void)tpool;
1081-
(void)exec_spads;
1082-
(void)exec_spad_cnt;
1072+
fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx ) {
10831073

10841074
fd_epoch_reward_status_global_t const * epoch_reward_status = fd_bank_epoch_reward_status_locking_query( slot_ctx->bank );
10851075

@@ -1102,27 +1092,26 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
11021092
ulong distribution_starting_block_height = status->distribution_starting_block_height;
11031093
ulong distribution_end_exclusive = distribution_starting_block_height + status->partitioned_stake_rewards.partitions_len;
11041094

1105-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
1106-
ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL );
1095+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
1096+
ulong epoch = fd_slot_to_epoch( &epoch_schedule, slot_ctx->slot, NULL );
11071097

1108-
if( FD_UNLIKELY( get_slots_in_epoch( epoch, epoch_schedule ) <= status->partitioned_stake_rewards.partitions_len ) ) {
1098+
if( FD_UNLIKELY( get_slots_in_epoch( epoch, &epoch_schedule ) <= status->partitioned_stake_rewards.partitions_len ) ) {
11091099
FD_LOG_ERR(( "Should not be distributing rewards" ));
11101100
}
11111101

11121102
if( (height>=distribution_starting_block_height) && (height < distribution_end_exclusive) ) {
11131103
ulong partition_index = height - distribution_starting_block_height;
11141104
distribute_epoch_rewards_in_partition( &partitions[ partition_index ],
11151105
pool,
1116-
slot_ctx,
1117-
runtime_spad );
1106+
slot_ctx );
11181107
}
11191108

11201109
fd_bank_epoch_reward_status_end_locking_query( slot_ctx->bank );
11211110

11221111
/* If we have finished distributing rewards, set the status to inactive */
11231112
if( fd_ulong_sat_add( height, 1UL ) >= distribution_end_exclusive ) {
11241113
set_epoch_reward_status_inactive( slot_ctx );
1125-
fd_sysvar_epoch_rewards_set_inactive( slot_ctx, runtime_spad );
1114+
fd_sysvar_epoch_rewards_set_inactive( slot_ctx );
11261115
}
11271116
}
11281117

@@ -1181,8 +1170,9 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
11811170
fd_spad_t * * exec_spads,
11821171
ulong exec_spad_cnt,
11831172
fd_spad_t * runtime_spad ) {
1184-
fd_sysvar_epoch_rewards_t * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad );
1185-
if( FD_UNLIKELY( epoch_rewards == NULL ) ) {
1173+
fd_sysvar_epoch_rewards_t epoch_rewards_;
1174+
fd_sysvar_epoch_rewards_t const * epoch_rewards = fd_sysvar_epoch_rewards_read( slot_ctx->sysvar_cache, &epoch_rewards_ );
1175+
if( FD_UNLIKELY( !epoch_rewards ) ) {
11861176
FD_LOG_NOTICE(( "Failed to read or decode epoch rewards sysvar - may not have been created yet" ));
11871177
set_epoch_reward_status_inactive( slot_ctx );
11881178
return;
@@ -1204,24 +1194,23 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
12041194
https://github.com/anza-xyz/agave/blob/2316fea4c0852e59c071f72d72db020017ffd7d0/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L566 */
12051195
FD_LOG_NOTICE(( "epoch rewards is active" ));
12061196

1207-
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
1208-
ulong epoch = fd_slot_to_epoch( epoch_schedule, slot_ctx->slot, NULL );
1197+
fd_epoch_schedule_t epoch_schedule = fd_sysvar_epoch_schedule_read_nofail( slot_ctx->sysvar_cache );
1198+
ulong epoch = fd_slot_to_epoch( &epoch_schedule, slot_ctx->slot, NULL );
12091199
ulong rewarded_epoch = fd_ulong_sat_sub( epoch, 1UL );
12101200

12111201
int _err[1] = {0};
1212-
ulong * new_warmup_cooldown_rate_epoch = fd_spad_alloc( runtime_spad, alignof(ulong), sizeof(ulong) );
1213-
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->slot,
1214-
slot_ctx->funk,
1215-
slot_ctx->funk_txn,
1216-
runtime_spad,
1202+
ulong new_warmup_cooldown_rate_epoch_;
1203+
ulong * new_warmup_cooldown_rate_epoch = &new_warmup_cooldown_rate_epoch_;
1204+
int is_some = fd_new_warmup_cooldown_rate_epoch( slot_ctx->sysvar_cache,
12171205
fd_bank_features_query( slot_ctx->bank ),
1206+
slot_ctx->slot,
12181207
new_warmup_cooldown_rate_epoch,
12191208
_err );
12201209
if( FD_UNLIKELY( !is_some ) ) {
12211210
new_warmup_cooldown_rate_epoch = NULL;
12221211
}
12231212

1224-
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( slot_ctx->funk, slot_ctx->funk_txn, runtime_spad );
1213+
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_join_const( slot_ctx->sysvar_cache );
12251214
if( FD_UNLIKELY( !stake_history ) ) {
12261215
FD_LOG_ERR(( "Unable to read and decode stake history sysvar" ));
12271216
}

src/flamenco/rewards/fd_rewards.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
5252
fd_spad_t * runtime_spad );
5353

5454
void
55-
fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx,
56-
fd_tpool_t * tpool,
57-
fd_spad_t * * exec_spads,
58-
ulong exec_spad_cnt,
59-
fd_spad_t * runtime_spad );
55+
fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx );
6056

6157
FD_PROTOTYPES_END
6258

src/flamenco/runtime/context/fd_exec_instr_ctx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "../info/fd_instr_info.h"
55
#include "../fd_executor_err.h"
6+
#include "../sysvar/fd_sysvar_cache.h"
67

78
/* Avoid circular include dependency with forward declaration */
89
struct fd_borrowed_account;
@@ -16,6 +17,7 @@ struct fd_exec_instr_ctx {
1617
uint depth; /* starts at 0 */
1718
fd_instr_info_t const * instr; /* The instruction info for this instruction */
1819
fd_exec_txn_ctx_t * txn_ctx; /* The transaction context for this instruction */
20+
fd_sysvar_cache_t const * sysvar_cache;
1921

2022
/* Most instructions log the base58 program id multiple times, so it's
2123
convenient to compute it once and reuse it. */

0 commit comments

Comments
 (0)