Skip to content

Commit

Permalink
update transfer error messages (#7968)
Browse files Browse the repository at this point in the history
* update transfer err messages

* apply @AdityaSripal review suggestion
  • Loading branch information
colin-axner authored Nov 18, 2020
1 parent 1cc8af8 commit f02a462
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions x/ibc/applications/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"fmt"
"strings"

"github.com/armon/go-metrics"
Expand Down Expand Up @@ -137,7 +138,7 @@ func (k Keeper) SendTransfer(
// NOTE: should not happen as the module account was
// retrieved on the step above and it has enough balace
// to burn.
return err
panic(fmt.Sprintf("cannot burn coins after a successful send to a module account: %v", err))
}
}

Expand Down Expand Up @@ -222,7 +223,11 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
// unescrow tokens
escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel())
if err := k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(token)); err != nil {
return err
// NOTE: this error is only expected to occur given an unexpected bug or a malicious
// counterparty module. The bug may occur in bank or any part of the code that allows
// the escrow address to be drained. A malicious counterparty module could drain the
// escrow address by allowing more tokens to be sent back then were escrowed.
return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module")
}

defer func() {
Expand Down Expand Up @@ -281,7 +286,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
if err := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, receiver, sdk.NewCoins(voucher),
); err != nil {
return err
panic(fmt.Sprintf("unable to send coins from module to account despite previously minting coins to module account: %v", err))
}

defer func() {
Expand Down Expand Up @@ -345,7 +350,15 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
if types.SenderChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) {
// unescrow tokens back to sender
escrowAddress := types.GetEscrowAddress(packet.GetSourcePort(), packet.GetSourceChannel())
return k.bankKeeper.SendCoins(ctx, escrowAddress, sender, sdk.NewCoins(token))
if err := k.bankKeeper.SendCoins(ctx, escrowAddress, sender, sdk.NewCoins(token)); err != nil {
// NOTE: this error is only expected to occur given an unexpected bug or a malicious
// counterparty module. The bug may occur in bank or any part of the code that allows
// the escrow address to be drained. A malicious counterparty module could drain the
// escrow address by allowing more tokens to be sent back then were escrowed.
return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module")
}

return nil
}

// mint vouchers back to sender
Expand All @@ -355,7 +368,11 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d
return err
}

return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(token))
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(token)); err != nil {
panic(fmt.Sprintf("unable to send coins from module to account despite previously minting coins to module account: %v", err))
}

return nil
}

// DenomPathFromHash returns the full denomination path prefix from an ibc denom with a hash
Expand Down

0 comments on commit f02a462

Please sign in to comment.