Skip to content

Commit

Permalink
Optimize ListBeaconCommittees to use committees cache (prysmaticlabs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored and cryptomental committed Feb 24, 2020
1 parent 70a6a9d commit 64a908c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion beacon-chain/blockchain/service.go
Expand Up @@ -195,7 +195,6 @@ func (s *Service) initializeBeaconChain(
eth1data *ethpb.Eth1Data) error {
_, span := trace.StartSpan(context.Background(), "beacon-chain.Service.initializeBeaconChain")
defer span.End()
log.Info("Genesis time reached, starting the beacon chain")
s.genesisTime = genesisTime
unixTime := uint64(genesisTime.Unix())

Expand All @@ -208,6 +207,8 @@ func (s *Service) initializeBeaconChain(
return errors.Wrap(err, "could not save genesis data")
}

log.Info("Initialized beacon chain genesis state")

// Update committee shuffled indices for genesis epoch.
if featureconfig.Get().EnableNewCache {
if err := helpers.UpdateCommitteeCache(genesisState, 0 /* genesis epoch */); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/service_test.go
Expand Up @@ -176,7 +176,7 @@ func TestChainStartStop_Uninitialized(t *testing.T) {
t.Error("Context was not canceled")
}
testutil.AssertLogsContain(t, hook, "Waiting")
testutil.AssertLogsContain(t, hook, "Genesis time reached")
testutil.AssertLogsContain(t, hook, "Initialized beacon chain genesis state")
}

func TestChainStartStop_Initialized(t *testing.T) {
Expand Down
8 changes: 3 additions & 5 deletions beacon-chain/rpc/beacon/committees.go
Expand Up @@ -105,10 +105,8 @@ func (bs *Server) ListBeaconCommittees(
countAtSlot = 1
}
committeeItems := make([]*ethpb.BeaconCommittees_CommitteeItem, countAtSlot)
for i := uint64(0); i < countAtSlot; i++ {
epochOffset := i + (slot%params.BeaconConfig().SlotsPerEpoch)*countAtSlot
totalCount := countAtSlot * params.BeaconConfig().SlotsPerEpoch
committee, err := helpers.ComputeCommittee(activeIndices, attesterSeed, epochOffset, totalCount)
for committeeIndex := uint64(0); committeeIndex < countAtSlot; committeeIndex++ {
committee, err := helpers.BeaconCommittee(activeIndices, attesterSeed, slot, committeeIndex)
if err != nil {
return nil, status.Errorf(
codes.Internal,
Expand All @@ -117,7 +115,7 @@ func (bs *Server) ListBeaconCommittees(
err,
)
}
committeeItems[i] = &ethpb.BeaconCommittees_CommitteeItem{
committeeItems[committeeIndex] = &ethpb.BeaconCommittees_CommitteeItem{
ValidatorIndices: committee,
}
}
Expand Down

0 comments on commit 64a908c

Please sign in to comment.