Skip to content

Commit

Permalink
Merge branch 'master' into aleem/8686-txevents-orderby
Browse files Browse the repository at this point in the history
  • Loading branch information
aleem1314 committed Mar 15, 2021
2 parents d384dd1 + d02a397 commit dd424ed
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 276 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
* (crypto/ed25519) [\#8690] Adopt zip1215 ed2559 verification rules.
* [\#8849](https://github.com/cosmos/cosmos-sdk/pull/8849) Upgrade module no longer supports time based upgrades.


### API Breaking Changes
Expand All @@ -66,8 +67,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
### State Machine Breaking

* (x/{bank,distrib,gov,slashing,staking}) [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Store keys have been modified to allow for variable-length addresses.
* (x/ibc) [\#8266](https://github.com/cosmos/cosmos-sdk/issues/8266) Add amino JSON for IBC messages in order to support Ledger text signing.
* (x/ibc) [\#8405](https://github.com/cosmos/cosmos-sdk/pull/8405) Refactor IBC client update governance proposals to use a substitute client to update a frozen or expired client.
* (x/evidence) [\#8502](https://github.com/cosmos/cosmos-sdk/pull/8502) `HandleEquivocationEvidence` persists the evidence to state.
* (x/gov) [\#7733](https://github.com/cosmos/cosmos-sdk/pull/7733) ADR 037 Implementation: Governance Split Votes
* (x/bank) [\#8656](https://github.com/cosmos/cosmos-sdk/pull/8656) balance and supply are now correctly tracked via `coin_spent`, `coin_received`, `coinbase` and `burn` events.
Expand All @@ -78,7 +77,6 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (x/ibc) [\#7949](https://github.com/cosmos/cosmos-sdk/issues/7949) Standardized channel `Acknowledgement` moved to its own file. Codec registration redundancy removed.
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.
* (grpc) [\#8815](https://github.com/cosmos/cosmos-sdk/pull/8815) Add orderBy parameter to `TxsByEvents` endpoint.

Expand Down
2 changes: 2 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ lint:
breaking:
use:
- FILE
except:
- FIELD_NO_DELETE
ignore:
- tendermint
- gogoproto
Expand Down
1 change: 0 additions & 1 deletion docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7362,7 +7362,6 @@ Plan specifies information about a planned upgrade and when it should occur.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `name` | [string](#string) | | Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height is reached and the software will exit. |
| `time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | The time after which the upgrade must be performed. Leave set to its zero value to use a pre-defined Height instead. |
| `height` | [int64](#int64) | | The height at which the upgrade must be performed. Only used if Time is not set. |
| `info` | [string](#string) | | Any application specific upgrade info to be included on-chain such as a git commit that validators could automatically upgrade to |

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/common v0.18.0
github.com/prometheus/common v0.19.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.20.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.18.0 h1:WCVKW7aL6LEe1uryfI9dnEc2ZqNB1Fn0ok930v0iL1Y=
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.19.0 h1:Itb4+NjG9wRdkAWgVucbM/adyIXxEhbw0866e0uZE6A=
github.com/prometheus/common v0.19.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
Expand Down
7 changes: 4 additions & 3 deletions proto/cosmos/upgrade/v1beta1/upgrade.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ message Plan {
// reached and the software will exit.
string name = 1;

// The time after which the upgrade must be performed.
// Leave set to its zero value to use a pre-defined Height instead.
google.protobuf.Timestamp time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Time based upgrades have been deprecated. Time based upgrade logic
// has been removed from the SDK.
reserved 2;
reserved "time";

// The height at which the upgrade must be performed.
// Only used if Time is not set.
Expand Down
10 changes: 2 additions & 8 deletions server/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ func FreeTCPAddr() (addr, port string, err error) {
return "", "", err
}

closer := func() {
err := l.Close()
if err != nil {
// TODO: Handle with #870
panic(err)
}
if err := l.Close(); err != nil {
return "", "", fmt.Errorf("couldn't close the listener: %w", err)
}

defer closer()

portI := l.Addr().(*net.TCPAddr).Port
port = fmt.Sprintf("%d", portI)
addr = fmt.Sprintf("tcp://0.0.0.0:%s", port)
Expand Down
1 change: 0 additions & 1 deletion x/gov/legacy/v040/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func migrateContent(oldContent v036gov.Content) *codectypes.Any {
Title: oldContent.Title,
Plan: v040upgrade.Plan{
Name: oldContent.Plan.Name,
Time: oldContent.Plan.Time,
Height: oldContent.Plan.Height,
Info: oldContent.Plan.Info,
},
Expand Down
3 changes: 1 addition & 2 deletions x/gov/legacy/v040/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ func TestMigrate(t *testing.T) {
"plan": {
"height": "123",
"info": "foo_upgrade_info",
"name": "foo_upgrade_name",
"time": "0001-01-01T00:00:00Z"
"name": "foo_upgrade_name"
},
"title": "foo_software_upgrade"
},
Expand Down
45 changes: 9 additions & 36 deletions x/upgrade/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,13 @@ func TestRequireName(t *testing.T) {
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}

func TestRequireFutureTime(t *testing.T) {
s := setupTest(10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: s.ctx.BlockHeader().Time}})
require.NotNil(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}

func TestRequireFutureBlock(t *testing.T) {
s := setupTest(10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight()}})
require.NotNil(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}

func TestCantSetBothTimeAndHeight(t *testing.T) {
s := setupTest(10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now(), Height: s.ctx.BlockHeight() + 1}})
require.NotNil(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}

func TestDoTimeUpgrade(t *testing.T) {
s := setupTest(10, map[int64]bool{})
t.Log("Verify can schedule an upgrade")
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}})
require.Nil(t, err)

VerifyDoUpgrade(t)
}

func TestDoHeightUpgrade(t *testing.T) {
s := setupTest(10, map[int64]bool{})
t.Log("Verify can schedule an upgrade")
Expand All @@ -119,7 +96,7 @@ func TestCanOverwriteScheduleUpgrade(t *testing.T) {
}

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

req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()}
Expand All @@ -137,7 +114,7 @@ func VerifyDoUpgrade(t *testing.T) {
}

func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName string) {
t.Log("Verify that a panic happens at the upgrade time/height")
t.Log("Verify that a panic happens at the upgrade height")
req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()}
require.Panics(t, func() {
s.module.BeginBlock(newCtx, req)
Expand Down Expand Up @@ -195,7 +172,7 @@ func VerifyCleared(t *testing.T, newCtx sdk.Context) {
func TestCanClear(t *testing.T) {
s := setupTest(10, map[int64]bool{})
t.Log("Verify upgrade is scheduled")
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.BlockHeight() + 100}})
require.Nil(t, err)

err = s.handler(s.ctx, &types.CancelSoftwareUpgradeProposal{Title: "cancel"})
Expand All @@ -206,11 +183,12 @@ func TestCanClear(t *testing.T) {

func TestCantApplySameUpgradeTwice(t *testing.T) {
s := setupTest(10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}})
height := s.ctx.BlockHeader().Height + 1
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: height}})
require.Nil(t, err)
VerifyDoUpgrade(t)
t.Log("Verify an executed upgrade \"test\" can't be rescheduled")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Time: time.Now()}})
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: height}})
require.NotNil(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}
Expand All @@ -225,20 +203,15 @@ func TestNoSpuriousUpgrades(t *testing.T) {
}

func TestPlanStringer(t *testing.T) {
ti, err := time.Parse(time.RFC3339, "2020-01-01T00:00:00Z")
require.Nil(t, err)
require.Equal(t, `Upgrade Plan
Name: test
Time: 2020-01-01T00:00:00Z
Info: .`, types.Plan{Name: "test", Time: ti}.String())
require.Equal(t, `Upgrade Plan
Name: test
Height: 100
Info: .`, types.Plan{Name: "test", Height: 100}.String())
Info: .`, types.Plan{Name: "test", Height: 100, Info: ""}.String())

require.Equal(t, fmt.Sprintf(`Upgrade Plan
Name: test
Height: 100
Info: .`), types.Plan{Name: "test", Height: 100}.String())
Info: .`), types.Plan{Name: "test", Height: 100, Info: ""}.String())
}

func VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) {
Expand Down
33 changes: 4 additions & 29 deletions x/upgrade/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cli

import (
"fmt"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -16,11 +13,7 @@ import (
)

const (
// TimeFormat specifies ISO UTC format for submitting the time for a new upgrade proposal
TimeFormat = "2006-01-02T15:04:05Z"

FlagUpgradeHeight = "upgrade-height"
FlagUpgradeTime = "upgrade-time"
FlagUpgradeInfo = "upgrade-info"
)

Expand All @@ -37,11 +30,11 @@ func GetTxCmd() *cobra.Command {
// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction.
func NewCmdSubmitUpgradeProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]",
Use: "software-upgrade [name] (--upgrade-height [height]) (--upgrade-info [info]) [flags]",
Args: cobra.ExactArgs(1),
Short: "Submit a software upgrade proposal",
Long: "Submit a software upgrade along with an initial deposit.\n" +
"Please specify a unique name and height OR time for the upgrade to take effect.\n" +
"Please specify a unique name and height for the upgrade to take effect.\n" +
"You may include info to reference a binary download link, in a format compatible with: https://github.com/cosmos/cosmos-sdk/tree/master/cosmovisor",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -84,8 +77,7 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command {
cmd.Flags().String(cli.FlagTitle, "", "title of proposal")
cmd.Flags().String(cli.FlagDescription, "", "description of proposal")
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen (not to be used together with --upgrade-time)")
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))
cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen")
cmd.Flags().String(FlagUpgradeInfo, "", "Optional info for the planned upgrade such as commit hash, etc.")

return cmd
Expand Down Expand Up @@ -168,29 +160,12 @@ func parseArgsToContent(cmd *cobra.Command, name string) (gov.Content, error) {
return nil, err
}

timeStr, err := cmd.Flags().GetString(FlagUpgradeTime)
if err != nil {
return nil, err
}

if height != 0 && len(timeStr) != 0 {
return nil, fmt.Errorf("only one of --upgrade-time or --upgrade-height should be specified")
}

var upgradeTime time.Time
if len(timeStr) != 0 {
upgradeTime, err = time.Parse(TimeFormat, timeStr)
if err != nil {
return nil, err
}
}

info, err := cmd.Flags().GetString(FlagUpgradeInfo)
if err != nil {
return nil, err
}

plan := types.Plan{Name: name, Time: upgradeTime, Height: height, Info: info}
plan := types.Plan{Name: name, Height: height, Info: info}
content := types.NewSoftwareUpgradeProposal(title, description, plan)
return content, nil
}
12 changes: 1 addition & 11 deletions x/upgrade/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rest

import (
"net/http"
"time"

"github.com/cosmos/cosmos-sdk/client/tx"

Expand Down Expand Up @@ -32,7 +31,6 @@ type PlanRequest struct {
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
UpgradeName string `json:"upgrade_name" yaml:"upgrade_name"`
UpgradeHeight int64 `json:"upgrade_height" yaml:"upgrade_height"`
UpgradeTime string `json:"upgrade_time" yaml:"upgrade_time"`
UpgradeInfo string `json:"upgrade_info" yaml:"upgrade_info"`
}

Expand Down Expand Up @@ -76,15 +74,7 @@ func newPostPlanHandler(clientCtx client.Context) http.HandlerFunc {
return
}

var t time.Time
if req.UpgradeTime != "" {
t, err = time.Parse(time.RFC3339, req.UpgradeTime)
if rest.CheckBadRequestError(w, err) {
return
}
}

plan := types.Plan{Name: req.UpgradeName, Time: t, Height: req.UpgradeHeight, Info: req.UpgradeInfo}
plan := types.Plan{Name: req.UpgradeName, Height: req.UpgradeHeight, Info: req.UpgradeInfo}
content := types.NewSoftwareUpgradeProposal(req.Title, req.Description, plan)
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, fromAddr)
if rest.CheckBadRequestError(w, err) {
Expand Down
10 changes: 5 additions & 5 deletions x/upgrade/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Package upgrade provides a Cosmos SDK module that can be used for smoothly upgrading a live Cosmos chain to a
new software version. It accomplishes this by providing a BeginBlocker hook that prevents the blockchain state
machine from proceeding once a pre-defined upgrade block time or height has been reached. The module does not prescribe
machine from proceeding once a pre-defined upgrade block height has been reached. The module does not prescribe
anything regarding how governance decides to do an upgrade, but just the mechanism for coordinating the upgrade safely.
Without software support for upgrades, upgrading a live chain is risky because all of the validators need to pause
their state machines at exactly the same point in the process. If this is not done correctly, there can be state
Expand All @@ -21,9 +21,9 @@ perform a migration, but also to identify if this is the old or new version (eg.
a handler registered for the named upgrade).
Once the release candidate along with an appropriate upgrade handler is frozen,
we can have a governance vote to approve this upgrade at some future block time
or block height (e.g. 200000). This is known as an upgrade.Plan. The v0.38.0 code will not know of this
handler, but will continue to run until block 200000, when the plan kicks in at BeginBlock. It will check
we can have a governance vote to approve this upgrade at some future block height (e.g. 200000).
This is known as an upgrade.Plan. The v0.38.0 code will not know of this handler, but will
continue to run until block 200000, when the plan kicks in at BeginBlock. It will check
for existence of the handler, and finding it missing, know that it is running the obsolete software,
and gracefully exit.
Expand Down Expand Up @@ -54,7 +54,7 @@ should call ScheduleUpgrade to schedule an upgrade and ClearUpgradePlan to cance
Performing Upgrades
Upgrades can be scheduled at either a predefined block height or time. Once this block height or time is reached, the
Upgrades can be scheduled at a predefined block height. Once this block height is reached, the
existing software will cease to process ABCI messages and a new version with code that handles the upgrade must be deployed.
All upgrades are coordinated by a unique upgrade name that cannot be reused on the same blockchain. In order for the upgrade
module to know that the upgrade has been safely applied, a handler with the name of the upgrade must be installed.
Expand Down
6 changes: 1 addition & 5 deletions x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error {
return err
}

if plan.Time.Unix() > 0 {
if !plan.Time.After(ctx.BlockHeader().Time) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past")
}
} else if plan.Height <= ctx.BlockHeight() {
if plan.Height <= ctx.BlockHeight() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past")
}

Expand Down
Loading

0 comments on commit dd424ed

Please sign in to comment.