Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reward/penalties processing #6819

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
optimized slightly
  • Loading branch information
Giulio2002 committed Feb 9, 2023
commit 9def107b036c82dac1a44e47e316d3892b375fb5
13 changes: 7 additions & 6 deletions cmd/erigon-cl/core/state/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (b *BeaconState) inactivityLeaking() bool {

// Implementation defined in ETH 2.0 specs: https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#get_flag_index_deltas.
// Although giulio made it efficient hopefully. results will be written in the input map.
func (b *BeaconState) processFlagIndexDeltas(flagIdx int, balanceDeltaMap map[uint64]int64) (err error) {
func (b *BeaconState) processFlagIndexDeltas(flagIdx int, balanceDeltaMap map[uint64]int64, eligibleValidators []uint64) (err error) {
// Initialize variables
var (
unslashedParticipatingIndicies []uint64
Expand Down Expand Up @@ -454,7 +454,7 @@ func (b *BeaconState) processFlagIndexDeltas(flagIdx int, balanceDeltaMap map[ui
activeIncrements := b.GetTotalActiveBalance() / b.beaconConfig.EffectiveBalanceIncrement
totalActiveBalance := b.GetTotalActiveBalance()
// Now process deltas and whats nots.
for _, index := range b.EligibleValidatorsIndicies() {
for _, index := range eligibleValidators {
if _, ok := isUnslashedParticipatingIndicies[index]; ok {
if b.inactivityLeaking() {
continue
Expand All @@ -473,7 +473,7 @@ func (b *BeaconState) processFlagIndexDeltas(flagIdx int, balanceDeltaMap map[ui
}

// Implemention defined in https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas.
func (b *BeaconState) processInactivityDeltas(balanceDeltaMap map[uint64]int64) (err error) {
func (b *BeaconState) processInactivityDeltas(balanceDeltaMap map[uint64]int64, eligibleValidators []uint64) (err error) {
var (
unslashedParticipatingIndicies []uint64
validator cltypes.Validator
Expand All @@ -499,7 +499,7 @@ func (b *BeaconState) processInactivityDeltas(balanceDeltaMap map[uint64]int64)
case clparams.BellatrixVersion:
penaltyQuotient = b.beaconConfig.InactivityPenaltyQuotientBellatrix
}
for _, index := range b.EligibleValidatorsIndicies() {
for _, index := range eligibleValidators {
if _, ok := isUnslashedParticipatingIndicies[index]; ok {
continue
}
Expand All @@ -517,13 +517,14 @@ func (b *BeaconState) processInactivityDeltas(balanceDeltaMap map[uint64]int64)
// BalanceDeltas return the delta for each validator index.
func (b *BeaconState) BalanceDeltas() (balanceDeltaMap map[uint64]int64, err error) {
balanceDeltaMap = map[uint64]int64{}
eligibleValidators := b.EligibleValidatorsIndicies()
// process each flag indexes by weight.
for i := range b.beaconConfig.ParticipationWeights() {
if err = b.processFlagIndexDeltas(i, balanceDeltaMap); err != nil {
if err = b.processFlagIndexDeltas(i, balanceDeltaMap, eligibleValidators); err != nil {
return
}
}
// process inactivity scores now.
err = b.processInactivityDeltas(balanceDeltaMap)
err = b.processInactivityDeltas(balanceDeltaMap, eligibleValidators)
return
}