From 45d2df1af7ef413f6f47c4260ed08671478373bf Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 13 Apr 2021 20:44:33 +0800 Subject: [PATCH] Simplify Effective Balance Calculation (#8743) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/core/epoch/epoch_processing.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index 2a09f2370..a7d49ffcb 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -252,12 +252,16 @@ func ProcessEffectiveBalanceUpdates(state iface.BeaconState) (iface.BeaconState, balance := bals[idx] if balance+downwardThreshold < val.EffectiveBalance || val.EffectiveBalance+upwardThreshold < balance { - newVal := stateV0.CopyValidator(val) - newVal.EffectiveBalance = maxEffBalance - if newVal.EffectiveBalance > balance-balance%effBalanceInc { - newVal.EffectiveBalance = balance - balance%effBalanceInc + effectiveBal := maxEffBalance + if effectiveBal > balance-balance%effBalanceInc { + effectiveBal = balance - balance%effBalanceInc } - return true, newVal, nil + if effectiveBal != val.EffectiveBalance { + newVal := stateV0.CopyValidator(val) + newVal.EffectiveBalance = effectiveBal + return true, newVal, nil + } + return false, val, nil } return false, val, nil }