|
|
@ -2,6 +2,7 @@ package commands |
|
|
|
|
|
|
|
import ( |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"github.com/spf13/cobra" |
|
|
|
|
|
|
@ -31,6 +32,22 @@ func MakeResetAllCommand(conf *config.Config, logger log.Logger) *cobra.Command |
|
|
|
return cmd |
|
|
|
} |
|
|
|
|
|
|
|
// MakeResetAllCommand constructs a command that removes the database of
|
|
|
|
// the specified Tendermint core instance.
|
|
|
|
func MakeResetStateCommand(conf *config.Config, logger log.Logger) *cobra.Command { |
|
|
|
var keyType string |
|
|
|
|
|
|
|
cmd := &cobra.Command{ |
|
|
|
Use: "unsafe-reset-state", |
|
|
|
Short: "(unsafe) Remove all the data and WAL", |
|
|
|
RunE: func(cmd *cobra.Command, args []string) error { |
|
|
|
return resetState(conf.DBDir(), logger, keyType) |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
return cmd |
|
|
|
} |
|
|
|
|
|
|
|
func MakeResetPrivateValidatorCommand(conf *config.Config, logger log.Logger) *cobra.Command { |
|
|
|
var keyType string |
|
|
|
|
|
|
@ -56,17 +73,74 @@ func MakeResetPrivateValidatorCommand(conf *config.Config, logger log.Logger) *c |
|
|
|
|
|
|
|
// resetAll removes address book files plus all data, and resets the privValdiator data.
|
|
|
|
// Exported so other CLI tools can use it.
|
|
|
|
func resetAll(dbDir, privValKeyFile, privValStateFile string, logger log.Logger, keyType string) error { |
|
|
|
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 resetAll(dbDir string, privValKeyFile, privValStateFile string, logger log.Logger, keyType string) error { |
|
|
|
if err := resetState(dbDir, logger, keyType); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return resetFilePV(privValKeyFile, privValStateFile, logger, keyType) |
|
|
|
} |
|
|
|
|
|
|
|
// resetState removes address book files plus all data.
|
|
|
|
// Exported so other CLI tools can use it.
|
|
|
|
func resetState(dbDir string, logger log.Logger, keyType string) error { |
|
|
|
blockdb := filepath.Join(dbDir, "blockstore.db") |
|
|
|
state := filepath.Join(dbDir, "state.db") |
|
|
|
wal := filepath.Join(dbDir, "cs.wal") |
|
|
|
evidence := filepath.Join(dbDir, "evidence.db") |
|
|
|
txIndex := filepath.Join(dbDir, "tx_index.db") |
|
|
|
peerstore := filepath.Join(dbDir, "peerstore.db") |
|
|
|
|
|
|
|
if tmos.FileExists(blockdb) { |
|
|
|
if err := os.RemoveAll(blockdb); err == nil { |
|
|
|
logger.Info("Removed all blockstore.db", "dir", blockdb) |
|
|
|
} else { |
|
|
|
logger.Error("error removing all blockstore.db", "dir", state, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if tmos.FileExists(state) { |
|
|
|
if err := os.RemoveAll(state); err == nil { |
|
|
|
logger.Info("Removed all state.db", "dir", state) |
|
|
|
} else { |
|
|
|
logger.Error("error removing all state.db", "dir", state, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if tmos.FileExists(wal) { |
|
|
|
if err := os.RemoveAll(wal); err == nil { |
|
|
|
logger.Info("Removed all cs.wal", "dir", wal) |
|
|
|
} else { |
|
|
|
logger.Error("error removing all cs.wal", "dir", wal, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if tmos.FileExists(evidence) { |
|
|
|
if err := os.RemoveAll(evidence); err == nil { |
|
|
|
logger.Info("Removed all evidence.db", "dir", evidence) |
|
|
|
} else { |
|
|
|
logger.Error("error removing all evidence.db", "dir", evidence, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if tmos.FileExists(txIndex) { |
|
|
|
if err := os.RemoveAll(txIndex); err == nil { |
|
|
|
logger.Info("Removed tx_index.db", "dir", txIndex) |
|
|
|
} else { |
|
|
|
logger.Error("error removing tx_index.db", "dir", txIndex, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if tmos.FileExists(peerstore) { |
|
|
|
if err := os.RemoveAll(peerstore); err == nil { |
|
|
|
logger.Info("Removed peerstore.db", "dir", peerstore) |
|
|
|
} else { |
|
|
|
logger.Error("error removing peerstore.db", "dir", peerstore, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
// recreate the dbDir since the privVal state needs to live there
|
|
|
|
if err := tmos.EnsureDir(dbDir, 0700); err != nil { |
|
|
|
logger.Error("unable to recreate dbDir", "err", err) |
|
|
|
} |
|
|
|
return resetFilePV(privValKeyFile, privValStateFile, logger, keyType) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func resetFilePV(privValKeyFile, privValStateFile string, logger log.Logger, keyType string) error { |
|
|
|