Skip to content
Open
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
26 changes: 22 additions & 4 deletions src/flamenco/rewards/fd_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/sdk/src/inflation.rs#L85 */
static double
total( fd_inflation_t const * inflation, double year ) {
if ( FD_UNLIKELY( year == 0.0 ) ) {
FD_LOG_ERR(( "inflation year 0" ));
}
if( FD_UNLIKELY( year < DBL_EPSILON ) ) FD_LOG_ERR(( "invalid inflation year parameter (corrupt genesis config?)" ));
double tapered = inflation->initial * pow( (1.0 - inflation->taper), year );
return (tapered > inflation->terminal) ? tapered : inflation->terminal;
}
Expand Down Expand Up @@ -88,6 +86,11 @@ static double
slot_in_year_for_inflation( fd_bank_t const * bank ) {
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
ulong num_slots = get_inflation_num_slots( bank, epoch_schedule, fd_bank_slot_get( bank ) );
FD_LOG_DEBUG(( "slot_in_year_for_inflation:"
" num_slots=%lu"
" slots_per_year=%g",
num_slots,
fd_bank_slots_per_year_get( bank ) ));
return (double)num_slots / (double)fd_bank_slots_per_year_get( bank );
}

Expand Down Expand Up @@ -441,7 +444,17 @@ calculate_previous_epoch_inflation_rewards( fd_bank_t const *
rewards->foundation_rate = foundation( fd_bank_inflation_query( bank ), slot_in_year );
rewards->prev_epoch_duration_in_years = epoch_duration_in_years( bank, prev_epoch );
rewards->validator_rewards = (ulong)(rewards->validator_rate * (double)prev_epoch_capitalization * rewards->prev_epoch_duration_in_years);
FD_LOG_DEBUG(( "Rewards %lu, Rate %.16f, Duration %.18f Capitalization %lu Slot in year %.16f", rewards->validator_rewards, rewards->validator_rate, rewards->prev_epoch_duration_in_years, prev_epoch_capitalization, slot_in_year ));
FD_LOG_DEBUG(( "calculate_previous_epoch_inflation_rewards:"
" slot_in_year=%g"
" valdiator_rewards=%lu"
" validator_rate=%g"
" prev_epoch_duration_in_years=%g"
" prev_epoch_capitalization=%lu",
slot_in_year,
rewards->validator_rewards,
rewards->validator_rate,
rewards->prev_epoch_duration_in_years,
prev_epoch_capitalization ));
}

/* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/lib.rs#L29 */
Expand Down Expand Up @@ -998,6 +1011,11 @@ fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank,
ulong distribution_starting_block_height = epoch_rewards->starting_block_height;
ulong distribution_end_exclusive = fd_epoch_rewards_get_exclusive_ending_block_height( epoch_rewards );

if( block_height < distribution_starting_block_height ) {
fd_bank_epoch_rewards_end_locking_query( bank );
return;
}

fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
ulong epoch = fd_bank_epoch_get( bank );

Expand Down
17 changes: 16 additions & 1 deletion src/flamenco/runtime/tests/fd_block_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ fd_solfuzz_pb_block_ctx_destroy( fd_solfuzz_runner_t * runner ) {
fd_progcache_clear( runner->progcache_admin );
}

static double
years_as_slots( double years,
ulong tick_duration_ns,
ulong ticks_per_slot ) {
return years * SECONDS_PER_YEAR * (1e9 / (double)tick_duration_ns) / (double)ticks_per_slot;
}

/* Sets up block execution context from an input test case to execute
against the runtime. Returns block_info on success and NULL on
failure. */
Expand Down Expand Up @@ -296,7 +303,15 @@ fd_solfuzz_pb_block_ctx_create( fd_solfuzz_runner_t * runner,

fd_bank_genesis_creation_time_set( bank, test_ctx->epoch_ctx.genesis_creation_time );

fd_bank_slots_per_year_set( bank, test_ctx->epoch_ctx.slots_per_year );
double slots_per_year = years_as_slots( 1.0, 6250000, test_ctx->epoch_ctx.ticks_per_slot );
if( FD_UNLIKELY( test_ctx->epoch_ctx.ticks_per_slot < 1 ||
test_ctx->epoch_ctx.ticks_per_slot > 1000 ||
slots_per_year<1000. ||
slots_per_year>10e9 ) ) {
FD_LOG_ERR(( "invalid ticks_per_slot value: %lu", test_ctx->epoch_ctx.ticks_per_slot ));
}

fd_bank_slots_per_year_set( bank, slots_per_year );

fd_bank_parent_signature_cnt_set( bank, test_ctx->slot_ctx.parent_signature_count );

Expand Down
Loading