Skip to content

Commit

Permalink
Prune Better For Larger Buckets (#8599)
Browse files Browse the repository at this point in the history
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
  • Loading branch information
nisdas and rauljordan authored Mar 12, 2021
1 parent 3b6b3f6 commit a3c96c2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions validator/db/kv/prune_attester_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@ import (
func (s *Store) PruneAttestations(ctx context.Context) error {
ctx, span := trace.StartSpan(ctx, "Validator.PruneAttestations")
defer span.End()
return s.update(func(tx *bolt.Tx) error {
pubkeys := [][]byte{}
err := s.view(func(tx *bolt.Tx) error {
bucket := tx.Bucket(pubKeysBucket)
return bucket.ForEach(func(pubKey []byte, _ []byte) error {
pkBucket := bucket.Bucket(pubKey)
key := make([]byte, len(pubKey))
copy(key, pubKey)
pubkeys = append(pubkeys, pubKey)
return nil
})
})
if err != nil {
return err
}
for _, k := range pubkeys {
err = s.update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(pubKeysBucket)
pkBucket := bucket.Bucket(k)
if pkBucket == nil {
return nil
}
Expand All @@ -32,7 +45,11 @@ func (s *Store) PruneAttestations(ctx context.Context) error {
}
return pruneSigningRootsBucket(pkBucket)
})
})
if err != nil {
return err
}
}
return nil
}

func pruneSourceEpochsBucket(bucket *bolt.Bucket) error {
Expand Down

0 comments on commit a3c96c2

Please sign in to comment.