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

[fix] Handle MsgTimeout and update balance when fail to send packet #408

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 23 additions & 0 deletions hooks/emitter/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (h *Hook) handleMsgAcknowledgement(ctx sdk.Context, msg *types.MsgAcknowled
"status": "failure",
"reason": events[0],
}
// Update balance of sender (refund)
h.AddAccountsInTx(data.Sender)
} else {
packet["acknowledgement"] = common.JsDict{
"status": "success",
Expand All @@ -101,6 +103,27 @@ func (h *Hook) handleMsgAcknowledgement(ctx sdk.Context, msg *types.MsgAcknowled
}
}

func (h *Hook) handleMsgTimeout(ctx sdk.Context, msg *types.MsgTimeout) {
packet := common.JsDict{
"src_channel": msg.Packet.SourceChannel,
"src_port": msg.Packet.SourcePort,
"sequence": msg.Packet.Sequence,
"block_time": ctx.BlockTime().UnixNano(),
}
// TODO: Handle other packet type
var data ibcxfertypes.FungibleTokenPacketData
err := ibcxfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data)
if err == nil {
// We use acknowledgement column to track packet status
packet["acknowledgement"] = common.JsDict{
"status": "timeout",
}
// Update balance of sender (refund)
h.AddAccountsInTx(data.Sender)
h.Write("UPDATE_OUTGOING_PACKET", packet)
}
}

func newPacket(
ctx sdk.Context,
srcPort string,
Expand Down
2 changes: 2 additions & 0 deletions hooks/emitter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (h *Hook) handleMsg(ctx sdk.Context, txHash []byte, msg sdk.Msg, log sdk.AB
h.handleMsgChannelCloseConfirm(ctx, msg)
case *channeltypes.MsgAcknowledgement:
h.handleMsgAcknowledgement(ctx, msg, evMap)
case *channeltypes.MsgTimeout:
h.handleMsgTimeout(ctx, msg)
case *authz.MsgGrant:
h.handleMsgGrant(msg, detail)
case *authz.MsgRevoke:
Expand Down
Loading