Skip to content

Commit

Permalink
chore(transfer): always validate forwarding.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Jun 18, 2024
1 parent c281138 commit b7b6268
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (im IBCModule) OnRecvPacket(

im.keeper.Logger(ctx).Info("successfully handled ICS-20 packet", "sequence", packet.Sequence)

if len(data.Forwarding.Hops) > 0 {
if data.ShouldBeForwarded() {
// NOTE: acknowledgement will be written asynchronously
return nil
}
Expand Down
14 changes: 6 additions & 8 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ func (msg MsgTransfer) ValidateBasic() error {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must not exceed %d bytes", MaximumMemoLength)
}

if len(msg.Forwarding.Hops) > 0 || msg.Forwarding.Memo != "" {
if err := msg.Forwarding.Validate(); err != nil {
return err
}
if err := msg.Forwarding.Validate(); err != nil {
return err
}

// We cannot have non-empty memo and non-empty forwarding hops at the same time.
if len(msg.Forwarding.Hops) > 0 && msg.Memo != "" {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must be empty if forwarding path hops is not empty: %s, %s", msg.Memo, msg.Forwarding.Hops)
}
// We cannot have non-empty memo and non-empty forwarding hops at the same time.
if len(msg.Forwarding.Hops) > 0 && msg.Memo != "" {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must be empty if forwarding path hops is not empty: %s, %s", msg.Memo, msg.Forwarding.Hops)
}

for _, coin := range msg.GetCoins() {
Expand Down
14 changes: 6 additions & 8 deletions modules/apps/transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ func (ftpd FungibleTokenPacketDataV2) ValidateBasic() error {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must not exceed %d bytes", MaximumMemoLength)
}

if len(ftpd.Forwarding.Hops) > 0 || ftpd.Forwarding.Memo != "" {
if err := ftpd.Forwarding.Validate(); err != nil {
return err
}
if err := ftpd.Forwarding.Validate(); err != nil {
return err
}

// We cannot have non-empty memo and non-empty forwarding path hops at the same time.
if len(ftpd.Forwarding.Hops) > 0 && ftpd.Memo != "" {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must be empty if forwarding path hops is not empty: %s, %s", ftpd.Memo, ftpd.Forwarding.Hops)
}
// We cannot have non-empty memo and non-empty forwarding path hops at the same time.
if len(ftpd.Forwarding.Hops) > 0 && ftpd.Memo != "" {
return errorsmod.Wrapf(ErrInvalidMemo, "memo must be empty if forwarding path hops is not empty: %s, %s", ftpd.Memo, ftpd.Forwarding.Hops)
}

return nil
Expand Down

0 comments on commit b7b6268

Please sign in to comment.