Browse Source

`unsafe_reset_all` also resets addrbook.json (#1731)

* `unsafe_reset_all` also resets addrbook.json

When executing `unsafe_reset_all` it also clear all IP addresses from
addrbook.json. This is the expected behaviour of `unsafe_reset_all`.

* Fix tests

* improve logging statements

* use correct file
pull/1739/head
Adrian Brink 6 years ago
committed by Anton Kaliaev
parent
commit
ac80b93b60
1 changed files with 23 additions and 15 deletions
  1. +23
    -15
      cmd/tendermint/commands/reset_priv_validator.go

+ 23
- 15
cmd/tendermint/commands/reset_priv_validator.go View File

@ -24,21 +24,10 @@ var ResetPrivValidatorCmd = &cobra.Command{
Run: resetPrivValidator, Run: resetPrivValidator,
} }
// ResetAll removes the privValidator files.
// Exported so other CLI tools can use it.
func ResetAll(dbDir, privValFile string, logger log.Logger) {
resetFilePV(privValFile, logger)
if err := os.RemoveAll(dbDir); err != nil {
logger.Error("Error removing directory", "err", err)
return
}
logger.Info("Removed all blockchain history", "dir", dbDir)
}
// XXX: this is totally unsafe. // XXX: this is totally unsafe.
// it's only suitable for testnets. // it's only suitable for testnets.
func resetAll(cmd *cobra.Command, args []string) { func resetAll(cmd *cobra.Command, args []string) {
ResetAll(config.DBDir(), config.PrivValidatorFile(), logger)
ResetAll(config.DBDir(), config.P2P.AddrBookFile(), config.PrivValidatorFile(), logger)
} }
// XXX: this is totally unsafe. // XXX: this is totally unsafe.
@ -47,15 +36,34 @@ func resetPrivValidator(cmd *cobra.Command, args []string) {
resetFilePV(config.PrivValidatorFile(), logger) resetFilePV(config.PrivValidatorFile(), logger)
} }
// ResetAll removes the privValidator and address book files plus all data.
// Exported so other CLI tools can use it.
func ResetAll(dbDir, addrBookFile, privValFile string, logger log.Logger) {
resetFilePV(privValFile, logger)
removeAddrBook(addrBookFile, logger)
if err := os.RemoveAll(dbDir); err == nil {
logger.Info("Removed all blockchain history", "dir", dbDir)
} else {
logger.Error("Error removing all blockchain history", "dir", dbDir, "err", err)
}
}
func resetFilePV(privValFile string, logger log.Logger) { func resetFilePV(privValFile string, logger log.Logger) {
// Get PrivValidator
if _, err := os.Stat(privValFile); err == nil { if _, err := os.Stat(privValFile); err == nil {
pv := privval.LoadFilePV(privValFile) pv := privval.LoadFilePV(privValFile)
pv.Reset() pv.Reset()
logger.Info("Reset PrivValidator to genesis state", "file", privValFile)
logger.Info("Reset private validator file to genesis state", "file", privValFile)
} else { } else {
pv := privval.GenFilePV(privValFile) pv := privval.GenFilePV(privValFile)
pv.Save() pv.Save()
logger.Info("Generated PrivValidator", "file", privValFile)
logger.Info("Generated private validator file", "file", privValFile)
}
}
func removeAddrBook(addrBookFile string, logger log.Logger) {
if err := os.Remove(addrBookFile); err == nil {
logger.Info("Removed existing address book", "file", addrBookFile)
} else if !os.IsNotExist(err) {
logger.Info("Error removing address book", "file", addrBookFile, "err", err)
} }
} }

Loading…
Cancel
Save