mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
7b38e97e83
* Invert the flag * Merge branch 'master' into invert-disable-new-state-mgmt * Merge refs/heads/master into invert-disable-new-state-mgmt * Add new-state-mgmt to e2e flag * Merge branch 'invert-disable-new-state-mgmt' of github.com:prysmaticlabs/prysm into invert-disable-new-state-mgmt * Merge refs/heads/master into invert-disable-new-state-mgmt
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
log "github.com/sirupsen/logrus"
|
|
bolt "go.etcd.io/bbolt"
|
|
)
|
|
|
|
var historicalStateDeletedKey = []byte("historical-states-deleted")
|
|
|
|
// HistoricalStatesDeleted verifies historical states exist in DB.
|
|
func (kv *Store) HistoricalStatesDeleted(ctx context.Context) error {
|
|
if !featureconfig.Get().NewStateMgmt {
|
|
return kv.db.Update(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(newStateServiceCompatibleBucket)
|
|
return bkt.Put(historicalStateDeletedKey, []byte{0x01})
|
|
})
|
|
}
|
|
|
|
var historicalStateDeleted bool
|
|
if err := kv.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(newStateServiceCompatibleBucket)
|
|
v := bkt.Get(historicalStateDeletedKey)
|
|
historicalStateDeleted = len(v) == 1 && v[0] == 0x01
|
|
return nil
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
if historicalStateDeleted {
|
|
log.Warn("Regenerating and saving historical states. This may take a while.")
|
|
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})
|
|
})
|
|
}
|