From 2d841bfc454fb85bbf262ef83bcf2573149f5982 Mon Sep 17 00:00:00 2001 From: Joe Bowman Date: Tue, 4 Jul 2023 12:44:10 +0100 Subject: [PATCH] fix: remove use of iota (#484) * fix: remove use of iota * upgrade handler for v1.4.4-beta.5 * fix: correct current values for unbonding records --- app/upgrades/types.go | 1 + app/upgrades/upgrades.go | 59 ++++++++++++++++--- x/epochs/types/keys.go | 2 +- x/interchainquery/types/keys.go | 6 +- .../types/withdrawal_record.go | 10 ++-- x/interchainstaking/types/zones.go | 14 +---- 6 files changed, 63 insertions(+), 29 deletions(-) diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 8e08085f5..19652beda 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -27,6 +27,7 @@ const ( V010403rc0UpgradeName = "v1.4.3-rc0" V010404beta0UpgradeName = "v1.4.4-beta.0" V010404beta1UpgradeName = "v1.4.4-beta.1" + V010404beta5UpgradeName = "v1.4.4-beta.5" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go index 67150214e..bcdd271c4 100644 --- a/app/upgrades/upgrades.go +++ b/app/upgrades/upgrades.go @@ -1,6 +1,7 @@ package upgrades import ( + "errors" "time" sdkmath "cosmossdk.io/math" @@ -12,7 +13,7 @@ import ( "github.com/ingenuity-build/quicksilver/app/keepers" "github.com/ingenuity-build/quicksilver/utils/addressutils" - "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" + icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -48,9 +49,9 @@ func V010402rc1UpgradeHandler( ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { if isTestnet(ctx) || isTest(ctx) { - appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *types.Zone) (stop bool) { + appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { for _, val := range zone.Validators { - newVal := types.Validator{ + newVal := icstypes.Validator{ ValoperAddress: val.ValoperAddress, CommissionRate: val.CommissionRate, DelegatorShares: val.DelegatorShares, @@ -115,7 +116,7 @@ func V010402rc4UpgradeHandler( appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("osmo-test-5/ibc/FBD3AC18A981B89F60F9FE5B21BD7F1DE87A53C3505D5A5E438E2399409CFB6F"))) appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rhye-1/uqosmo"))) rcptTime := time.Unix(1682932342, 0) - rcpt1 := types.Receipt{ + rcpt1 := icstypes.Receipt{ ChainId: "theta-testnet-001", Sender: "cosmos1e6p7tk969ftlzmz82drp84ruukwge6z6udand8", Txhash: "005AABC399866544CBEC4DC57887A7297289BF40C056A1544D3CE18946DB7DB9", @@ -124,7 +125,7 @@ func V010402rc4UpgradeHandler( Completed: nil, } - rcpt2 := types.Receipt{ + rcpt2 := icstypes.Receipt{ ChainId: "elgafar-1", Sender: "stars1e6p7tk969ftlzmz82drp84ruukwge6z6g32wxk", Txhash: "01041964B4CDDD3ECA1C9F1EFC039B547C2D30D5B85C55089EB6F7DF311786B6", @@ -152,7 +153,7 @@ func V010402rc5UpgradeHandler( rcptTime := time.Unix(1682932342, 0) - rcpts := []types.Receipt{ + rcpts := []icstypes.Receipt{ { ChainId: "theta-testnet-001", Sender: "cosmos1e6p7tk969ftlzmz82drp84ruukwge6z6udand8", @@ -229,7 +230,7 @@ func V010402rc6UpgradeHandler( return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { if isTestnet(ctx) || isTest(ctx) { // for each zone, trigger an icq request to update all delegations. - appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *types.Zone) (stop bool) { + appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { vals := appKeepers.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) delegationQuery := stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: zone.DelegationAddress.Address, Pagination: &query.PageRequest{Limit: uint64(len(vals))}} bz := appKeepers.InterchainstakingKeeper.GetCodec().MustMarshal(&delegationQuery) @@ -241,7 +242,7 @@ func V010402rc6UpgradeHandler( "cosmos.staking.v1beta1.Query/DelegatorDelegations", bz, sdk.NewInt(-1), - types.ModuleName, + icstypes.ModuleName, "delegations", 0, ) @@ -284,7 +285,7 @@ func V010404beta0UpgradeHandler( ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { if isTestnet(ctx) || isTest(ctx) { - appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *types.Zone) (stop bool) { + appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { zone.Is_118 = true appKeepers.InterchainstakingKeeper.SetZone(ctx, zone) return false @@ -295,6 +296,46 @@ func V010404beta0UpgradeHandler( } } +func V010404beta5UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + appKeepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if isDevnet(ctx) || isTest(ctx) { + // 6d3cc69d3276dd59a93a252e1ea15fc1e507c56512266c87c615fac4dcddb5cb + wr, found := appKeepers.InterchainstakingKeeper.GetWithdrawalRecord(ctx, "theta-testnet-001", "6d3cc69d3276dd59a93a252e1ea15fc1e507c56512266c87c615fac4dcddb5cb", 3) + if !found { + return nil, errors.New("unable to find withdrawal record 6d3cc69d3276dd59a93a252e1ea15fc1e507c56512266c87c615fac4dcddb5cb") + } + appKeepers.InterchainstakingKeeper.UpdateWithdrawalRecordStatus(ctx, &wr, icstypes.WithdrawStatusQueued) + + // b9c6587af3317bfb4b21a29df3f7e1a00709c25b0590446cceb01b8c6996b656 + wr, found = appKeepers.InterchainstakingKeeper.GetWithdrawalRecord(ctx, "theta-testnet-001", "b9c6587af3317bfb4b21a29df3f7e1a00709c25b0590446cceb01b8c6996b656", 3) + if !found { + return nil, errors.New("unable to find withdrawal record b9c6587af3317bfb4b21a29df3f7e1a00709c25b0590446cceb01b8c6996b656") + } + appKeepers.InterchainstakingKeeper.UpdateWithdrawalRecordStatus(ctx, &wr, icstypes.WithdrawStatusQueued) + + // 995c6a77a568a7c03906ce6c7d470c11daa7e506f33264360cf1fec71fc774fe + wr, found = appKeepers.InterchainstakingKeeper.GetWithdrawalRecord(ctx, "regen-redwood-1", "995c6a77a568a7c03906ce6c7d470c11daa7e506f33264360cf1fec71fc774fe", 4) + if !found { + return nil, errors.New("unable to find withdrawal record 995c6a77a568a7c03906ce6c7d470c11daa7e506f33264360cf1fec71fc774fe") + } + appKeepers.InterchainstakingKeeper.UpdateWithdrawalRecordStatus(ctx, &wr, icstypes.WithdrawStatusUnbond) + + // 95aec506a8281c90cb45395ecc7b562248135f8643e1017db469d847db125fbd + wr, found = appKeepers.InterchainstakingKeeper.GetWithdrawalRecord(ctx, "uni-6", "95aec506a8281c90cb45395ecc7b562248135f8643e1017db469d847db125fbd", 4) + if !found { + return nil, errors.New("unable to find withdrawal record 95aec506a8281c90cb45395ecc7b562248135f8643e1017db469d847db125fbd") + } + appKeepers.InterchainstakingKeeper.UpdateWithdrawalRecordStatus(ctx, &wr, icstypes.WithdrawStatusUnbond) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + // func V010400UpgradeHandler( // mm *module.Manager, // configurator module.Configurator, diff --git a/x/epochs/types/keys.go b/x/epochs/types/keys.go index 6bcc66892..2fc9e1065 100644 --- a/x/epochs/types/keys.go +++ b/x/epochs/types/keys.go @@ -13,7 +13,7 @@ const ( // prefix bytes for the epoch persistent store. const ( - prefixEpoch = iota + 1 + prefixEpoch = 0x01 ) const ( diff --git a/x/interchainquery/types/keys.go b/x/interchainquery/types/keys.go index 3812bba2c..c2d631a12 100644 --- a/x/interchainquery/types/keys.go +++ b/x/interchainquery/types/keys.go @@ -16,9 +16,9 @@ const ( // prefix bytes for the interchainquery persistent store. const ( - prefixData = iota + 1 - prefixQuery = iota + 1 - prefixLatestHeight = iota + 1 + prefixData = 0x01 + prefixQuery = 0x02 + prefixLatestHeight = 0x03 ) var ( diff --git a/x/interchainstaking/types/withdrawal_record.go b/x/interchainstaking/types/withdrawal_record.go index 07a5d3e6f..df49780d6 100644 --- a/x/interchainstaking/types/withdrawal_record.go +++ b/x/interchainstaking/types/withdrawal_record.go @@ -10,11 +10,11 @@ const ( DefaultWithdrawalRequeueDelay = 6 * time.Hour // setting WithdrawStatusTokenize as 0 causes the value to be omitted when (un)marshalling :/. - WithdrawStatusTokenize int32 = iota + 1 - WithdrawStatusQueued int32 = iota + 1 - WithdrawStatusUnbond int32 = iota + 1 - WithdrawStatusSend int32 = iota + 1 - WithdrawStatusCompleted int32 = iota + 1 + WithdrawStatusTokenize int32 = 1 + WithdrawStatusQueued int32 = 2 + WithdrawStatusUnbond int32 = 3 + WithdrawStatusSend int32 = 4 + WithdrawStatusCompleted int32 = 5 ) // DelayCompletion updates a withdrawal record completion date to: diff --git a/x/interchainstaking/types/zones.go b/x/interchainstaking/types/zones.go index 63f3742a9..d33bb8886 100644 --- a/x/interchainstaking/types/zones.go +++ b/x/interchainstaking/types/zones.go @@ -87,18 +87,10 @@ COINS: return out } -// decode memo -// field_id = [ -// 0x00 = map -// 0x01 = rts -// 0x02 = validator intent -// ] // will scale to future fields - const ( - FieldTypeAccountMap int = iota - FieldTypeReturnToSender - FieldTypeIntent - // add more here. + FieldTypeAccountMap int = 0x00 + FieldTypeReturnToSender int = 0x01 + FieldTypeIntent int = 0x02 ) type MemoField struct {