From 4a446329b299663c485a954b5057e2ad0bee1f93 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 14 Feb 2020 08:59:21 -0800 Subject: [PATCH] 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 --- validator/client/validator_metrics.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/client/validator_metrics.go b/validator/client/validator_metrics.go index 5670487b9..09ddadc8e 100644 --- a/validator/client/validator_metrics.go +++ b/validator/client/validator_metrics.go @@ -75,9 +75,9 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) if slot < params.BeaconConfig().SlotsPerEpoch { 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) percentNet := (newBalance - prevBalance) / prevBalance log.WithFields(logrus.Fields{