Skip to content

Commit

Permalink
fix: stuck unbondings and UpdateRedemption (#1732)
Browse files Browse the repository at this point in the history
... vercel sucks.

* fix
* lint fix
  • Loading branch information
ajansari95 authored Oct 24, 2024
1 parent f6b6f31 commit ba3e06e
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
V010601UpgradeName = "v1.6.1"
V010602UpgradeName = "v1.6.2"
V010603UpgradeName = "v1.6.3"
V010604UpgradeName = "v1.6.4"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
Expand Down
1 change: 1 addition & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Upgrades() []Upgrade {
{UpgradeName: V010601UpgradeName, CreateUpgradeHandler: V010601UpgradeHandler},
{UpgradeName: V010602UpgradeName, CreateUpgradeHandler: NoOpHandler},
{UpgradeName: V010603UpgradeName, CreateUpgradeHandler: V010603UpgradeHandler},
{UpgradeName: V010604UpgradeName, CreateUpgradeHandler: V010604UpgradeHandler},
}
}

Expand Down
49 changes: 49 additions & 0 deletions app/upgrades/v1_6.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package upgrades
import (
"encoding/json"
"fmt"
"time"

abci "github.com/tendermint/tendermint/abci/types"

Expand Down Expand Up @@ -307,3 +308,51 @@ func V010603UpgradeHandler(
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func V010604UpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
appKeepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if isMainnet(ctx) || isTest(ctx) {

hashes := []struct {
Zone string
Hash string
}{
{Zone: "cosmoshub-4", Hash: "6cc942b42150a43b45d56c39d05155206ffb40eb18268dbd0b3c1ce5248b2645"},
{Zone: "stargaze-1", Hash: "10af0ee10a97f01467039a69cbfb8df05dc3111c975d955ca51adda201f36555"},
{Zone: "juno-1", Hash: "627db4f106a8ef99053a0726f3f71d2f23bbfd4a9155b6d083ff7015bdfa44c0"},
{Zone: "cosmoshub-4", Hash: "0c8269f04109a55a152d3cdfd22937b4e5c2746111d579935eef4cd7ffa71f7f"},
{Zone: "cosmoshub-4", Hash: "677691e596338af42387cbafae9831c5e0fe4b7f31b683ad69d2cc3f17687bd8"},
{Zone: "cosmoshub-4", Hash: "c8351fe7e6775b39b9f480182f9ea57c914ea566dd35912a4597f234b12405a6"},
{Zone: "cosmoshub-4", Hash: "d750de16665edbfca2a889ccec7a16ce107987416a80304154453ff6e8e25c5d"},
{Zone: "cosmoshub-4", Hash: "e5a44be995514d10cce7795a28d8a997e4eb95ba805d54cfaa9ce62e78a87a50"},
{Zone: "cosmoshub-4", Hash: "fb73556a38faeffa4740923c585b609a002869d1a9006f660567166cd4f5a79b"},
{Zone: "cosmoshub-4", Hash: "fd42b32563d8beecb64ae2aa47f9b38ddecd436ac4e8b84bf9d9c46f447439e6"},
}
for _, hashRecord := range hashes {
record, found := appKeepers.InterchainstakingKeeper.GetWithdrawalRecord(ctx, hashRecord.Zone, hashRecord.Hash, icstypes.WithdrawStatusSend)
if !found {
appKeepers.InterchainstakingKeeper.Logger(ctx).Error(fmt.Sprintf("unable to find record for hash %s", hashRecord.Hash))
continue
}

// update the record so that it will re-trigger.
record.Status = icstypes.WithdrawStatusQueued
record.Acknowledged = false
record.CompletionTime = time.Time{}

err := appKeepers.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record)
if err != nil {
return nil, err
}

appKeepers.InterchainstakingKeeper.Logger(ctx).Info("reset ack for withdrawal record", "hash", hashRecord.Hash, "zone", hashRecord.Zone)
}
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
50 changes: 50 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,53 @@ func (s *AppTestSuite) TestV010603UpgradeHandler() {

s.Equal(postBalance.Amount.Int64(), preBalance.Add(record.BurnAmount).Amount.Int64())
}

func (s *AppTestSuite) TestV010604UpgradeHandler() {
s.InitV160TestZones()
app := s.GetQuicksilverApp(s.chainA)

ctx := s.chainA.GetContext()

hashes := []struct {
Zone string
Hash string
}{
{Zone: "cosmoshub-4", Hash: "6cc942b42150a43b45d56c39d05155206ffb40eb18268dbd0b3c1ce5248b2645"},
{Zone: "stargaze-1", Hash: "10af0ee10a97f01467039a69cbfb8df05dc3111c975d955ca51adda201f36555"},
{Zone: "juno-1", Hash: "627db4f106a8ef99053a0726f3f71d2f23bbfd4a9155b6d083ff7015bdfa44c0"},
{Zone: "cosmoshub-4", Hash: "0c8269f04109a55a152d3cdfd22937b4e5c2746111d579935eef4cd7ffa71f7f"},
{Zone: "cosmoshub-4", Hash: "677691e596338af42387cbafae9831c5e0fe4b7f31b683ad69d2cc3f17687bd8"},
{Zone: "cosmoshub-4", Hash: "c8351fe7e6775b39b9f480182f9ea57c914ea566dd35912a4597f234b12405a6"},
{Zone: "cosmoshub-4", Hash: "d750de16665edbfca2a889ccec7a16ce107987416a80304154453ff6e8e25c5d"},
{Zone: "cosmoshub-4", Hash: "e5a44be995514d10cce7795a28d8a997e4eb95ba805d54cfaa9ce62e78a87a50"},
{Zone: "cosmoshub-4", Hash: "fb73556a38faeffa4740923c585b609a002869d1a9006f660567166cd4f5a79b"},
{Zone: "cosmoshub-4", Hash: "fd42b32563d8beecb64ae2aa47f9b38ddecd436ac4e8b84bf9d9c46f447439e6"},
}

for _, hashRecord := range hashes {
record := icstypes.WithdrawalRecord{
ChainId: hashRecord.Zone,
Delegator: "quick1zyj57u72nwr23q2glz77jaana9kpvn8cxdp5gl",
Recipient: "cosmos1xnvuycukuex5eae336u7umrhfea9xndr0ksjlj",
Txhash: hashRecord.Hash,
Status: icstypes.WithdrawStatusSend,
BurnAmount: sdk.NewCoin("uqatom", math.NewInt(4754000000)),
Acknowledged: true,
CompletionTime: time.Now(),
}

s.NoError(app.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record))
}

handler := upgrades.V010604UpgradeHandler(app.mm, app.configurator, &app.AppKeepers)

_, err := handler(ctx, types.Plan{}, app.mm.GetVersionMap())
s.NoError(err)

for _, hashRecord := range hashes {
record, found := app.InterchainstakingKeeper.GetWithdrawalRecord(ctx, hashRecord.Zone, hashRecord.Hash, icstypes.WithdrawStatusQueued)
s.True(found)
s.False(record.Acknowledged)
s.True(record.CompletionTime.IsZero())
}
}
1 change: 1 addition & 0 deletions x/interchainstaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (k msgServer) UpdateRedemption(goCtx context.Context, msg *types.MsgUpdateR
r.Amount = nil
r.Distribution = nil
r.CompletionTime = time.Time{}
r.Acknowledged = false
}

k.UpdateWithdrawalRecordStatus(ctx, r, msg.NewStatus)
Expand Down

0 comments on commit ba3e06e

Please sign in to comment.