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:
mkinney 2019-10-31 02:55:32 -07:00 committed by Nishant Das
parent a29032c2bf
commit 9ca95530fa
7 changed files with 46 additions and 34 deletions

View File

@ -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:
```
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
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.

View File

@ -59,6 +59,7 @@ var appFlags = []cli.Flag{
cmd.MonitoringPortFlag,
cmd.DisableMonitoringFlag,
cmd.ClearDB,
cmd.ForceClearDB,
cmd.LogFormat,
cmd.MaxGoroutines,
debug.PProfFlag,

View File

@ -9,38 +9,41 @@ import (
"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 err error
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. " +
"Your database backups will not be removed - do you want to proceed? (Y/N)")
for {
fmt.Print(">> ")
for {
fmt.Print(">> ")
line, _, err := reader.ReadLine()
if err != nil {
return nil, err
}
trimmedLine := strings.TrimSpace(string(line))
lineInput := strings.ToUpper(trimmedLine)
if lineInput != "Y" && lineInput != "N" {
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
continue
}
if lineInput == "Y" {
log.Warn("Deleting beaconchain.db from data directory")
clearDB = true
break
}
log.Info("Not deleting chain database, the db will be initialized" +
" with the current data directory.")
break
}
line, _, err := reader.ReadLine()
if err != nil {
return nil, err
}
trimmedLine := strings.TrimSpace(string(line))
lineInput := strings.ToUpper(trimmedLine)
if lineInput != "Y" && lineInput != "N" {
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
continue
}
if lineInput == "Y" {
clearDB = true
break
}
log.Info("Not deleting chain database, the db will be initialized" +
" with the current data directory.")
break
}
}
if clearDB {
log.Warning("Removing database")
if err := d.ClearDB(); err != nil {
return nil, err
}

View File

@ -22,13 +22,13 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
interopcoldstart "github.com/prysmaticlabs/prysm/beacon-chain/interop-cold-start"
"github.com/prysmaticlabs/prysm/beacon-chain/operations"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
initialsync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync"
"github.com/prysmaticlabs/prysm/shared"
@ -200,17 +200,19 @@ func (b *BeaconNode) Close() {
func (b *BeaconNode) startDB(ctx *cli.Context) error {
baseDir := ctx.GlobalString(cmd.DataDirFlag.Name)
dbPath := path.Join(baseDir, beaconChainDBName)
clearDB := ctx.GlobalBool(cmd.ClearDB.Name)
forceClearDB := ctx.GlobalBool(cmd.ForceClearDB.Name)
d, err := db.NewDB(dbPath)
if err != nil {
return err
}
if b.ctx.GlobalBool(cmd.ClearDB.Name) {
d, err = confirmDelete(d, dbPath)
if clearDB || forceClearDB {
d, err = confirmDelete(d, dbPath, forceClearDB)
if err != nil {
return err
}
}
log.WithField("database-path", dbPath).Info("Checking DB")
b.db = d
b.depositCache = depositcache.NewDepositCache()

View File

@ -58,6 +58,7 @@ var appHelpFlagGroups = []flagGroup{
cmd.MonitoringPortFlag,
cmd.DisableMonitoringFlag,
cmd.MaxGoroutines,
cmd.ForceClearDB,
cmd.ClearDB,
},
},

View File

@ -13,4 +13,4 @@ while test $# -gt 0; do
esac
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

View File

@ -119,10 +119,15 @@ var (
Usage: "The encoding format of messages sent over the wire. The default is 0, which represents 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{
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 = cli.StringFlag{