-
Notifications
You must be signed in to change notification settings - Fork 616
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
Use global success value in acknowledgment #7621
base: feat/ibc-eureka
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,20 +131,20 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*typ | |
|
||
// build up the recv results for each application callback. | ||
ack := types.Acknowledgement{ | ||
RecvSuccess: true, | ||
AppAcknowledgements: [][]byte{}, | ||
} | ||
|
||
var isAsync bool | ||
cacheCtx, writeFn = sdkCtx.CacheContext() | ||
for _, pd := range msg.Packet.Payloads { | ||
// Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful. | ||
cacheCtx, writeFn = sdkCtx.CacheContext() | ||
cb := k.Router.Route(pd.DestinationPort) | ||
res := cb.OnRecvPacket(cacheCtx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, pd, signer) | ||
|
||
if res.Status != types.PacketStatus_Failure { | ||
// write application state changes for asynchronous and successful acknowledgements | ||
writeFn() | ||
} else { | ||
if res.Status == types.PacketStatus_Failure { | ||
// Set RecvSuccess to false | ||
ack.RecvSuccess = false | ||
// Modify events in cached context to reflect unsuccessful acknowledgement | ||
sdkCtx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) | ||
} | ||
|
@@ -163,6 +163,11 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*typ | |
ack.AppAcknowledgements = append(ack.AppAcknowledgements, res.Acknowledgement) | ||
} | ||
|
||
if ack.RecvSuccess { | ||
// write application state changes for successful acknowledgements | ||
writeFn() | ||
} | ||
|
||
// note this should never happen as the payload would have had to be empty. | ||
if len(ack.AppAcknowledgements) == 0 { | ||
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) | ||
|
@@ -212,7 +217,7 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *types.MsgAcknowledgem | |
for i, pd := range msg.Packet.Payloads { | ||
cbs := k.Router.Route(pd.SourcePort) | ||
ack := msg.Acknowledgement.AppAcknowledgements[i] | ||
err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, ack, pd, relayer) | ||
err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, msg.Acknowledgement.RecvSuccess, ack, pd, relayer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: We will need to tweak this eventually since it would be weird to call ack callback with a successful ack bytes but a false recvSuccess but not necessary for single payload change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be good to add a TODO comment here for that |
||
if err != nil { | ||
return nil, errorsmod.Wrapf(err, "failed OnAcknowledgementPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, msg.Packet.SourceChannel, msg.Packet.DestinationChannel) | ||
} | ||
|
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 can break here and just have no
AppAcknowledgements
on an 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.
I looked into doing this. It became too complicated because it caused empty acks to be valid which I didn't want to do. Otherwise I need to create a sentinel ack and fill it in for the acks that didn't error which was more complicated than necessary especially since we only support single payload for now