Fix Status Update Progression in RPC Server (#2495)

* fix status updates

* standardize logs in validator

* tests

* fix conditional
This commit is contained in:
Raul Jordan 2019-05-05 17:39:12 -05:00 committed by GitHub
parent f60f3dfd2d
commit d68111e051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 29 deletions

View File

@ -260,17 +260,16 @@ func (vs *ValidatorServer) validatorStatus(
if !ok {
return &pb.ValidatorStatusResponse{
Status: pb.ValidatorStatus_PENDING_ACTIVE,
Status: pb.ValidatorStatus_UNKNOWN_STATUS,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch,
Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(),
}
}
status := vs.lookupValidatorStatusFlag(uint64(valIdx), beaconState)
depositBlockSlot, err := vs.depositBlockSlot(ctx, beaconState.Slot, eth1BlockNumBigInt, beaconState)
if err != nil {
return &pb.ValidatorStatusResponse{
Status: status,
Status: pb.ValidatorStatus_UNKNOWN_STATUS,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch,
Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(),
}
@ -278,7 +277,7 @@ func (vs *ValidatorServer) validatorStatus(
if depositBlockSlot == 0 {
return &pb.ValidatorStatusResponse{
Status: status,
Status: pb.ValidatorStatus_UNKNOWN_STATUS,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch,
Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(),
}
@ -317,6 +316,7 @@ func (vs *ValidatorServer) validatorStatus(
positionInQueue = validatorIndex - lastActivatedValidatorIdx
}
status := vs.lookupValidatorStatusFlag(uint64(valIdx), beaconState)
return &pb.ValidatorStatusResponse{
Status: status,
Eth1DepositBlockNumber: eth1BlockNumBigInt.Uint64(),
@ -329,12 +329,11 @@ func (vs *ValidatorServer) validatorStatus(
func (vs *ValidatorServer) lookupValidatorStatusFlag(validatorIdx uint64, beaconState *pbp2p.BeaconState) pb.ValidatorStatus {
var status pb.ValidatorStatus
v := beaconState.ValidatorRegistry[validatorIdx]
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
epoch := helpers.CurrentEpoch(beaconState)
if v.ActivationEpoch == farFutureEpoch {
if v.ActivationEpoch > epoch {
status = pb.ValidatorStatus_PENDING_ACTIVE
} else if v.ActivationEpoch <= epoch && epoch < v.ExitEpoch {
} else if v.ActivationEpoch >= helpers.EntryExitEffectEpoch(epoch) && epoch < v.ExitEpoch {
status = pb.ValidatorStatus_ACTIVE
} else if v.StatusFlags == pbp2p.Validator_INITIATED_EXIT {
status = pb.ValidatorStatus_INITIATED_EXIT

View File

@ -387,11 +387,12 @@ func TestValidatorStatus_Active(t *testing.T) {
db.InsertDeposit(ctx, deposit, big.NewInt(0))
// Active because activation epoch <= current epoch < exit epoch.
activeEpoch := helpers.EntryExitEffectEpoch(params.BeaconConfig().GenesisEpoch)
if err := db.SaveState(ctx, &pbp2p.BeaconState{
GenesisTime: uint64(time.Unix(0, 0).Unix()),
Slot: params.BeaconConfig().GenesisSlot,
Slot: params.BeaconConfig().GenesisSlot + 10000,
ValidatorRegistry: []*pbp2p.Validator{{
ActivationEpoch: params.BeaconConfig().GenesisEpoch,
ActivationEpoch: activeEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
Pubkey: pubKey},
}}); err != nil {
@ -416,8 +417,9 @@ func TestValidatorStatus_Active(t *testing.T) {
}
expected := &pb.ValidatorStatusResponse{
Status: pb.ValidatorStatus_ACTIVE,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch,
Status: pb.ValidatorStatus_ACTIVE,
ActivationEpoch: 5,
DepositInclusionSlot: 3413,
}
if !proto.Equal(resp, expected) {
t.Errorf("Wanted %v, got %v", expected, resp)
@ -436,7 +438,7 @@ func TestValidatorStatus_InitiatedExit(t *testing.T) {
// Initiated exit because validator status flag = Validator_INITIATED_EXIT.
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: params.BeaconConfig().GenesisSlot,
Slot: params.BeaconConfig().GenesisSlot + 10000,
ValidatorRegistry: []*pbp2p.Validator{{
StatusFlags: pbp2p.Validator_INITIATED_EXIT,
Pubkey: pubKey},
@ -490,7 +492,7 @@ func TestValidatorStatus_Withdrawable(t *testing.T) {
// Withdrawable exit because validator status flag = Validator_WITHDRAWABLE.
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: params.BeaconConfig().GenesisSlot,
Slot: params.BeaconConfig().GenesisSlot + 10000,
ValidatorRegistry: []*pbp2p.Validator{{
StatusFlags: pbp2p.Validator_WITHDRAWABLE,
Pubkey: pubKey},
@ -544,7 +546,7 @@ func TestValidatorStatus_ExitedSlashed(t *testing.T) {
// Exit slashed because exit epoch and slashed epoch are =< current epoch.
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: params.BeaconConfig().GenesisSlot,
Slot: params.BeaconConfig().GenesisSlot + 10000,
ValidatorRegistry: []*pbp2p.Validator{{
Pubkey: pubKey},
}}); err != nil {
@ -597,7 +599,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
// Exit because only exit epoch is =< current epoch.
if err := db.SaveState(ctx, &pbp2p.BeaconState{
Slot: params.BeaconConfig().GenesisSlot + 64,
Slot: params.BeaconConfig().GenesisSlot + 10000,
ValidatorRegistry: []*pbp2p.Validator{{
Pubkey: pubKey,
SlashedEpoch: params.BeaconConfig().FarFutureEpoch},

View File

@ -126,27 +126,27 @@ func (v *validator) checkAndLogValidatorStatus(validatorStatuses []*pb.Validator
}
if status.Status.DepositInclusionSlot == 0 {
log.WithFields(logrus.Fields{
"PublicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"Status": fmt.Sprintf("%s", status.Status.Status.String()),
}).Info("Not Deposited Yet")
"publicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"status": fmt.Sprintf("%s", status.Status.Status.String()),
}).Info("Not yet included in state...")
continue
}
if status.Status.ActivationEpoch == (params.BeaconConfig().FarFutureEpoch - params.BeaconConfig().GenesisEpoch) {
log.WithFields(logrus.Fields{
"PublicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"Status": status.Status.Status.String(),
"DepositInclusionSlot": status.Status.DepositInclusionSlot,
"PositionInActivationQueue": status.Status.PositionInActivationQueue,
}).Info("Waiting to be Activated")
"publicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"status": status.Status.Status.String(),
"depositInclusionSlot": status.Status.DepositInclusionSlot,
"positionInActivationQueue": status.Status.PositionInActivationQueue,
}).Info("Waiting to be activated")
continue
}
log.WithFields(logrus.Fields{
"PublicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"Status": status.Status.Status.String(),
"DepositInclusionSlot": status.Status.DepositInclusionSlot,
"ActivationEpoch": status.Status.ActivationEpoch,
"PositionInActivationQueue": status.Status.PositionInActivationQueue,
}).Info("Validator Status")
"publicKey": fmt.Sprintf("%#x", bytesutil.Trunc(status.PublicKey)),
"status": status.Status.Status.String(),
"depositInclusionSlot": status.Status.DepositInclusionSlot,
"activationEpoch": status.Status.ActivationEpoch,
"positionInActivationQueue": status.Status.PositionInActivationQueue,
}).Info("Validator status")
}
return activatedKeys
}