Wrong rpc inflation rate (#14063)

* Fix wrong inflation calculation in rpc

* Reorder

* Fix test
This commit is contained in:
Ryo Onodera
2020-12-11 16:42:39 +09:00
committed by GitHub
parent 4fba7e6865
commit 09bd412b13
2 changed files with 16 additions and 14 deletions

View File

@ -1511,6 +1511,13 @@ impl Bank {
self.epoch_schedule.get_first_slot_in_epoch(self.epoch()) - inflation_start_slot
}
pub fn slot_in_year_for_inflation(&self) -> f64 {
let num_slots = self.get_inflation_num_slots();
// calculated as: num_slots / (slots / year)
num_slots as f64 / self.slots_per_year
}
// update rewards based on the previous epoch
fn update_rewards(
&mut self,
@ -1522,10 +1529,7 @@ impl Bank {
}
// if I'm the first Bank in an epoch, count, claim, disburse rewards from Inflation
// calculated as: num_slots / (slots / year)
let num_slots = self.get_inflation_num_slots();
let slot_in_year = num_slots as f64 / self.slots_per_year;
let slot_in_year = self.slot_in_year_for_inflation();
let epoch_duration_in_years = self.epoch_duration_in_years(prev_epoch);
let (validator_rate, foundation_rate) = {