Skip to content

Commit 4863dfa

Browse files
authored
feat: remove time-based upgrade (#889)
* feat: remove time-based upgrade * test: fix typo * docs: add changelog * test: fix validate func * chore: revert irrelevant test * fix: fix typo, chore: remove __debug_bin binary * test: restore height based plan test
1 parent b886473 commit 4863dfa

File tree

10 files changed

+23
-104
lines changed

10 files changed

+23
-104
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343
* (x/wasm) [\#850](https://github.com/line/lbm-sdk/pull/850) remove `x/wasm` module in lbm-sdk
4444
* (log) [\#883](https://github.com/line/lbm-sdk/pull/883) add zerolog based rolling log system
4545
* (Ostracon) [\#887](https://github.com/line/lbm-sdk/pull/887) apply the changes of vrf location in Ostracon
46+
* (x/upgrade) [\#889](https://github.com/line/lbm-sdk/pull/889) remove time based upgrade
4647

4748
### Improvements
4849
* (cosmovisor) [\#792](https://github.com/line/lbm-sdk/pull/792) Use upstream's cosmovisor

x/upgrade/abci_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestCanOverwriteScheduleUpgrade(t *testing.T) {
9696
}
9797

9898
func VerifyDoUpgrade(t *testing.T) {
99-
t.Log("Verify that a panic happens at the upgrade time/height")
99+
t.Log("Verify that a panic happens at the upgrade height")
100100
newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now())
101101

102102
req := ocabci.RequestBeginBlock{Header: newCtx.BlockHeader()}
@@ -116,7 +116,7 @@ func VerifyDoUpgrade(t *testing.T) {
116116
}
117117

118118
func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName string) {
119-
t.Log("Verify that a panic happens at the upgrade time/height")
119+
t.Log("Verify that a panic happens at the upgrade height")
120120
req := ocabci.RequestBeginBlock{Header: newCtx.BlockHeader()}
121121
require.Panics(t, func() {
122122
s.module.BeginBlock(newCtx, req)

x/upgrade/client/cli/tx.go

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cli
22

33
import (
4-
"fmt"
5-
"time"
6-
74
"github.com/spf13/cobra"
85

96
"github.com/line/lbm-sdk/client"
@@ -15,11 +12,7 @@ import (
1512
)
1613

1714
const (
18-
// TimeFormat specifies ISO UTC format for submitting the time for a new upgrade proposal
19-
TimeFormat = "2006-01-02T15:04:05Z"
20-
2115
FlagUpgradeHeight = "upgrade-height"
22-
FlagUpgradeTime = "upgrade-time"
2316
FlagUpgradeInfo = "upgrade-info"
2417
)
2518

@@ -36,11 +29,11 @@ func GetTxCmd() *cobra.Command {
3629
// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction.
3730
func NewCmdSubmitUpgradeProposal() *cobra.Command {
3831
cmd := &cobra.Command{
39-
Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]",
32+
Use: "software-upgrade [name] (--upgrade-height [height]) (--upgrade-info [info]) [flags]",
4033
Args: cobra.ExactArgs(1),
4134
Short: "Submit a software upgrade proposal",
4235
Long: "Submit a software upgrade along with an initial deposit.\n" +
43-
"Please specify a unique name and height OR time for the upgrade to take effect.\n" +
36+
"Please specify a unique name and height for the upgrade to take effect.\n" +
4437
"You may include info to reference a binary download link, in a format compatible with: https://github.com/line/lbm-sdk/tree/master/cosmovisor",
4538
RunE: func(cmd *cobra.Command, args []string) error {
4639
clientCtx, err := client.GetClientTxContext(cmd)
@@ -76,8 +69,7 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command {
7669
cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
7770
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
7871
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
79-
cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen (not to be used together with --upgrade-time)")
80-
cmd.Flags().String(FlagUpgradeTime, "", fmt.Sprintf("The time at which the upgrade must happen (ex. %s) (not to be used together with --upgrade-height)", TimeFormat))
72+
cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen")
8173
cmd.Flags().String(FlagUpgradeInfo, "", "Optional info for the planned upgrade such as commit hash, etc.")
8274

8375
return cmd
@@ -153,29 +145,12 @@ func parseArgsToContent(cmd *cobra.Command, name string) (gov.Content, error) {
153145
return nil, err
154146
}
155147

156-
timeStr, err := cmd.Flags().GetString(FlagUpgradeTime)
157-
if err != nil {
158-
return nil, err
159-
}
160-
161-
if height != 0 && len(timeStr) != 0 {
162-
return nil, fmt.Errorf("only one of --upgrade-time or --upgrade-height should be specified")
163-
}
164-
165-
var upgradeTime time.Time
166-
if len(timeStr) != 0 {
167-
upgradeTime, err = time.Parse(TimeFormat, timeStr)
168-
if err != nil {
169-
return nil, err
170-
}
171-
}
172-
173148
info, err := cmd.Flags().GetString(FlagUpgradeInfo)
174149
if err != nil {
175150
return nil, err
176151
}
177152

178-
plan := types.Plan{Name: name, Time: upgradeTime, Height: height, Info: info}
153+
plan := types.Plan{Name: name, Height: height, Info: info}
179154
content := types.NewSoftwareUpgradeProposal(title, description, plan)
180155
return content, nil
181156
}

x/upgrade/doc.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Package upgrade provides a Cosmos SDK module that can be used for smoothly upgrading a live Cosmos chain to a
33
new software version. It accomplishes this by providing a BeginBlocker hook that prevents the blockchain state
4-
machine from proceeding once a pre-defined upgrade block time or height has been reached. The module does not prescribe
4+
machine from proceeding once a pre-defined upgrade block height has been reached. The module does not prescribe
55
anything regarding how governance decides to do an upgrade, but just the mechanism for coordinating the upgrade safely.
66
Without software support for upgrades, upgrading a live chain is risky because all of the validators need to pause
77
their state machines at exactly the same point in the process. If this is not done correctly, there can be state
@@ -21,9 +21,9 @@ perform a migration, but also to identify if this is the old or new version (eg.
2121
a handler registered for the named upgrade).
2222
2323
Once the release candidate along with an appropriate upgrade handler is frozen,
24-
we can have a governance vote to approve this upgrade at some future block time
25-
or block height (e.g. 200000). This is known as an upgrade.Plan. The v0.38.0 code will not know of this
26-
handler, but will continue to run until block 200000, when the plan kicks in at BeginBlock. It will check
24+
we can have a governance vote to approve this upgrade at some future block height (e.g. 200000).
25+
This is known as an upgrade.Plan. The v0.38.0 code will not know of this handler, but will
26+
continue to run until block 200000, when the plan kicks in at BeginBlock. It will check
2727
for existence of the handler, and finding it missing, know that it is running the obsolete software,
2828
and gracefully exit.
2929
@@ -55,7 +55,7 @@ should call ScheduleUpgrade to schedule an upgrade and ClearUpgradePlan to cance
5555
5656
# Performing Upgrades
5757
58-
Upgrades can be scheduled at either a predefined block height or time. Once this block height or time is reached, the
58+
Upgrades can be scheduled at a predefined block height. Once this block height is reached, the
5959
existing software will cease to process ABCI messages and a new version with code that handles the upgrade must be deployed.
6060
All upgrades are coordinated by a unique upgrade name that cannot be reused on the same blockchain. In order for the upgrade
6161
module to know that the upgrade has been safely applied, a handler with the name of the upgrade must be installed.

x/upgrade/keeper/keeper_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,6 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() {
9898
setup: func() {},
9999
expPass: false,
100100
},
101-
{
102-
name: "unsuccessful time schedule: due date in past",
103-
plan: types.Plan{
104-
Name: "all-good",
105-
Info: "some text here",
106-
Time: s.ctx.BlockTime(),
107-
},
108-
setup: func() {},
109-
expPass: false,
110-
},
111101
{
112102
name: "unsuccessful height schedule: due date in past",
113103
plan: types.Plan{

x/upgrade/spec/01_concepts.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ order: 1
77
## Plan
88

99
The `x/upgrade` module defines a `Plan` type in which a live upgrade is scheduled
10-
to occur. A `Plan` can be scheduled at a specific block height or time, but not both.
10+
to occur. A `Plan` can be scheduled at a specific block height.
1111
A `Plan` is created once a (frozen) release candidate along with an appropriate upgrade
1212
`Handler` (see below) is agreed upon, where the `Name` of a `Plan` corresponds to a
1313
specific `Handler`. Typically, a `Plan` is created through a governance proposal
@@ -52,7 +52,7 @@ type UpgradeHandler func(Context, Plan, VersionMap) (VersionMap, error)
5252
```
5353

5454
During each `EndBlock` execution, the `x/upgrade` module checks if there exists a
55-
`Plan` that should execute (is scheduled at that time or height). If so, the corresponding
55+
`Plan` that should execute (is scheduled at that height). If so, the corresponding
5656
`Handler` is executed. If the `Plan` is expected to execute but no `Handler` is registered
5757
or if the binary was upgraded too early, the node will gracefully panic and exit.
5858

@@ -87,7 +87,7 @@ will ensure these `StoreUpgrades` takes place only in planned upgrade handler.
8787
Typically, a `Plan` is proposed and submitted through governance via a `SoftwareUpgradeProposal`.
8888
This proposal prescribes to the standard governance process. If the proposal passes,
8989
the `Plan`, which targets a specific `Handler`, is persisted and scheduled. The
90-
upgrade can be delayed or hastened by updating the `Plan.Time` in a new proposal.
90+
upgrade can be delayed or hastened by updating the `Plan.Height` in a new proposal.
9191

9292
```go
9393
type SoftwareUpgradeProposal struct {

x/upgrade/spec/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parent:
1212
`x/upgrade` is an implementation of a Cosmos SDK module that facilitates smoothly
1313
upgrading a live Cosmos chain to a new (breaking) software version. It accomplishes this by
1414
providing a `BeginBlocker` hook that prevents the blockchain state machine from
15-
proceeding once a pre-defined upgrade block time or height has been reached.
15+
proceeding once a pre-defined upgrade block height has been reached.
1616

1717
The module does not prescribe anything regarding how governance decides to do an
1818
upgrade, but just the mechanism for coordinating the upgrade safely. Without software

x/upgrade/types/plan.go

+4-18
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,36 @@ package types
22

33
import (
44
"fmt"
5-
"strings"
65

76
sdk "github.com/line/lbm-sdk/types"
87
sdkerrors "github.com/line/lbm-sdk/types/errors"
98
)
109

1110
func (p Plan) String() string {
1211
due := p.DueAt()
13-
dueUp := strings.ToUpper(due[0:1]) + due[1:]
1412
return fmt.Sprintf(`Upgrade Plan
1513
Name: %s
1614
%s
17-
Info: %s.`, p.Name, dueUp, p.Info)
15+
Info: %s.`, p.Name, due, p.Info)
1816
}
1917

2018
// ValidateBasic does basic validation of a Plan
2119
func (p Plan) ValidateBasic() error {
22-
if !p.Time.IsZero() {
23-
return sdkerrors.ErrInvalidRequest.Wrap("time-based upgrades have been deprecated in the SDK")
24-
}
2520
if p.UpgradedClientState != nil {
2621
return sdkerrors.ErrInvalidRequest.Wrap("upgrade logic for IBC has been moved to the IBC module")
2722
}
2823
if len(p.Name) == 0 {
2924
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot be empty")
3025
}
31-
if p.Height < 0 {
32-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
33-
}
34-
if p.Time.Unix() <= 0 && p.Height == 0 {
35-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
36-
}
37-
if p.Time.Unix() > 0 && p.Height != 0 {
38-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
26+
if p.Height <= 0 {
27+
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height must be greater than 0")
3928
}
4029

4130
return nil
4231
}
4332

4433
// ShouldExecute returns true if the Plan is ready to execute given the current context
4534
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
46-
if p.Time.Unix() > 0 {
47-
return !ctx.BlockTime().Before(p.Time)
48-
}
4935
if p.Height > 0 {
5036
return p.Height <= ctx.BlockHeight()
5137
}
@@ -54,5 +40,5 @@ func (p Plan) ShouldExecute(ctx sdk.Context) bool {
5440

5541
// DueAt is a string representation of when this plan is due to be executed
5642
func (p Plan) DueAt() string {
57-
return fmt.Sprintf("height: %d", p.Height)
43+
return fmt.Sprintf("Height: %d", p.Height)
5844
}

x/upgrade/types/plan_test.go

-33
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func TestPlanValid(t *testing.T) {
7070
Height: 123450000,
7171
},
7272
},
73-
"time-base upgrade": {
74-
p: types.Plan{
75-
Time: time.Now(),
76-
},
77-
},
7873
"IBC upgrade": {
7974
p: types.Plan{
8075
Height: 123450000,
@@ -115,34 +110,6 @@ func TestShouldExecute(t *testing.T) {
115110
ctxHeight int64
116111
expected bool
117112
}{
118-
"past time": {
119-
p: types.Plan{
120-
Name: "do-good",
121-
Info: "some text here",
122-
Time: mustParseTime("2019-07-08T11:33:55Z"),
123-
},
124-
ctxTime: mustParseTime("2019-07-08T11:32:00Z"),
125-
ctxHeight: 100000,
126-
expected: false,
127-
},
128-
"on time": {
129-
p: types.Plan{
130-
Name: "do-good",
131-
Time: mustParseTime("2019-07-08T11:33:55Z"),
132-
},
133-
ctxTime: mustParseTime("2019-07-08T11:33:55Z"),
134-
ctxHeight: 100000,
135-
expected: true,
136-
},
137-
"future time": {
138-
p: types.Plan{
139-
Name: "do-good",
140-
Time: mustParseTime("2019-07-08T11:33:55Z"),
141-
},
142-
ctxTime: mustParseTime("2019-07-08T11:33:57Z"),
143-
ctxHeight: 100000,
144-
expected: true,
145-
},
146113
"past height": {
147114
p: types.Plan{
148115
Name: "do-good",

x/upgrade/types/proposal_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func TestContentAccessors(t *testing.T) {
2626
}{
2727
"upgrade": {
2828
p: types.NewSoftwareUpgradeProposal("Title", "desc", types.Plan{
29-
Name: "due_time",
30-
Info: "https://foo.bar",
31-
Time: mustParseTime("2019-07-08T11:33:55Z"),
29+
Name: "due_height",
30+
Info: "https://foo.bar",
31+
Height: 99999999999,
3232
}),
3333
title: "Title",
3434
desc: "desc",

0 commit comments

Comments
 (0)