Skip to content

Commit

Permalink
#111 Remove time based upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
blewater committed Aug 10, 2021
1 parent 223ef14 commit aea0c58
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
7 changes: 0 additions & 7 deletions networktest/emcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"regexp"
"strconv"
"strings"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -58,12 +57,6 @@ func (cli Emcli) UpgSchedByHeight(authority Key, planName string, height int64)
return execCmdWithInput(args, KeyPwd)
}

func (cli Emcli) UpgSchedByTime(authority Key, planName string, time time.Time) (string, bool, error) {
args := cli.addTransactionFlags("tx", "authority", "schedule-upgrade",
authority.name, planName, "--upgrade-height", strconv.FormatInt(time.Unix(), 10))
return execCmdWithInput(args, KeyPwd)
}

func (cli Emcli) AuthorityDestroyIssuer(authority, issuer Key) (string, bool, error) {
args := cli.addTransactionFlags("tx", "authority", "destroy-issuer", authority.name, issuer.GetAddress())
return execCmdWithInput(args, KeyPwd)
Expand Down
23 changes: 5 additions & 18 deletions x/authority/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func GetCmdScheduleUpgrade() *cobra.Command {
Use: "schedule-upgrade [authority_key_or_address] plan_name",
Short: "Schedule a software upgrade",
Example: `emd tx authority schedule-upgrade someplan --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t 0.43
emd tx authority schedule-upgrade 'New Staking Rewards 36%' --upgrade-time 1628956125 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t # Unix seconds for 2021-08-14 15:48:45 +0000 UTC
emd tx authority schedule-upgrade sdk-v0.43.0 --upgrade-height 2001 --from emoney1xue7fm6es84jze49grm4slhlmr4ffz8a3u7g3t --upgrade-info '{"binaries":{"linux/amd64":"http://localhost:8765/test-upg-0.2.0/emd.zip?checksum=sha256:cadd5b52fe90a04e20b2cbb93291b0d1d0204f17b64b2215eb09f5dc78a127f1"}}'`,
Long: `Schedule a software upgrade by submitting a unique plan name that
has not been used before with either an absolute block height or block time. An
Expand All @@ -207,9 +206,7 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in
return err
}

if err := validateUpgFlags(
UpgHeight, upgHeightVal, UpgTime, upgTimeSecsVal,
); err != nil {
if err := validateUpgFlags(UpgHeight, upgHeightVal); err != nil {
return err
}

Expand Down Expand Up @@ -239,9 +236,6 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in
}
f := cmd.Flags()
f.Int64VarP(&upgHeightVal, UpgHeight, "n", 0, "Upgrade block height number")
f.Int64VarP(
&upgTimeSecsVal, UpgTime, "t", 0, "upgrade block time (in Unix seconds)",
)
f.StringVarP(
&upgInfoVal, UpgInfo, "i", "", "Upgrade info",
)
Expand All @@ -250,29 +244,22 @@ the upgraded binary download url with the --upgrade-info flag i.e., --upgrade-in
return cmd
}

func validateUpgFlags(
upgHeight string, upgHeightVal int64, upgTime string, timeVal int64,
) error {
if upgHeightVal == 0 && timeVal == 0 {
func validateUpgFlags(upgHeight string, upgHeightVal int64) error {
if upgHeightVal == 0 {
return sdkerrors.Wrapf(
types.ErrMissingFlag,
"need to specify --%s or --%s", upgHeight, upgTime,
"need to specify --%s", upgHeight,
)
}

flagsSet := 0
if upgHeightVal != 0 {
flagsSet++
}
if timeVal != 0 {
flagsSet++
}
if flagsSet != 1 {
return sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"specify only one of the flags: --%s or --%s", upgHeight,
upgTime,
)
"specify only one of the flags: --%s", upgHeight)
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions x/authority/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

Expand Down Expand Up @@ -124,6 +125,13 @@ func (m msgServer) ScheduleUpgrade(
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "authority")
}

if msg.Plan.Time.Unix() != 0 {
return nil, sdkerrors.Wrap(
types.ErrPlanTimeIsSet,
fmt.Sprintf("Plan time: %s", msg.Plan.Time.String()),
)
}

result, err := m.k.ScheduleUpgrade(ctx, authority, msg.Plan)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion x/authority/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func TestScheduleUpgrade(t *testing.T) {
},
expErr: true,
},
"missing time or height": {
"missing height": {
req: &types.MsgScheduleUpgrade{
Authority: authorityAddr.String(),
Plan: upgradetypes.Plan{
Expand Down
1 change: 1 addition & 0 deletions x/authority/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ var (
ErrInvalidGasPrices = sdkerrors.Register(ModuleName, 5, "Invalid gas prices")
ErrUnknownDenom = sdkerrors.Register(ModuleName, 6, "Unknown denomination specified")
ErrMissingFlag = sdkerrors.Register(ModuleName, 7, "missing flag")
ErrPlanTimeIsSet = sdkerrors.Register(ModuleName, 8, "upgrade plan cannot set time")
)

0 comments on commit aea0c58

Please sign in to comment.