Skip to content
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

Open
wants to merge 5 commits into
base: gjermund/use-branch-service-in-recv-packet
Choose a base branch
from

Conversation

technicallyty
Copy link
Collaborator

@technicallyty technicallyty commented Jan 27, 2025

Description

adds a hack that enables emitting error prefixed events when a Failed Acknowledgement occurs in the core module keeper.

closes: n/a


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@@ -394,23 +395,31 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypes.MsgRecvPacket
}

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 {
Copy link
Collaborator

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 and cacheCtx

Copy link
Collaborator Author

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

@technicallyty technicallyty marked this pull request as ready for review January 28, 2025 18:25
// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its due to some mismatch between the type sdk.Event and event.Event. I will just change convertToErrorEvents to do this conversion instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

// EmitKV emits a key value pair event.
func (e Events) EmitKV(eventType string, attrs ...event.Attribute) error {
	attributes := make([]sdk.Attribute, 0, len(attrs))

	for _, attr := range attrs {
		attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value))
	}

	e.EventManagerI.EmitEvents(sdk.Events{sdk.NewEvent(eventType, attributes...)})
	return nil
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@technicallyty technicallyty changed the title fix: hack events fix: emit events for ErrFailedAcknowledgement Jan 30, 2025
@technicallyty
Copy link
Collaborator Author

@gjermundgaraba i added a check ack nil as it was causing tests to panic without it. let me know if this is the correct behavior.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants