Skip to content

Commit

Permalink
Cleanup v15 (#950)
Browse files Browse the repository at this point in the history
Co-authored-by: sampocs <[email protected]>
Co-authored-by: sampocs <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent ca43a34 commit 91a984a
Show file tree
Hide file tree
Showing 24 changed files with 407 additions and 1,898 deletions.
8 changes: 0 additions & 8 deletions proto/stride/stakeibc/callbacks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ message UndelegateCallback {
repeated uint64 epoch_unbonding_record_ids = 3;
}

message UndelegateHostCallback {
string amt = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
repeated SplitDelegation split_delegations = 2;
}

message RedemptionCallback {
string host_zone_id = 1;
repeated uint64 epoch_unbonding_record_ids = 2;
Expand Down
10 changes: 0 additions & 10 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ service Msg {
rpc CalibrateDelegation(MsgCalibrateDelegation)
returns (MsgCalibrateDelegationResponse);
rpc ClearBalance(MsgClearBalance) returns (MsgClearBalanceResponse);
rpc UndelegateHost(MsgUndelegateHost) returns (MsgUndelegateHostResponse);
rpc UpdateInnerRedemptionRateBounds(MsgUpdateInnerRedemptionRateBounds)
returns (MsgUpdateInnerRedemptionRateBoundsResponse);
rpc ResumeHostZone(MsgResumeHostZone) returns (MsgResumeHostZoneResponse);
Expand Down Expand Up @@ -189,15 +188,6 @@ message MsgUpdateValidatorSharesExchRate {
}
message MsgUpdateValidatorSharesExchRateResponse {}

message MsgUndelegateHost {
string creator = 1;
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
message MsgUndelegateHostResponse {}

message MsgCalibrateDelegation {
string creator = 1;
string chain_id = 2;
Expand Down
1 change: 0 additions & 1 deletion x/stakeibc/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdUpdateValidatorSharesExchRate())
cmd.AddCommand(CmdCalibrateDelegation())
cmd.AddCommand(CmdClearBalance())
cmd.AddCommand(CmdUndelegateHost())
cmd.AddCommand(CmdUpdateInnerRedemptionRateBounds())
cmd.AddCommand(CmdResumeHostZone())

Expand Down
49 changes: 0 additions & 49 deletions x/stakeibc/client/cli/tx_undelegate_host.go

This file was deleted.

3 changes: 0 additions & 3 deletions x/stakeibc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ func NewMessageHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgUpdateValidatorSharesExchRate:
res, err := msgServer.UpdateValidatorSharesExchRate(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgUndelegateHost:
res, err := msgServer.UndelegateHost(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgCalibrateDelegation:
res, err := msgServer.CalibrateDelegation(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
Expand Down
3 changes: 0 additions & 3 deletions x/stakeibc/keeper/grpc_query_host_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ func TestHostZoneQuerySingle(t *testing.T) {
keeper, ctx := keepertest.StakeibcKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
msgs := createNHostZone(keeper, ctx, 2)
for _, msg := range msgs {
t.Log(msg.ChainId)
}
for _, tc := range []struct {
desc string
request *types.QueryGetHostZoneRequest
Expand Down
16 changes: 7 additions & 9 deletions x/stakeibc/keeper/icacallbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ import (
)

const (
ICACallbackID_Delegate = "delegate"
ICACallbackID_Claim = "claim"
ICACallbackID_Undelegate = "undelegate"
ICACallbackID_UndelegateHost = "undelegatehost"
ICACallbackID_Reinvest = "reinvest"
ICACallbackID_Redemption = "redemption"
ICACallbackID_Rebalance = "rebalance"
ICACallbackID_Detokenize = "detokenize"
ICACallbackID_Delegate = "delegate"
ICACallbackID_Claim = "claim"
ICACallbackID_Undelegate = "undelegate"
ICACallbackID_Reinvest = "reinvest"
ICACallbackID_Redemption = "redemption"
ICACallbackID_Rebalance = "rebalance"
ICACallbackID_Detokenize = "detokenize"
)

func (k Keeper) Callbacks() icacallbackstypes.ModuleCallbacks {
return []icacallbackstypes.ICACallback{
{CallbackId: ICACallbackID_Delegate, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.DelegateCallback)},
{CallbackId: ICACallbackID_Claim, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.ClaimCallback)},
{CallbackId: ICACallbackID_Undelegate, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.UndelegateCallback)},
{CallbackId: ICACallbackID_UndelegateHost, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.UndelegateHostCallback)},
{CallbackId: ICACallbackID_Reinvest, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.ReinvestCallback)},
{CallbackId: ICACallbackID_Redemption, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.RedemptionCallback)},
{CallbackId: ICACallbackID_Rebalance, CallbackFunc: icacallbackstypes.ICACallbackFunction(k.RebalanceCallback)},
Expand Down
84 changes: 0 additions & 84 deletions x/stakeibc/keeper/icacallbacks_undelegate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -227,86 +226,3 @@ func (k Keeper) BurnTokens(ctx sdk.Context, hostZone types.HostZone, stTokenBurn
k.Logger(ctx).Info(fmt.Sprintf("Total supply %s", k.bankKeeper.GetSupply(ctx, stCoinDenom)))
return nil
}

// ICA Callback after undelegating host
//
// If successful:
// * sets SetUndelegateHostPrevented
// If timeout:
// * Does nothing
// If failure:
// * Does nothing
func (k Keeper) UndelegateHostCallback(ctx sdk.Context, packet channeltypes.Packet, ackResponse *icacallbackstypes.AcknowledgementResponse, args []byte) error {
// Fetch callback args
var undelegateHostCallback types.UndelegateHostCallback
if err := proto.Unmarshal(args, &undelegateHostCallback); err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal undelegate host callback args: %s", err.Error()))
}
k.Logger(ctx).Info("Starting undelegate host callback for amount %v%s", undelegateHostCallback.Amt)

// Regardless of failure/success/timeout, indicate that this ICA has completed
hostZone, found := k.GetHostZone(ctx, EvmosHostZoneChainId)
if !found {
return errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "Host zone not found: %s", EvmosHostZoneChainId)
}
for _, splitDelegation := range undelegateHostCallback.SplitDelegations {
if err := k.DecrementValidatorDelegationChangesInProgress(&hostZone, splitDelegation.Validator); err != nil {
// TODO: Revert after v14 upgrade
if errors.Is(err, types.ErrInvalidValidatorDelegationUpdates) {
k.Logger(ctx).Error(utils.LogICACallbackWithHostZone(EvmosHostZoneChainId, ICACallbackID_Undelegate,
"Invariant failed - delegation changes in progress fell below 0 for %s", splitDelegation.Validator))
continue
}
return err
}
}
k.SetHostZone(ctx, hostZone)

// Check for timeout (ack nil)
if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT {
k.Logger(ctx).Error("UndelegateHostCallback Timeout:", icacallbackstypes.AckResponseStatus_TIMEOUT, packet)
return nil
}

// Check for a failed transaction (ack error)
if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE {
k.Logger(ctx).Error("UndelegateHostCallback failure (ack error):", icacallbackstypes.AckResponseStatus_FAILURE, packet)
return nil
}

// Get the host zone
evmosHost, found := k.GetHostZone(ctx, EvmosHostZoneChainId)
if !found {
return errorsmod.Wrapf(types.ErrHostZoneNotFound, "host zone %s not found", EvmosHostZoneChainId)
}

k.Logger(ctx).Info("UndelegateHostCallback success:", icacallbackstypes.AckResponseStatus_SUCCESS, packet)

// Update delegation balances
err := k.UpdateDelegationBalancesHost(ctx, evmosHost, undelegateHostCallback)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UndelegateCallback | %s", err.Error()))
return err
}

k.Logger(ctx).Info("UndelegateHostCallback: SetUndelegateHostPrevented")
if err := k.SetUndelegateHostPrevented(ctx); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UndelegateHostCallback failed due to SetUndelegateHostPrevented | %s", err.Error()))
return err
}

return nil
}

// Decrement the delegation field on host and each validator's delegations after a successful unbonding ICA
func (k Keeper) UpdateDelegationBalancesHost(ctx sdk.Context, hostZone types.HostZone, undelegateHostCallback types.UndelegateHostCallback) error {
// Undelegate from each validator and update Evmos staked balance, if successful
for _, undelegation := range undelegateHostCallback.SplitDelegations {
err := k.AddDelegationToValidator(ctx, &hostZone, undelegation.Validator, undelegation.Amount.Neg(), ICACallbackID_UndelegateHost)
if err != nil {
return err
}
}
k.SetHostZone(ctx, hostZone)
return nil
}
Loading

0 comments on commit 91a984a

Please sign in to comment.