Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cosmovisor go install and upgrade path case sensitiveness #12918

Merged
merged 7 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
<!-- NOTE: when creating a new release, update cosmovisor/cmd/cosmovisor/cmd/version.go:Version -->

## v1.2.1 2022-08-15

* [\12918](https://github.com/cosmos/cosmos-sdk/pull/12918) Fix failure when installing cosmovisor via `go install`.
* [\12918](https://github.com/cosmos/cosmos-sdk/pull/12918) Automatically set version using module version.
* [\12918](https://github.com/cosmos/cosmos-sdk/pull/12918) Fix plan path case sensitivity issue.

## v1.2.0 2022-07-26

### Features
Expand Down
4 changes: 1 addition & 3 deletions cosmovisor/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/make -f

VERSION := $(shell echo $(shell git describe --always --match "cosmovisor/v*") | sed 's/^cosmovisor[/]//')

all: cosmovisor test

cosmovisor:
go build -ldflags="-X 'github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor/cmd.Version=$(VERSION)'" -mod=readonly ./cmd/cosmovisor
go build -mod=readonly ./cmd/cosmovisor

test:
go test -mod=readonly -race ./...
Expand Down
36 changes: 19 additions & 17 deletions cosmovisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
`cosmovisor` is a small process manager for Cosmos SDK application binaries that monitors the governance module for incoming chain upgrade proposals. If it sees a proposal that gets approved, `cosmovisor` can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary.

<!-- TOC -->
- [Design](#design)
- [Contributing](#contributing)
- [Setup](#setup)
- [Installation](#installation)
- [Command Line Arguments And Environment Variables](#command-line-arguments-and-environment-variables)
- [Folder Layout](#folder-layout)
- [Usage](#usage)
- [Initialization](#initialization)
- [Detecting Upgrades](#detecting-upgrades)
- [Auto-Download](#auto-download)
- [Example: SimApp Upgrade](#example-simapp-upgrade)
- [Chain Setup](#chain-setup)


* [Design](#design)
* [Contributing](#contributing)
* [Setup](#setup)
* [Installation](#installation)
* [Command Line Arguments And Environment Variables](#command-line-arguments-and-environment-variables)
* [Folder Layout](#folder-layout)
* [Usage](#usage)
* [Initialization](#initialization)
* [Detecting Upgrades](#detecting-upgrades)
* [Auto-Download](#auto-download)
* [Example: SimApp Upgrade](#example-simapp-upgrade)
* [Chain Setup](#chain-setup)
* [Prepare Cosmovisor and Start the Chain](#prepare-cosmovisor-and-start-the-chain)
* [Update App](#update-app)

## Design

Expand All @@ -35,25 +35,27 @@ Cosmovisor is designed to be used as a wrapper for a `Cosmos SDK` app:

Cosmovisor is part of the Cosmos SDK monorepo, but it's a separate module with it's own release schedule.

Release branches have the following format `release/cosmovisor/vA.B.x`, where A and B are a number (e.g. `release/cosmovisor/v0.1.x`). Releases are tagged using the following format: `cosmovisor/vA.B.C`.
Release branches have the following format `release/cosmovisor/vA.B.x`, where A and B are a number (e.g. `release/cosmovisor/v1.2.x`). Releases are tagged using the following format: `cosmovisor/vA.B.C`.

## Setup

### Installation

You can download Cosmovisor from the [Github releases](https://github.com/cosmos/cosmos-sdk/releases/tag/cosmovisor%2Fv1.2.1).

To install the latest version of `cosmovisor`, run the following command:

```sh
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest
```

To install a previous version, you can specify the version. IMPORTANT: Chains that use Cosmos-SDK v0.44.3 or earlier (eg v0.44.2) and want to use auto-download feature MUST use Cosmovisor v0.1.0
To install a previous version, you can specify the version. IMPORTANT: Chains that use Cosmos-SDK v0.44.3 or earlier (eg v0.44.2) and want to use auto-download feature MUST use `cosmovisor v0.1.0`

```sh
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
```

You can run `cosmovisor version` to check the Cosmovisor version (works only with Cosmovisor >1.1.0).
Run `cosmovisor version` to check the cosmovisor version.

You can also install from source by pulling the cosmos-sdk repository and switching to the correct version and building as follows:

Expand Down
15 changes: 5 additions & 10 deletions cosmovisor/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Cosmovisor v1.2.0 Release Notes

### New Features

With the `cosmovisor init` command, all the necessary folders for using cosmovisor are automatically created. You do not need to manually symlink the chain binary anymore.

We've added a new configuration option: `DAEMON_RESTART_DELAY` (as env variable). When set, Cosmovisor will wait that delay between the node halt and backup. See the [README](https://github.com/cosmos/cosmos-sdk/blob/main/cosmovisor/README.md#command-line-arguments-and-environment-variables) file for more details.
# Cosmovisor v1.2.1 Release Notes

### Bug Fixes

* Fix Cosmovisor binary usage for pre-upgrade. Cosmovisor was using the wrong binary when running a `pre-upgrade` command.

* Fix failure when installing cosmovisor via `go install`.
* Fix plan path case sensitivity issue.

### Changelog

For more details, please see the [CHANGELOG](https://github.com/cosmos/cosmos-sdk/blob/cosmovisor/v1.1.0/cosmovisor/CHANGELOG.md).
For more details, please see the [CHANGELOG](https://github.com/cosmos/cosmos-sdk/blob/cosmovisor/v1.2.1/cosmovisor/CHANGELOG.md).
7 changes: 7 additions & 0 deletions cosmovisor/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ func (s *argsTestSuite) TestConfigPaths() {
expectGenesis: fmt.Sprintf("/longer/prefix/%s/genesis/bin/yourd", rootName),
expectUpgrade: "/longer/prefix/cosmovisor/upgrades/some%20spaces/bin/yourd",
},
"handle casing": {
cfg: Config{Home: "/longer/prefix/", Name: "appd"},
upgradeName: "myUpgrade",
expectRoot: fmt.Sprintf("/longer/prefix/%s", rootName),
expectGenesis: fmt.Sprintf("/longer/prefix/%s/genesis/bin/appd", rootName),
expectUpgrade: "/longer/prefix/cosmovisor/upgrades/myUpgrade/bin/appd",
},
}

for _, tc := range cases {
Expand Down
22 changes: 14 additions & 8 deletions cosmovisor/cmd/cosmovisor/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"runtime/debug"
"strings"

"github.com/cosmos/cosmos-sdk/cosmovisor"
Expand All @@ -15,12 +16,8 @@ func init() {
rootCmd.AddCommand(versionCmd)
}

var (
// Version represents Cosmovisor version value. Overwritten during build
Version = "1.2.0"
// OutputFlag defines the output format flag
OutputFlag = "output"
)
// OutputFlag defines the output format flag
var OutputFlag = "output"

var versionCmd = &cobra.Command{
Use: "version",
Expand All @@ -37,8 +34,17 @@ var versionCmd = &cobra.Command{
},
}

func getVersion() string {
version, ok := debug.ReadBuildInfo()
if !ok {
panic("failed to get cosmovisor version")
}

return strings.TrimSpace(version.Main.Version)
}

func printVersion(logger *zerolog.Logger, args []string) error {
fmt.Println("cosmovisor version: ", Version)
fmt.Printf("cosmovisor version: %s\n", getVersion())

if err := Run(logger, append([]string{"version"}, args...)); err != nil {
return fmt.Errorf("failed to run version command: %w", err)
Expand Down Expand Up @@ -66,7 +72,7 @@ func printVersionJSON(logger *zerolog.Logger, args []string) error {
Version string `json:"cosmovisor_version"`
AppVersion json.RawMessage `json:"app_version"`
}{
Version: Version,
Version: getVersion(),
AppVersion: json.RawMessage(buf.String()),
})
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cosmovisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,3 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
12 changes: 9 additions & 3 deletions cosmovisor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8=
Expand Down Expand Up @@ -642,6 +647,8 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
Expand Down Expand Up @@ -903,8 +910,6 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI=
github.com/remyoudompheng/go-dbus v0.0.0-20121104212943-b7232d34b1d5/go.mod h1:+u151txRmLpwxBmpYn9z3d1sdJdjRPQpsXuYeY9jNls=
github.com/remyoudompheng/go-liblzma v0.0.0-20190506200333-81bf2d431b96/go.mod h1:90HvCY7+oHHUKkbeMCiHt1WuFR2/hPJ9QrljDG+v6ls=
github.com/remyoudompheng/go-misc v0.0.0-20190427085024-2d6ac652a50e/go.mod h1:80FQABjoFzZ2M5uEa6FUaJYEmqU2UOKojlFVak1UAwI=
Expand Down Expand Up @@ -1437,8 +1442,10 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -1624,7 +1631,6 @@ google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfG
google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
Expand Down
4 changes: 0 additions & 4 deletions cosmovisor/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,5 @@ func parseUpgradeInfoFile(filename string) (upgradetypes.Plan, error) {
return upgradetypes.Plan{}, fmt.Errorf("invalid upgrade-info.json content; name and height must be not empty; got: %v", ui)
}

// Normalize name to prevent operator error in upgrade name case sensitivity
// errors.
ui.Name = strings.ToLower(ui.Name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in #11608, but I believe only the EqualFold addition was necessary. Otherwise, we get #12915 bug.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So was not a bug, only not documented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderbez should I revert that change and add docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julienrbrt yes pls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #12921


return ui, err
}
79 changes: 46 additions & 33 deletions cosmovisor/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,52 @@ func TestParseUpgradeInfoFile(t *testing.T) {
filename string
expectUpgrade upgradetypes.Plan
expectErr bool
}{{
filename: "f1-good.json",
expectUpgrade: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 123},
expectErr: false,
}, {
filename: "f2-bad-type.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "f2-bad-type-2.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "f3-empty.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "f4-empty-obj.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "f5-partial-obj-1.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "f5-partial-obj-2.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}, {
filename: "unknown.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}}
}{
{
filename: "f1-good.json",
expectUpgrade: upgradetypes.Plan{Name: "upgrade1", Info: "some info", Height: 123},
expectErr: false,
},
{
filename: "f2-good.json",
expectUpgrade: upgradetypes.Plan{Name: "Upgrade2", Info: "some info", Height: 125},
expectErr: false,
},
{
filename: "f2-bad-type.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "f2-bad-type-2.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "f3-empty.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "f4-empty-obj.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "f5-partial-obj-1.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "f5-partial-obj-2.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
},
{
filename: "unknown.json",
expectUpgrade: upgradetypes.Plan{},
expectErr: true,
}}

for i := range cases {
tc := cases[i]
Expand Down
1 change: 1 addition & 0 deletions cosmovisor/testdata/upgrade-files/f2-good.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "Upgrade2", "info": "some info", "height": 125}