Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup v15 #950

Merged
merged 32 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cc5a1c2
undel host: rm protos, proto-gen
riley-stride Oct 11, 2023
7cbafdd
undel host: revert all logic
riley-stride Oct 11, 2023
c0b6b99
undel host: revert all logic, add back undelcb proto + proto-gen
riley-stride Oct 11, 2023
2742044
Merge branch 'cleanup_v15' of ssh://github.com/Stride-Labs/stride int…
riley-stride Oct 11, 2023
4c42dfe
undel host: re-add tx update delegation
riley-stride Oct 11, 2023
e8bad99
calibration: revert proto + protogen; re-add delegation protos from u…
riley-stride Oct 11, 2023
876b1e0
calibration: logic cleanup
riley-stride Oct 11, 2023
00f5f27
calibration: fix typo
riley-stride Oct 11, 2023
2541d18
Revert "calibration: fix typo"
riley-stride Oct 11, 2023
7f8e57e
Revert "calibration: logic cleanup"
riley-stride Oct 11, 2023
d897ace
Revert "calibration: revert proto + protogen; re-add delegation proto…
riley-stride Oct 11, 2023
753bdce
undel host: add back undelegatecallback + proto-gen
riley-stride Oct 11, 2023
57d61c6
calibrate: rm admin gate
riley-stride Oct 11, 2023
9463f14
calibration: do not block ICAs
riley-stride Oct 11, 2023
9e2c398
calibration: limit calibration adjustment to record keeping to <1000m…
riley-stride Oct 11, 2023
dea43a7
calibration: limit calibration adjustment to record keeping to <1000m…
riley-stride Oct 11, 2023
1b1095b
Merge branch 'cleanup_v15' of ssh://github.com/Stride-Labs/stride int…
riley-stride Oct 11, 2023
856bf8c
add calibrate delegation test
riley-stride Oct 11, 2023
6ca4fef
raise calibration threshold
riley-stride Oct 31, 2023
834898c
small fixes per sam's pr comments
riley-stride Nov 9, 2023
86cbe4a
Set CalibrationThreshold to 3000
riley-stride Nov 30, 2023
e4b05ad
add test for slash beyond threshold
riley-stride Dec 4, 2023
ed6fce9
Merge branch 'main' of ssh://github.com/Stride-Labs/stride into clean…
riley-stride Dec 4, 2023
bf47e1b
fix errors.go
riley-stride Dec 4, 2023
2996313
remove callback data for calibrationquery (sam's pr comment)
riley-stride Dec 4, 2023
b953092
fix typo
riley-stride Dec 4, 2023
6542233
Unit tests for calibration ICQ callback (#1013)
sampocs Dec 5, 2023
06144f3
added back GetValidatorFromAddress check
riley-stride Dec 6, 2023
5ba3c7a
Merge branch 'main' into cleanup_v15
riley-stride Dec 6, 2023
e981184
Merge branch 'main' into cleanup_v15
riley-stride Dec 7, 2023
3599e14
Merge branch 'main' into cleanup_v15
sampocs Dec 13, 2023
b16fd21
lint
sampocs Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 0 additions & 9 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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 @@ -180,14 +179,6 @@ message MsgUpdateValidatorSharesExchRate {
string valoper = 3;
}
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;
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
83 changes: 0 additions & 83 deletions x/stakeibc/keeper/icacallbacks_undelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,86 +233,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
Loading