mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
4f9752bb3e
* include migration and logic for stopping early in slashing protection checks * remove commented code * extract methods * migration logic tested up * migration up and down tests * Update validator/db/kv/attester_protection.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * added in pruning and batched migrations Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/shared/cmd"
|
|
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
|
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func migrateUp(cliCtx *cli.Context) error {
|
|
dataDir := cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
if !fileutil.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) {
|
|
return errors.New("No validator db found at path, nothing to migrate")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
log.Info("Opening DB")
|
|
validatorDB, err := kv.NewKVStore(ctx, dataDir, &kv.Config{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Info("Running migrations")
|
|
return validatorDB.RunUpMigrations(ctx)
|
|
}
|
|
|
|
func migrateDown(cliCtx *cli.Context) error {
|
|
dataDir := cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
if !fileutil.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) {
|
|
return errors.New("No validator db found at path, nothing to rollback")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
log.Info("Opening DB")
|
|
validatorDB, err := kv.NewKVStore(ctx, dataDir, &kv.Config{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Info("Running migrations")
|
|
return validatorDB.RunDownMigrations(ctx)
|
|
}
|