Refactor EligibleForRewards into its own helper (#8739)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence tsao 2021-04-12 13:26:08 -07:00 committed by GitHub
parent 76e36b95f7
commit 1c1bf37b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,8 +70,7 @@ func AttestationsDelta(state iface.ReadOnlyBeaconState, pBal *Balance, vp []*Val
} }
func attestationDelta(pBal *Balance, v *Validator, prevEpoch, finalizedEpoch types.Epoch) (uint64, uint64) { func attestationDelta(pBal *Balance, v *Validator, prevEpoch, finalizedEpoch types.Epoch) (uint64, uint64) {
eligible := v.IsActivePrevEpoch || (v.IsSlashed && !v.IsWithdrawableCurrentEpoch) if !EligibleForRewards(v) || pBal.ActiveCurrentEpoch == 0 {
if !eligible || pBal.ActiveCurrentEpoch == 0 {
return 0, 0 return 0, 0
} }
@ -177,3 +176,11 @@ func ProposersDelta(state iface.ReadOnlyBeaconState, pBal *Balance, vp []*Valida
} }
return rewards, nil return rewards, nil
} }
// EligibleForRewards for validator.
//
// Spec code:
// if is_active_validator(v, previous_epoch) or (v.slashed and previous_epoch + 1 < v.withdrawable_epoch)
func EligibleForRewards(v *Validator) bool {
return v.IsActivePrevEpoch || (v.IsSlashed && !v.IsWithdrawableCurrentEpoch)
}