mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
allow passing no,prompt,force options to clear-db (#3871)
* allow passing no,prompt,force options to clear-db * ensure the node test runs ok * remove clear-db option and add force-clear-db; remove no longer needed file * add clear-db option back; force-clear-db overrides * add clear-db option back to usage * revert to only using --clear-db
This commit is contained in:
@@ -142,14 +142,14 @@ docker run -it -v $HOME/prysm-data:/data -p 4000:4000 --name beacon-node \
|
|||||||
|
|
||||||
4) To run the beacon node, issue the command:
|
4) To run the beacon node, issue the command:
|
||||||
```
|
```
|
||||||
docker run -it -v c:/tmp/prysm-data:/data -p 4000:4000 gcr.io/prysmaticlabs/prysm/beacon-chain:latest --datadir=/data --clear-db
|
docker run -it -v c:/tmp/prysm-data:/data -p 4000:4000 gcr.io/prysmaticlabs/prysm/beacon-chain:latest --datadir=/data
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running via Bazel
|
### Running via Bazel
|
||||||
|
|
||||||
1) To start your Beacon Node with Bazel, issue the command:
|
1) To start your Beacon Node with Bazel, issue the command:
|
||||||
```
|
```
|
||||||
bazel run //beacon-chain -- --clear-db --datadir=/tmp/prysm-data
|
bazel run //beacon-chain -- --datadir=/tmp/prysm-data
|
||||||
```
|
```
|
||||||
This will sync up the Beacon Node with the latest head block in the network. Note that the beacon node must be **completely synced** before attempting to initialise a validator client, otherwise the validator will not be able to complete the deposit and funds will be lost.
|
This will sync up the Beacon Node with the latest head block in the network. Note that the beacon node must be **completely synced** before attempting to initialise a validator client, otherwise the validator will not be able to complete the deposit and funds will be lost.
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ var appFlags = []cli.Flag{
|
|||||||
cmd.MonitoringPortFlag,
|
cmd.MonitoringPortFlag,
|
||||||
cmd.DisableMonitoringFlag,
|
cmd.DisableMonitoringFlag,
|
||||||
cmd.ClearDB,
|
cmd.ClearDB,
|
||||||
|
cmd.ForceClearDB,
|
||||||
cmd.LogFormat,
|
cmd.LogFormat,
|
||||||
cmd.MaxGoroutines,
|
cmd.MaxGoroutines,
|
||||||
debug.PProfFlag,
|
debug.PProfFlag,
|
||||||
|
|||||||
@@ -9,38 +9,41 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func confirmDelete(d db.Database, path string) (db.Database, error) {
|
func confirmDelete(d db.Database, path string, force bool) (db.Database, error) {
|
||||||
var clearDB bool
|
var clearDB bool
|
||||||
var err error
|
var err error
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
if force {
|
||||||
|
clearDB = true
|
||||||
|
} else {
|
||||||
|
log.Warn("This will delete your beacon chain data base stored in your data directory. " +
|
||||||
|
"Your database backups will not be removed - do you want to proceed? (Y/N)")
|
||||||
|
|
||||||
log.Warn("This will delete your beacon chain data base stored in your data directory. " +
|
for {
|
||||||
"Your database backups will not be removed - do you want to proceed? (Y/N)")
|
fmt.Print(">> ")
|
||||||
|
|
||||||
for {
|
line, _, err := reader.ReadLine()
|
||||||
fmt.Print(">> ")
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
line, _, err := reader.ReadLine()
|
}
|
||||||
if err != nil {
|
trimmedLine := strings.TrimSpace(string(line))
|
||||||
return nil, err
|
lineInput := strings.ToUpper(trimmedLine)
|
||||||
}
|
if lineInput != "Y" && lineInput != "N" {
|
||||||
trimmedLine := strings.TrimSpace(string(line))
|
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
|
||||||
lineInput := strings.ToUpper(trimmedLine)
|
continue
|
||||||
if lineInput != "Y" && lineInput != "N" {
|
}
|
||||||
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
|
if lineInput == "Y" {
|
||||||
continue
|
clearDB = true
|
||||||
}
|
break
|
||||||
if lineInput == "Y" {
|
}
|
||||||
log.Warn("Deleting beaconchain.db from data directory")
|
log.Info("Not deleting chain database, the db will be initialized" +
|
||||||
clearDB = true
|
" with the current data directory.")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
log.Info("Not deleting chain database, the db will be initialized" +
|
}
|
||||||
" with the current data directory.")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if clearDB {
|
if clearDB {
|
||||||
|
log.Warning("Removing database")
|
||||||
if err := d.ClearDB(); err != nil {
|
if err := d.ClearDB(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
|
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
|
||||||
interopcoldstart "github.com/prysmaticlabs/prysm/beacon-chain/interop-cold-start"
|
interopcoldstart "github.com/prysmaticlabs/prysm/beacon-chain/interop-cold-start"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations"
|
"github.com/prysmaticlabs/prysm/beacon-chain/operations"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/rpc"
|
"github.com/prysmaticlabs/prysm/beacon-chain/rpc"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||||
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||||
initialsync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync"
|
initialsync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync"
|
||||||
"github.com/prysmaticlabs/prysm/shared"
|
"github.com/prysmaticlabs/prysm/shared"
|
||||||
@@ -200,17 +200,19 @@ func (b *BeaconNode) Close() {
|
|||||||
func (b *BeaconNode) startDB(ctx *cli.Context) error {
|
func (b *BeaconNode) startDB(ctx *cli.Context) error {
|
||||||
baseDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
baseDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
||||||
dbPath := path.Join(baseDir, beaconChainDBName)
|
dbPath := path.Join(baseDir, beaconChainDBName)
|
||||||
|
clearDB := ctx.GlobalBool(cmd.ClearDB.Name)
|
||||||
|
forceClearDB := ctx.GlobalBool(cmd.ForceClearDB.Name)
|
||||||
|
|
||||||
d, err := db.NewDB(dbPath)
|
d, err := db.NewDB(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if b.ctx.GlobalBool(cmd.ClearDB.Name) {
|
if clearDB || forceClearDB {
|
||||||
d, err = confirmDelete(d, dbPath)
|
d, err = confirmDelete(d, dbPath, forceClearDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithField("database-path", dbPath).Info("Checking DB")
|
log.WithField("database-path", dbPath).Info("Checking DB")
|
||||||
b.db = d
|
b.db = d
|
||||||
b.depositCache = depositcache.NewDepositCache()
|
b.depositCache = depositcache.NewDepositCache()
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ var appHelpFlagGroups = []flagGroup{
|
|||||||
cmd.MonitoringPortFlag,
|
cmd.MonitoringPortFlag,
|
||||||
cmd.DisableMonitoringFlag,
|
cmd.DisableMonitoringFlag,
|
||||||
cmd.MaxGoroutines,
|
cmd.MaxGoroutines,
|
||||||
|
cmd.ForceClearDB,
|
||||||
cmd.ClearDB,
|
cmd.ClearDB,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ while test $# -gt 0; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
bazel run //beacon-chain -- --clear-db --deposit-contract $DEPOSIT_CONTRACT --web3provider=wss://goerli.infura.io/ws/v3/be3fb7ed377c418087602876a40affa1
|
bazel run //beacon-chain -- --clear-db --deposit-contract $DEPOSIT_CONTRACT --web3provider=wss://goerli.infura.io/ws/v3/be3fb7ed377c418087602876a40affa1
|
||||||
|
|||||||
@@ -119,10 +119,15 @@ var (
|
|||||||
Usage: "The encoding format of messages sent over the wire. The default is 0, which represents ssz",
|
Usage: "The encoding format of messages sent over the wire. The default is 0, which represents ssz",
|
||||||
Value: "ssz",
|
Value: "ssz",
|
||||||
}
|
}
|
||||||
// ClearDB tells the beacon node to remove any previously stored data at the data directory.
|
// ForceClearDB removes any previously stored data at the data directory.
|
||||||
|
ForceClearDB = cli.BoolFlag{
|
||||||
|
Name: "force-clear-db",
|
||||||
|
Usage: "Clear any previously stored data at the data directory",
|
||||||
|
}
|
||||||
|
// ClearDB prompts user to see if they want to remove any previously stored data at the data directory.
|
||||||
ClearDB = cli.BoolFlag{
|
ClearDB = cli.BoolFlag{
|
||||||
Name: "clear-db",
|
Name: "clear-db",
|
||||||
Usage: "Clears any previously stored data at the data directory",
|
Usage: "Prompt for clearing any previously stored data at the data directory",
|
||||||
}
|
}
|
||||||
// LogFormat specifies the log output format.
|
// LogFormat specifies the log output format.
|
||||||
LogFormat = cli.StringFlag{
|
LogFormat = cli.StringFlag{
|
||||||
|
|||||||
Reference in New Issue
Block a user