|
1 | 1 | #include "fd_rewards.h" |
| 2 | +#include <cfloat> |
2 | 3 | #include <math.h> |
3 | 4 |
|
4 | 5 | #include "../runtime/fd_acc_mgr.h" |
|
17 | 18 | /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/sdk/src/inflation.rs#L85 */ |
18 | 19 | static double |
19 | 20 | total( fd_inflation_t const * inflation, double year ) { |
20 | | - if ( FD_UNLIKELY( year == 0.0 ) ) { |
21 | | - FD_LOG_ERR(( "inflation year 0" )); |
22 | | - } |
| 21 | + if( FD_UNLIKELY( year < DBL_EPSILON ) ) FD_LOG_ERR(( "invalid inflation year parameter (corrupt genesis config?)" )); |
23 | 22 | double tapered = inflation->initial * pow( (1.0 - inflation->taper), year ); |
24 | 23 | return (tapered > inflation->terminal) ? tapered : inflation->terminal; |
25 | 24 | } |
@@ -88,6 +87,11 @@ static double |
88 | 87 | slot_in_year_for_inflation( fd_bank_t const * bank ) { |
89 | 88 | fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); |
90 | 89 | ulong num_slots = get_inflation_num_slots( bank, epoch_schedule, fd_bank_slot_get( bank ) ); |
| 90 | + FD_LOG_DEBUG(( "slot_in_year_for_inflation:" |
| 91 | + " num_slots=%lu" |
| 92 | + " slots_per_year=%g", |
| 93 | + num_slots, |
| 94 | + fd_bank_slots_per_year_get( bank ) )); |
91 | 95 | return (double)num_slots / (double)fd_bank_slots_per_year_get( bank ); |
92 | 96 | } |
93 | 97 |
|
@@ -441,7 +445,17 @@ calculate_previous_epoch_inflation_rewards( fd_bank_t const * |
441 | 445 | rewards->foundation_rate = foundation( fd_bank_inflation_query( bank ), slot_in_year ); |
442 | 446 | rewards->prev_epoch_duration_in_years = epoch_duration_in_years( bank, prev_epoch ); |
443 | 447 | rewards->validator_rewards = (ulong)(rewards->validator_rate * (double)prev_epoch_capitalization * rewards->prev_epoch_duration_in_years); |
444 | | - 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 )); |
| 448 | + FD_LOG_DEBUG(( "calculate_previous_epoch_inflation_rewards:" |
| 449 | + " slot_in_year=%g" |
| 450 | + " valdiator_rewards=%lu" |
| 451 | + " validator_rate=%g" |
| 452 | + " prev_epoch_duration_in_years=%g" |
| 453 | + " prev_epoch_capitalization=%lu", |
| 454 | + slot_in_year, |
| 455 | + rewards->validator_rewards, |
| 456 | + rewards->validator_rate, |
| 457 | + rewards->prev_epoch_duration_in_years, |
| 458 | + prev_epoch_capitalization )); |
445 | 459 | } |
446 | 460 |
|
447 | 461 | /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/lib.rs#L29 */ |
@@ -998,6 +1012,11 @@ fd_distribute_partitioned_epoch_rewards( fd_bank_t * bank, |
998 | 1012 | ulong distribution_starting_block_height = epoch_rewards->starting_block_height; |
999 | 1013 | ulong distribution_end_exclusive = fd_epoch_rewards_get_exclusive_ending_block_height( epoch_rewards ); |
1000 | 1014 |
|
| 1015 | + if( block_height < distribution_starting_block_height ) { |
| 1016 | + fd_bank_epoch_rewards_end_locking_query( bank ); |
| 1017 | + return; |
| 1018 | + } |
| 1019 | + |
1001 | 1020 | fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank ); |
1002 | 1021 | ulong epoch = fd_bank_epoch_get( bank ); |
1003 | 1022 |
|
|
0 commit comments