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

Create pre-upgrade command. Fix minimum-gas-prices repacking unset. #1594

Merged
merged 33 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b8f5741
Create a new pre_upgrade command that updates the config files. Make …
SpicyLemon Jun 13, 2023
4863fb6
Force the timeout commit to 5s in all cases. Add some comments and in…
SpicyLemon Jun 14, 2023
245f65e
Undo the PersistentPreRunE extraction change since I ended up not nee…
SpicyLemon Jun 14, 2023
82b946e
Fix the existing LogIfError functions.
SpicyLemon Jun 14, 2023
cea713a
Tweak errors returned from pre-upgrade to contain more context and st…
SpicyLemon Jun 14, 2023
093655f
Allow creation of the root command that won't seal the app config so …
SpicyLemon Jun 14, 2023
7ae0a76
Add unit tests on the pre-upgrade command.
SpicyLemon Jun 14, 2023
0b39af0
Add a unit test for when the config can't be written.
SpicyLemon Jun 14, 2023
74aea01
Add newline to end of success message.
SpicyLemon Jun 15, 2023
8806ed1
Move the global min-gas-prices setting stuff into the interceptor so …
SpicyLemon Jun 15, 2023
588515a
For the init cmd test, don't seal the config (so other things that mi…
SpicyLemon Jun 15, 2023
8874407
Update some tests that started failing because the default timeout_co…
SpicyLemon Jun 15, 2023
521bee0
Just pass sealConfig into the SetConfig function instead of optionall…
SpicyLemon Jun 15, 2023
67b157b
For the pre-unpgrade tests, just add the home dir as a flag for the c…
SpicyLemon Jun 15, 2023
522fd50
Add temporary changelog entries.
SpicyLemon Jun 15, 2023
4f0ed39
Remove some lines added just for debugging.
SpicyLemon Jun 15, 2023
488cb85
When starting a node with a timeout_commit of less than 4 seconds, ou…
SpicyLemon Jun 15, 2023
068a3be
Update the initialization script to put the timeout_commit back to 1s…
SpicyLemon Jun 15, 2023
535835a
Merge branch 'main' into dwedul/1.16-pre-upgrade-cmd
SpicyLemon Jun 16, 2023
a038026
Only issue low timeout_commit warning on mainnet.
SpicyLemon Jun 16, 2023
bd445b6
Replace some deprecated stuff and fix some receivers.
SpicyLemon Jun 16, 2023
d3599e0
During pre-upgrae Only update the configured value if it's lower than…
SpicyLemon Jun 16, 2023
e7491d7
Only log the warning on mainnet and only if it's less than half the d…
SpicyLemon Jun 16, 2023
0269846
Add the --timeout-commit flag to the init command. If provided, use t…
SpicyLemon Jun 16, 2023
925a4b1
Update the initialize script to provide the --timeout-commit to init …
SpicyLemon Jun 16, 2023
137e9c7
Merge branch 'main' into dwedul/1.16-pre-upgrade-cmd
SpicyLemon Jun 16, 2023
da2044a
Upper-case the first letter of all commmand and flag usage strings. F…
SpicyLemon Jun 16, 2023
1b76d14
Fix the --help flag capitalization.
SpicyLemon Jun 16, 2023
b3021cb
Undo the usage capitalization stuff. That's a bit too off-topic for t…
SpicyLemon Jun 16, 2023
c615a61
In the pre-upgrade command only change the timeout_commit for mainnet…
SpicyLemon Jun 16, 2023
efcc9a7
Get rid of the global ChainID variable (in cmd/root.go) since it wasn…
SpicyLemon Jun 16, 2023
4b8c798
Merge branch 'main' into dwedul/1.16-pre-upgrade-cmd
SpicyLemon Jun 16, 2023
287956d
Merge branch 'main' into dwedul/1.16-pre-upgrade-cmd
SpicyLemon Jun 20, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Features

* Add pre-upgrade command that updates config files to newest format and sets `consensus.timeout_commit` to `5s` [PR 1594](https://github.com/provenance-io/provenance/pull/1594)

### Bug Fixes

* Add `NewUpdateAccountAttributeExpirationCmd` to the CLI [#1592](https://github.com/provenance-io/provenance/issues/1592).
* Fix `minimum-gas-prices` from sometimes getting unset in the configs [PR 1594](https://github.com/provenance-io/provenance/pull/1594)

---

Expand Down
3 changes: 1 addition & 2 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (s *UpgradeTestSuite) GetLogOutput(msg string, args ...interface{}) string
// Use this if there's a possible error that we probably don't care about (but might).
func (s *UpgradeTestSuite) LogIfError(err error, format string, args ...interface{}) {
if err != nil {
args = append(args, err)
s.T().Logf(format+": %v", args)
s.T().Logf(format+" error: %v", append(args, err)...)
}
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/provenanced/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
)

func TestInitCmd(t *testing.T) {
rootCmd, _ := cmd.NewRootCmd()
home := t.TempDir()
rootCmd, _ := cmd.NewRootCmd(false)
rootCmd.SetArgs([]string{
"--home", home,
"init", // Test the init cmd
"simapp-test", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists
Expand Down
81 changes: 40 additions & 41 deletions cmd/provenanced/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"regexp"
"strings"
Expand All @@ -17,16 +17,15 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
sdksim "github.com/cosmos/cosmos-sdk/simapp"

"github.com/provenance-io/provenance/cmd/provenanced/cmd"
provconfig "github.com/provenance-io/provenance/cmd/provenanced/config"
"github.com/provenance-io/provenance/internal/pioconfig"

tmconfig "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
)

type ConfigTestSuite struct {
Expand Down Expand Up @@ -57,7 +56,7 @@ func (s *ConfigTestSuite) SetupTest() {
WithCodec(encodingConfig.Codec).
WithHomeDir(s.Home)
clientCtx.Viper = viper.New()
serverCtx := server.NewContext(clientCtx.Viper, tmconfig.DefaultConfig(), log.NewNopLogger())
serverCtx := server.NewContext(clientCtx.Viper, provconfig.DefaultTmConfig(), log.NewNopLogger())

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
Expand Down Expand Up @@ -86,7 +85,7 @@ func TestConfigTestSuite(t *testing.T) {
// Test setup above. Test helpers below.
//

func (s ConfigTestSuite) getConfigCmd() *cobra.Command {
func (s *ConfigTestSuite) getConfigCmd() *cobra.Command {
// What I really need here is a cobra.Command
// that already has a context.
// So I'm going to call --help on the config command
Expand All @@ -104,7 +103,7 @@ func (s ConfigTestSuite) getConfigCmd() *cobra.Command {
return configCmd
}

func (s ConfigTestSuite) ensureConfigFiles() {
func (s *ConfigTestSuite) ensureConfigFiles() {
configCmd := s.getConfigCmd()
// Extract the individual config objects.
appConfig, aerr := provconfig.ExtractAppConfig(configCmd)
Expand All @@ -118,66 +117,66 @@ func (s ConfigTestSuite) ensureConfigFiles() {
provconfig.SaveConfigs(configCmd, appConfig, tmConfig, clientConfig, false)
}

func (s ConfigTestSuite) makeConfigHeaderLine(t, fn string) string {
func (s *ConfigTestSuite) makeConfigHeaderLine(t, fn string) string {
return fmt.Sprintf("%s Config: %s/config/%s (or env)", t, s.Home, fn)
}

func (s ConfigTestSuite) makeAppConfigHeaderLines() string {
func (s *ConfigTestSuite) makeAppConfigHeaderLines() string {
return s.makeConfigHeaderLine(s.HeaderStrApp, s.BaseFNApp) + "\n----------------"
}

func (s ConfigTestSuite) makeTMConfigHeaderLines() string {
func (s *ConfigTestSuite) makeTMConfigHeaderLines() string {
return s.makeConfigHeaderLine(s.HeaderStrTM, s.BaseFNTM) + "\n-----------------------"
}

func (s ConfigTestSuite) makeClientConfigHeaderLines() string {
func (s *ConfigTestSuite) makeClientConfigHeaderLines() string {
return s.makeConfigHeaderLine(s.HeaderStrClient, s.baseFNClient) + "\n-------------------"
}

func (s ConfigTestSuite) makeConfigUpdatedLine(t, fn string) string {
func (s *ConfigTestSuite) makeConfigUpdatedLine(t, fn string) string {
return fmt.Sprintf("%s Config Updated: %s/config/%s", t, s.Home, fn)
}

func (s ConfigTestSuite) makeAppConfigUpdateLines() string {
func (s *ConfigTestSuite) makeAppConfigUpdateLines() string {
return s.makeConfigUpdatedLine(s.HeaderStrApp, s.BaseFNApp) + "\n------------------------"
}

func (s ConfigTestSuite) makeTMConfigUpdateLines() string {
func (s *ConfigTestSuite) makeTMConfigUpdateLines() string {
return s.makeConfigUpdatedLine(s.HeaderStrTM, s.BaseFNTM) + "\n-------------------------------"
}

func (s ConfigTestSuite) makeClientConfigUpdateLines() string {
func (s *ConfigTestSuite) makeClientConfigUpdateLines() string {
return s.makeConfigUpdatedLine(s.HeaderStrClient, s.baseFNClient) + "\n---------------------------"
}

func (s ConfigTestSuite) makeConfigDiffHeaderLine(t, fn string) string {
func (s *ConfigTestSuite) makeConfigDiffHeaderLine(t, fn string) string {
return fmt.Sprintf("%s Config Differences from Defaults: %s/config/%s (or env)", t, s.Home, fn)
}

func (s ConfigTestSuite) makeAppDiffHeaderLines() string {
func (s *ConfigTestSuite) makeAppDiffHeaderLines() string {
return s.makeConfigDiffHeaderLine(s.HeaderStrApp, s.BaseFNApp) + "\n------------------------------------------"
}

func (s ConfigTestSuite) makeTMDiffHeaderLines() string {
func (s *ConfigTestSuite) makeTMDiffHeaderLines() string {
return s.makeConfigDiffHeaderLine(s.HeaderStrTM, s.BaseFNTM) + "\n-------------------------------------------------"
}

func (s ConfigTestSuite) makeClientDiffHeaderLines() string {
func (s *ConfigTestSuite) makeClientDiffHeaderLines() string {
return s.makeConfigDiffHeaderLine(s.HeaderStrClient, s.baseFNClient) + "\n---------------------------------------------"
}

func (s ConfigTestSuite) makeMultiLine(lines ...string) string {
func (s *ConfigTestSuite) makeMultiLine(lines ...string) string {
return strings.Join(lines, "\n") + "\n"
}

func (s ConfigTestSuite) makeKeyUpdatedLine(key, oldVal, newVal string) string {
func (s *ConfigTestSuite) makeKeyUpdatedLine(key, oldVal, newVal string) string {
return fmt.Sprintf("%s Was: %s, Is Now: %s", key, oldVal, newVal)
}

func applyMockIODiscardOutErr(c *cobra.Command) *bytes.Buffer {
b := bytes.NewBufferString("")
c.SetOut(ioutil.Discard)
c.SetErr(ioutil.Discard)
c.SetOut(io.Discard)
c.SetErr(io.Discard)
return b
}

Expand Down Expand Up @@ -227,7 +226,7 @@ func (s *ConfigTestSuite) TestConfigCmdGet() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
s.Require().NoError(err, "%s - unexpected error executing configCmd", configCmd.Name())
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
s.Require().NoError(err, "%s - unexpected error reading configCmd output", configCmd.Name())
outStr := string(out)

Expand All @@ -248,7 +247,7 @@ func (s *ConfigTestSuite) TestConfigCmdGet() {
// Tendermint header and a few entries.
{"tendermint header", regexp.MustCompile(`(?m)^Tendermint Config: .*/config/` + s.BaseFNTM + ` \(or env\)$`)},
{"tendermint fast_sync", regexp.MustCompile(`(?m)^fast_sync=true$`)},
{"tendermint consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit="1s"$`)},
{"tendermint consensus.timeout_commit", regexp.MustCompile(`(?m)^consensus.timeout_commit="5s"$`)},
{"tendermint mempool.size", regexp.MustCompile(`(?m)^mempool.size=5000$`)},
{"tendermint statesync.trust_period", regexp.MustCompile(`(?m)^statesync.trust_period="168h0m0s"$`)},
{"tendermint p2p.recv_rate", regexp.MustCompile(`(?m)^p2p.recv_rate=5120000$`)},
Expand Down Expand Up @@ -276,7 +275,7 @@ func (s *ConfigTestSuite) TestConfigCmdGet() {
b2 := applyMockIOOutErr(configCmd2)
err2 := configCmd2.Execute()
require.NoError(t, err2, "%s - unexpected error executing configCmd", configCmd2.Name())
out2, err2 := ioutil.ReadAll(b2)
out2, err2 := io.ReadAll(b2)
require.NoError(t, err2, "%s - unexpected error reading configCmd output", configCmd2.Name())
out2Str := string(out2)
require.Equal(t, outStr, out2Str, "output of no-args vs output of %s", args)
Expand Down Expand Up @@ -319,7 +318,7 @@ func (s *ConfigTestSuite) TestConfigCmdGet() {
b3 := applyMockIOOutErr(configCmd3)
err3 := configCmd3.Execute()
require.NoError(t, err3, "%s - unexpected error executing configCmd", configCmd3.Name())
out3, rerr3 := ioutil.ReadAll(b3)
out3, rerr3 := io.ReadAll(b3)
require.NoError(t, rerr3, "%s - unexpected error reading configCmd output", configCmd3.Name())
out3Str := string(out3)
require.Contains(t, outStr, out3Str, "output of no-args vs output of %s", tc.args)
Expand Down Expand Up @@ -392,7 +391,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error executing configCmd", configCmd.Name(), args)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err, "%s %s - unexpected error reading configCmd output", configCmd.Name(), args)
outStr := string(out)
assert.Equal(t, tc.expected, outStr, "%s %s - output", configCmd.Name(), args)
Expand All @@ -417,7 +416,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - expected error executing configCmd", configCmd.Name(), args)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err, "%s %s - unexpected error reading configCmd output", configCmd.Name(), args)
outStr := string(out)
assert.Equal(t, expected, outStr, "%s %s - output", configCmd.Name(), args)
Expand All @@ -440,7 +439,7 @@ func (s *ConfigTestSuite) TestConfigGetMulti() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - expected error executing configCmd", configCmd.Name(), args)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err, "%s %s - unexpected error reading configCmd output", configCmd.Name(), args)
outStr := string(out)
assert.Equal(t, expected, outStr, "%s %s - output", configCmd.Name(), args)
Expand All @@ -466,7 +465,7 @@ func (s *ConfigTestSuite) TestConfigChanged() {
allEqual("client"),
"",
}
expectedAllOutLines := []string{}
var expectedAllOutLines []string
expectedAllOutLines = append(expectedAllOutLines, expectedAppOutLines...)
expectedAllOutLines = append(expectedAllOutLines, expectedTMOutLines...)
expectedAllOutLines = append(expectedAllOutLines, expectedClientOutLines...)
Expand Down Expand Up @@ -505,7 +504,7 @@ func (s *ConfigTestSuite) TestConfigChanged() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error executing configCmd", configCmd.Name(), tc.args)
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err, "%s %s - unexpected error reading configCmd output", configCmd.Name(), tc.args)
outStr := string(out)
assert.Equal(t, tc.out, outStr, "%s %s - output", configCmd.Name(), tc.args)
Expand Down Expand Up @@ -544,7 +543,7 @@ func (s *ConfigTestSuite) TestConfigSetValidation() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s unexpected error executing configCmd", configCmd.Name(), tc.args)
out, rerr := ioutil.ReadAll(b)
out, rerr := io.ReadAll(b)
require.NoError(t, rerr, "%s %s unexpected error reading output", configCmd.Name(), tc.args)
outStr := string(out)
assert.True(t, strings.Contains(outStr, expected), "%s %s output", configCmd.Name(), tc.args)
Expand Down Expand Up @@ -610,7 +609,7 @@ func (s *ConfigTestSuite) TestConfigCmdSet() {
},
{
name: "consensus.timeout_commit",
oldVal: `"1s"`,
oldVal: `"5s"`,
newVal: `"2s"`,
toMatch: []*regexp.Regexp{reTMConfigUpdated},
},
Expand Down Expand Up @@ -669,7 +668,7 @@ func (s *ConfigTestSuite) TestConfigCmdSet() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), args)
out, rerr := ioutil.ReadAll(b)
out, rerr := io.ReadAll(b)
require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), args)
outStr := string(out)
for _, re := range tc.toMatch {
Expand Down Expand Up @@ -702,7 +701,7 @@ func (s *ConfigTestSuite) TestConfigSetMulti() {
out: s.makeMultiLine(
s.makeTMConfigUpdateLines(),
s.makeKeyUpdatedLine("log_format", `"plain"`, `"json"`),
s.makeKeyUpdatedLine("consensus.timeout_commit", `"1s"`, `"950ms"`),
s.makeKeyUpdatedLine("consensus.timeout_commit", `"5s"`, `"950ms"`),
""),
},
{
Expand Down Expand Up @@ -746,7 +745,7 @@ func (s *ConfigTestSuite) TestConfigSetMulti() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), tc.args)
out, rerr := ioutil.ReadAll(b)
out, rerr := io.ReadAll(b)
require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), tc.args)
outStr := string(out)
assert.Equal(t, tc.out, outStr, "%s %s output", configCmd.Name(), tc.args)
Expand All @@ -766,7 +765,7 @@ func (s *ConfigTestSuite) TestPackUnpack() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), args)
out, rerr := ioutil.ReadAll(b)
out, rerr := io.ReadAll(b)
require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), args)
outStr := string(out)

Expand All @@ -780,7 +779,7 @@ func (s *ConfigTestSuite) TestPackUnpack() {
assert.False(t, provconfig.FileExists(appFile), "file exists: app")
tmFile := provconfig.GetFullPathToAppConf(configCmd)
assert.Contains(t, outStr, tmFile, "tendermint filename")
assert.False(t, provconfig.FileExists(tmFile), "file exists: tenderming")
assert.False(t, provconfig.FileExists(tmFile), "file exists: tendermint")
clientFile := provconfig.GetFullPathToAppConf(configCmd)
assert.Contains(t, outStr, clientFile, "client filename")
assert.False(t, provconfig.FileExists(clientFile), "file exists: client")
Expand All @@ -793,7 +792,7 @@ func (s *ConfigTestSuite) TestPackUnpack() {
b := applyMockIOOutErr(configCmd)
err := configCmd.Execute()
require.NoError(t, err, "%s %s - unexpected error in execution", configCmd.Name(), args)
out, rerr := ioutil.ReadAll(b)
out, rerr := io.ReadAll(b)
require.NoError(t, rerr, "%s %s - unexpected error in reading", configCmd.Name(), args)
outStr := string(out)

Expand All @@ -805,7 +804,7 @@ func (s *ConfigTestSuite) TestPackUnpack() {
assert.True(t, provconfig.FileExists(appFile), "file exists: app")
tmFile := provconfig.GetFullPathToAppConf(configCmd)
assert.Contains(t, outStr, tmFile, "tendermint filename")
assert.True(t, provconfig.FileExists(tmFile), "file exists: tenderming")
assert.True(t, provconfig.FileExists(tmFile), "file exists: tendermint")
clientFile := provconfig.GetFullPathToAppConf(configCmd)
assert.Contains(t, outStr, clientFile, "client filename")
assert.True(t, provconfig.FileExists(clientFile), "file exists: client")
Expand Down
Loading
Loading