Skip to content

Commit

Permalink
Solve -1 ActivationEpoch in validator logging (#5569)
Browse files Browse the repository at this point in the history
* Fix wrong activation epoch

* Fix bug with activationEpoch

* Add back default of FarFutureEpoch

* Fix tests

* Fix test

* Fix test again

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
0xKiwi and prylabs-bulldozer[bot] authored Apr 22, 2020
1 parent 9c012cc commit 8b058b5
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "349b301bbe44b8bea8c2bf2afe8c2e4e8630168a",
commit = "4685995df20b6d7a926fb98778c940e380db33ee",
importpath = "github.com/prysmaticlabs/ethereumapis",
)

Expand Down
93 changes: 92 additions & 1 deletion beacon-chain/rpc/validator/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,98 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
},
{PublicKey: pubKey2,
Status: &ethpb.ValidatorStatusResponse{
ActivationEpoch: int64(params.BeaconConfig().FarFutureEpoch),
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
},
},
},
},
).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: 1,
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,
ActivationEpoch: 1,
},
},
{
PublicKey: pubKey2,
Status: &ethpb.ValidatorStatusResponse{
Status: ethpb.ValidatorStatus_PENDING,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
PositionInActivationQueue: 1,
},
},
{
PublicKey: pubKey3,
Status: &ethpb.ValidatorStatusResponse{
Status: ethpb.ValidatorStatus_EXITED,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/rpc/validator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (vs *Server) validatorStatus(ctx context.Context, pubKey []byte, headState

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

switch resp.Status {
Expand All @@ -116,7 +116,7 @@ func (vs *Server) validatorStatus(ctx context.Context, pubKey []byte, headState
if err != nil {
return resp
}
resp.DepositInclusionSlot = int64(depositBlockSlot)
resp.DepositInclusionSlot = depositBlockSlot
// Deposited and Pending mean the validator has been put into the state.
case ethpb.ValidatorStatus_DEPOSITED, ethpb.ValidatorStatus_PENDING:
var lastActivatedValidatorIdx uint64
Expand All @@ -132,7 +132,7 @@ func (vs *Server) validatorStatus(ctx context.Context, pubKey []byte, headState
}
// Our position in the activation queue is the above index - our validator index.
if lastActivatedValidatorIdx < idx {
resp.PositionInActivationQueue = int64(idx - lastActivatedValidatorIdx)
resp.PositionInActivationQueue = idx - lastActivatedValidatorIdx
}
default:
return resp
Expand Down

0 comments on commit 8b058b5

Please sign in to comment.