diff --git a/consensus-types/types/validator.go b/consensus-types/types/validator.go index 79630c6e1..b7dcb8e87 100644 --- a/consensus-types/types/validator.go +++ b/consensus-types/types/validator.go @@ -246,9 +246,7 @@ func (v Validator) IsActive(epoch math.Epoch) bool { // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue // //nolint:lll -func (v Validator) IsEligibleForActivation( - finalizedEpoch math.Epoch, -) bool { +func (v Validator) IsEligibleForActivation(finalizedEpoch math.Epoch) bool { return v.ActivationEligibilityEpoch <= finalizedEpoch && v.ActivationEpoch == math.Epoch(constants.FarFutureEpoch) } @@ -337,6 +335,14 @@ func (v *Validator) GetActivationEligibilityEpoch() math.Epoch { return v.ActivationEligibilityEpoch } +func (v *Validator) SetActivationEpoch(e math.Epoch) { + v.ActivationEpoch = e +} + +func (v *Validator) GetActivationEpoch() math.Epoch { + return v.ActivationEpoch +} + // GetWithdrawalCredentials returns the withdrawal credentials of the validator. func (v Validator) GetWithdrawalCredentials() WithdrawalCredentials { return v.WithdrawalCredentials diff --git a/state-transition/core/state_processor_genesis.go b/state-transition/core/state_processor_genesis.go index d65685d83..bce1f1fc7 100644 --- a/state-transition/core/state_processor_genesis.go +++ b/state-transition/core/state_processor_genesis.go @@ -120,6 +120,7 @@ func (sp *StateProcessor[ var idx math.ValidatorIndex for _, val := range vals { val.SetActivationEligibilityEpoch(0) + val.SetActivationEpoch(0) idx, err = st.ValidatorIndexByPubkey(val.GetPubkey()) if err != nil { return nil, err diff --git a/state-transition/core/state_processor_genesis_test.go b/state-transition/core/state_processor_genesis_test.go index 730e5e65f..8cdf496f4 100644 --- a/state-transition/core/state_processor_genesis_test.go +++ b/state-transition/core/state_processor_genesis_test.go @@ -157,6 +157,7 @@ func checkValidatorNonBartio( // checks on validators for any network but Bartio require.Equal(t, math.Epoch(0), val.GetActivationEligibilityEpoch()) + require.Equal(t, math.Epoch(0), val.GetActivationEpoch()) valBal, err := bs.GetBalance(idx) require.NoError(t, err) @@ -284,6 +285,17 @@ func checkValidatorBartio( // checks on validators common to all networks commonChecksValidators(t, cs, val, dep) + require.Equal( + t, + math.Epoch(constants.FarFutureEpoch), + val.GetActivationEligibilityEpoch(), + ) + require.Equal( + t, + math.Epoch(constants.FarFutureEpoch), + val.GetActivationEpoch(), + ) + // Bartio specific checks on validators valBal, err := bs.GetBalance(idx) require.NoError(t, err) diff --git a/state-transition/core/state_processor_validators.go b/state-transition/core/state_processor_validators.go index 953646ab7..aedeca36e 100644 --- a/state-transition/core/state_processor_validators.go +++ b/state-transition/core/state_processor_validators.go @@ -49,10 +49,20 @@ func (sp *StateProcessor[ minEffectiveBalance := math.Gwei(sp.cs.EjectionBalance() + sp.cs.EffectiveBalanceIncrement()) + // We do not currently have a cap on validator churn, + // so we can process validators in a single loop var idx math.ValidatorIndex for si, val := range vals { + valModified := false if val.IsEligibleForActivationQueue(minEffectiveBalance) { val.SetActivationEligibilityEpoch(nextEpoch) + valModified = true + } + if val.IsEligibleForActivation(currEpoch) { + val.SetActivationEpoch(nextEpoch) + valModified = true + } + if valModified { idx, err = st.ValidatorIndexByPubkey(val.GetPubkey()) if err != nil { return fmt.Errorf("registry update, failed loading validator index, state index %d: %w", si, err) diff --git a/state-transition/core/types.go b/state-transition/core/types.go index 9412acb90..f56ba84ea 100644 --- a/state-transition/core/types.go +++ b/state-transition/core/types.go @@ -244,6 +244,8 @@ type Validator[ IsSlashed() bool IsEligibleForActivationQueue(threshold math.Gwei) bool + IsEligibleForActivation(finalizedEpoch math.Epoch) bool + // GetPubkey returns the public key of the validator. GetPubkey() crypto.BLSPubkey // GetEffectiveBalance returns the effective balance of the validator in @@ -258,6 +260,9 @@ type Validator[ GetActivationEligibilityEpoch() math.Epoch SetActivationEligibilityEpoch(math.Epoch) + + GetActivationEpoch() math.Epoch + SetActivationEpoch(math.Epoch) } type Validators interface {