-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Implement ICS-20 Callbacks #5984
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5984 +/- ##
==========================================
- Coverage 58.19% 58.12% -0.07%
==========================================
Files 396 396
Lines 23669 23709 +40
==========================================
+ Hits 13773 13780 +7
- Misses 8933 8966 +33
Partials 963 963 |
Error: "", | ||
} | ||
if err := am.keeper.OnRecvPacket(ctx, packet, data); err != nil { | ||
acknowledgement = FungibleTokenPacketAcknowledgement{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently any error returned by keeper.OnRecvPacket
will cause a failed acknowledgement to be committed rather than reverting the transaction. Is this the behavior we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the behaviour we want. Reverting the transaction would mean that the sequence number (e.g. in an ordered channel) would never proceed, which we don't want - IBC packets always have to be executed.
@@ -22,7 +22,6 @@ type ChannelKeeper interface { | |||
SendPacket(ctx sdk.Context, channelCap *capability.Capability, packet channelexported.PacketI) error | |||
PacketExecuted(ctx sdk.Context, packet channelexported.PacketI, acknowledgement []byte) error | |||
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error | |||
TimeoutExecuted(ctx sdk.Context, packet channelexported.PacketI) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnTimeoutPacket
no longer calls TimeoutExecuted
. TimeoutExecuted
is called by the ibc handler after running callback
|
||
return nil, err | ||
} | ||
err = k.ChannelKeeper.TimeoutExecuted(ctx, cap, msg.Packet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: ibc handler now calls this function rather than callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// See spec for onAcknowledgePacket: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay | ||
type AckDataTransfer struct{} | ||
type FungibleTokenPacketAcknowledgement struct { | ||
Success bool `json:"success" yaml:"success"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, can we make these fields private and have getter functions for them? Just to prevent them from being reset.
type AckDataTransfer struct{} | ||
type FungibleTokenPacketAcknowledgement struct { | ||
Success bool `json:"success" yaml:"success"` | ||
Error string `json:"error" yaml:"error"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: why not an error
type instead? then you can remove the success field and do:
if ack.Error() != nil {
return ack.Error()
}
// success
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just went off the spec. Agreed this has the same behavior.
@cwgoes any danger in switching to the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no danger, it just needs to be serialised correctly.
x/ibc/20-transfer/module.go
Outdated
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event type is only for msg handlers afaik. This should instead be something like EventTimeout
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory), | ||
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ack.Error() == nil
x/ibc/20-transfer/module.go
Outdated
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory), | ||
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), | ||
sdk.NewAttribute(AttributeKeyAckError, ack.Error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return error message if ack.Error() != nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(AttributeKeyReceiver, data.Receiver.String()),
sdk.NewAttribute(AttributeKeyValue, data.Amount.String()),
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)),
),
)
if ack.Error != "" {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypePacket,
sdk.NewAttribute(AttributeKeyAckError, ack.Error),
),
)
}
x/ibc/20-transfer/module.go
Outdated
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, this should be EventTypeChannelClosed
x/ibc/20-transfer/module.go
Outdated
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto event could be packet acknowledged and attributes should be packet type, and transfer details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start; see comments.
Error: "", | ||
} | ||
if err := am.keeper.OnRecvPacket(ctx, packet, data); err != nil { | ||
acknowledgement = FungibleTokenPacketAcknowledgement{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the behaviour we want. Reverting the transaction would mean that the sequence number (e.g. in an ordered channel) would never proceed, which we don't want - IBC packets always have to be executed.
x/ibc/20-transfer/module.go
Outdated
// TODO: handle packet receipt that due to an error (specify) | ||
// the receiving chain couldn't process the transfer | ||
|
||
// source chain sent invalid packet, shutdown our channel end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely don't want to do this, not sure when/where this was from, but invalid packets should not close the channel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Pending comments from @cwgoes and changes to FungibleTokenPacketAcknowledgement
fields
x/ibc/20-transfer/module.go
Outdated
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory), | ||
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)), | ||
sdk.NewAttribute(AttributeKeyAckError, ack.Error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(AttributeKeyReceiver, data.Receiver.String()),
sdk.NewAttribute(AttributeKeyValue, data.Amount.String()),
sdk.NewAttribute(AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success)),
),
)
if ack.Error != "" {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypePacket,
sdk.NewAttribute(AttributeKeyAckError, ack.Error),
),
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
type AckDataTransfer struct{} | ||
type FungibleTokenPacketAcknowledgement struct { | ||
Success bool `json:"success" yaml:"success"` | ||
Error string `json:"error" yaml:"error"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no danger, it just needs to be serialised correctly.
Believe this should be merged as-is. Tried to change the Seems like there isn't a native JSON marshalling of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ready to go. When should I start integrating this into the relayer?
Closes: #5923 and #5947
Description
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)