Skip to content

Commit

Permalink
Fix ibc transfer to native
Browse files Browse the repository at this point in the history
  • Loading branch information
lebascou committed Feb 22, 2024
1 parent 4f801b0 commit 61ca6b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions x/millions/keeper/callbacks_transfer_to_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TransferToNativeCallback(k Keeper, ctx sdk.Context, packet channeltypes.Pac
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal transfer to native callback args: %s", err.Error()))
}

// If the response status is a timeout, that's not an "error" since the relayer will retry then fail or succeed.
// We just log it out and return no error
if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT {
// Timeout is considered a failure on IBC transfers
k.Logger(ctx).Debug("Received timeout for a transfer to native packet")
return k.OnTransferDepositToRemoteZoneCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDepositId(), true)
} else if ackResponse.Status == icacallbackstypes.AckResponseStatus_FAILURE {
k.Logger(ctx).Debug("Received failure for a transfer to native packet")
return k.OnTransferDepositToRemoteZoneCompleted(ctx, transferCallback.GetPoolId(), transferCallback.GetDepositId(), true)
Expand Down
17 changes: 4 additions & 13 deletions x/millions/keeper/msg_server_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,9 @@ func (k msgServer) DepositRetry(goCtx context.Context, msg *types.MsgDepositRetr
return nil, types.ErrInvalidDepositorAddress
}

// State should be set to failure in order to retry something
if deposit.State != types.DepositState_Failure {
return nil, errorsmod.Wrapf(
types.ErrInvalidDepositState,
"state is %s instead of %s",
deposit.State.String(), types.DepositState_Failure.String(),
)
}

newState := types.DepositState_Unspecified
if deposit.State == types.DepositState_IbcTransfer && ctx.BlockTime().After(deposit.UpdatedAt.Add(2*types.IBCTimeoutNanos*time.Nanosecond)) {
// Handle IBC stucked operation for more than twice the specified IBC timeout
if deposit.State == types.DepositState_IbcTransfer && ctx.BlockTime().After(deposit.UpdatedAt.Add(types.IBCForceRetryNanos*time.Nanosecond)) {
// Handle IBC stucked operation for more than 3 days (no timeout received)
newState = types.DepositState_IbcTransfer
if err := k.TransferDepositToRemoteZone(ctx, deposit.PoolId, deposit.DepositId); err != nil {
return nil, err
Expand All @@ -157,8 +148,8 @@ func (k msgServer) DepositRetry(goCtx context.Context, msg *types.MsgDepositRetr
} else {
return nil, errorsmod.Wrapf(
types.ErrInvalidDepositState,
"error_state is %s instead of %s or %s",
deposit.ErrorState.String(), types.DepositState_IbcTransfer.String(), types.DepositState_IcaDelegate.String(),
"state is %s instead of %s",
deposit.State.String(), types.DepositState_Failure.String(),
)
}

Expand Down
3 changes: 2 additions & 1 deletion x/millions/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
)

const (
IBCTimeoutNanos = 1_800_000_000_000 // 30 minutes
IBCTimeoutNanos = 1_800_000_000_000 // 30 minutes
IBCForceRetryNanos = 259_200_000_000_000 // 3 days
)

const (
Expand Down

0 comments on commit 61ca6b5

Please sign in to comment.