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.

41 lines
1015 B

  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("Eg. ~/.tendermint/config/priv_validator.json ~/.tendermint/config/priv_validator_key.json ~/.tendermint/data/priv_validator_state.json")
  16. os.Exit(1)
  17. }
  18. err := loadAndUpgrade(args[0], args[1], args[2])
  19. if err != nil {
  20. fmt.Println(err)
  21. os.Exit(1)
  22. }
  23. }
  24. func loadAndUpgrade(oldPVPath, newPVKeyPath, newPVStatePath string) error {
  25. oldPV, err := privval.LoadOldFilePV(oldPVPath)
  26. if err != nil {
  27. return fmt.Errorf("Error reading OldPrivValidator from %v: %v\n", oldPVPath, err)
  28. }
  29. logger.Info("Upgrading PrivValidator file",
  30. "old", oldPVPath,
  31. "newKey", newPVKeyPath,
  32. "newState", newPVStatePath,
  33. )
  34. oldPV.Upgrade(newPVKeyPath, newPVStatePath)
  35. return nil
  36. }