Skip to content

Commit

Permalink
Add a runtime argument to set-validators, removing need for startup s…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
poktblade committed Jun 27, 2022
1 parent 296bc72 commit 435562a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
9 changes: 4 additions & 5 deletions app/cmd/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ var (
testnet bool
profileApp bool
useCache bool
useLean bool
validatorsPathLean string
peerNodeLean string
forceSetValidatorsLean bool
useLean bool
)

var CLIVersion = app.AppVersion
Expand Down Expand Up @@ -62,7 +61,7 @@ func init() {
startCmd.Flags().BoolVar(&profileApp, "profileApp", false, "expose cpu & memory profiling")
startCmd.Flags().BoolVar(&useCache, "useCache", false, "use cache")
startCmd.Flags().BoolVar(&useLean, "useLean", false, "enable usage of lean pocket through cli")
//startCmd.Flags().StringVar(&peerNodeLean, "set-peer-node-lean", "", "change the node lean file to be one of the specified validator by address")
startCmd.Flags().BoolVar(&forceSetValidatorsLean, "forceSetValidatorsLean", false, "reads your lean_pocket_user_key_file (lean_nodes_keys.json) and updates your last signed state/validator files before starting your node")
rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(resetCmd)
rootCmd.AddCommand(version)
Expand Down Expand Up @@ -97,7 +96,7 @@ func start(cmd *cobra.Command, args []string) {
if testnet {
genesisType = app.TestnetGenesisType
}
tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType, useCache, useLean)
tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType, useCache, useLean, forceSetValidatorsLean)
go rpc.StartRPC(app.GlobalConfig.PocketConfig.RPCPort, app.GlobalConfig.PocketConfig.RPCTimeout, simulateRelay, profileApp, allBlockTxs, app.GlobalConfig.PocketConfig.ChainsHotReload)
// trap kill signals (2,3,15,9)
signalChannel := make(chan os.Signal, 1)
Expand Down
31 changes: 14 additions & 17 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const (
DefaultGenesisType
)

func InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL string, keybase bool, genesisType GenesisType, useCache bool, useLean bool) *node.Node {
func InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL string, keybase bool, genesisType GenesisType, useCache bool, useLean bool, forceSetValidatorsLean bool) *node.Node {
// init config
InitConfig(datadir, tmNode, persistentPeers, seeds, remoteCLIURL)
GlobalConfig.PocketConfig.Cache = useCache
Expand All @@ -98,20 +98,18 @@ func InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL string, keyba
if GlobalConfig.PocketConfig.LeanPocket {
userProvidedKeyPath := GlobalConfig.PocketConfig.GetLeanPocketUserKeyFilePath()
pvkName := path.Join(GlobalConfig.PocketConfig.DataDir, GlobalConfig.TendermintConfig.PrivValidatorKey)
if _, err := os.Stat(pvkName); err != nil { // user has not ran set-validators
if os.IsNotExist(err) {
// read the user provided lean nodes
keys, err := ReadValidatorPrivateKeyFileLean(userProvidedKeyPath)
if err != nil {
logger.Error("Can't read user provided validator keys, did you create keys in", userProvidedKeyPath, err)
os.Exit(1)
}
// set them
err = SetValidatorsFilesLean(keys)
if err != nil {
logger.Error("Failed to set validators for user provided file, try pocket accounts set-validators", userProvidedKeyPath, err)
os.Exit(1)
}
if _, err := os.Stat(pvkName); err != nil && os.IsNotExist(err) || forceSetValidatorsLean { // user has not ran set-validators
// read the user provided lean nodes
keys, err := ReadValidatorPrivateKeyFileLean(userProvidedKeyPath)
if err != nil {
logger.Error("Can't read user provided validator keys, did you create keys in", userProvidedKeyPath, err)
os.Exit(1)
}
// set them
err = SetValidatorsFilesLean(keys)
if err != nil {
logger.Error("Failed to set validators for user provided file, try pocket accounts set-validators", userProvidedKeyPath, err)
os.Exit(1)
}
}
}
Expand Down Expand Up @@ -409,7 +407,6 @@ func InitKeyfiles(logger log.Logger) {
}
}


func InitNodesLean(logger log.Logger) error {
pvkName := path.Join(GlobalConfig.PocketConfig.DataDir, GlobalConfig.TendermintConfig.PrivValidatorKey)
if _, err := os.Stat(pvkName); err != nil {
Expand Down Expand Up @@ -1076,7 +1073,7 @@ func resetFilePV(privValKeyFile, privValStateFile string, logger log.Logger) {
"stateFile", privValStateFile)
}

func resetFilePVLean(privValKeyFile, privValStateFile string, logger log.Logger){
func resetFilePVLean(privValKeyFile, privValStateFile string, logger log.Logger) {
_, err := os.Stat(privValKeyFile)
if err == nil {
_ = os.Remove(privValKeyFile)
Expand Down

0 comments on commit 435562a

Please sign in to comment.