mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-05-02 03:02:54 -04:00
Use Current Time Slot for Fetching Committees in RPC (#5094)
* use genesis time fetcher * Merge branch 'master' into use-time-fetcher * fix breaking * Merge branch 'use-time-fetcher' of github.com:prysmaticlabs/prysm into use-time-fetcher * list beacon committees tests fixed * Merge branch 'master' into use-time-fetcher * Merge branch 'master' into use-time-fetcher * Merge refs/heads/master into use-time-fetcher * Update beacon-chain/rpc/beacon/committees_test.go
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user