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

update: v1.4.4-beta.7 upgrade handler #492

Merged
merged 1 commit into from
Jul 11, 2023
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
1 change: 1 addition & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
V010404beta0UpgradeName = "v1.4.4-beta.0"
V010404beta1UpgradeName = "v1.4.4-beta.1"
V010404beta5UpgradeName = "v1.4.4-beta.5"
V010404beta7UpgradeName = "v1.4.4-beta.7"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
Expand Down
43 changes: 43 additions & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/ingenuity-build/quicksilver/app/keepers"
"github.com/ingenuity-build/quicksilver/utils/addressutils"
epochtypes "github.com/ingenuity-build/quicksilver/x/epochs/types"
icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types"
)
Expand All @@ -30,6 +31,7 @@ func Upgrades() []Upgrade {
{UpgradeName: V010404beta0UpgradeName, CreateUpgradeHandler: V010404beta0UpgradeHandler},
{UpgradeName: V010404beta1UpgradeName, CreateUpgradeHandler: NoOpHandler},
{UpgradeName: V010404beta5UpgradeName, CreateUpgradeHandler: V010404beta5UpgradeHandler},
{UpgradeName: V010404beta7UpgradeName, CreateUpgradeHandler: V010404beta7UpgradeHandler},
}
}

Expand Down Expand Up @@ -337,6 +339,47 @@ func V010404beta5UpgradeHandler(
}
}

func V010404beta7UpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
appKeepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
const (
thetaUnbondingPeriod = int64(172800)
uniUnbondingPeriod = int64(2419200)
osmoUnbondingPeriod = int64(86400)
regenUnbondingPeriod = int64(1814400)
epochDurations = int64(10800)
)

appKeepers.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(idx int64, key []byte, redelegation icstypes.RedelegationRecord) (stop bool) {
var UnbondingPeriod int64
switch redelegation.ChainId {
case "theta-testnet-001":
UnbondingPeriod = thetaUnbondingPeriod
case "uni-6":
UnbondingPeriod = uniUnbondingPeriod
case "osmo-test-5":
UnbondingPeriod = osmoUnbondingPeriod
case "regen-redwood-1":
UnbondingPeriod = regenUnbondingPeriod
}

epochInfo := appKeepers.EpochsKeeper.GetEpochInfo(ctx, epochtypes.EpochIdentifierEpoch)

if UnbondingPeriod < (epochInfo.CurrentEpoch-redelegation.EpochNumber)*epochDurations {
appKeepers.InterchainstakingKeeper.Logger(ctx).Info("garbage collecting completed redelegations", "key", key, "completion", redelegation.CompletionTime)
appKeepers.InterchainstakingKeeper.DeleteRedelegationRecordByKey(ctx, append(icstypes.KeyPrefixRedelegationRecord, key...))
}

return false
})

return mm.RunMigrations(ctx, configurator, fromVM)
}
}

// func V010400UpgradeHandler(
// mm *module.Manager,
// configurator module.Configurator,
Expand Down
60 changes: 60 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,66 @@ func (s *AppTestSuite) TestV010404beta0UpgradeHandler() {
s.Require().True(zone.Is_118)
}

func (s *AppTestSuite) TestV010404beta7UpgradeHandler() {
app := s.GetQuicksilverApp(s.chainA)
// osmosis zone
zone := icstypes.Zone{
ConnectionId: "connection-77002",
ChainId: upgrades.OsmosisTestnetChainID,
AccountPrefix: "osmo",
LocalDenom: "uqosmo",
BaseDenom: "uosmo",
MultiSend: false,
LiquidityModule: true,
}

ctx := s.chainA.GetContext()
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

rdRecord := icstypes.RedelegationRecord{
ChainId: upgrades.OsmosisTestnetChainID,
EpochNumber: 4,
Source: "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk",
Destination: "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc",
Amount: 3000000,
CompletionTime: time.Time{},
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetRedelegationRecord(s.chainA.GetContext(), rdRecord)

rdRecord = icstypes.RedelegationRecord{
ChainId: upgrades.OsmosisTestnetChainID,
EpochNumber: 6,
Source: "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk",
Destination: "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc",
Amount: 3000000,
CompletionTime: time.Time{},
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetRedelegationRecord(s.chainA.GetContext(), rdRecord)

rdRecord = icstypes.RedelegationRecord{
ChainId: upgrades.OsmosisTestnetChainID,
EpochNumber: 34,
Source: "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk",
Destination: "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc",
Amount: 3000000,
CompletionTime: time.Time{},
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetRedelegationRecord(s.chainA.GetContext(), rdRecord)

handler := upgrades.V010404beta7UpgradeHandler(app.mm, app.configurator, &app.AppKeepers)
_, err := handler(ctx, types.Plan{}, app.mm.GetVersionMap())
s.Require().NoError(err)

_, found := app.InterchainstakingKeeper.GetRedelegationRecord(ctx, upgrades.OsmosisTestnetChainID, "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", 4)
s.Require().False(found)

_, found = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, upgrades.OsmosisTestnetChainID, "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", 6)
s.Require().False(found)

_, found = app.InterchainstakingKeeper.GetRedelegationRecord(ctx, upgrades.OsmosisTestnetChainID, "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", 34)
s.Require().True(found)
}

// func (s *AppTestSuite) TestV010400rc6UpgradeHandler() {
// app := s.GetQuicksilverApp(s.chainA)
//
Expand Down