From b7f9124c4e01feee99c86ff0c6764dcb8c33375d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 14 Nov 2023 22:37:00 +0100 Subject: [PATCH] chore: simplify and cleanup upgrades.go (#2324) * chore: cleanup old upgrades * remove unused code * lint * lint --- app/upgrades.go | 233 ++-------- app/upgradev3/migrations.go | 2 - app/upgradev3x3/gov_legacy.pb.go | 453 -------------------- app/upgradev3x3/migrate.go | 24 -- app/upgradev3x3/proposal_legacy.go | 31 -- app/wasm.go | 4 +- x/leverage/keeper/migrations.go | 39 -- x/oracle/keeper/keeper.go | 1 - x/oracle/migrations/exg_rates_migrations.go | 15 - x/oracle/migrations/migrations.go | 15 - 10 files changed, 29 insertions(+), 788 deletions(-) delete mode 100644 app/upgradev3x3/gov_legacy.pb.go delete mode 100644 app/upgradev3x3/migrate.go delete mode 100644 app/upgradev3x3/proposal_legacy.go delete mode 100644 x/oracle/migrations/exg_rates_migrations.go diff --git a/app/upgrades.go b/app/upgrades.go index 069a3127a6..46a4b45ac8 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -24,25 +24,14 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/cosmos-sdk/x/group" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/nft" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/umee-network/umee/v6/app/upgradev3x3" "github.com/umee-network/umee/v6/util" - "github.com/umee-network/umee/v6/x/incentive" - leveragekeeper "github.com/umee-network/umee/v6/x/leverage/keeper" leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" - "github.com/umee-network/umee/v6/x/metoken" - - oraclemigrator "github.com/umee-network/umee/v6/x/oracle/migrations" - oracletypes "github.com/umee-network/umee/v6/x/oracle/types" - "github.com/umee-network/umee/v6/x/ugov" - "github.com/umee-network/umee/v6/x/uibc" ) // RegisterUpgradeHandlersregisters upgrade handlers. @@ -52,21 +41,23 @@ func (app UmeeApp) RegisterUpgradeHandlers() { panic(err) } - app.registerUpgrade3_0(upgradeInfo) - app.registerUpgrade("v3.1.0", upgradeInfo) - app.registerUpgrade3_1to3_3(upgradeInfo) - app.registerUpgrade3_2to3_3(upgradeInfo) - app.registerUpgrade3_3to4_0(upgradeInfo) - app.registerUpgrade("v4.0.1", upgradeInfo) - app.registerUpgrade4_1(upgradeInfo) - app.registerUpgrade("v4.2", upgradeInfo, uibc.ModuleName) + // below we only kee interesting upgrades + app.registerOutdatedPlaceholderUpgrade("v1.1-v3.0") // upgrade from v1->v3.0 + app.registerOutdatedPlaceholderUpgrade("v3.1.0") // upgrade from v3.0->v3.1 + app.registerOutdatedPlaceholderUpgrade("v3.1-v3.3") // upgrade from v3.1->v3.3 + app.registerOutdatedPlaceholderUpgrade("v3.2-v3.3") // upgrade from v3.2 -> v3.3 + app.registerOutdatedPlaceholderUpgrade("v4.0") // upgrade from v3.3 -> v4.0 + app.registerOutdatedPlaceholderUpgrade("v4.0.1") // upgrade from v4.0 -> v4.0.1 + app.registerOutdatedPlaceholderUpgrade("v4.1.0") // upgrade from v4.0 -> v4.1 + app.registerOutdatedPlaceholderUpgrade("v4.2") app.registerUpgrade4_3(upgradeInfo) - app.registerUpgrade("v4.4", upgradeInfo) - app.registerUpgrade("v5.0", upgradeInfo, ugov.ModuleName, wasmtypes.ModuleName) - app.registerUpgrade5_1(upgradeInfo) - app.registerUpgrade("v5.2", upgradeInfo) // v5.2 migration is not compatible with v6, so leaving default here. + app.registerOutdatedPlaceholderUpgrade("v4.4") + app.registerOutdatedPlaceholderUpgrade("v5.0") + app.registerOutdatedPlaceholderUpgrade("v5.1") + app.registerOutdatedPlaceholderUpgrade("v5.2") app.registerUpgrade6(upgradeInfo) - app.registerUpgrade6_1("v6.1", upgradeInfo) + app.registerOutdatedPlaceholderUpgrade("v6.1") + app.registerUpgrade6_2(upgradeInfo) } @@ -105,11 +96,12 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) { subspace.WithKeyTable(keyTable) } } - baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + printPlanName(planName, ctx.Logger()) + // Migrate CometBFT consensus parameters from x/params module to a dedicated x/consensus module. baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) @@ -138,36 +130,6 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) { // app.registerNewTokenEmissionUpgrade(upgradeInfo) } -func (app *UmeeApp) registerUpgrade6_1(planName string, upgradeInfo upgradetypes.Plan) { - app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - printPlanName(planName, ctx.Logger()) - err := app.OracleKeeper.SetHistoricAvgCounterParams(ctx, oracletypes.DefaultAvgCounterParams()) - if err != nil { - return fromVM, err - } - - oracleUpgrader := oraclemigrator.NewMigrator(&app.OracleKeeper) - oracleUpgrader.ExgRatesWithTimestamp(ctx) - - // reference: (today) avg block size in Ethereum is 170kb - // Cosmwasm binaries can be few hundreds KB up to 3MB - // our blocks with oracle txs as JSON are about 80kB, so protobuf should be less than 40kB. - var newMaxBytes int64 = 4_000_000 // 4 MB - p := app.GetConsensusParams(ctx) - ctx.Logger().Info("Changing consensus params", "prev", p.Block.MaxBytes, "new", newMaxBytes) - p.Block.MaxBytes = newMaxBytes - app.StoreConsensusParams(ctx, p) - - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, - ) - - app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{ - Added: []string{metoken.ModuleName}, - }) -} - func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) { planName := "v6.0" gravityModuleName := "gravity" // hardcoded to avoid dependency on GB module @@ -191,26 +153,6 @@ func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) { }) } -func (app *UmeeApp) registerUpgrade5_1(upgradeInfo upgradetypes.Plan) { - planName := "v5.1" - app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // GravityBridge is deleted after v5.1 - // if err := app.GravityKeeper.MigrateFundsToDrainAccount( - // ctx, - // sdk.MustAccAddressFromBech32("umee1gx9svenfs6ktvajje2wgqau3gk5mznwnyghq4l"), - // ); err != nil { - // return nil, err - // } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, - ) - - app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{ - Added: []string{incentive.ModuleName}, - }) -} - // performs upgrade from v4.2 to v4.3 func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) { const planName = "v4.3" @@ -260,136 +202,6 @@ func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) { }) } -// performs upgrade from v4.0 to v4.1 -func (app *UmeeApp) registerUpgrade4_1(_ upgradetypes.Plan) { - const planName = "v4.1.0" - app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Upgrade handler execution", "name", planName) - leverageUpgrader := leveragekeeper.NewMigrator(&app.LeverageKeeper) - migrated, err := leverageUpgrader.MigrateBNB(ctx) - if err != nil { - ctx.Logger().Error("Error in v4.1 leverage Migration!", "err", err) - return fromVM, err - } - if migrated { - // If leverage BNB migration was skipped, also skip oracle so they stay in sync - oracleUpgrader := oraclemigrator.NewMigrator(&app.OracleKeeper) - oracleUpgrader.MigrateBNB(ctx) - } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, - ) -} - -// performs upgrade from v3.3 -> v4 -func (app *UmeeApp) registerUpgrade3_3to4_0(_ upgradetypes.Plan) { - const planName = "v4.0" - app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Upgrade handler execution", "name", planName) - ctx.Logger().Info("Run v4.0 migration") - upgrader := oraclemigrator.NewMigrator(&app.OracleKeeper) - err := upgrader.HistoracleParams3x4(ctx) - if err != nil { - ctx.Logger().Error("Unable to run v4.0 Migration!", "err", err) - return fromVM, err - } - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, - ) -} - -// performs upgrade from v3.1 -> v3.3 (including the v3.2 changes) -func (app *UmeeApp) registerUpgrade3_1to3_3(_ upgradetypes.Plan) { - const planName = "v3.1-v3.3" - app.UpgradeKeeper.SetUpgradeHandler( - planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Upgrade handler execution", "name", planName) - ctx.Logger().Info("Run v3.3 migrator") - err := upgradev3x3.Migrator(*app.GovKeeper, app.interfaceRegistry)(ctx) - if err != nil { - return fromVM, err - } - ctx.Logger().Info("Run x/bank v0.46.5 migration") - // err = bankkeeper.NewMigrator(app.BankKeeper, app.GetSubspace(banktypes.ModuleName)).Migrate3_V046_4_To_V046_5(ctx) - if err != nil { - return fromVM, err - } - ctx.Logger().Info("Run module migrations") - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }) -} - -// performs upgrade from v3.2 -> v3.3 -func (app *UmeeApp) registerUpgrade3_2to3_3(_ upgradetypes.Plan) { - const planName = "v3.2-v3.3" - app.UpgradeKeeper.SetUpgradeHandler( - planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Upgrade handler execution", "name", planName) - ctx.Logger().Info("Run v3.3 migrator") - err := upgradev3x3.Migrator(*app.GovKeeper, app.interfaceRegistry)(ctx) - if err != nil { - return fromVM, err - } - ctx.Logger().Info("Run module migrations") - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }) -} - -// performs upgrade from v1->v3 -func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) { - const planName = "v1.1-v3.0" - app.UpgradeKeeper.SetUpgradeHandler( - planName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Upgrade handler execution", "name", planName) - // ctx.Logger().Info("Running setupBech32ibcKeeper") - // err := upgradev3.SetupBech32ibcKeeper(&app.bech32IbcKeeper, ctx) - // if err != nil { - // return nil, errors.Wrapf( - // err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", planName) - // } - - ctx.Logger().Info("Running module migrations") - vm, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) - if err != nil { - return vm, err - } - - // ctx.Logger().Info("Updating validator minimum commission rate param of staking module") - // minCommissionRate, err := upgradev3.UpdateMinimumCommissionRateParam(ctx, app.StakingKeeper) - // if err != nil { - // return vm, errors.Wrapf( - // err, "%q Upgrade: failed to update minimum commission rate param of staking module", - // planName) - // } - - // ctx.Logger().Info("Upgrade handler execution finished, updating minimum commission rate of all validators", - // "name", planName) - // err = upgradev3.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate) - // if err != nil { - // return vm, errors.Wrapf( - // err, "%q Upgrade: failed to update minimum commission rate for validators", - // planName) - // } - - return vm, err - }) - - app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{ - Added: []string{ - group.ModuleName, - nft.ModuleName, - // bech32ibctypes.ModuleName, // removed dependency - oracletypes.ModuleName, - leveragetypes.ModuleName, - }, - }) -} - func onlyModuleMigrations(app *UmeeApp, planName string) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { printPlanName(planName, ctx.Logger()) @@ -410,6 +222,8 @@ func (app *UmeeApp) storeUpgrade(planName string, ui upgradetypes.Plan, stores s // registerUpgrade sets an upgrade handler which only runs module migrations // and adds new storages storages +// +//nolint:unused func (app *UmeeApp) registerUpgrade(planName string, upgradeInfo upgradetypes.Plan, newStores ...string) { app.UpgradeKeeper.SetUpgradeHandler(planName, onlyModuleMigrations(app, planName)) @@ -420,6 +234,15 @@ func (app *UmeeApp) registerUpgrade(planName string, upgradeInfo upgradetypes.Pl } } +// oldUpgradePlan is a noop, placeholder handler required for old (completed) upgrade plans. +func (app *UmeeApp) registerOutdatedPlaceholderUpgrade(planName string) { + app.UpgradeKeeper.SetUpgradeHandler( + planName, + func(_ sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + panic("Can't migrate state < 'head - 2' while running a logic with the 'head' version") + }) +} + func printPlanName(planName string, logger log.Logger) { logger.Info("-----------------------------\n-----------------------------") logger.Info("Upgrade handler execution", "name", planName) diff --git a/app/upgradev3/migrations.go b/app/upgradev3/migrations.go index d3ab5015ef..a5ac16b4d0 100644 --- a/app/upgradev3/migrations.go +++ b/app/upgradev3/migrations.go @@ -9,9 +9,7 @@ var minCommissionRate = sdk.MustNewDecFromStr("0.05") // UpdateMinimumCommissionRateParam is update the minimum commission rate param of staking. func UpdateMinimumCommissionRateParam(ctx sdk.Context, keeper StakingKeeper) (sdk.Dec, error) { params := keeper.GetParams(ctx) - // update the minCommissionRate param params.MinCommissionRate = minCommissionRate - keeper.SetParams(ctx, params) return minCommissionRate, nil diff --git a/app/upgradev3x3/gov_legacy.pb.go b/app/upgradev3x3/gov_legacy.pb.go deleted file mode 100644 index b58d3fe04f..0000000000 --- a/app/upgradev3x3/gov_legacy.pb.go +++ /dev/null @@ -1,453 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: umee/leverage/v1/gov.proto - -package upgradev3x3 - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" - - "github.com/umee-network/umee/v6/x/leverage/types" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// UpdateRegistryProposal defines a governance proposal type where the token -// registry can be updated in the Umee capital facility. Note, the registry -// defined in the proposal replaces the current registry in its entirety. -type UpdateRegistryProposal struct { - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - Registry []types.Token `protobuf:"bytes,3,rep,name=registry,proto3" json:"registry"` -} - -func (m *UpdateRegistryProposal) Reset() { *m = UpdateRegistryProposal{} } -func (*UpdateRegistryProposal) ProtoMessage() {} -func (*UpdateRegistryProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_3febb94c702124d7, []int{0} -} -func (m *UpdateRegistryProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UpdateRegistryProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UpdateRegistryProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UpdateRegistryProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateRegistryProposal.Merge(m, src) -} -func (m *UpdateRegistryProposal) XXX_Size() int { - return m.Size() -} -func (m *UpdateRegistryProposal) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateRegistryProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateRegistryProposal proto.InternalMessageInfo - -func init() { - proto.RegisterType((*UpdateRegistryProposal)(nil), "umee.leverage.v1.UpdateRegistryProposal") -} - -func init() { proto.RegisterFile("umee/leverage/v1/gov.proto", fileDescriptor_3febb94c702124d7) } - -var fileDescriptor_3febb94c702124d7 = []byte{ - // 271 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0xcd, 0x4d, 0x4d, - 0xd5, 0xcf, 0x49, 0x2d, 0x4b, 0x2d, 0x4a, 0x4c, 0x4f, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0xcf, 0x2f, - 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x00, 0xc9, 0xe9, 0xc1, 0xe4, 0xf4, 0xca, 0x0c, - 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x92, 0xfa, 0x20, 0x16, 0x44, 0x9d, 0x94, 0x3c, 0x86, - 0x19, 0x70, 0x3d, 0x60, 0x05, 0x4a, 0x33, 0x19, 0xb9, 0xc4, 0x42, 0x0b, 0x52, 0x12, 0x4b, 0x52, - 0x83, 0x52, 0xd3, 0x33, 0x8b, 0x4b, 0x8a, 0x2a, 0x03, 0x8a, 0xf2, 0x0b, 0xf2, 0x8b, 0x13, 0x73, - 0x84, 0x44, 0xb8, 0x58, 0x4b, 0x32, 0x4b, 0x72, 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, - 0x20, 0x1c, 0x21, 0x05, 0x2e, 0xee, 0x94, 0xd4, 0xe2, 0xe4, 0xa2, 0xcc, 0x82, 0x92, 0xcc, 0xfc, - 0x3c, 0x09, 0x26, 0xb0, 0x1c, 0xb2, 0x90, 0x90, 0x25, 0x17, 0x47, 0x11, 0xd4, 0x2c, 0x09, 0x66, - 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x71, 0x3d, 0x74, 0xe7, 0xea, 0x85, 0xe4, 0x67, 0xa7, 0xe6, 0x39, - 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x57, 0x6e, 0xc5, 0xd3, 0xb1, 0x40, 0x9e, 0x61, 0xc6, - 0x02, 0x79, 0x86, 0x17, 0x0b, 0xe4, 0x19, 0x9d, 0xfc, 0x4e, 0x3c, 0x94, 0x63, 0x38, 0xf1, 0x48, - 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, - 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, - 0xe4, 0xfc, 0x5c, 0x7d, 0x90, 0xf1, 0xba, 0x79, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0x60, 0x8e, - 0x7e, 0x99, 0xb1, 0x7e, 0x05, 0xc2, 0xdf, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x2f, - 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x28, 0xf0, 0xed, 0x0b, 0x59, 0x01, 0x00, 0x00, -} - -func (this *UpdateRegistryProposal) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UpdateRegistryProposal) - if !ok { - that2, ok := that.(UpdateRegistryProposal) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Title != that1.Title { - return false - } - if this.Description != that1.Description { - return false - } - if len(this.Registry) != len(that1.Registry) { - return false - } - for i := range this.Registry { - if !this.Registry[i].Equal(&that1.Registry[i]) { - return false - } - } - return true -} -func (m *UpdateRegistryProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UpdateRegistryProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UpdateRegistryProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Registry) > 0 { - for iNdEx := len(m.Registry) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Registry[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGov(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintGov(dAtA []byte, offset int, v uint64) int { - offset -= sovGov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *UpdateRegistryProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovGov(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovGov(uint64(l)) - } - if len(m.Registry) > 0 { - for _, e := range m.Registry { - l = e.Size() - n += 1 + l + sovGov(uint64(l)) - } - } - return n -} - -func sovGov(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGov(x uint64) (n int) { - return sovGov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *UpdateRegistryProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UpdateRegistryProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UpdateRegistryProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Registry", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Registry = append(m.Registry, types.Token{}) - if err := m.Registry[len(m.Registry)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGov(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGov - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGov(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGov - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGov - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGov - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGov = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGov = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGov = fmt.Errorf("proto: unexpected end of group") -) diff --git a/app/upgradev3x3/migrate.go b/app/upgradev3x3/migrate.go deleted file mode 100644 index 3c638a392d..0000000000 --- a/app/upgradev3x3/migrate.go +++ /dev/null @@ -1,24 +0,0 @@ -package upgradev3x3 - -import ( - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" -) - -type migrator struct { - gov govkeeper.Keeper -} - -// Creates migration handler for gov leverage proposals to new the gov system -// and MsgGovUpdateRegistry type. -func Migrator(gk govkeeper.Keeper, _ cdctypes.InterfaceRegistry) module.MigrationHandler { - // note: content was removed, use v3.3 for implementation details. - m := migrator{gk} - return m.migrate -} - -func (m migrator) migrate(_ sdk.Context) error { - panic("use v3.3 binary") -} diff --git a/app/upgradev3x3/proposal_legacy.go b/app/upgradev3x3/proposal_legacy.go deleted file mode 100644 index 921f44c114..0000000000 --- a/app/upgradev3x3/proposal_legacy.go +++ /dev/null @@ -1,31 +0,0 @@ -package upgradev3x3 - -import ( - "encoding/json" - - gov1b1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -// Assert UpdateRegistryProposal implements govtypes.Content at compile-time -var _ gov1b1.Content = &UpdateRegistryProposal{} - -// String implements the Stringer interface. -func (p UpdateRegistryProposal) String() string { - b, _ := json.Marshal(p) - return string(b) -} - -// GetTitle returns the title of the proposal. -func (p *UpdateRegistryProposal) GetTitle() string { return p.Title } - -// GetDescription returns the description of the proposal. -func (p *UpdateRegistryProposal) GetDescription() string { return p.Description } - -// ProposalRoute returns the x/gov routing key of the proposal. -func (p *UpdateRegistryProposal) ProposalRoute() string { return "not needed" } - -// ProposalType returns the x/gov type of the proposal. -func (p *UpdateRegistryProposal) ProposalType() string { return "not needed" } - -// ValidateBasic validates the proposal returning an error if invalid. -func (p *UpdateRegistryProposal) ValidateBasic() error { return nil } diff --git a/app/wasm.go b/app/wasm.go index b794b958c1..7ea9da6f49 100644 --- a/app/wasm.go +++ b/app/wasm.go @@ -2,9 +2,7 @@ package app import wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" -var ( - EmptyWasmOpts []wasmkeeper.Option -) +var EmptyWasmOpts []wasmkeeper.Option // AllCapabilities returns all capabilities available with the current wasmvm // See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md diff --git a/x/leverage/keeper/migrations.go b/x/leverage/keeper/migrations.go index ef4e760714..81d056ba53 100644 --- a/x/leverage/keeper/migrations.go +++ b/x/leverage/keeper/migrations.go @@ -1,12 +1,5 @@ package keeper -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/umee-network/umee/v6/util/coin" - "github.com/umee-network/umee/v6/x/leverage/types" -) - // Migrator is a struct for handling in-place store migrations. type Migrator struct { keeper *Keeper @@ -16,35 +9,3 @@ type Migrator struct { func NewMigrator(keeper *Keeper) Migrator { return Migrator{keeper: keeper} } - -// MigrateBNB fixes the BNB base denom for the 4.1 upgrade. -// Also returns a boolean representing whether the token was changed. -func (m Migrator) MigrateBNB(ctx sdk.Context) (bool, error) { - // Bad BNB token denom - badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40" - // Ensure zero supply of the token being removed from leverage registry - uSupply := m.keeper.GetUTokenSupply(ctx, coin.ToUTokenDenom(badDenom)) - if !uSupply.IsZero() { - ctx.Logger().Error("can't correctly migrate leverage with existing supply", - "token", badDenom, "total_u_supply", uSupply) - return false, nil - } - token, err := m.keeper.GetTokenSettings(ctx, badDenom) - if err != nil { - ctx.Logger().Error("leverage migration skipped due to missing token", "err", err.Error()) - // If it's not a registered token, then we don't need to run this migration - return false, nil - } - // Delete previous entry in token registry - store := ctx.KVStore(m.keeper.storeKey) - store.Delete(types.KeyRegisteredToken(badDenom)) - // Modify base denom and add back to store, bypassing the hooks in SetRegisteredToken - correctDenom := "ibc/8184469200C5E667794375F5B0EC3B9ABB6FF79082941BF5D0F8FF59FEBA862E" - token.BaseDenom = correctDenom - bz, err := m.keeper.cdc.Marshal(&token) - if err != nil { - return false, err - } - store.Set(types.KeyRegisteredToken(correctDenom), bz) - return true, nil -} diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index a32202f170..c2404a1ea8 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -129,7 +129,6 @@ func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec) { sdkutil.Emit(&ctx, &types.EventSetFxRate{ Denom: denom, Rate: rate, }) - } // IterateExchangeRates iterates over all USD rates in the store. diff --git a/x/oracle/migrations/exg_rates_migrations.go b/x/oracle/migrations/exg_rates_migrations.go deleted file mode 100644 index cd8cc8ef68..0000000000 --- a/x/oracle/migrations/exg_rates_migrations.go +++ /dev/null @@ -1,15 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// ExgRatesWithTimestamp will migrate old exchnage rate of denoms into new exchange rate format with -// timestamp into store. -func (m Migrator) ExgRatesWithTimestamp(ctx sdk.Context) { - m.keeper.IterateOldExchangeRates(ctx, func(s string, d sdk.Dec) bool { - ctx.Logger().Info("Migrating old exchange rate to new exchange rate format", "denom", s) - m.keeper.SetExchangeRateWithTimestamp(ctx, s, d, ctx.BlockTime()) - return false - }) -} diff --git a/x/oracle/migrations/migrations.go b/x/oracle/migrations/migrations.go index c7b5ea6c6e..bd5434eda5 100644 --- a/x/oracle/migrations/migrations.go +++ b/x/oracle/migrations/migrations.go @@ -35,18 +35,3 @@ func (m Migrator) HistoracleParams3x4(ctx sdk.Context) error { m.keeper.SetMaximumMedianStamps(ctx, p.MaximumMedianStamps) return nil } - -// MigrateBNB fixes the BNB base denom for the 4.1 upgrade without using leverage hooks -func (m Migrator) MigrateBNB(ctx sdk.Context) { - badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40" - correctDenom := "ibc/8184469200C5E667794375F5B0EC3B9ABB6FF79082941BF5D0F8FF59FEBA862E" - acceptList := m.keeper.AcceptList(ctx) - for index := range acceptList { - // Switch the base denom of the token with changing anything else - if acceptList[index].BaseDenom == badDenom { - acceptList[index].BaseDenom = correctDenom - } - } - // Overwrite previous accept list - m.keeper.SetAcceptList(ctx, acceptList) -}