From b837f90b35401dcfb9d2ec2cc570b0c7db8b194a Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Mon, 25 Oct 2021 17:09:47 +0300 Subject: [PATCH] Fix GetDuties (#9811) * Fix GetDuties * Add regression test --- .../prysm/v1alpha1/validator/assignments.go | 2 +- .../v1alpha1/validator/assignments_test.go | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go index 10870c912..47a9b3ae3 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go @@ -183,7 +183,7 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb. } // Are the validators in current or next epoch sync committee. - if coreTime.AltairCompatible(s, req.Epoch) { + if ok && coreTime.AltairCompatible(s, req.Epoch) { assignment.IsSyncCommittee, err = helpers.IsCurrentPeriodSyncCommittee(s, idx) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine current epoch sync committee: %v", err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go index e44e7a055..083789193 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go @@ -10,6 +10,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache" + "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" @@ -199,6 +200,60 @@ func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) { } } +func TestGetAltairDuties_UnknownPubkey(t *testing.T) { + params.SetupTestConfigCleanup(t) + params.UseMainnetConfig() + cfg := params.BeaconConfig().Copy() + cfg.AltairForkEpoch = types.Epoch(0) + params.OverrideBeaconConfig(cfg) + + genesis := util.NewBeaconBlock() + deposits, _, err := util.DeterministicDepositsAndKeys(params.BeaconConfig().SyncCommitteeSize) + require.NoError(t, err) + eth1Data, err := util.DeterministicEth1Data(len(deposits)) + require.NoError(t, err) + bs, err := util.GenesisBeaconState(context.Background(), deposits, 0, eth1Data) + require.NoError(t, err) + h := ðpb.BeaconBlockHeader{ + StateRoot: bytesutil.PadTo([]byte{'a'}, 32), + ParentRoot: bytesutil.PadTo([]byte{'b'}, 32), + BodyRoot: bytesutil.PadTo([]byte{'c'}, 32), + } + require.NoError(t, bs.SetLatestBlockHeader(h)) + require.NoError(t, err, "Could not setup genesis bs") + genesisRoot, err := genesis.Block.HashTreeRoot() + require.NoError(t, err, "Could not get signing root") + + require.NoError(t, bs.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(params.BeaconConfig().EpochsPerSyncCommitteePeriod)-1)) + require.NoError(t, helpers.UpdateSyncCommitteeCache(bs)) + + slot := uint64(params.BeaconConfig().SlotsPerEpoch) * uint64(params.BeaconConfig().EpochsPerSyncCommitteePeriod) * params.BeaconConfig().SecondsPerSlot + chain := &mockChain.ChainService{ + State: bs, Root: genesisRoot[:], Genesis: time.Now().Add(time.Duration(-1*int64(slot-1)) * time.Second), + } + depositCache, err := depositcache.New() + require.NoError(t, err) + + vs := &Server{ + HeadFetcher: chain, + TimeFetcher: chain, + Eth1InfoFetcher: &mockPOW.POWChain{}, + SyncChecker: &mockSync.Sync{IsSyncing: false}, + DepositFetcher: depositCache, + } + + unknownPubkey := bytesutil.PadTo([]byte{'u'}, 48) + req := ðpb.DutiesRequest{ + PublicKeys: [][]byte{deposits[0].Data.PublicKey, unknownPubkey}, + } + res, err := vs.GetDuties(context.Background(), req) + require.NoError(t, err) + assert.Equal(t, true, res.CurrentEpochDuties[0].IsSyncCommittee) + assert.Equal(t, true, res.NextEpochDuties[0].IsSyncCommittee) + assert.Equal(t, false, res.CurrentEpochDuties[1].IsSyncCommittee) + assert.Equal(t, false, res.NextEpochDuties[1].IsSyncCommittee) +} + func TestGetDuties_SlotOutOfUpperBound(t *testing.T) { chain := &mockChain.ChainService{ Genesis: time.Now(),