2020-03-31 23:54:24 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
2020-04-20 20:19:53 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-03-31 23:54:24 +00:00
|
|
|
bolt "go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var historicalStateDeletedKey = []byte("historical-states-deleted")
|
|
|
|
|
2020-04-15 00:38:52 +00:00
|
|
|
// HistoricalStatesDeleted verifies historical states exist in DB.
|
|
|
|
func (kv *Store) HistoricalStatesDeleted(ctx context.Context) error {
|
2020-04-21 22:30:22 +00:00
|
|
|
if !featureconfig.Get().NewStateMgmt {
|
2020-03-31 23:54:24 +00:00
|
|
|
return kv.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(newStateServiceCompatibleBucket)
|
|
|
|
return bkt.Put(historicalStateDeletedKey, []byte{0x01})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var historicalStateDeleted bool
|
2020-04-13 04:11:09 +00:00
|
|
|
if err := kv.db.View(func(tx *bolt.Tx) error {
|
2020-03-31 23:54:24 +00:00
|
|
|
bkt := tx.Bucket(newStateServiceCompatibleBucket)
|
|
|
|
v := bkt.Get(historicalStateDeletedKey)
|
|
|
|
historicalStateDeleted = len(v) == 1 && v[0] == 0x01
|
|
|
|
return nil
|
2020-04-13 04:11:09 +00:00
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-31 23:54:24 +00:00
|
|
|
|
|
|
|
if historicalStateDeleted {
|
2020-04-20 20:19:53 +00:00
|
|
|
log.Warn("Regenerating and saving historical states. This may take a while.")
|
2020-03-31 23:54:24 +00:00
|
|
|
if err := kv.regenHistoricalStates(ctx); err != nil {
|
|
|
|
return errors.Wrap(err, "could not regenerate historical states, please retry")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kv.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(newStateServiceCompatibleBucket)
|
|
|
|
return bkt.Put(historicalStateDeletedKey, []byte{0x00})
|
|
|
|
})
|
|
|
|
}
|