2020-01-19 23:33:28 +00:00
|
|
|
use integer_sqrt::IntegerSquareRoot;
|
|
|
|
use types::*;
|
|
|
|
|
|
|
|
/// Returns the base reward for some validator.
|
|
|
|
///
|
2020-04-01 11:03:03 +00:00
|
|
|
/// Spec v0.11.1
|
2020-01-19 23:33:28 +00:00
|
|
|
pub fn get_base_reward<T: EthSpec>(
|
|
|
|
state: &BeaconState<T>,
|
|
|
|
index: usize,
|
|
|
|
// Should be == get_total_active_balance(state, spec)
|
|
|
|
total_active_balance: u64,
|
|
|
|
spec: &ChainSpec,
|
|
|
|
) -> Result<u64, BeaconStateError> {
|
|
|
|
if total_active_balance == 0 {
|
|
|
|
Ok(0)
|
|
|
|
} else {
|
|
|
|
Ok(
|
|
|
|
state.get_effective_balance(index, spec)? * spec.base_reward_factor
|
|
|
|
/ total_active_balance.integer_sqrt()
|
|
|
|
/ spec.base_rewards_per_epoch,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|