Skip to content

Commit

Permalink
fix: track acknowledgements via a field (#507)
Browse files Browse the repository at this point in the history
* track acknowledgements via a fiels

* added test cases for ack fix

* upgrade handler to migrate state

* nil completion time for elgafar-1 are ack'd

---------

Co-authored-by: Alex Johnson <[email protected]>
  • Loading branch information
ajansari95 and Alex Johnson authored Jul 19, 2023
1 parent 866011d commit c0a0dd5
Show file tree
Hide file tree
Showing 7 changed files with 580 additions and 126 deletions.
1 change: 1 addition & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
V010404beta5UpgradeName = "v1.4.4-beta.5"
V010404beta7UpgradeName = "v1.4.4-beta.7"
V010404rc0UpgradeName = "v1.4.4-rc.0"
V010404beta8UpgradeName = "v1.4.4-beta.8"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
Expand Down
25 changes: 25 additions & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Upgrades() []Upgrade {
{UpgradeName: V010404beta5UpgradeName, CreateUpgradeHandler: V010404beta5UpgradeHandler},
{UpgradeName: V010404beta7UpgradeName, CreateUpgradeHandler: V010404beta7UpgradeHandler},
{UpgradeName: V010404rc0UpgradeName, CreateUpgradeHandler: V010404rc0UpgradeHandler},
{UpgradeName: V010404beta8UpgradeName, CreateUpgradeHandler: V010404beta8UpgradeHandler},
}
}

Expand Down Expand Up @@ -442,6 +443,30 @@ func V010404rc0UpgradeHandler(
}
}

func V010404beta8UpgradeHandler(
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 isTestnet(ctx) || isTest(ctx) || isDevnet(ctx) {
appKeepers.InterchainstakingKeeper.IterateWithdrawalRecords(ctx, func(index int64, record icstypes.WithdrawalRecord) (stop bool) {
if (record.Status == icstypes.WithdrawStatusSend) || record.Requeued || ((record.CompletionTime != time.Time{}) && (record.CompletionTime.Before(ctx.BlockTime()))) {
record.Acknowledged = true
}

if (record.ChainId == "elgafar-1") && (record.CompletionTime == time.Time{}) {
record.Acknowledged = true
}

appKeepers.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record)
return false
})
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

// func V010400UpgradeHandler(
// mm *module.Manager,
// configurator module.Configurator,
Expand Down
31 changes: 23 additions & 8 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ paths:
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
title: >-
- ClaimTypeUndefined: Undefined action (per protobuf
Expand Down Expand Up @@ -923,6 +924,7 @@ paths:
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
title: >-
- ClaimTypeUndefined: Undefined action (per protobuf
Expand Down Expand Up @@ -1084,6 +1086,7 @@ paths:
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
title: >-
- ClaimTypeUndefined: Undefined action (per protobuf
Expand Down Expand Up @@ -1245,6 +1248,7 @@ paths:
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
title: >-
- ClaimTypeUndefined: Undefined action (per protobuf
Expand Down Expand Up @@ -1688,8 +1692,12 @@ paths:
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or ...
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}
Example 3: Pack and unpack a message in Python.
Example 3: Pack and unpack a message in Python.
foo = Foo(...)
any = Any()
Expand All @@ -1699,7 +1707,7 @@ paths:
any.Unpack(foo)
...
Example 4: Pack and unpack a message in Go
Example 4: Pack and unpack a message in Go
foo := &pb.Foo{...}
any, err := anypb.New(foo)
Expand Down Expand Up @@ -1727,10 +1735,8 @@ paths:
name "y.z".
JSON
====
The JSON representation of an `Any` value uses the regular
Expand Down Expand Up @@ -1999,8 +2005,12 @@ paths:
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
// or ...
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
foo = any.unpack(Foo.getDefaultInstance());
}
Example 3: Pack and unpack a message in Python.
Example 3: Pack and unpack a message in Python.
foo = Foo(...)
any = Any()
Expand All @@ -2010,7 +2020,7 @@ paths:
any.Unpack(foo)
...
Example 4: Pack and unpack a message in Go
Example 4: Pack and unpack a message in Go
foo := &pb.Foo{...}
any, err := anypb.New(foo)
Expand Down Expand Up @@ -2038,10 +2048,8 @@ paths:
name "y.z".
JSON
====
The JSON representation of an `Any` value uses the regular
Expand Down Expand Up @@ -2641,6 +2649,8 @@ paths:
format: date-time
requeued:
type: boolean
acknowledged:
type: boolean
pagination:
type: object
properties:
Expand Down Expand Up @@ -4415,6 +4425,8 @@ paths:
format: date-time
requeued:
type: boolean
acknowledged:
type: boolean
pagination:
type: object
properties:
Expand Down Expand Up @@ -4606,6 +4618,8 @@ paths:
format: date-time
requeued:
type: boolean
acknowledged:
type: boolean
pagination:
type: object
properties:
Expand Down Expand Up @@ -4914,6 +4928,7 @@ paths:
- ClaimTypeOsmosisPool
- ClaimTypeCrescentPool
- ClaimTypeSifchainPool
- ClaimTypeUmeeToken
default: ClaimTypeUndefined
title: '- ClaimTypeUndefined: Undefined action (per protobuf spec)'
proofs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ message WithdrawalRecord {
(gogoproto.stdtime) = true
];
bool requeued = 10;
bool acknowledged = 11;
}

message UnbondingRecord {
Expand Down
5 changes: 4 additions & 1 deletion x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (k *Keeper) GCCompletedRedelegations(ctx sdk.Context) error {

func (k *Keeper) HandleMaturedUnbondings(ctx sdk.Context, zone *types.Zone) error {
k.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, types.WithdrawStatusUnbond, func(idx int64, withdrawal types.WithdrawalRecord) bool {
if ctx.BlockTime().After(withdrawal.CompletionTime) && !withdrawal.CompletionTime.Equal(time.Time{}) { // completion date has passed.
if ctx.BlockTime().After(withdrawal.CompletionTime) && withdrawal.Acknowledged { // completion date has passed.
k.Logger(ctx).Info("found completed unbonding")
sendMsg := &banktypes.MsgSend{FromAddress: zone.DelegationAddress.GetAddress(), ToAddress: withdrawal.Recipient, Amount: sdk.Coins{withdrawal.Amount[0]}}
err := k.SubmitTx(ctx, []sdk.Msg{sendMsg}, zone.DelegationAddress, types.TxUnbondSendMemo(withdrawal.Txhash), zone.MessagesPerTx)
Expand Down Expand Up @@ -712,6 +712,9 @@ func (k *Keeper) HandleUndelegate(ctx sdk.Context, msg sdk.Msg, completion time.
if !found {
return fmt.Errorf("unable to lookup withdrawal record; chain: %s, hash: %s", zone.ChainId, hash)
}

record.Acknowledged = true

if completion.After(record.CompletionTime) {
record.CompletionTime = completion
}
Expand Down
Loading

0 comments on commit c0a0dd5

Please sign in to comment.