-
Notifications
You must be signed in to change notification settings - Fork 656
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: emit events for ErrFailedAcknowledgement #7891
base: gjermund/use-branch-service-in-recv-packet
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"context" | ||
"errors" | ||
|
||
"cosmossdk.io/core/event" | ||
errorsmod "cosmossdk.io/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
@@ -394,23 +395,31 @@ | |
} | ||
|
||
var ack exported.Acknowledgement | ||
if err := k.BranchService.Execute(ctx, func(ctx context.Context) error { | ||
var events []sdk.Event | ||
if err := k.BranchService.Execute(ctx, func(subCtx context.Context) error { | ||
// Perform application logic callback | ||
ack = cbs.OnRecvPacket(ctx, channelVersion, msg.Packet, relayer) | ||
ack = cbs.OnRecvPacket(subCtx, channelVersion, msg.Packet, relayer) | ||
if !ack.Success() { | ||
// we must return an error here so that false positive events are not emitted | ||
events = sdk.UnwrapSDKContext(subCtx).EventManager().Events() | ||
return channeltypes.ErrFailedAcknowledgement | ||
} | ||
|
||
// write application state changes for asynchronous and successful acknowledgements | ||
return nil | ||
}); err != nil { | ||
if errors.Is(err, channeltypes.ErrFailedAcknowledgement) { | ||
// k.EventService.EventManager(ctx).EmitKV() | ||
// Modify events in cached context to reflect unsuccessful acknowledgement | ||
|
||
// We lost apis to propagate and err prefix events from a branched multistore ctx | ||
// ctx.EventManager().EmitEvents(convertToErrorEvents(cacheCtx.EventManager().Events())) | ||
errEvents := convertToErrorEvents(events) | ||
for _, e := range errEvents { | ||
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. It's not immediately clear to me why we need to loop through these again here? 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. its due to some mismatch between the type 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. the event manager in the SDK will convert from event.Event to sdk.Event inside this EmitKV method. so its a bunch of back and forth really
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. acutally it is a bit of a pain to update the tests for this, i think it might be best to just keep this conversion isolated here.. lmk what you think 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. I'm OK with that. Maybe put a comment to explain so we keep the context in the code. 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. |
||
var attrs []event.Attribute | ||
for _, attr := range e.Attributes { | ||
attrs = append(attrs, event.Attribute{ | ||
Key: attr.Key, | ||
Value: attr.Value, | ||
}) | ||
} | ||
k.EventService.EventManager(ctx).EmitKV(e.Type, attrs...) | ||
Check failure on line 421 in modules/core/keeper/msg_server.go
|
||
} | ||
} | ||
} | ||
|
||
|
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.
Maybe we could rename these
executionCtx
andcacheCtx
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.
they use both cacheCtx and subCtx throughout the code, but leave ctx as just ctx. i feel like we're ok here