Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tuan/add-query-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed Mar 26, 2024
2 parents 6223679 + 02bd08d commit 89a83ad
Show file tree
Hide file tree
Showing 49 changed files with 2,131 additions and 1,230 deletions.
2 changes: 2 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
V010407rc2UpgradeName = "v1.4.7-rc2"
V010500rc0UpgradeName = "v1.5.0-rc0"
V010500rc1UpgradeName = "v1.5.0-rc1"
V010503rc0UpgradeName = "v1.5.3-rc0"

// mainnet upgrades
V010217UpgradeName = "v1.2.17"
Expand All @@ -32,6 +33,7 @@ const (
V010407UpgradeName = "v1.4.7"
V010500UpgradeName = "v1.5.0"
V010501UpgradeName = "v1.5.1"
V010503UpgradeName = "v1.5.3"
V010600UpgradeName = "v1.6.0"
)

Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Upgrades() []Upgrade {
{UpgradeName: V010407rc2UpgradeName, CreateUpgradeHandler: V010407rc2UpgradeHandler},
{UpgradeName: V010500rc0UpgradeName, CreateUpgradeHandler: NoOpHandler},
{UpgradeName: V010500rc1UpgradeName, CreateUpgradeHandler: V010500rc1UpgradeHandler},
{UpgradeName: V010503rc0UpgradeName, CreateUpgradeHandler: V010503rc0UpgradeHandler},

// v1.2: this needs to be present to support upgrade on mainnet
{UpgradeName: V010217UpgradeName, CreateUpgradeHandler: NoOpHandler},
Expand All @@ -26,6 +27,7 @@ func Upgrades() []Upgrade {
{UpgradeName: V010407UpgradeName, CreateUpgradeHandler: V010407UpgradeHandler},
{UpgradeName: V010500UpgradeName, CreateUpgradeHandler: V010500UpgradeHandler},
{UpgradeName: V010501UpgradeName, CreateUpgradeHandler: V010501UpgradeHandler},
{UpgradeName: V010503UpgradeName, CreateUpgradeHandler: V010503UpgradeHandler},
{UpgradeName: V010600UpgradeName, CreateUpgradeHandler: V010600UpgradeHandler},
}
}
Expand Down
120 changes: 117 additions & 3 deletions app/upgrades/v1_5.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"fmt"
"time"

"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"

"github.com/quicksilver-zone/quicksilver/app/keepers"
"github.com/quicksilver-zone/quicksilver/utils"
cmtypes "github.com/quicksilver-zone/quicksilver/x/claimsmanager/types"
icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
prkeeper "github.com/quicksilver-zone/quicksilver/x/participationrewards/keeper"
prtypes "github.com/quicksilver-zone/quicksilver/x/participationrewards/types"
Expand Down Expand Up @@ -49,8 +52,119 @@ func V010500rc1UpgradeHandler(
}
}

func V010503rc0UpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
appKeepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// update all withdrawal records' distributors to use new Amount field.
appKeepers.InterchainstakingKeeper.IterateWithdrawalRecords(ctx, func(index int64, record icstypes.WithdrawalRecord) (stop bool) {
if record.Distribution == nil {
// skip records that are queued.
return false
}

newDist := make([]*icstypes.Distribution, 0, len(record.Distribution))
for _, d := range record.Distribution {
d.Amount = math.NewIntFromUint64(d.XAmount)
d.XAmount = 0
newDist = append(newDist, d)
}
record.Distribution = newDist
appKeepers.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record)

return false
})

// for all claims, update to use new Amount field
appKeepers.ClaimsManagerKeeper.IterateAllClaims(ctx, func(index int64, key []byte, data cmtypes.Claim) (stop bool) {
data.Amount = math.NewIntFromUint64(data.XAmount)
appKeepers.ClaimsManagerKeeper.SetClaim(ctx, &data)
return false
})

appKeepers.ClaimsManagerKeeper.IterateAllLastEpochClaims(ctx, func(index int64, key []byte, data cmtypes.Claim) (stop bool) {
data.Amount = math.NewIntFromUint64(data.XAmount)
appKeepers.ClaimsManagerKeeper.SetClaim(ctx, &data)
return false
})

// for all redelegation records, migrate
appKeepers.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(index int64, key []byte, record icstypes.RedelegationRecord) (stop bool) {
record.Amount = math.NewInt(record.XAmount)
appKeepers.InterchainstakingKeeper.SetRedelegationRecord(ctx, record)
return false
})

appKeepers.InterchainstakingKeeper.SetConnectionForPort(ctx, "connection-4", "icacontroller-osmo-test-5.performance")

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

// =========== PRODUCTION UPGRADE HANDLER ===========

func V010503UpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
appKeepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// fix paid up juno records wher ack was never received.
appKeepers.InterchainstakingKeeper.IterateZoneStatusWithdrawalRecords(ctx, "juno-1", 4, func(index int64, record icstypes.WithdrawalRecord) (stop bool) {
// burn burnAmount!
if err := appKeepers.BankKeeper.BurnCoins(ctx, icstypes.EscrowModuleAccount, sdk.NewCoins(record.BurnAmount)); err != nil {
// if we can't burn the coins, fail.
panic(err)
}
appKeepers.InterchainstakingKeeper.DeleteWithdrawalRecord(ctx, record.ChainId, record.Txhash, record.Status)
return false
})

// update all withdrawal records' distributors to use new Amount field.
appKeepers.InterchainstakingKeeper.IterateWithdrawalRecords(ctx, func(index int64, record icstypes.WithdrawalRecord) (stop bool) {
if record.Distribution == nil {
// skip records that are queued.
return false
}

newDist := make([]*icstypes.Distribution, 0, len(record.Distribution))
for _, d := range record.Distribution {
d.Amount = math.NewIntFromUint64(d.XAmount)
d.XAmount = 0
newDist = append(newDist, d)
}
record.Distribution = newDist
appKeepers.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record)

return false
})

// for all claims, update to use new Amount field
appKeepers.ClaimsManagerKeeper.IterateAllClaims(ctx, func(index int64, key []byte, data cmtypes.Claim) (stop bool) {
data.Amount = math.NewIntFromUint64(data.XAmount)
appKeepers.ClaimsManagerKeeper.SetClaim(ctx, &data)
return false
})

appKeepers.ClaimsManagerKeeper.IterateAllLastEpochClaims(ctx, func(index int64, key []byte, data cmtypes.Claim) (stop bool) {
data.Amount = math.NewIntFromUint64(data.XAmount)
appKeepers.ClaimsManagerKeeper.SetLastEpochClaim(ctx, &data)
return false
})

// for all redelegation records, migrate
appKeepers.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(index int64, key []byte, record icstypes.RedelegationRecord) (stop bool) {
record.Amount = math.NewInt(record.XAmount)
appKeepers.InterchainstakingKeeper.SetRedelegationRecord(ctx, record)
return false
})

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

func V010501UpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down Expand Up @@ -526,16 +640,16 @@ func collateRequeuedWithdrawals(ctx sdk.Context, appKeepers *keepers.AppKeepers)
}
// merge distributions
newRecord.Distribution = func(dist1, dist2 []*icstypes.Distribution) []*icstypes.Distribution {
distMap := map[string]uint64{}
distMap := map[string]math.Int{}
for _, dist := range dist1 {
distMap[dist.Valoper] = dist.Amount
}

for _, dist := range dist2 {
if _, ok = distMap[dist.Valoper]; !ok {
distMap[dist.Valoper] = 0
distMap[dist.Valoper] = math.ZeroInt()
}
distMap[dist.Valoper] += dist.Amount
distMap[dist.Valoper] = distMap[dist.Valoper].Add(dist.Amount)
}

out := make([]*icstypes.Distribution, 0, len(distMap))
Expand Down
Loading

0 comments on commit 89a83ad

Please sign in to comment.