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

ica: TrySendTx error handling nits #491

Merged
merged 4 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 8 additions & 8 deletions modules/apps/27-interchain-accounts/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import (
// manage helper module access to owner addresses they do not have capabilities for
func (k Keeper) TrySendTx(ctx sdk.Context, portID string, icaPacketData types.InterchainAccountPacketData) (uint64, error) {
// Check for the active channel
activeChannelId, found := k.GetActiveChannel(ctx, portID)
activeChannelID, found := k.GetActiveChannel(ctx, portID)
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
if !found {
return 0, types.ErrActiveChannelNotFound
return 0, sdkerrors.Wrapf(types.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID)
}

sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelId)
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID)
if !found {
return 0, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelId)
return 0, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelID)
}

destinationPort := sourceChannelEnd.GetCounterparty().GetPortID()
destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID()

return k.createOutgoingPacket(ctx, portID, activeChannelId, destinationPort, destinationChannel, icaPacketData)
return k.createOutgoingPacket(ctx, portID, activeChannelID, destinationPort, destinationChannel, icaPacketData)
}

func (k Keeper) createOutgoingPacket(
Expand All @@ -50,7 +50,7 @@ func (k Keeper) createOutgoingPacket(
// get the next sequence
sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel)
if !found {
return 0, channeltypes.ErrSequenceSendNotFound
return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", sourceChannel, sourcePort)
}

// timeoutTimestamp is set to be a max number here so that we never recieve a timeout
Expand Down Expand Up @@ -171,7 +171,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error
var data types.InterchainAccountPacketData

if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return sdkerrors.Wrapf(types.ErrUnknownPacketData, "cannot unmarshal ICS-27 interchain account packet data")
return sdkerrors.Wrapf(types.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data")
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
}

switch data.Type {
Expand All @@ -188,7 +188,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error

return nil
default:
return types.ErrUnknownPacketData
return types.ErrUnknownDataType
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var (
ErrUnknownPacketData = sdkerrors.Register(ModuleName, 2, "unknown packet data")
ErrUnknownDataType = sdkerrors.Register(ModuleName, 2, "unknown data type")
ErrAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "account already exist")
ErrPortAlreadyBound = sdkerrors.Register(ModuleName, 4, "port is already bound")
ErrUnsupportedChain = sdkerrors.Register(ModuleName, 5, "unsupported chain")
Expand Down