Rename / move logic about updating validator indices (#3402)

* rename, move

* pr feedback
This commit is contained in:
Preston Van Loon 2019-09-03 13:57:08 -07:00 committed by GitHub
parent 6614816061
commit 0a61c379a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -113,15 +113,17 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
}
}
// Epoch boundary bookkeeping such as logging epoch summaries
// and saving newly activated validator indices in db.
// Update validator indices in database as needed.
if err := s.saveNewValidators(ctx, preStateValidatorCount, postState); err != nil {
return errors.Wrap(err, "could not save finalized checkpoint")
}
// Epoch boundary bookkeeping such as logging epoch summaries.
if helpers.IsEpochStart(postState.Slot) {
if err := s.saveNewValidator(ctx, preStateValidatorCount, postState); err != nil {
return errors.Wrap(err, "could not save finalized checkpoint")
}
logEpochData(postState)
reportStateMetrics(postState)
}
return nil
}
@ -165,8 +167,9 @@ func (s *Store) verifyBlkFinalizedSlot(b *ethpb.BeaconBlock) error {
return nil
}
// saveNewValidator saves newly added validator index from state to db.
func (s *Store) saveNewValidator(ctx context.Context, preStateValidatorCount int, postState *pb.BeaconState) error {
// saveNewValidators saves newly added validator index from state to db. Does nothing if validator count has not
// changed.
func (s *Store) saveNewValidators(ctx context.Context, preStateValidatorCount int, postState *pb.BeaconState) error {
postStateValidatorCount := len(postState.Validators)
if preStateValidatorCount != postStateValidatorCount {
for i := preStateValidatorCount; i < postStateValidatorCount; i++ {

View File

@ -85,7 +85,7 @@ func TestStore_OnBlock(t *testing.T) {
}
}
func TestStore_SaveNewValidator(t *testing.T) {
func TestStore_SaveNewValidators(t *testing.T) {
ctx := context.Background()
db := testDB.SetupDB(t)
defer testDB.TeardownDB(t, db)
@ -96,7 +96,7 @@ func TestStore_SaveNewValidator(t *testing.T) {
{PublicKey: []byte{0}}, {PublicKey: []byte{1}},
{PublicKey: []byte{2}}, {PublicKey: []byte{3}},
}}
if err := store.saveNewValidator(ctx, preCount, s); err != nil {
if err := store.saveNewValidators(ctx, preCount, s); err != nil {
t.Fatal(err)
}