Skip to content

Commit

Permalink
Merge pull request #3113 from oasisprotocol/tjanez/cli-remove-retries
Browse files Browse the repository at this point in the history
go/oasis-node/cmd: Remove retry functionality from staking CLI commands
  • Loading branch information
tjanez authored Jul 17, 2020
2 parents 3263a4d + 4630569 commit c28bc0c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 103 deletions.
4 changes: 4 additions & 0 deletions .changelog/3113.breaking.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 0 additions & 11 deletions go/oasis-node/cmd/common/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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)")
Expand All @@ -112,7 +102,6 @@ func init() {
for _, v := range []*flag.FlagSet{
VerboseFlags,
ForceFlags,
RetriesFlags,
DebugTestEntityFlags,
GenesisFileFlags,
ConsensusValidatorFlag,
Expand Down
2 changes: 0 additions & 2 deletions go/oasis-node/cmd/stake/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down
139 changes: 49 additions & 90 deletions go/oasis-node/cmd/stake/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
}

Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c28bc0c

Please sign in to comment.