-
Notifications
You must be signed in to change notification settings - Fork 590
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
Simplify Acknowledgement structure #7555
Changes from 1 commit
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ package keeper | |
|
||
import ( | ||
"context" | ||
"slices" | ||
"time" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
@@ -130,9 +129,10 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*typ | |
|
||
// build up the recv results for each application callback. | ||
ack := types.Acknowledgement{ | ||
AcknowledgementResults: []types.AcknowledgementResult{}, | ||
AppAcknowledgements: [][]byte{}, | ||
} | ||
|
||
var isAsync bool | ||
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() | ||
|
@@ -147,23 +147,26 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*typ | |
sdkCtx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) | ||
} | ||
|
||
ack.AcknowledgementResults = append(ack.AcknowledgementResults, types.AcknowledgementResult{ | ||
AppName: pd.DestinationPort, | ||
RecvPacketResult: res, | ||
}) | ||
if res.Status == types.PacketStatus_Async { | ||
// Set packet acknowledgement to async if any of the acknowledgements are async. | ||
isAsync = true | ||
// Return error if there is more than 1 payload | ||
// TODO: Handle case where there are multiple payloads | ||
if len(msg.Packet.Payloads) > 1 { | ||
return nil, errorsmod.Wrapf(types.ErrInvalidPacket, "packet with multiple payloads cannot have async acknowledgement") | ||
} | ||
} | ||
|
||
// append app acknowledgement to the overall acknowledgement | ||
ack.AppAcknowledgements = append(ack.AppAcknowledgements, res.Acknowledgement) | ||
} | ||
|
||
// note this should never happen as the payload would have had to be empty. | ||
if len(ack.AcknowledgementResults) == 0 { | ||
if len(ack.AppAcknowledgements) == 0 { | ||
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) | ||
return &types.MsgRecvPacketResponse{Result: types.FAILURE}, errorsmod.Wrapf(err, "receive packet failed source-channel %s invalid acknowledgement results", msg.Packet.SourceChannel) | ||
} | ||
|
||
// NOTE: TBD how we will handle async acknowledgements with more than one payload. | ||
isAsync := slices.ContainsFunc(ack.AcknowledgementResults, func(ackResult types.AcknowledgementResult) bool { | ||
return ackResult.RecvPacketResult.Status == types.PacketStatus_Async | ||
}) | ||
|
||
if !isAsync { | ||
// Set packet acknowledgement only if the acknowledgement is not async. | ||
// NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the | ||
|
@@ -203,14 +206,10 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *types.MsgAcknowledgem | |
return nil, errorsmod.Wrap(err, "acknowledge packet verification failed") | ||
} | ||
|
||
recvResults := make(map[string]types.RecvPacketResult) | ||
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. This puts the list into a map which will remove any subsequent acknowledgements from the same app. This is an error since we want to support sending multiple packets with the same portIDs. Moreover it is unnecessary, the acknowledgement list is meant to match 1-1 to the list of payloads so we can associate each individual acknowledgement to the correct payload by looking at the portIDs in the matching payload in the payload list 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. good catch, and yeah makes sense that we can just use the index. |
||
for _, r := range msg.Acknowledgement.AcknowledgementResults { | ||
recvResults[r.AppName] = r.RecvPacketResult | ||
} | ||
|
||
for _, pd := range msg.Packet.Payloads { | ||
for i, pd := range msg.Packet.Payloads { | ||
cbs := k.Router.Route(pd.SourcePort) | ||
err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, recvResults[pd.DestinationPort].Acknowledgement, relayer) | ||
ack := msg.Acknowledgement.AppAcknowledgements[i] | ||
err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, ack, relayer) | ||
Comment on lines
+211
to
+212
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. See here: We just match using the index |
||
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.
Currently just error for multipayload in async ack case