Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v23 upgrade handler (final) #1243

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
Loading