Prevent balance goes out of bound (#4865)

* Prevent balance goes out of bound
* Prevent balance goes out of bound
* Merge branch 'master' into fix-balance
This commit is contained in:
terence tsao 2020-02-14 08:59:21 -08:00 committed by GitHub
parent 6b40fa01ec
commit 4a446329b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,9 +75,9 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64)
if slot < params.BeaconConfig().SlotsPerEpoch { if slot < params.BeaconConfig().SlotsPerEpoch {
v.prevBalance[bytesutil.ToBytes48(pkey)] = params.BeaconConfig().MaxEffectiveBalance v.prevBalance[bytesutil.ToBytes48(pkey)] = params.BeaconConfig().MaxEffectiveBalance
} }
newBalance := float64(resp.BalancesAfterEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth)
if v.prevBalance[bytesutil.ToBytes48(pkey)] > 0 { if v.prevBalance[bytesutil.ToBytes48(pkey)] > 0 && len(resp.BalancesAfterEpochTransition) > i {
newBalance := float64(resp.BalancesAfterEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth)
prevBalance := float64(resp.BalancesBeforeEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth) prevBalance := float64(resp.BalancesBeforeEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth)
percentNet := (newBalance - prevBalance) / prevBalance percentNet := (newBalance - prevBalance) / prevBalance
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{