Skip to content

Commit

Permalink
fix deposit address setWithdrawalAddress callback (#284)
Browse files Browse the repository at this point in the history
* fix deposit address setWithdrawalAddress callback

* lint fixes

Co-authored-by: Joe Bowman <[email protected]>
  • Loading branch information
ajansari95 and Joe Bowman authored Jan 19, 2023
1 parent 9a3355e commit d4a45f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,17 @@ func (k *Keeper) HandleUpdatedWithdrawAddress(ctx sdk.Context, msg sdk.Msg) erro
if zone == nil {
zone = k.GetZoneForPerformanceAccount(ctx, original.DelegatorAddress)
if zone == nil {
return errors.New("unable to find zone")
if ctx.ChainID() == "quicksilver-2" && ctx.BlockHeight() < 248000 {
return errors.New("unable to find zone") // mirror existing behaviour before 248000
}
// after 248000 correctly handle SetWithdrawalAddress callback.
zone = k.GetZoneForDepositAccount(ctx, original.DelegatorAddress)
if zone == nil {
return errors.New("unable to find zone")
}
if err := zone.DepositAddress.SetWithdrawalAddress(original.WithdrawAddress); err != nil {
return err
}
}
if err := zone.PerformanceAddress.SetWithdrawalAddress(original.WithdrawAddress); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions x/interchainstaking/keeper/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ func (k Keeper) GetZoneForPerformanceAccount(ctx sdk.Context, address string) *t
return zone
}

func (k Keeper) GetZoneForDepositAccount(ctx sdk.Context, address string) *types.Zone {
var zone *types.Zone
k.IterateZones(ctx, func(_ int64, zoneInfo types.Zone) (stop bool) {
if zoneInfo.DepositAddress != nil && zoneInfo.DepositAddress.Address == address {
zone = &zoneInfo
return true
}
return false
})
return zone
}

func (k Keeper) EnsureICAsActive(ctx sdk.Context, zone *types.Zone) error {
k.Logger(ctx).Info("Ensuring ICAs for zone", "zone", zone.ChainId)
if err := k.EnsureICAActive(ctx, zone, zone.DepositAddress); err != nil {
Expand Down

0 comments on commit d4a45f7

Please sign in to comment.