Allow update cache at last slot of the epoch (#8094)

* Epoch boundary updates at the last slot of the epoch

* Report metric on first slot

* Remove comment

* Add locks to param config

* Remove lock for copy

* Revert "Add locks to param config"

This reverts commit 79d5130b58.

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
terence tsao
2020-12-15 13:19:02 -08:00
committed by GitHub
parent 6244163770
commit 0449cd3450
2 changed files with 26 additions and 2 deletions

View File

@@ -330,7 +330,15 @@ func (s *Service) handleBlockAfterBatchVerify(ctx context.Context, signed *ethpb
// Epoch boundary bookkeeping such as logging epoch summaries.
func (s *Service) handleEpochBoundary(ctx context.Context, postState *stateTrie.BeaconState) error {
if postState.Slot() >= s.nextEpochBoundarySlot {
if postState.Slot() == s.nextEpochBoundarySlot-1 {
// Update caches for the next epoch at epoch boundary slot - 1.
if err := helpers.UpdateCommitteeCache(postState, helpers.NextEpoch(postState)); err != nil {
return err
}
if err := helpers.UpdateProposerIndicesInCache(postState, helpers.NextEpoch(postState)); err != nil {
return err
}
} else if postState.Slot() >= s.nextEpochBoundarySlot {
if err := reportEpochMetrics(ctx, postState, s.head.state); err != nil {
return err
}
@@ -339,7 +347,9 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState *stateTrie.
if err != nil {
return err
}
// Update committees cache at epoch boundary slot.
// Update caches at epoch boundary slot.
// The following updates have short cut to return nil cheaply if fulfilled during boundary slot - 1.
if err := helpers.UpdateCommitteeCache(postState, helpers.CurrentEpoch(postState)); err != nil {
return err
}
@@ -347,6 +357,7 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState *stateTrie.
return err
}
}
return nil
}

View File

@@ -888,3 +888,16 @@ func TestHandleEpochBoundary_BadMetrics(t *testing.T) {
service.head = &head{}
require.ErrorContains(t, "failed to initialize precompute: nil inner state", service.handleEpochBoundary(ctx, s))
}
func TestHandleEpochBoundary_UpdateFirstSlot(t *testing.T) {
ctx := context.Background()
cfg := &Config{}
service, err := NewService(ctx, cfg)
require.NoError(t, err)
s, _ := testutil.DeterministicGenesisState(t, 1024)
service.head = &head{state: s}
require.NoError(t, s.SetSlot(2*params.BeaconConfig().SlotsPerEpoch))
require.NoError(t, service.handleEpochBoundary(ctx, s))
require.Equal(t, 3*params.BeaconConfig().SlotsPerEpoch, service.nextEpochBoundarySlot)
}