Fix GetDuties (#9811)

* Fix GetDuties

* Add regression test
This commit is contained in:
Kirill Fedoseev 2021-10-25 17:09:47 +03:00 committed by GitHub
parent 7f3ec4221f
commit b837f90b35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View File

@ -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)

View File

@ -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 := &ethpb.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 := &ethpb.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(),