Prune Better For Larger Buckets (#8599)

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
Nishant Das 2021-03-12 23:05:20 +08:00 committed by GitHub
parent 3b6b3f6ef6
commit a3c96c2f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
@ -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 {