You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/tendermint/tendermint/libs/log"
  6. "github.com/tendermint/tendermint/privval"
  7. )
  8. var (
  9. logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  10. )
  11. func main() {
  12. args := os.Args[1:]
  13. if len(args) != 3 {
  14. fmt.Println("Expected three args: <old path> <new key path> <new state path>")
  15. fmt.Println(
  16. "Eg. ~/.tendermint/config/priv_validator.json" +
  17. " ~/.tendermint/config/priv_validator_key.json" +
  18. " ~/.tendermint/data/priv_validator_state.json",
  19. )
  20. os.Exit(1)
  21. }
  22. err := loadAndUpgrade(args[0], args[1], args[2])
  23. if err != nil {
  24. fmt.Println(err)
  25. os.Exit(1)
  26. }
  27. }
  28. func loadAndUpgrade(oldPVPath, newPVKeyPath, newPVStatePath string) error {
  29. oldPV, err := privval.LoadOldFilePV(oldPVPath)
  30. if err != nil {
  31. return fmt.Errorf("Error reading OldPrivValidator from %v: %v\n", oldPVPath, err)
  32. }
  33. logger.Info("Upgrading PrivValidator file",
  34. "old", oldPVPath,
  35. "newKey", newPVKeyPath,
  36. "newState", newPVStatePath,
  37. )
  38. oldPV.Upgrade(newPVKeyPath, newPVStatePath)
  39. return nil
  40. }