Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
/ cosmos-sdk Public archive
forked from cosmos/cosmos-sdk

Commit

Permalink
refactor: make cosmovisor depend on x/upgrade only (cosmos#14881)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored and tsenart committed Apr 12, 2023
1 parent 185c3fe commit 6abf877
Show file tree
Hide file tree
Showing 20 changed files with 616 additions and 345 deletions.
9 changes: 9 additions & 0 deletions tools/cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## Client Breaking Changes

* [#14881](https://github.com/cosmos/cosmos-sdk/pull/14881) Cosmovisor supports only upgrade plan with a checksum. This is enforced by the `x/upgrade` module for better security.

## Improvements

* [#14881](https://github.com/cosmos/cosmos-sdk/pull/14881) Refactor Cosmovisor to use `x/upgrade` validation logic.
* [#14881](https://github.com/cosmos/cosmos-sdk/pull/14881) Refactor Cosmovisor to depend only on the `x/upgrade` module.

## v1.4.0 2022-10-23

### API Breaking Changes
Expand Down
7 changes: 4 additions & 3 deletions tools/cosmovisor/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"time"

cverrors "cosmossdk.io/tools/cosmovisor/errors"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
"cosmossdk.io/x/upgrade/plan"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -275,7 +276,7 @@ func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) (rerr error) {
// ensure named upgrade exists
bin := cfg.UpgradeBin(u.Name)

if err := EnsureBinary(bin); err != nil {
if err := plan.EnsureBinary(bin); err != nil {
return err
}

Expand Down
12 changes: 6 additions & 6 deletions tools/cosmovisor/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/suite"

"cosmossdk.io/tools/cosmovisor/errors"
"cosmossdk.io/x/upgrade/plan"
)

type argsTestSuite struct {
Expand Down Expand Up @@ -250,20 +251,19 @@ func (s *argsTestSuite) TestEnsureBin() {
cfg := Config{Home: absPath, Name: "dummyd", DataBackupPath: absPath}
s.Require().Len(cfg.validate(), 0, "validation errors")

s.Require().NoError(EnsureBinary(cfg.GenesisBin()))
s.Require().NoError(plan.EnsureBinary(cfg.GenesisBin()))

cases := map[string]struct {
upgrade string
hasBin bool
}{
"proper": {"chain2", true},
"no binary": {"nobin", false},
"not executable": {"noexec", false},
"no directory": {"foobarbaz", false},
"proper": {"chain2", true},
"no binary": {"nobin", false},
"no directory": {"foobarbaz", false},
}

for _, tc := range cases {
err := EnsureBinary(cfg.UpgradeBin(tc.upgrade))
err := plan.EnsureBinary(cfg.UpgradeBin(tc.upgrade))
if tc.hasBin {
s.Require().NoError(err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion tools/cosmovisor/cmd/cosmovisor/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the proposal. Cosmovisor interprets that data to perform an update: switch a cur
and restart the App.
Configuration of Cosmovisor is done through environment variables, which are
documented in: https://github.com/cosmos/cosmos-sdk/tree/main/tools/cosmovisor/README.md`,
documented in: https://docs.cosmos.network/main/tooling/cosmovisor`,
cosmovisor.EnvName, cosmovisor.EnvHome,
)
}
2 changes: 1 addition & 1 deletion tools/cosmovisor/cmd/cosmovisor/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *HelpTestSuite) TestGetHelpText() {
expectedPieces := []string{
"Cosmovisor",
cosmovisor.EnvName, cosmovisor.EnvHome,
"https://github.com/cosmos/cosmos-sdk/tree/main/tools/cosmovisor/README.md",
"https://docs.cosmos.network/main/tooling/cosmovisor",
}

actual := GetHelpText()
Expand Down
6 changes: 2 additions & 4 deletions tools/cosmovisor/cmd/cosmovisor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"cosmossdk.io/tools/cosmovisor"
cverrors "cosmossdk.io/tools/cosmovisor/errors"
"cosmossdk.io/x/upgrade/plan"
)

func init() {
Expand Down Expand Up @@ -77,10 +78,7 @@ func InitializeCosmovisor(logger *zerolog.Logger, args []string) error {
logger.Info().Msgf("the %q file already exists", genBinExe)
}
logger.Info().Msgf("making sure %q is executable", genBinExe)
if err = cosmovisor.MarkExecutable(genBinExe); err != nil {
return err
}
if err = cosmovisor.EnsureBinary(genBinExe); err != nil {
if err = plan.EnsureBinary(genBinExe); err != nil {
return err
}

Expand Down
8 changes: 6 additions & 2 deletions tools/cosmovisor/cmd/cosmovisor/version_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package main

import (
"bytes"
"context"
"testing"

"cosmossdk.io/tools/cosmovisor"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/stretchr/testify/require"
)

func TestVersionCommand_Error(t *testing.T) {
logger := cosmovisor.NewLogger()

rootCmd.SetArgs([]string{"version"})
_, out := testutil.ApplyMockIO(rootCmd)

out := bytes.NewBufferString("")
rootCmd.SetOut(out)
rootCmd.SetErr(out)

ctx := context.WithValue(context.Background(), cosmovisor.LoggerKey, logger)

require.Error(t, rootCmd.ExecuteContext(ctx))
Expand Down
68 changes: 46 additions & 22 deletions tools/cosmovisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module cosmossdk.io/tools/cosmovisor
go 1.19

require (
github.com/cosmos/cosmos-sdk v0.47.0-rc2
github.com/hashicorp/go-getter v1.6.2
cosmossdk.io/x/upgrade v0.0.0-20230202115111-f719cd32adf3
github.com/otiai10/copy v1.9.0
github.com/rs/zerolog v1.29.0
github.com/spf13/cobra v1.6.1
Expand All @@ -18,45 +17,54 @@ require (
cloud.google.com/go/iam v0.8.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/collections v0.0.0-20230202103518-eb86b68caea0 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-beta.4 // indirect
cosmossdk.io/store v0.0.0-20230202103518-eb86b68caea0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/DataDog/zstd v1.4.5 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.40.45 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20220817183557-09c6e030a677 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v0.0.0-20230119180254-161cf3632b7c // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/cosmos-sdk v0.47.0-rc2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.4 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.5-rc.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.1 // indirect
github.com/cosmos/iavl v0.20.0-alpha1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.17.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -65,29 +73,37 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.10 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
Expand All @@ -99,9 +115,11 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -112,17 +130,15 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/tendermint v0.37.0-rc2 // indirect
github.com/tendermint/tm-db v0.6.7 // indirect
github.com/tidwall/btree v1.5.2 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
Expand All @@ -135,6 +151,14 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
pgregory.net/rapid v0.5.3 // indirect
gotest.tools/v3 v3.4.0 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

// Using this replace directive as v0.20.0-alpha1 > v0.20.0-alpha.2
// This can be deleted when a v0.20.0-alpha3 is tagged or anything lexicographically above than v0.20.0-alpha1
replace github.com/cosmos/iavl => github.com/cosmos/iavl v0.20.0-alpha.2

replace github.com/cosmos/cosmos-sdk => ../..
Loading

0 comments on commit 6abf877

Please sign in to comment.