forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added effective balances processing (erigontech#6822)
- Loading branch information
1 parent
07af929
commit c41087a
Showing
4 changed files
with
66 additions
and
34 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
cmd/erigon-cl/core/transition/process_effective_balance_update.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package transition | ||
|
||
// ProcessEffectiveBalanceUpdates updates the effective balance of validators. Specs at: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates | ||
func (s *StateTransistor) ProcessEffectiveBalanceUpdates() error { | ||
histeresisIncrement := s.beaconConfig.EffectiveBalanceIncrement / s.beaconConfig.HysteresisQuotient | ||
downwardThreshold := histeresisIncrement * s.beaconConfig.HysteresisDownwardMultiplier | ||
upwardThreshold := histeresisIncrement * s.beaconConfig.HysteresisUpwardMultiplier | ||
for index, validator := range s.state.Validators() { | ||
balance, err := s.state.ValidatorBalance(index) | ||
if err != nil { | ||
return err | ||
} | ||
if balance+downwardThreshold < validator.EffectiveBalance || | ||
validator.EffectiveBalance+upwardThreshold < balance { | ||
validator.EffectiveBalance = balance - balance%s.beaconConfig.EffectiveBalanceIncrement | ||
if validator.EffectiveBalance > s.beaconConfig.MaxEffectiveBalance { | ||
validator.EffectiveBalance = s.beaconConfig.MaxEffectiveBalance | ||
} | ||
if err := s.state.SetValidatorAt(index, validator); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+170 KB
cmd/erigon-cl/core/transition/test_data/effective_balances_expected.ssz_snappy
Binary file not shown.
Binary file added
BIN
+170 KB
cmd/erigon-cl/core/transition/test_data/effective_balances_test_state.ssz_snappy
Binary file not shown.