Skip to content

Commit

Permalink
v23 upgrade handler (final) (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Jul 19, 2024
1 parent 3ebcbc0 commit e4b6bee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -305,6 +306,7 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
app.mm,
app.configurator,
app.IBCKeeper.ClientKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
),
)
Expand Down Expand Up @@ -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},
}
}

Expand Down
24 changes: 24 additions & 0 deletions app/upgrades/v23/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
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
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) {
Expand All @@ -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)
}
Expand All @@ -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)
}
34 changes: 30 additions & 4 deletions app/upgrades/v23/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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{
Expand All @@ -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")
}

0 comments on commit e4b6bee

Please sign in to comment.