From 4630569e82830f7fafd27b0faa209a0a3eed7f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Fri, 17 Jul 2020 13:56:08 +0200 Subject: [PATCH] go/oasis-node/cmd: Remove retry functionality from staking CLI commands The retry functionality is not needed since the staking client waits for a response from the gRPC server. --- .changelog/3113.breaking.md | 4 + go/oasis-node/cmd/common/flags/flags.go | 11 -- go/oasis-node/cmd/stake/account.go | 2 - go/oasis-node/cmd/stake/stake.go | 139 +++++++++--------------- 4 files changed, 53 insertions(+), 103 deletions(-) create mode 100644 .changelog/3113.breaking.md diff --git a/.changelog/3113.breaking.md b/.changelog/3113.breaking.md new file mode 100644 index 00000000000..f663bc5ce6a --- /dev/null +++ b/.changelog/3113.breaking.md @@ -0,0 +1,4 @@ +go/oasis-node/cmd: Remove `--retry` flag from staking CLI commands + +Remove obsolete `--retry` flag from `oasis-node stake info`, +`oasis-node stake list` and `oasis-node stake account info` CLI commands. diff --git a/go/oasis-node/cmd/common/flags/flags.go b/go/oasis-node/cmd/common/flags/flags.go index b26379f21b6..1380ecdd9d8 100644 --- a/go/oasis-node/cmd/common/flags/flags.go +++ b/go/oasis-node/cmd/common/flags/flags.go @@ -21,7 +21,6 @@ const ( cfgVerbose = "verbose" cfgForce = "force" - cfgRetries = "retries" // CfgDryRun is the flag used to specify a dry-run of an operation. CfgDryRun = "dry_run" @@ -32,8 +31,6 @@ var ( VerboseFlags = flag.NewFlagSet("", flag.ContinueOnError) // ForceFlags has the force flag. ForceFlags = flag.NewFlagSet("", flag.ContinueOnError) - // RetriesFlags has the retries flag. - RetriesFlags = flag.NewFlagSet("", flag.ContinueOnError) // DebugTestEntityFlags has the test entity enable flag. DebugTestEntityFlags = flag.NewFlagSet("", flag.ContinueOnError) @@ -59,11 +56,6 @@ func Force() bool { return viper.GetBool(cfgForce) } -// Retries returns the retries flag value. -func Retries() int { - return viper.GetInt(cfgRetries) -} - // ConsensusValidator returns true iff the node is opting in to be a consensus // validator. func ConsensusValidator() bool { @@ -95,8 +87,6 @@ func init() { ForceFlags.Bool(cfgForce, false, "force") - RetriesFlags.Int(cfgRetries, 0, "retries (-1 = forever)") - ConsensusValidatorFlag.Bool(CfgConsensusValidator, false, "node is a consensus validator") DebugTestEntityFlags.Bool(CfgDebugTestEntity, false, "use the test entity (UNSAFE)") @@ -112,7 +102,6 @@ func init() { for _, v := range []*flag.FlagSet{ VerboseFlags, ForceFlags, - RetriesFlags, DebugTestEntityFlags, GenesisFileFlags, ConsensusValidatorFlag, diff --git a/go/oasis-node/cmd/stake/account.go b/go/oasis-node/cmd/stake/account.go index dbdb18bffc7..1aec77bbef7 100644 --- a/go/oasis-node/cmd/stake/account.go +++ b/go/oasis-node/cmd/stake/account.go @@ -12,7 +12,6 @@ import ( cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" cmdConsensus "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/consensus" - cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" cmdGrpc "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc" staking "github.com/oasisprotocol/oasis-core/go/staking/api" ) @@ -321,7 +320,6 @@ func registerAccountCmd() { func init() { accountInfoFlags.String(CfgAccountAddr, "", "account address") _ = viper.BindPFlags(accountInfoFlags) - accountInfoFlags.AddFlagSet(cmdFlags.RetriesFlags) accountInfoFlags.AddFlagSet(cmdGrpc.ClientFlags) amountFlags.String(CfgAmount, "0", "amount of stake (in base units) for the transaction") diff --git a/go/oasis-node/cmd/stake/stake.go b/go/oasis-node/cmd/stake/stake.go index 1fd324c6a73..3cb62736015 100644 --- a/go/oasis-node/cmd/stake/stake.go +++ b/go/oasis-node/cmd/stake/stake.go @@ -15,7 +15,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" "github.com/oasisprotocol/oasis-core/go/common/errors" "github.com/oasisprotocol/oasis-core/go/common/logging" - "github.com/oasisprotocol/oasis-core/go/common/quantity" consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" @@ -71,25 +70,6 @@ func doConnect(cmd *cobra.Command) (*grpc.ClientConn, api.Backend) { return conn, client } -func doWithRetries(cmd *cobra.Command, descr string, fn func() error) { - nrRetries := cmdFlags.Retries() - for i := 0; i <= nrRetries; i++ { - err := fn() - switch err { - case nil: - return - default: - logger.Warn("failed to "+descr, - "err", err, - "attempt", i+1, - ) - } - } - - // Retries exhausted, just bail. - os.Exit(1) -} - func doInfo(cmd *cobra.Command, args []string) { if err := cmdCommon.Init(); err != nil { cmdCommon.EarlyLogAndExit(err) @@ -100,35 +80,32 @@ func doInfo(cmd *cobra.Command, args []string) { ctx := context.Background() - doWithRetries(cmd, "query total supply", func() error { - q, err := client.TotalSupply(ctx, consensus.HeightLatest) - if err != nil { - return err - } - - fmt.Printf("Total supply: %v\n", q) - return nil - }) - - doWithRetries(cmd, "query common pool", func() error { - q, err := client.CommonPool(ctx, consensus.HeightLatest) - if err != nil { - return err - } - - fmt.Printf("Common pool: %v\n", q) - return nil - }) + totalSupply, err := client.TotalSupply(ctx, consensus.HeightLatest) + if err != nil { + logger.Error("failed to query total supply", + "err", err, + ) + os.Exit(1) + } + fmt.Printf("Total supply: %v\n", totalSupply) - doWithRetries(cmd, "query last block fees", func() error { - q, err := client.LastBlockFees(ctx, consensus.HeightLatest) - if err != nil { - return err - } + commonPool, err := client.CommonPool(ctx, consensus.HeightLatest) + if err != nil { + logger.Error("failed to query common pool", + "err", err, + ) + os.Exit(1) + } + fmt.Printf("Common pool: %v\n", commonPool) - fmt.Printf("Last block fees: %v\n", q) - return nil - }) + lastBlockFees, err := client.LastBlockFees(ctx, consensus.HeightLatest) + if err != nil { + logger.Error("failed to query last block fees", + "err", err, + ) + os.Exit(1) + } + fmt.Printf("Last block fees: %v\n", lastBlockFees) thresholdsToQuery := []api.ThresholdKind{ api.KindEntity, @@ -139,38 +116,19 @@ func doInfo(cmd *cobra.Command, args []string) { api.KindRuntimeCompute, api.KindRuntimeKeyManager, } - type threshold struct { - value *quantity.Quantity - valid bool - } - thresholds := make(map[api.ThresholdKind]*threshold) - doWithRetries(cmd, "query staking threshold(s)", func() error { - for _, k := range thresholdsToQuery { - if thresholds[k] != nil { + for _, kind := range thresholdsToQuery { + thres, err := client.Threshold(ctx, &api.ThresholdQuery{Kind: kind, Height: consensus.HeightLatest}) + if err != nil { + if errors.Is(err, api.ErrInvalidThreshold) { + logger.Warn(fmt.Sprintf("invalid staking threshold kind: %s", kind)) continue } - - q, err := client.Threshold(ctx, &api.ThresholdQuery{Kind: k, Height: consensus.HeightLatest}) - if err != nil { - if errors.Is(err, api.ErrInvalidThreshold) { - logger.Warn(fmt.Sprintf("invalid staking threshold kind: %s", k)) - thresholds[k] = &threshold{} - continue - } - return err - } - thresholds[k] = &threshold{ - value: q, - valid: true, - } - } - return nil - }) - for _, k := range thresholdsToQuery { - thres := thresholds[k] - if thres.valid { - fmt.Printf("Staking threshold (%s): %v\n", k, thres.value) + logger.Error("failed to query staking threshold", + "err", err, + ) + os.Exit(1) } + fmt.Printf("Staking threshold (%s): %v\n", kind, thres) } } @@ -184,12 +142,13 @@ func doList(cmd *cobra.Command, args []string) { ctx := context.Background() - var addresses []api.Address - doWithRetries(cmd, "query addresses", func() error { - var err error - addresses, err = client.Addresses(ctx, consensus.HeightLatest) - return err - }) + addresses, err := client.Addresses(ctx, consensus.HeightLatest) + if err != nil { + logger.Error("failed to query addresses", + "err", err, + ) + os.Exit(1) + } for _, addr := range addresses { var s string @@ -210,12 +169,14 @@ func doList(cmd *cobra.Command, args []string) { } func getAccount(ctx context.Context, cmd *cobra.Command, addr api.Address, client api.Backend) *api.Account { - var acct *api.Account - doWithRetries(cmd, "query account "+addr.String(), func() error { - var err error - acct, err = client.Account(ctx, &api.OwnerQuery{Owner: addr, Height: consensus.HeightLatest}) - return err - }) + acct, err := client.Account(ctx, &api.OwnerQuery{Owner: addr, Height: consensus.HeightLatest}) + if err != nil { + logger.Error("failed to query account", + "address", addr, + "err", err, + ) + os.Exit(1) + } return acct } @@ -262,10 +223,8 @@ func Register(parentCmd *cobra.Command) { } func init() { - infoFlags.AddFlagSet(cmdFlags.RetriesFlags) infoFlags.AddFlagSet(cmdGrpc.ClientFlags) - listFlags.AddFlagSet(cmdFlags.RetriesFlags) listFlags.AddFlagSet(cmdFlags.VerboseFlags) listFlags.AddFlagSet(cmdGrpc.ClientFlags)