diff --git a/app/upgrades.go b/app/upgrades.go index dea4436e07..854fa3d5a0 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -40,6 +40,7 @@ import ( v7 "github.com/Stride-Labs/stride/v22/app/upgrades/v7" v8 "github.com/Stride-Labs/stride/v22/app/upgrades/v8" v9 "github.com/Stride-Labs/stride/v22/app/upgrades/v9" + airdroptypes "github.com/Stride-Labs/stride/v22/x/airdrop/types" autopilottypes "github.com/Stride-Labs/stride/v22/x/autopilot/types" claimtypes "github.com/Stride-Labs/stride/v22/x/claim/types" icacallbacktypes "github.com/Stride-Labs/stride/v22/x/icacallbacks/types" @@ -305,6 +306,7 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { app.mm, app.configurator, app.IBCKeeper.ClientKeeper, + app.RecordsKeeper, app.StakeibcKeeper, ), ) @@ -368,7 +370,7 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { } case "v23": storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{ibcwasmtypes.ModuleName}, + Added: []string{ibcwasmtypes.ModuleName, airdroptypes.ModuleName}, } } diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index 77583a514b..fa30f94c7b 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -1,17 +1,23 @@ package v23 import ( + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" + recordskeeper "github.com/Stride-Labs/stride/v22/x/records/keeper" + recordstypes "github.com/Stride-Labs/stride/v22/x/records/types" stakeibckeeper "github.com/Stride-Labs/stride/v22/x/stakeibc/keeper" ) var ( UpgradeName = "v23" + + CosmosChainId = "cosmoshub-4" + FailedLSMDepositDenom = "cosmosvaloper1yh089p0cre4nhpdqw35uzde5amg3qzexkeggdn/37467" ) // CreateUpgradeHandler creates an SDK upgrade handler for v23 @@ -19,6 +25,7 @@ func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, clientKeeper clientkeeper.Keeper, + recordsKeeper recordskeeper.Keeper, stakeibcKeeper stakeibckeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { @@ -30,6 +37,9 @@ func CreateUpgradeHandler( ctx.Logger().Info("Migrating trade routes...") MigrateTradeRoutes(ctx, stakeibcKeeper) + ctx.Logger().Info("Resetting failed LSM detokenization record...") + ResetLSMRecord(ctx, recordsKeeper) + ctx.Logger().Info("Running module migrations...") return mm.RunMigrations(ctx, configurator, vm) } @@ -50,3 +60,17 @@ func MigrateTradeRoutes(ctx sdk.Context, k stakeibckeeper.Keeper) { k.SetTradeRoute(ctx, tradeRoute) } } + +// Reset the failed LSM detokenization record status and decrement the amount by 1 +// so that it will succeed on the retry +func ResetLSMRecord(ctx sdk.Context, k recordskeeper.Keeper) { + lsmDeposit, found := k.GetLSMTokenDeposit(ctx, CosmosChainId, FailedLSMDepositDenom) + if !found { + // No need to panic in this case since the difference is immaterial + ctx.Logger().Error("Failed LSM deposit record not found") + return + } + lsmDeposit.Status = recordstypes.LSMTokenDeposit_DETOKENIZATION_QUEUE + lsmDeposit.Amount = lsmDeposit.Amount.Sub(sdkmath.OneInt()) + k.SetLSMTokenDeposit(ctx, lsmDeposit) +} diff --git a/app/upgrades/v23/upgrades_test.go b/app/upgrades/v23/upgrades_test.go index 55f56e342c..03b40eafb7 100644 --- a/app/upgrades/v23/upgrades_test.go +++ b/app/upgrades/v23/upgrades_test.go @@ -3,11 +3,14 @@ package v23_test import ( "testing" - "github.com/stretchr/testify/suite" - sdkmath "cosmossdk.io/math" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + "github.com/stretchr/testify/suite" "github.com/Stride-Labs/stride/v22/app/apptesting" + v23 "github.com/Stride-Labs/stride/v22/app/upgrades/v23" + recordstypes "github.com/Stride-Labs/stride/v22/x/records/types" stakeibctypes "github.com/Stride-Labs/stride/v22/x/stakeibc/types" ) @@ -24,8 +27,14 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *UpgradeTestSuite) TestUpgrade() { - dummyUpgradeHeight := int64(5) + dummyUpgradeHeight := int64(4) + minTransferAmount := sdkmath.NewInt(100) + initialDetokenizeAmount := sdkmath.NewInt(100) + expectedDetokenizeAmount := sdkmath.NewInt(99) + + // Set the allowed ibc clients to an empty list + s.App.IBCKeeper.ClientKeeper.SetParams(s.Ctx, ibcclienttypes.Params{AllowedClients: []string{}}) // Create a trade route with the deprecated trade config tradeRoutes := stakeibctypes.TradeRoute{ @@ -38,11 +47,28 @@ func (s *UpgradeTestSuite) TestUpgrade() { } s.App.StakeibcKeeper.SetTradeRoute(s.Ctx, tradeRoutes) + // Create the failed detokenization record + s.App.RecordsKeeper.SetLSMTokenDeposit(s.Ctx, recordstypes.LSMTokenDeposit{ + ChainId: v23.CosmosChainId, + Denom: v23.FailedLSMDepositDenom, + Amount: initialDetokenizeAmount, + }) + // Run the upgrade - s.ConfirmUpgradeSucceededs("v23", dummyUpgradeHeight) + s.ConfirmUpgradeSucceededs(v23.UpgradeName, dummyUpgradeHeight) // Confirm trade route was migrated for _, tradeRoute := range s.App.StakeibcKeeper.GetAllTradeRoutes(s.Ctx) { s.Require().Equal(tradeRoute.MinTransferAmount, minTransferAmount) } + + // Confirm the ibc wasm client was added + params := s.App.IBCKeeper.ClientKeeper.GetParams(s.Ctx) + s.Require().Equal([]string{ibcwasmtypes.Wasm}, params.AllowedClients, "ibc allowed clients") + + // Confirm the lsm deposit record was reset + lsmRecord, found := s.App.RecordsKeeper.GetLSMTokenDeposit(s.Ctx, v23.CosmosChainId, v23.FailedLSMDepositDenom) + s.Require().True(found, "lsm deposit record should have been found") + s.Require().Equal(recordstypes.LSMTokenDeposit_DETOKENIZATION_QUEUE, lsmRecord.Status, "lsm record status") + s.Require().Equal(expectedDetokenizeAmount, lsmRecord.Amount, "lsm deposit record amount") }