-
Notifications
You must be signed in to change notification settings - Fork 673
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
chore: rm event emission after context caching #2662
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b83b7c3
rm event emission after context caching
charleenfei 75e21ff
Merge branch 'main' into charly/2646_event_emission
charleenfei 3d21f5e
Merge branch 'main' into charly/2646_event_emission
charleenfei d3a1487
update event emissions
charleenfei f3565a7
Merge branch 'main' into charly/2646_event_emission
charleenfei 632e094
rm unnecessary event emission
charleenfei 5f4e1fb
Merge branch 'charly/2646_event_emission' of github.com:cosmos/ibc-go…
charleenfei 591946a
fix pr comments
charleenfei 1ceea32
Merge branch 'main' into charly/2646_event_emission
charleenfei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -395,13 +395,11 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke | |||||
cacheCtx, writeFn := ctx.CacheContext() | ||||||
err = k.ChannelKeeper.RecvPacket(cacheCtx, cap, msg.Packet, msg.ProofCommitment, msg.ProofHeight) | ||||||
|
||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
|
||||||
switch err { | ||||||
case nil: | ||||||
writeFn() | ||||||
case channeltypes.ErrNoOpMsg: | ||||||
// no-ops do not need event emission as they will be ignored | ||||||
return &channeltypes.MsgRecvPacketResponse{Result: channeltypes.NOOP}, nil | ||||||
default: | ||||||
return nil, sdkerrors.Wrap(err, "receive packet verification failed") | ||||||
|
@@ -412,12 +410,13 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke | |||||
// Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful. | ||||||
cacheCtx, writeFn = ctx.CacheContext() | ||||||
ack := cbs.OnRecvPacket(cacheCtx, msg.Packet, relayer) | ||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
// Events from callback are emitted regardless of acknowledgement success | ||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
if ack == nil || ack.Success() { | ||||||
// write application state changes for asynchronous and successful acknowledgements | ||||||
writeFn() | ||||||
} else { | ||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
// Events should still be emitted from failed acks and asynchronous acks | ||||||
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.
Suggested change
|
||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
} | ||||||
|
||||||
// Set packet acknowledgement only if the acknowledgement is not nil. | ||||||
|
@@ -473,13 +472,11 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c | |||||
cacheCtx, writeFn := ctx.CacheContext() | ||||||
err = k.ChannelKeeper.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv) | ||||||
|
||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
|
||||||
switch err { | ||||||
case nil: | ||||||
writeFn() | ||||||
case channeltypes.ErrNoOpMsg: | ||||||
// no-ops do not need event emission as they will be ignored | ||||||
return &channeltypes.MsgTimeoutResponse{Result: channeltypes.NOOP}, nil | ||||||
default: | ||||||
return nil, sdkerrors.Wrap(err, "timeout packet verification failed") | ||||||
|
@@ -541,13 +538,11 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo | |||||
cacheCtx, writeFn := ctx.CacheContext() | ||||||
err = k.ChannelKeeper.TimeoutOnClose(cacheCtx, cap, msg.Packet, msg.ProofUnreceived, msg.ProofClose, msg.ProofHeight, msg.NextSequenceRecv) | ||||||
|
||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
|
||||||
switch err { | ||||||
case nil: | ||||||
writeFn() | ||||||
case channeltypes.ErrNoOpMsg: | ||||||
// no-ops do not need event emission as they will be ignored | ||||||
return &channeltypes.MsgTimeoutOnCloseResponse{Result: channeltypes.NOOP}, nil | ||||||
default: | ||||||
return nil, sdkerrors.Wrap(err, "timeout on close packet verification failed") | ||||||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -612,13 +607,11 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn | |||||
cacheCtx, writeFn := ctx.CacheContext() | ||||||
err = k.ChannelKeeper.AcknowledgePacket(cacheCtx, cap, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) | ||||||
|
||||||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||||||
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | ||||||
|
||||||
switch err { | ||||||
case nil: | ||||||
writeFn() | ||||||
case channeltypes.ErrNoOpMsg: | ||||||
// no-ops do not need event emission as they will be ignored | ||||||
return &channeltypes.MsgAcknowledgementResponse{Result: channeltypes.NOOP}, nil | ||||||
default: | ||||||
return nil, sdkerrors.Wrap(err, "acknowledge packet verification failed") | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the safety here is that the cached context is being used to cache execution of all msg executions. We use another cache context for each individual message execution (which emits events using result events since message handler will construct a new event manager)
ie
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.
++