(cherry picked from commit 89bca6110a
)
Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
This commit is contained in:
@ -920,24 +920,26 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update reward for previous epoch
|
// update reward for previous epoch
|
||||||
fn update_rewards(&mut self, epoch: Epoch) {
|
fn update_rewards(&mut self, prev_epoch: Epoch) {
|
||||||
if epoch == self.epoch() {
|
if prev_epoch == self.epoch() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if I'm the first Bank in an epoch, count, claim, disburse rewards from Inflation
|
// if I'm the first Bank in an epoch, count, claim, disburse rewards from Inflation
|
||||||
|
|
||||||
// years_elapsed = slots_elapsed / slots/year
|
// calculated as: prev_slot / (slots / year)
|
||||||
let year = (self.epoch_schedule.get_last_slot_in_epoch(epoch)) as f64 / self.slots_per_year;
|
let slot_in_year =
|
||||||
|
(self.epoch_schedule.get_last_slot_in_epoch(prev_epoch)) as f64 / self.slots_per_year;
|
||||||
|
|
||||||
// period: time that has passed as a fraction of a year, basically the length of
|
// period: time that has passed as a fraction of a year, basically the length of
|
||||||
// an epoch as a fraction of a year
|
// an epoch as a fraction of a year
|
||||||
// years_elapsed = slots_elapsed / slots/year
|
// calculated as: slots_elapsed / (slots / year)
|
||||||
let period = self.epoch_schedule.get_slots_in_epoch(epoch) as f64 / self.slots_per_year;
|
let period_in_year =
|
||||||
|
self.epoch_schedule.get_slots_in_epoch(prev_epoch) as f64 / self.slots_per_year;
|
||||||
|
|
||||||
let validator_rewards = {
|
let validator_rewards = {
|
||||||
let inflation = self.inflation.read().unwrap();
|
let inflation = self.inflation.read().unwrap();
|
||||||
|
|
||||||
(*inflation).validator(year) * self.capitalization() as f64 * period
|
(*inflation).validator(slot_in_year) * self.capitalization() as f64 * period_in_year
|
||||||
} as u64;
|
} as u64;
|
||||||
|
|
||||||
let vote_balance_and_staked = self.stakes.read().unwrap().vote_balance_and_staked();
|
let vote_balance_and_staked = self.stakes.read().unwrap().vote_balance_and_staked();
|
||||||
|
@ -55,6 +55,7 @@ impl Inflation {
|
|||||||
}
|
}
|
||||||
/// inflation rate at year
|
/// inflation rate at year
|
||||||
pub fn total(&self, year: f64) -> f64 {
|
pub fn total(&self, year: f64) -> f64 {
|
||||||
|
assert!(year >= 0.0);
|
||||||
let tapered = self.initial * ((1.0 - self.taper).powf(year));
|
let tapered = self.initial * ((1.0 - self.taper).powf(year));
|
||||||
|
|
||||||
if tapered > self.terminal {
|
if tapered > self.terminal {
|
||||||
|
Reference in New Issue
Block a user