mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/validator"
|
|
)
|
|
|
|
// ValidatorStatus returns a validator's status at the given epoch.
|
|
func ValidatorStatus(val state.ReadOnlyValidator, epoch primitives.Epoch) (validator.Status, error) {
|
|
valStatus, err := ValidatorSubStatus(val, epoch)
|
|
if err != nil {
|
|
return 0, errors.Wrap(err, "could not get validator sub status")
|
|
}
|
|
switch valStatus {
|
|
case validator.PendingInitialized, validator.PendingQueued:
|
|
return validator.Pending, nil
|
|
case validator.ActiveOngoing, validator.ActiveSlashed, validator.ActiveExiting:
|
|
return validator.Active, nil
|
|
case validator.ExitedUnslashed, validator.ExitedSlashed:
|
|
return validator.Exited, nil
|
|
case validator.WithdrawalPossible, validator.WithdrawalDone:
|
|
return validator.Withdrawal, nil
|
|
}
|
|
return 0, errors.New("invalid validator state")
|
|
}
|
|
|
|
// ValidatorSubStatus returns a validator's sub-status at the given epoch.
|
|
func ValidatorSubStatus(val state.ReadOnlyValidator, epoch primitives.Epoch) (validator.Status, error) {
|
|
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
|
|
|
|
// Pending.
|
|
if val.ActivationEpoch() > epoch {
|
|
if val.ActivationEligibilityEpoch() == farFutureEpoch {
|
|
return validator.PendingInitialized, nil
|
|
} else if val.ActivationEligibilityEpoch() < farFutureEpoch {
|
|
return validator.PendingQueued, nil
|
|
}
|
|
}
|
|
|
|
// Active.
|
|
if val.ActivationEpoch() <= epoch && epoch < val.ExitEpoch() {
|
|
if val.ExitEpoch() == farFutureEpoch {
|
|
return validator.ActiveOngoing, nil
|
|
} else if val.ExitEpoch() < farFutureEpoch {
|
|
if val.Slashed() {
|
|
return validator.ActiveSlashed, nil
|
|
}
|
|
return validator.ActiveExiting, nil
|
|
}
|
|
}
|
|
|
|
// Exited.
|
|
if val.ExitEpoch() <= epoch && epoch < val.WithdrawableEpoch() {
|
|
if val.Slashed() {
|
|
return validator.ExitedSlashed, nil
|
|
}
|
|
return validator.ExitedUnslashed, nil
|
|
}
|
|
|
|
if val.WithdrawableEpoch() <= epoch {
|
|
if val.EffectiveBalance() != 0 {
|
|
return validator.WithdrawalPossible, nil
|
|
} else {
|
|
return validator.WithdrawalDone, nil
|
|
}
|
|
}
|
|
|
|
return 0, errors.New("invalid validator state")
|
|
}
|