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

Solve -1 ActivationEpoch in validator logging #5569

Merged
merged 17 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
89 changes: 88 additions & 1 deletion beacon-chain/rpc/validator/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,95 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
},
},
{PublicKey: pubKey2,
Status: &ethpb.ValidatorStatusResponse{},
},
},
},
).Return(nil)

if err := vs.WaitForActivation(req, mockChainStream); err != nil {
t.Fatalf("Could not setup wait for activation stream: %v", err)
}
}

func TestWaitForActivation_MultipleStatuses(t *testing.T) {
db := dbutil.SetupDB(t)
defer dbutil.TeardownDB(t, db)

priv1 := bls.RandKey()
priv2 := bls.RandKey()
priv3 := bls.RandKey()

pubKey1 := priv1.PublicKey().Marshal()[:]
pubKey2 := priv2.PublicKey().Marshal()[:]
pubKey3 := priv3.PublicKey().Marshal()[:]

beaconState := &pbp2p.BeaconState{
Slot: 4000,
Validators: []*ethpb.Validator{
{
PublicKey: pubKey1,
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
},
{
PublicKey: pubKey2,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEligibilityEpoch: 6,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
},
{
PublicKey: pubKey3,
ActivationEpoch: 0,
ActivationEligibilityEpoch: 0,
ExitEpoch: 0,
},
},
}
block := blk.NewGenesisBlock([]byte{})
genesisRoot, err := ssz.HashTreeRoot(block.Block)
if err != nil {
t.Fatalf("Could not get signing root %v", err)
}
trie, err := stateTrie.InitializeFromProtoUnsafe(beaconState)
if err != nil {
t.Fatal(err)
}
vs := &Server{
BeaconDB: db,
Ctx: context.Background(),
CanonicalStateChan: make(chan *pbp2p.BeaconState, 1),
ChainStartFetcher: &mockPOW.POWChain{},
HeadFetcher: &mockChain.ChainService{State: trie, Root: genesisRoot[:]},
}
req := &ethpb.ValidatorActivationRequest{
PublicKeys: [][]byte{pubKey1, pubKey2, pubKey3},
}
ctrl := gomock.NewController(t)

defer ctrl.Finish()
mockChainStream := internal.NewMockBeaconNodeValidator_WaitForActivationServer(ctrl)
mockChainStream.EXPECT().Context().Return(context.Background())
mockChainStream.EXPECT().Send(
&ethpb.ValidatorActivationResponse{
Statuses: []*ethpb.ValidatorActivationResponse_Status{
{
PublicKey: pubKey1,
Status: &ethpb.ValidatorStatusResponse{
Status: ethpb.ValidatorStatus_ACTIVE,
},
},
{
PublicKey: pubKey2,
Status: &ethpb.ValidatorStatusResponse{
Status: ethpb.ValidatorStatus_PENDING,
PositionInActivationQueue: 1,
},
},
{
PublicKey: pubKey3,
Status: &ethpb.ValidatorStatusResponse{
ActivationEpoch: int64(params.BeaconConfig().FarFutureEpoch),
Status: ethpb.ValidatorStatus_EXITED,
},
},
},
Expand Down
7 changes: 4 additions & 3 deletions beacon-chain/rpc/validator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (vs *Server) validatorStatus(ctx context.Context, pubKey []byte, headState
defer span.End()

resp := &ethpb.ValidatorStatusResponse{
Status: ethpb.ValidatorStatus_UNKNOWN_STATUS,
ActivationEpoch: int64(params.BeaconConfig().FarFutureEpoch),
Status: ethpb.ValidatorStatus_UNKNOWN_STATUS,
}
vStatus, idx, err := vs.retrieveStatusFromState(ctx, pubKey, headState)
if err != nil && err != errPubkeyDoesNotExist {
Expand All @@ -91,7 +90,9 @@ func (vs *Server) validatorStatus(ctx context.Context, pubKey []byte, headState
traceutil.AnnotateError(span, err)
return resp
}
resp.ActivationEpoch = int64(val.ActivationEpoch)
if val.ActivationEpoch != params.BeaconConfig().FarFutureEpoch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this back. Far future epoch is the new "zero".

resp.ActivationEpoch = int64(val.ActivationEpoch)
}
}

switch resp.Status {
Expand Down