mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/eth/v1"
|
|
)
|
|
|
|
// ValidatorStatus returns a validator's status at the given epoch.
|
|
func ValidatorStatus(validator state.ReadOnlyValidator, epoch types.Epoch) (ethpb.ValidatorStatus, error) {
|
|
valStatus, err := ValidatorSubStatus(validator, epoch)
|
|
if err != nil {
|
|
return 0, errors.Wrap(err, "could not get sub status")
|
|
}
|
|
switch valStatus {
|
|
case ethpb.ValidatorStatus_PENDING_INITIALIZED, ethpb.ValidatorStatus_PENDING_QUEUED:
|
|
return ethpb.ValidatorStatus_PENDING, nil
|
|
case ethpb.ValidatorStatus_ACTIVE_ONGOING, ethpb.ValidatorStatus_ACTIVE_SLASHED, ethpb.ValidatorStatus_ACTIVE_EXITING:
|
|
return ethpb.ValidatorStatus_ACTIVE, nil
|
|
case ethpb.ValidatorStatus_EXITED_UNSLASHED, ethpb.ValidatorStatus_EXITED_SLASHED:
|
|
return ethpb.ValidatorStatus_EXITED, nil
|
|
case ethpb.ValidatorStatus_WITHDRAWAL_POSSIBLE, ethpb.ValidatorStatus_WITHDRAWAL_DONE:
|
|
return ethpb.ValidatorStatus_WITHDRAWAL, nil
|
|
}
|
|
return 0, errors.New("invalid validator state")
|
|
}
|
|
|
|
// ValidatorSubStatus returns a validator's sub-status at the given epoch.
|
|
func ValidatorSubStatus(validator state.ReadOnlyValidator, epoch types.Epoch) (ethpb.ValidatorStatus, error) {
|
|
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
|
|
|
|
// Pending.
|
|
if validator.ActivationEpoch() > epoch {
|
|
if validator.ActivationEligibilityEpoch() == farFutureEpoch {
|
|
return ethpb.ValidatorStatus_PENDING_INITIALIZED, nil
|
|
} else if validator.ActivationEligibilityEpoch() < farFutureEpoch {
|
|
return ethpb.ValidatorStatus_PENDING_QUEUED, nil
|
|
}
|
|
}
|
|
|
|
// Active.
|
|
if validator.ActivationEpoch() <= epoch && epoch < validator.ExitEpoch() {
|
|
if validator.ExitEpoch() == farFutureEpoch {
|
|
return ethpb.ValidatorStatus_ACTIVE_ONGOING, nil
|
|
} else if validator.ExitEpoch() < farFutureEpoch {
|
|
if validator.Slashed() {
|
|
return ethpb.ValidatorStatus_ACTIVE_SLASHED, nil
|
|
}
|
|
return ethpb.ValidatorStatus_ACTIVE_EXITING, nil
|
|
}
|
|
}
|
|
|
|
// Exited.
|
|
if validator.ExitEpoch() <= epoch && epoch < validator.WithdrawableEpoch() {
|
|
if validator.Slashed() {
|
|
return ethpb.ValidatorStatus_EXITED_SLASHED, nil
|
|
}
|
|
return ethpb.ValidatorStatus_EXITED_UNSLASHED, nil
|
|
}
|
|
|
|
if validator.WithdrawableEpoch() <= epoch {
|
|
if validator.EffectiveBalance() != 0 {
|
|
return ethpb.ValidatorStatus_WITHDRAWAL_POSSIBLE, nil
|
|
} else {
|
|
return ethpb.ValidatorStatus_WITHDRAWAL_DONE, nil
|
|
}
|
|
}
|
|
|
|
return 0, errors.New("invalid validator state")
|
|
}
|