diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index 2f92813251..4d0c8e6a0a 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -219,7 +219,7 @@ func (ms *ChainService) GenesisTime() time.Time { // CurrentSlot mocks the same method in the chain service. func (ms *ChainService) CurrentSlot() uint64 { - return 0 + return ms.HeadSlot() } // Participation mocks the same method in the chain service. diff --git a/beacon-chain/rpc/beacon/committees.go b/beacon-chain/rpc/beacon/committees.go index 0d9d61e2ee..e0ef93130b 100644 --- a/beacon-chain/rpc/beacon/committees.go +++ b/beacon-chain/rpc/beacon/committees.go @@ -22,7 +22,7 @@ func (bs *Server) ListBeaconCommittees( var requestingGenesis bool var startSlot uint64 - headSlot := bs.HeadFetcher.HeadSlot() + headSlot := bs.GenesisTimeFetcher.CurrentSlot() switch q := req.QueryFilter.(type) { case *ethpb.ListCommitteesRequest_Epoch: startSlot = helpers.StartSlot(q.Epoch) @@ -58,8 +58,8 @@ func (bs *Server) retrieveCommitteesForEpoch( var activeIndices []uint64 var err error startSlot := helpers.StartSlot(epoch) - headEpoch := helpers.SlotToEpoch(bs.HeadFetcher.HeadSlot()) - if helpers.SlotToEpoch(startSlot)+1 < headEpoch { + currentEpoch := helpers.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + if helpers.SlotToEpoch(startSlot)+1 < currentEpoch { activeIndices, err = bs.HeadFetcher.HeadValidatorsIndices(helpers.SlotToEpoch(startSlot)) if err != nil { return nil, nil, status.Errorf( @@ -86,7 +86,7 @@ func (bs *Server) retrieveCommitteesForEpoch( ) } attesterSeed = bytesutil.ToBytes32(archivedCommitteeInfo.AttesterSeed) - } else if helpers.SlotToEpoch(startSlot)+1 == headEpoch || helpers.SlotToEpoch(startSlot) == headEpoch { + } else if helpers.SlotToEpoch(startSlot)+1 == currentEpoch || helpers.SlotToEpoch(startSlot) == currentEpoch { // Otherwise, we use current beacon state to calculate the committees. requestedEpoch := helpers.SlotToEpoch(startSlot) activeIndices, err = bs.HeadFetcher.HeadValidatorsIndices(requestedEpoch) @@ -112,7 +112,7 @@ func (bs *Server) retrieveCommitteesForEpoch( return nil, nil, status.Errorf( codes.InvalidArgument, "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", - headEpoch, + currentEpoch, helpers.SlotToEpoch(startSlot), ) } diff --git a/beacon-chain/rpc/beacon/committees_test.go b/beacon-chain/rpc/beacon/committees_test.go index 7de72fac6b..98eaba1ee9 100644 --- a/beacon-chain/rpc/beacon/committees_test.go +++ b/beacon-chain/rpc/beacon/committees_test.go @@ -8,14 +8,14 @@ import ( "github.com/gogo/protobuf/proto" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" + pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" + "gopkg.in/d4l3k/messagediff.v1" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" - pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/params" - "gopkg.in/d4l3k/messagediff.v1" ) func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) { @@ -34,10 +34,12 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) { t.Fatal(err) } + m := &mock.ChainService{ + State: headState, + } bs := &Server{ - HeadFetcher: &mock.ChainService{ - State: headState, - }, + HeadFetcher: m, + GenesisTimeFetcher: m, } activeIndices, err := helpers.ActiveValidatorIndices(headState, 0) @@ -84,10 +86,12 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { headState.SetRandaoMixes(mixes) headState.SetSlot(params.BeaconConfig().SlotsPerEpoch * 2) + m := &mock.ChainService{ + State: headState, + } bs := &Server{ - HeadFetcher: &mock.ChainService{ - State: headState, - }, + HeadFetcher: m, + GenesisTimeFetcher: m, } activeIndices, err := helpers.ActiveValidatorIndices(headState, 1) @@ -183,11 +187,13 @@ func TestServer_ListBeaconCommittees_FromArchive(t *testing.T) { t.Fatal(err) } + m := &mock.ChainService{ + State: headState, + } bs := &Server{ - BeaconDB: db, - HeadFetcher: &mock.ChainService{ - State: headState, - }, + BeaconDB: db, + HeadFetcher: m, + GenesisTimeFetcher: m, } activeIndices, err := helpers.ActiveValidatorIndices(headState, 0)