Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
haasted authored Sep 10, 2021
2 parents 2bd037b + 148451b commit 4fcc324
Show file tree
Hide file tree
Showing 28 changed files with 1,734 additions and 124 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* [\#10077](https://github.com/cosmos/cosmos-sdk/pull/10077) Remove telemetry on `GasKV` and `CacheKV` store Get/Set operations, significantly improving their performance.
* [\#10022](https://github.com/cosmos/cosmos-sdk/pull/10022) `AuthKeeper` interface in `x/auth` now includes a function `HasAccount`.
* [\#9759](https://github.com/cosmos/cosmos-sdk/pull/9759) `NewAccountKeeeper` in `x/auth` now takes an additional `bech32Prefix` argument that represents `sdk.Bech32MainPrefix`.
* [\#9628](https://github.com/cosmos/cosmos-sdk/pull/9628) Rename `x/{mod}/legacy` to `x/{mod}/migrations`.
Expand Down Expand Up @@ -86,12 +87,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (types) [\#10076](https://github.com/cosmos/cosmos-sdk/pull/10076) Significantly speedup and lower allocations for `Coins.String()`.
* (x/bank) [\#10022](https://github.com/cosmos/cosmos-sdk/pull/10022) `BankKeeper.SendCoins` now takes less execution time.
* (deps) [\#9956](https://github.com/cosmos/cosmos-sdk/pull/9956) Bump Tendermint to [v0.34.12](https://github.com/tendermint/tendermint/releases/tag/v0.34.12).
* (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command.
* (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls.

### Bug Fixes

* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.
* [\#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`)
* (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt`
Expand All @@ -103,7 +107,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9829](https://github.com/cosmos/cosmos-sdk/pull/9829) Fixed Coin denom sorting not being checked during `Balance.Validate` check. Refactored the Validation logic to use `Coins.Validate` for `Balance.Coins`.
+ [\#9965](https://github.com/cosmos/cosmos-sdk/pull/9965) Fixed `simd version` command output to report the right release tag.
+ [\#9980](https://github.com/cosmos/cosmos-sdk/pull/9980) Returning the error when the invalid argument is passed to bank query total supply cli.
+ [\#10061](https://github.com/cosmos/cosmos-sdk/pull/10061) Ensure that `LegacyAminoPubKey` struct correctly unmarshals from JSON.
+ [\#10061](https://github.com/cosmos/cosmos-sdk/pull/10061) Ensure that `LegacyAminoPubKey` struct correctly unmarshals from JSON
* (server) [#10016](https://github.com/cosmos/cosmos-sdk/issues/10016) Fix marshaling of index-events into server config file.


### State Machine Breaking

Expand Down
8 changes: 2 additions & 6 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,8 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
return clientCtx, nil
}

// ReadHomeFlag checks if home flag is changed.
// If this is a case, we update HomeDir field of Client Context
/* Discovered a bug with Cory
./build/simd init andrei --home ./test
cd test/config there is no client.toml configuration file
*/
// ReadHomeFlag checks if home flag is changed. If this is a case, we update
// HomeDir field of Client Context.
func ReadHomeFlag(clientCtx Context, cmd *cobra.Command) Context {
if cmd.Flags().Changed(flags.FlagHome) {
rootDir, _ := cmd.Flags().GetString(flags.FlagHome)
Expand Down
1 change: 1 addition & 0 deletions cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

+ [\#10018](https://github.com/cosmos/cosmos-sdk/pull/10018) Strict boolean argument parsing: cosmovisor will fail if user will not set correctly a boolean variable. Correct values are: "true", "false", "" (not setting) - all case not sensitive.
+ [\#10036](https://github.com/cosmos/cosmos-sdk/pull/10036) Improve logs when downloading the binary.

## v0.1 2021-08-06

Expand Down
71 changes: 71 additions & 0 deletions cosmovisor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -64,6 +65,13 @@ func (l Launcher) Run(args []string, stdout, stderr io.Writer) (bool, error) {
return false, err
}

if !SkipUpgrade(args, l.fw.currentInfo) {
err = doPreUpgrade(l.cfg)
if err != nil {
return false, err
}
}

return true, DoUpgrade(l.cfg, l.fw.currentInfo)
}

Expand All @@ -84,6 +92,7 @@ func (l Launcher) WaitForUpgradeOrExit(cmd *exec.Cmd) (bool, error) {
select {
case <-l.fw.MonitorUpdate(currentUpgrade):
// upgrade - kill the process and restart
fmt.Println("[cosmovisor] Daemon shutting down in an attempt to restart")
_ = cmd.Process.Kill()
case err := <-cmdDone:
l.fw.Stop()
Expand Down Expand Up @@ -142,3 +151,65 @@ func doBackup(cfg *Config) error {

return nil
}

// doPreUpgrade runs the pre-upgrade command defined by the application
func doPreUpgrade(cfg *Config) error {
bin, err := cfg.CurrentBin()
preUpgradeCmd := exec.Command(bin, "pre-upgrade")

_, err = preUpgradeCmd.Output()

if err != nil {
if err.(*exec.ExitError).ProcessState.ExitCode() == 1 {
fmt.Println("pre-upgrade command does not exist. continuing the upgrade.")
return nil
}
if err.(*exec.ExitError).ProcessState.ExitCode() == 30 {
return fmt.Errorf("pre-upgrade command failed : %w", err)
}
if err.(*exec.ExitError).ProcessState.ExitCode() == 31 {
fmt.Println("pre-upgrade command failed. retrying.")
return doPreUpgrade(cfg)
}
}
fmt.Println("pre-upgrade successful. continuing the upgrade.")
return nil
}

// skipUpgrade checks if pre-upgrade script must be run. If the height in the upgrade plan matches any of the heights provided in --safe-skip-upgrade, the script is not run
func SkipUpgrade(args []string, upgradeInfo UpgradeInfo) bool {
skipUpgradeHeights := UpgradeSkipHeights(args)
for _, h := range skipUpgradeHeights {
if h == int(upgradeInfo.Height) {
return true
}

}
return false
}

// UpgradeSkipHeights gets all the heights provided when
// simd start --unsafe-skip-upgrades <height1> <optional_height_2> ... <optional_height_N>
func UpgradeSkipHeights(args []string) []int {
var heights []int
for i, arg := range args {
if arg == "--unsafe-skip-upgrades" {
j := i + 1

for j < len(args) {
tArg := args[j]
if strings.HasPrefix(tArg, "-") {
break
}
h, err := strconv.Atoi(tArg)
if err == nil {
heights = append(heights, h)
}
j++
}

break
}
}
return heights
}
76 changes: 76 additions & 0 deletions cosmovisor/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/cosmovisor"
Expand Down Expand Up @@ -127,3 +128,78 @@ func (s *processTestSuite) TestLaunchProcessWithDownloads() {
require.NoError(err)
require.Equal(cfg.UpgradeBin("chain3"), currentBin)
}

// TestSkipUpgrade tests heights that are identified to be skipped and return if upgrade height matches the skip heights
func TestSkipUpgrade(t *testing.T) {
cases := []struct {
args []string
upgradeInfo cosmovisor.UpgradeInfo
expectRes bool
}{{
args: []string{"appb", "start", "--unsafe-skip-upgrades"},
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 123},
expectRes: false,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "--abcd"},
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 123},
expectRes: false,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "--abcd"},
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 11},
expectRes: false,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd"},
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 20},
expectRes: true,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd", "34"},
upgradeInfo: cosmovisor.UpgradeInfo{Name: "upgrade1", Info: "some info", Height: 34},
expectRes: false,
}}

for i := range cases {
tc := cases[i]
require := require.New(t)
h := cosmovisor.SkipUpgrade(tc.args, tc.upgradeInfo)
require.Equal(h, tc.expectRes)
}
}

// TestUpgradeSkipHeights tests if correct skip upgrade heights are identified from the cli args
func TestUpgradeSkipHeights(t *testing.T) {
cases := []struct {
args []string
expectRes []int
}{{
args: []string{},
expectRes: nil,
}, {
args: []string{"appb", "start"},
expectRes: nil,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades"},
expectRes: nil,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "--abcd"},
expectRes: nil,
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "--abcd"},
expectRes: []int{10},
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd"},
expectRes: []int{10, 20},
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "20", "--abcd", "34"},
expectRes: []int{10, 20},
}, {
args: []string{"appb", "start", "--unsafe-skip-upgrades", "10", "as", "20", "--abcd"},
expectRes: []int{10, 20},
}}

for i := range cases {
tc := cases[i]
require := require.New(t)
h := cosmovisor.UpgradeSkipHeights(tc.args)
require.Equal(h, tc.expectRes)
}
}
2 changes: 2 additions & 0 deletions cosmovisor/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ func DoUpgrade(cfg *Config, info UpgradeInfo) error {
}

// If not there, then we try to download it... maybe
fmt.Println("[cosmovisor] No upgrade binary found, beginning to download it")
if err := DownloadBinary(cfg, info); err != nil {
return fmt.Errorf("cannot download binary. %w", err)
}
fmt.Println("[cosmovisor] Downloading binary complete")

// and then set the binary again
if err := EnsureBinary(cfg.UpgradeBin(info.Name)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module.exports = {
"key": "v0.42"
},
{
"label": "v0.43",
"key": "v0.43"
"label": "v0.44",
"key": "v0.44"
},
{
"label": "master",
Expand Down
3 changes: 2 additions & 1 deletion docs/.vuepress/enhanceApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default ({ router }) => {
{ path: '/master/spec/*', redirect: '/master/modules/' },
{ path: '/master/spec/governance/', redirect: '/master/modules/gov/' },
{ path: '/v0.41/', redirect: '/v0.42/' },
{ path: '/v0.43/', redirect: '/v0.44/' },
])
}
}
2 changes: 1 addition & 1 deletion docs/core/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Cosmos SDK uses two methods to perform upgrades.

- Exporting the entire application state to a JSON file using the `export` CLI command, making changes, and then starting a new binary with the changed JSON file as the genesis file. See [Chain Upgrade Guide to v0.42](https://docs.cosmos.network/v0.42/migrations/chain-upgrade-guide-040.html).

- Version v0.43 and later can perform upgrades in place to significantly decrease the upgrade time for chains with a larger state. Use the [Module Upgrade Guide](../building-modules/upgrade.md) to set up your application modules to take advantage of in-place upgrades.
- Version v0.44 and later can perform upgrades in place to significantly decrease the upgrade time for chains with a larger state. Use the [Module Upgrade Guide](../building-modules/upgrade.md) to set up your application modules to take advantage of in-place upgrades.

This document provides steps to use the In-Place Store Migrations upgrade method.

Expand Down
8 changes: 3 additions & 5 deletions docs/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ parent:

# Migrations

This folder contains all the migration guides to update your app and modules to Cosmos v0.40 Stargate.
This folder contains all the migration guides to update your app and modules to Cosmos SDK v0.44.

1. [App and Modules Migration](./app_and_modules.md)
1. [Chain Upgrade Guide to v0.40](./chain-upgrade-guide-040.md)
1. [REST Endpoints Migration](./rest.md)
1. [Keyring Migration](./keyring.md)
1. [Chain Upgrade Guide to v0.44](./chain-upgrade-guide-044.md)
2. [REST Endpoints Migration](./rest.md)
Loading

0 comments on commit 4fcc324

Please sign in to comment.