From 01500800be91c9b1226b8704c327819fbf3049cc Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:14:51 -0600 Subject: [PATCH 01/19] Move the call to registerUpgradeHandlers back down to where that stuff was originally so that we can have it inject an upgrade which now overwrites the pre-blocker (instead of begin-blocker). --- app/app.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/app.go b/app/app.go index ddf453953..8ccb826f8 100644 --- a/app/app.go +++ b/app/app.go @@ -947,11 +947,6 @@ func New( panic(err) } - // Register upgrade handlers and set the store loader. - // This must be done after the module manager and configurator are set, - // but before the baseapp is sealed via LoadLatestVersion() down below. - app.registerUpgradeHandlers(appOpts) - autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() @@ -983,6 +978,11 @@ func New( app.setFeeHandler() app.SetAggregateEventsFunc(piohandlers.AggregateEvents) + // Register upgrade handlers and set the store loader. + // This must be done after the module manager, configurator, and pre-blocker are set, + // but before the baseapp is sealed via LoadLatestVersion() below. + app.registerUpgradeHandlers(appOpts) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { cmtos.Exit(err.Error()) @@ -1358,8 +1358,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino // injectUpgrade causes the named upgrade to be run as the chain starts. // -// To use this, add a call to it in New after the call to InstallCustomUpgradeHandlers -// but before the line that looks for an upgrade file. +// To use this, add a call to it in registerUpgradeHandlers immediately after the +// call to InstallCustomUpgradeHandlers, but before the line that looks for an upgrade file. // // This function is for testing an upgrade against an existing chain's data (e.g. mainnet). // Here's how: @@ -1390,15 +1390,16 @@ func (app *App) injectUpgrade(name string) { //nolint:unused // This is designed if err := app.UpgradeKeeper.DumpUpgradeInfoToDisk(plan.Height, plan); err != nil { panic(err) } - // Define a new BeginBlocker that will inject the upgrade. + + // Define a new PreBlocker that will inject the upgrade. injected := false - app.SetBeginBlocker(func(ctx sdk.Context) (sdk.BeginBlock, error) { + app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { if !injected { app.Logger().Info("Injecting upgrade plan", "plan", plan) // Ideally, we'd just call ScheduleUpgrade(ctx, plan) here (and panic on error). - // But the upgrade keeper often its own migration stuff that change some store key stuff. - // ScheduleUpgrade tries to read some of that changed store stuff and fails if the migration hasn't - // been applied yet. So we're doing things the hard way here. + // But the upgrade keeper often has its own migration stuff that change some store stuff. + // ScheduleUpgrade would try to read some of that old state using the update pattern, + // causing a failure. So we're doing things the hard way here. if err := app.UpgradeKeeper.ClearUpgradePlan(ctx); err != nil { panic(err) } @@ -1407,6 +1408,6 @@ func (app *App) injectUpgrade(name string) { //nolint:unused // This is designed store.Set(upgradetypes.PlanKey(), bz) injected = true } - return app.BeginBlocker(ctx) + return app.PreBlocker(ctx, req) }) } From c2bc793e74d0e36b3c443abe1d1fe2eb6d4dab14 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:15:35 -0600 Subject: [PATCH 02/19] Add the consensus params to the list of added modules for umber. --- app/upgrades.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 0ca930b6f..e24052238 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -50,7 +51,7 @@ type appUpgrade struct { // or vice versa, please add comments explaining why in both entries. var upgrades = map[string]appUpgrade{ "umber-rc1": { // upgrade for v1.19.0-rc1 - Added: []string{crisistypes.ModuleName}, + Added: []string{crisistypes.ModuleName, consensusparamtypes.ModuleName}, Deleted: []string{"reward"}, Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error @@ -89,7 +90,7 @@ var upgrades = map[string]appUpgrade{ }, }, "umber": { // upgrade for v1.19.0 - Added: []string{crisistypes.ModuleName}, + Added: []string{crisistypes.ModuleName, consensusparamtypes.ModuleName}, Deleted: []string{"reward"}, Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) { var err error From c5c8aa324ae62748d14a684e6b82413dfef6befb Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:30:40 -0600 Subject: [PATCH 03/19] inject the umber upgrade (and add a TODO to remove it). --- app/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app.go b/app/app.go index 8ccb826f8..49300d83c 100644 --- a/app/app.go +++ b/app/app.go @@ -1041,6 +1041,8 @@ func (app *App) registerUpgradeHandlers(appOpts servertypes.AppOptions) { // Add the upgrade handlers for each release. InstallCustomUpgradeHandlers(app) + app.injectUpgrade("umber") // TODO: Delete this line. + // Use the dump of $home/data/upgrade-info.json:{"name":"$plan","height":321654} to determine // if we load a store upgrade from the handlers. No file == no error from read func. upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() From 2c649c8e180926217d01b6632d4d9564df760221 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:31:11 -0600 Subject: [PATCH 04/19] Use the correct type for the marker module's max supply param entry. --- app/upgrades.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index e24052238..dd6221e2c 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -374,9 +375,9 @@ func migrateMarkerParams(ctx sdk.Context, app *App) { // TODO: remove markertypes.ParamStoreKeyMaxSupply with the umber handlers. if markerParamSpace.Has(ctx, markertypes.ParamStoreKeyMaxSupply) { - var maxSupply string + var maxSupply sdkmath.Int markerParamSpace.Get(ctx, markertypes.ParamStoreKeyMaxSupply, &maxSupply) - params.MaxSupply = markertypes.StringToBigInt(maxSupply) + params.MaxSupply = maxSupply } app.MarkerKeeper.SetParams(ctx, params) From 9dca58061bdac58ddcbeec80c9a5e13dd8742737 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:54:40 -0600 Subject: [PATCH 05/19] Fix the os locator params migration. Make it just set it to the default. Those params never got defined in testnet, and mainnet has an empty entry for it. So both were just using the default value there anyway. --- app/upgrades.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index dd6221e2c..eb8040776 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -389,13 +389,8 @@ func migrateMarkerParams(ctx sdk.Context, app *App) { // TODO: Remove with the umber handlers. func migrateMetadataOSLocatorParams(ctx sdk.Context, app *App) { ctx.Logger().Info("Migrating metadata os locator params.") - metadataParamSpace := app.ParamsKeeper.Subspace(metadatatypes.ModuleName).WithKeyTable(metadatatypes.ParamKeyTable()) - maxValueLength := uint32(metadatatypes.DefaultMaxURILength) - // TODO: remove metadatatypes.ParamStoreKeyMaxValueLength with the umber handlers. - if metadataParamSpace.Has(ctx, metadatatypes.ParamStoreKeyMaxValueLength) { - metadataParamSpace.Get(ctx, metadatatypes.ParamStoreKeyMaxValueLength, &maxValueLength) - } - app.MetadataKeeper.SetOSLocatorParams(ctx, metadatatypes.OSLocatorParams{MaxUriLength: maxValueLength}) + params := metadatatypes.DefaultOSLocatorParams() + app.MetadataKeeper.SetOSLocatorParams(ctx, params) ctx.Logger().Info("Done migrating metadata os locator params.") } From ab5802199213b57381acd0441a1866f6d2af3231 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 17:58:15 -0600 Subject: [PATCH 06/19] Fix the name params migration to properly identify the keytable. --- app/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index eb8040776..2f0d7cd8f 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -398,7 +398,7 @@ func migrateMetadataOSLocatorParams(ctx sdk.Context, app *App) { // TODO: Remove with the umber handlers. func migrateNameParams(ctx sdk.Context, app *App) { ctx.Logger().Info("Migrating name params.") - nameParamSpace := app.ParamsKeeper.Subspace(nametypes.ModuleName) + nameParamSpace := app.ParamsKeeper.Subspace(nametypes.ModuleName).WithKeyTable(nametypes.ParamKeyTable()) params := nametypes.DefaultParams() From ce7dfbfae57c565cc87cd5ea8fa74888c80935f6 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 12 Jun 2024 18:03:25 -0600 Subject: [PATCH 07/19] Fix the ibchooks params migration. --- app/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index 2f0d7cd8f..a1a8914a7 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -459,7 +459,7 @@ func migrateMsgFeesParams(ctx sdk.Context, app *App) { // TODO: Remove with the umber handlers. func migrateIbcHooksParams(ctx sdk.Context, app *App) { ctx.Logger().Info("Migrating ibchooks params.") - ibcHooksParamSpace := app.ParamsKeeper.Subspace(ibchookstypes.ModuleName) + ibcHooksParamSpace := app.ParamsKeeper.Subspace(ibchookstypes.ModuleName).WithKeyTable(ibchookstypes.ParamKeyTable()) params := ibchookstypes.DefaultParams() From f85df2738f6d8855abd04c76040929d2b89b76cd Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 12:57:37 -0600 Subject: [PATCH 08/19] Small cleanup in app.New to reuse stuff from the sdk config. --- app/app.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/app.go b/app/app.go index 49300d83c..55d4c2db3 100644 --- a/app/app.go +++ b/app/app.go @@ -328,13 +328,14 @@ func New( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { + sdkConfig := sdk.GetConfig() + addrPrefix := sdkConfig.GetBech32AccountAddrPrefix() + valAddrPrefix := sdkConfig.GetBech32ValidatorAddrPrefix() + consAddrPrefix := sdkConfig.GetBech32ConsensusAddrPrefix() + signingOptions := signing.Options{ - AddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - }, - ValidatorAddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), - }, + AddressCodec: address.Bech32Codec{Bech32Prefix: addrPrefix}, + ValidatorAddressCodec: address.Bech32Codec{Bech32Prefix: valAddrPrefix}, } exchange.DefineCustomGetSigners(&signingOptions) interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ @@ -430,13 +431,8 @@ func New( // capability keeper must be sealed after scope to module registrations are completed. app.CapabilityKeeper.Seal() - // Obtain prefixes so running tests can use "cosmos" while we use "pb" - addrPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() - valAddrPrefix := sdk.GetConfig().GetBech32ValidatorAddrPrefix() - consAddrPrefix := sdk.GetConfig().GetBech32ConsensusAddrPrefix() - // add keepers - app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(addrPrefix), addrPrefix, govAuthority) + app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, signingOptions.AddressCodec, addrPrefix, govAuthority) app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, From 9fd940c4572a31a0f065cbf7f22eb7f9ef0cee2a Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 12:59:37 -0600 Subject: [PATCH 09/19] Refactor app.SetConfig(bool, bool) to be able to switch back to mainnet after initially being changed to testnet. --- app/prefix.go | 14 ++-- app/prefix_test/prefix_test.go | 147 +++++++++++++++++++++++++-------- 2 files changed, 120 insertions(+), 41 deletions(-) diff --git a/app/prefix.go b/app/prefix.go index 2e97fc951..8afac2aad 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -26,16 +26,17 @@ var ( // SetConfig sets the configuration for the network using mainnet or testnet func SetConfig(testnet bool, seal bool) { - // not the default (mainnet) so reset with testnet config + AccountAddressPrefix = AccountAddressPrefixMainNet + CoinType = CoinTypeMainNet if testnet { AccountAddressPrefix = AccountAddressPrefixTestNet - AccountPubKeyPrefix = AccountAddressPrefixTestNet + "pub" - ValidatorAddressPrefix = AccountAddressPrefixTestNet + "valoper" - ValidatorPubKeyPrefix = AccountAddressPrefixTestNet + "valoperpub" - ConsNodeAddressPrefix = AccountAddressPrefixTestNet + "valcons" - ConsNodePubKeyPrefix = AccountAddressPrefixTestNet + "valconspub" CoinType = CoinTypeTestNet } + AccountPubKeyPrefix = AccountAddressPrefix + "pub" + ValidatorAddressPrefix = AccountAddressPrefix + "valoper" + ValidatorPubKeyPrefix = AccountAddressPrefix + "valoperpub" + ConsNodeAddressPrefix = AccountAddressPrefix + "valcons" + ConsNodePubKeyPrefix = AccountAddressPrefix + "valconspub" config := sdk.GetConfig() config.SetCoinType(uint32(CoinType)) @@ -43,6 +44,7 @@ func SetConfig(testnet bool, seal bool) { config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix) config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) + if seal { config.Seal() } diff --git a/app/prefix_test/prefix_test.go b/app/prefix_test/prefix_test.go index f1b6b093d..07349b510 100644 --- a/app/prefix_test/prefix_test.go +++ b/app/prefix_test/prefix_test.go @@ -22,6 +22,7 @@ package prefix_test import ( "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,55 +30,131 @@ import ( "github.com/provenance-io/provenance/app" ) -func TestFullBIP44Path(t *testing.T) { +func TestSetConfig(t *testing.T) { cases := []struct { - name string - expected string - isTestnet bool - seal bool - panicMessage string + name string + isTestnet bool + seal bool + expPath string + expHRP string + expCoinType int + expPanic string }{ { - // Note: The way our SetConfig function works, calling it with isTestnet = true makes some changes that aren't undone - // when later calling it with isTestnet = false. So to test the mainnet BIP44, we need to do it first. - name: "has correct bip44th path for mainnet", - expected: "m/44'/505'/0'/0/0", - isTestnet: false, - seal: false, - panicMessage: "", + name: "mainnet", + isTestnet: false, + seal: false, + expPath: "m/44'/505'/0'/0/0", + expHRP: app.AccountAddressPrefixMainNet, + expCoinType: app.CoinTypeMainNet, }, { - // Note: This is the 2nd to last test, so we're doing seal = true. - name: "has correct bip44th path for testnet", - expected: "m/44'/1'/0'/0/0", - isTestnet: true, - seal: true, - panicMessage: "", + name: "testnet", + isTestnet: true, + seal: false, + expPath: "m/44'/1'/0'/0/0", + expHRP: app.AccountAddressPrefixTestNet, + expCoinType: app.CoinTypeTestNet, }, { - // Note: The previous test should have had seal = true, making this an + name: "back to mainnet", + isTestnet: false, + seal: false, + expPath: "m/44'/505'/0'/0/0", + expHRP: app.AccountAddressPrefixMainNet, + expCoinType: app.CoinTypeMainNet, + }, + { + // This is the last valid test, so we're doing seal = true. + name: "back to testnet with seal", + isTestnet: true, + seal: true, + expPath: "m/44'/1'/0'/0/0", + expHRP: app.AccountAddressPrefixTestNet, + expCoinType: app.CoinTypeTestNet, + }, + { + // Note: A previous test should have had seal = true, making this an + // attempt to change the config after sealing it. + name: "already sealed: mainnet, no reseal", + isTestnet: false, + seal: false, + expPanic: "Config is sealed", + }, + { + // Note: A previous test should have had seal = true, making this an + // attempt to change the config after sealing it. + name: "already sealed: testnet, no reseal", + isTestnet: true, + seal: false, + expPanic: "Config is sealed", + }, + { + // Note: A previous test should have had seal = true, making this an // attempt to change the config after sealing it. - name: "cannot double seal", - expected: "", - isTestnet: false, - seal: true, - panicMessage: "Config is sealed", + name: "already sealed: mainnet, with reseal", + isTestnet: false, + seal: true, + expPanic: "Config is sealed", + }, + { + // Note: A previous test should have had seal = true, making this an + // attempt to change the config after sealing it. + name: "already sealed: testnet, with reseal", + isTestnet: true, + seal: true, + expPanic: "Config is sealed", }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - if len(tc.panicMessage) > 0 { - require.PanicsWithValue(t, tc.panicMessage, func() { - app.SetConfig(tc.isTestnet, tc.seal) - }, "SetConfig") + testFunc := func() { + app.SetConfig(tc.isTestnet, tc.seal) + } + if len(tc.expPanic) > 0 { + require.PanicsWithValue(t, tc.expPanic, testFunc, "SetConfig") } else { - require.NotPanics(t, func() { - app.SetConfig(tc.isTestnet, tc.seal) - }, "SetConfig") - config := sdk.GetConfig() - fullBIP44Path := config.GetFullBIP44Path() - require.Equal(t, tc.expected, fullBIP44Path, "GetFullBIP44Path") + require.NotPanics(t, testFunc, "SetConfig") + + expAddrPre := tc.expHRP + expValPre := tc.expHRP + "valoper" + expValPubPre := tc.expHRP + "valoperpub" + expAddrPrePub := tc.expHRP + "pub" + expConsPre := tc.expHRP + "valcons" + expConsPubPre := tc.expHRP + "valconspub" + + sdkConfig := sdk.GetConfig() + fullBIP44Path := sdkConfig.GetFullBIP44Path() + addrPre := sdkConfig.GetBech32AccountAddrPrefix() + addrPubPre := sdkConfig.GetBech32AccountPubPrefix() + valPre := sdkConfig.GetBech32ValidatorAddrPrefix() + valPubPre := sdkConfig.GetBech32ValidatorPubPrefix() + consPre := sdkConfig.GetBech32ConsensusAddrPrefix() + consPubPre := sdkConfig.GetBech32ConsensusPubPrefix() + coinType := sdkConfig.GetCoinType() + purpose := sdkConfig.GetPurpose() + + // Using require to check the main HRPs because if they're wrong, the rest will almost certainly also be wrong. + require.Equal(t, expAddrPre, app.AccountAddressPrefix, "AccountAddressPrefix") + require.Equal(t, expAddrPre, addrPre, "sdkConfig.GetBech32AccountAddrPrefix()") + // Asserts from here on out so we get a larger picture upon failure. + assert.Equal(t, expAddrPrePub, app.AccountPubKeyPrefix, "AccountPubKeyPrefix") + assert.Equal(t, expAddrPrePub, addrPubPre, "sdkConfig.GetBech32AccountPubPrefix()") + assert.Equal(t, expValPre, app.ValidatorAddressPrefix, "ValidatorAddressPrefix") + assert.Equal(t, expValPre, valPre, "sdkConfig.GetBech32ValidatorAddrPrefix()") + assert.Equal(t, expValPubPre, app.ValidatorPubKeyPrefix, "ValidatorPubKeyPrefix") + assert.Equal(t, expValPubPre, valPubPre, "sdkConfig.GetBech32ValidatorPubPrefix()") + assert.Equal(t, expConsPre, app.ConsNodeAddressPrefix, "ConsNodeAddressPrefix") + assert.Equal(t, expConsPre, consPre, "sdkConfig.GetBech32ConsensusAddrPrefix()") + assert.Equal(t, expConsPubPre, app.ConsNodePubKeyPrefix, "ConsNodePubKeyPrefix") + assert.Equal(t, expConsPubPre, consPubPre, "sdkConfig.GetBech32ConsensusPubPrefix()") + + assert.Equal(t, tc.expPath, fullBIP44Path, "sdkConfig.GetFullBIP44Path()") + assert.Equal(t, tc.expCoinType, app.CoinType, "CoinType") + assert.Equal(t, tc.expCoinType, int(coinType), "sdkConfig.GetCoinType()") + assert.Equal(t, 44, app.Purpose, "Purpose") + assert.Equal(t, 44, int(purpose), "sdkConfig.GetPurpose()") } }) } From c43aca3a99e30abf8f587ef67d1f868c6080937e Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 13:00:26 -0600 Subject: [PATCH 10/19] Move the EnvTypeFlag and CoinTypeFlag variables into the interceptor with some other flags so that we can use them in there as needed. --- cmd/provenanced/cmd/init.go | 3 ++- cmd/provenanced/cmd/root.go | 15 ++++----------- cmd/provenanced/config/interceptor.go | 6 +++++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/provenanced/cmd/init.go b/cmd/provenanced/cmd/init.go index 38c1dbbff..7773a2e2c 100644 --- a/cmd/provenanced/cmd/init.go +++ b/cmd/provenanced/cmd/init.go @@ -34,6 +34,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/go-bip39" + "github.com/provenance-io/provenance/cmd/provenanced/config" provconfig "github.com/provenance-io/provenance/cmd/provenanced/config" "github.com/provenance-io/provenance/internal/pioconfig" markertypes "github.com/provenance-io/provenance/x/marker/types" @@ -78,7 +79,7 @@ func Init( moniker string, ) error { chainID, _ := cmd.Flags().GetString(flags.FlagChainID) - isTestnet, _ := cmd.Flags().GetBool(EnvTypeFlag) + isTestnet, _ := cmd.Flags().GetBool(config.EnvTypeFlag) doRecover, _ := cmd.Flags().GetBool(FlagRecover) doOverwrite, _ := cmd.Flags().GetBool(FlagOverwrite) timeoutCommit, err := cmd.Flags().GetDuration(FlagTimeoutCommit) diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index 72f2c7460..037464c49 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -51,13 +51,6 @@ import ( "github.com/provenance-io/provenance/internal/pioconfig" ) -const ( - // EnvTypeFlag is a flag for indicating a testnet - EnvTypeFlag = "testnet" - // CoinTypeFlag is a flag for indicating coin type. - CoinTypeFlag = "coin-type" -) - // NewRootCmd creates a new root command for provenanced. It is called once in the main function. // Providing sealConfig = false is only for unit tests that want to run multiple commands. func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) { @@ -111,12 +104,12 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) { // set app context based on initialized EnvTypeFlag vpr := server.GetServerContextFromCmd(cmd).Viper - testnet := vpr.GetBool(EnvTypeFlag) + testnet := vpr.GetBool(config.EnvTypeFlag) app.SetConfig(testnet, sealConfig) overwriteFlagDefaults(cmd, map[string]string{ // Override default value for coin-type to match our mainnet or testnet value. - CoinTypeFlag: fmt.Sprint(app.CoinType), + config.CoinTypeFlag: fmt.Sprint(app.CoinType), // Override min gas price(server level config) here since the provenance config would have been set based on flags. server.FlagMinGasPrices: pioconfig.GetProvenanceConfig().ProvenanceMinGasPrices, }) @@ -128,7 +121,7 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) { overwriteFlagDefaults(rootCmd, map[string]string{ flags.FlagChainID: "", flags.FlagKeyringBackend: "test", - CoinTypeFlag: fmt.Sprint(app.CoinTypeMainNet), + config.CoinTypeFlag: fmt.Sprint(app.CoinTypeMainNet), }) // add keyring to autocli opts @@ -158,7 +151,7 @@ func Execute(rootCmd *cobra.Command) error { ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext()) - rootCmd.PersistentFlags().BoolP(EnvTypeFlag, "t", false, "Indicates this command should use the testnet configuration (default: false [mainnet])") + rootCmd.PersistentFlags().BoolP(config.EnvTypeFlag, "t", false, "Indicates this command should use the testnet configuration (default: false [mainnet])") rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)") rootCmd.PersistentFlags().String(flags.FlagLogFormat, cmtconfig.LogFormatPlain, "The logging format (json|plain)") diff --git a/cmd/provenanced/config/interceptor.go b/cmd/provenanced/config/interceptor.go index 97ad5ce8c..e854bdc62 100644 --- a/cmd/provenanced/config/interceptor.go +++ b/cmd/provenanced/config/interceptor.go @@ -19,6 +19,10 @@ const ( CustomDenomFlag = "custom-denom" // CustomMsgFeeFloorPriceFlag flag to take in custom msg floor fees, defaults to 1905nhash if not passed in. CustomMsgFeeFloorPriceFlag = "msgfee-floor-price" + // EnvTypeFlag is a flag for indicating a testnet + EnvTypeFlag = "testnet" + // CoinTypeFlag is a flag for indicating coin type. + CoinTypeFlag = "coin-type" ) // InterceptConfigsPreRunHandler performs a pre-run function for all commands. @@ -52,7 +56,7 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command) error { // This needs to be done before we load the config files for the cases when: // 1. The files don't exist yet, and we're loading the defaults. // 2. The config is packed and we're filling in the missing with defaults. - if vpr.GetBool("testnet") { + if vpr.GetBool(EnvTypeFlag) { DefaultKeyringBackend = "test" } // Read the configs into viper and the contexts. From 319d9696418662c407ab39a13e9124c17221069b Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 13:57:02 -0600 Subject: [PATCH 11/19] Add key tables to all the params subspaces. Needed now because the migrations all failed because the needed keys weren't registered. --- app/app.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index 55d4c2db3..61109351e 100644 --- a/app/app.go +++ b/app/app.go @@ -10,6 +10,7 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmv2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -89,6 +90,7 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -1333,16 +1335,16 @@ func GetMaccPerms() map[string][]string { func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable()) paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(minttypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName) - paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) + paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) + paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) + paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) - paramsKeeper.Subspace(wasmtypes.ModuleName) + paramsKeeper.Subspace(wasmtypes.ModuleName).WithKeyTable(wasmv2.ParamKeyTable()) // register the key tables for legacy param subspaces keyTable := ibcclienttypes.ParamKeyTable() @@ -1350,6 +1352,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable) paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable()) paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) + paramsKeeper.Subspace(icqtypes.ModuleName).WithKeyTable(icqtypes.ParamKeyTable()) return paramsKeeper } From 0f18f0d623187ec0049efcc5a0d9bf3e61d2a317 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 13:58:17 -0600 Subject: [PATCH 12/19] Tweak the log messages in migrateBaseappParams to better reflect what's being done (all of the params stuff is 'legacy' now, so it didn't really describe what was happening. --- app/upgrades.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index a1a8914a7..722be0c87 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -300,14 +300,14 @@ func updateIBCClients(ctx sdk.Context, app *App) { // migrateBaseappParams migrates to new ConsensusParamsKeeper // TODO: Remove with the umber handlers. func migrateBaseappParams(ctx sdk.Context, app *App) error { - ctx.Logger().Info("Migrating legacy params.") + ctx.Logger().Info("Migrating consensus params.") legacyBaseAppSubspace := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) err := baseapp.MigrateParams(ctx, legacyBaseAppSubspace, app.ConsensusParamsKeeper.ParamsStore) if err != nil { ctx.Logger().Error(fmt.Sprintf("Unable to migrate legacy params to ConsensusParamsKeeper, error: %s.", err)) return err } - ctx.Logger().Info("Done migrating legacy params.") + ctx.Logger().Info("Done migrating consensus params.") return nil } From 401b8fd3fc73b8706323a355ead920564c627fbc Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 14:08:07 -0600 Subject: [PATCH 13/19] Delete the call to injectUpgrade. --- app/app.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/app.go b/app/app.go index 61109351e..136d80a7e 100644 --- a/app/app.go +++ b/app/app.go @@ -1039,8 +1039,6 @@ func (app *App) registerUpgradeHandlers(appOpts servertypes.AppOptions) { // Add the upgrade handlers for each release. InstallCustomUpgradeHandlers(app) - app.injectUpgrade("umber") // TODO: Delete this line. - // Use the dump of $home/data/upgrade-info.json:{"name":"$plan","height":321654} to determine // if we load a store upgrade from the handlers. No file == no error from read func. upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() From 1f4b7e9f223c59e5a2384db4c3c60e9fb99c49c0 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 14:13:38 -0600 Subject: [PATCH 14/19] Add nolint:staticcheck to all the newly added calls to the deprecated ParamKeyTable functions. --- app/app.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index 136d80a7e..b23d19da0 100644 --- a/app/app.go +++ b/app/app.go @@ -1333,16 +1333,17 @@ func GetMaccPerms() map[string][]string { func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + //nolint:staticcheck // The ParamKeyTable functions are deprecated, but needed here for the migrations. paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable()) paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) - paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) - paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) - paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) - - paramsKeeper.Subspace(wasmtypes.ModuleName).WithKeyTable(wasmv2.ParamKeyTable()) + paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable()) //nolint:staticcheck + paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable()) //nolint:staticcheck + paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable()) //nolint:staticcheck + paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) //nolint:staticcheck + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) //nolint:staticcheck + paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) //nolint:staticcheck + + paramsKeeper.Subspace(wasmtypes.ModuleName).WithKeyTable(wasmv2.ParamKeyTable()) //nolint:staticcheck // register the key tables for legacy param subspaces keyTable := ibcclienttypes.ParamKeyTable() From f37d37c431c27a530e78515ebbbf4e677d618076 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 14:13:50 -0600 Subject: [PATCH 15/19] Fix double import. --- cmd/provenanced/cmd/init.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/provenanced/cmd/init.go b/cmd/provenanced/cmd/init.go index 7773a2e2c..3e39f8bac 100644 --- a/cmd/provenanced/cmd/init.go +++ b/cmd/provenanced/cmd/init.go @@ -34,7 +34,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/go-bip39" - "github.com/provenance-io/provenance/cmd/provenanced/config" provconfig "github.com/provenance-io/provenance/cmd/provenanced/config" "github.com/provenance-io/provenance/internal/pioconfig" markertypes "github.com/provenance-io/provenance/x/marker/types" @@ -79,7 +78,7 @@ func Init( moniker string, ) error { chainID, _ := cmd.Flags().GetString(flags.FlagChainID) - isTestnet, _ := cmd.Flags().GetBool(config.EnvTypeFlag) + isTestnet, _ := cmd.Flags().GetBool(provconfig.EnvTypeFlag) doRecover, _ := cmd.Flags().GetBool(FlagRecover) doOverwrite, _ := cmd.Flags().GetBool(FlagOverwrite) timeoutCommit, err := cmd.Flags().GetDuration(FlagTimeoutCommit) From 53650f3e260c14c505bbef8e256acb8585dd4652 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 14:17:58 -0600 Subject: [PATCH 16/19] Fix the umber tests to have the expected log messages for the consensus params migration (that I updated a few commits ago). --- app/upgrades_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 251b4995a..81c310b2d 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -366,8 +366,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() { expInLog := []string{ "INF Pruning expired consensus states for IBC.", "INF Done pruning expired consensus states for IBC.", - "INF Migrating legacy params.", - "INF Done migrating legacy params.", + "INF Migrating consensus params.", + "INF Done migrating consensus params.", "INF Migrating bank params.", "INF Done migrating bank params.", "INF Migrating attribute params.", @@ -397,8 +397,8 @@ func (s *UpgradeTestSuite) TestUmber() { expInLog := []string{ "INF Pruning expired consensus states for IBC.", "INF Done pruning expired consensus states for IBC.", - "INF Migrating legacy params.", - "INF Done migrating legacy params.", + "INF Migrating consensus params.", + "INF Done migrating consensus params.", "INF Migrating bank params.", "INF Done migrating bank params.", "INF Migrating attribute params.", From 2df498193abe75c4ea777c412a38a298f29bb69b Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 14:36:43 -0600 Subject: [PATCH 17/19] Add changelog entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0477b658..311bb93f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,6 +118,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * The `add-net-asset-values` command now correctly uses the from `flag`'s `AccAddress` [#1995](https://github.com/provenance-io/provenance/issues/1995). * Fix the sim tests [#2015](https://github.com/provenance-io/provenance/pull/2015). +* Fix the `umber` and `umber-rc1` upgrades [#2033](https://github.com/provenance-io/provenance/pull/2033). ### Deprecated From 864bfd594f8e4f06a76f62dcadebca1487103543 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 15:42:58 -0600 Subject: [PATCH 18/19] Remove the TODO in app.New about adding the circuit breaker (which was added in a different PR). --- app/app.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/app.go b/app/app.go index 6cf9bb2b3..e47401ce5 100644 --- a/app/app.go +++ b/app/app.go @@ -362,7 +362,6 @@ func New( bApp.SetInterfaceRegistry(interfaceRegistry) sdk.SetCoinDenomRegex(SdkCoinDenomRegex) - // TODO[1760]: Add the circuit breaker module to the app. keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, From 4eb2d9020e57bdb1fda7798ed7d6a5169f23eb61 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 13 Jun 2024 15:44:02 -0600 Subject: [PATCH 19/19] Replace the last two v50 epic TODOs with standard TODOs since we're gonna have to just live with our forks for the async-icq and ibc-go libraries for now. --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 839a35472..b224c6f36 100644 --- a/go.mod +++ b/go.mod @@ -214,9 +214,9 @@ replace ( github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.50.0-pio-2 github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.7-pio-1 - // TODO[1760]: Update once async-icq creates tag with our changes https://github.com/cosmos/ibc-apps/pull/168 + // TODO: Update once async-icq creates tag with our changes https://github.com/cosmos/ibc-apps/pull/168 github.com/cosmos/ibc-apps/modules/async-icq/v8 => github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 - // TODO[1760]: Update or change once a tag is made containing a fix for https://github.com/cosmos/ibc-go/issues/6375 + // TODO: Update or change once a tag is made containing a fix for https://github.com/cosmos/ibc-go/issues/6375 github.com/cosmos/ibc-go/v8 => github.com/provenance-io/ibc-go/v8 v8.2.1-pio-1 // dgrijalva/jwt-go is deprecated and doesn't receive security updates.