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

Unify cache_ctx wraps #2519

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions osmoutils/cache_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err err
} else {
// no error, write the output of f
write()
// Temporary, should be removed once: https://github.com/cosmos/cosmos-sdk/issues/12912
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
}
return err
}
Expand Down
18 changes: 9 additions & 9 deletions x/epochs/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func panicCatchingEpochHook(
epochIdentifier string,
epochNumber int64,
) {
defer func() {
if recovErr := recover(); recovErr != nil {
osmoutils.PrintPanicRecoveryError(ctx, recovErr)
}
}()
cacheCtx, write := ctx.CacheContext()
hookFn(cacheCtx, epochIdentifier, epochNumber)
write()
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
wrappedHookFn := func(ctx sdk.Context) error {
Copy link
Member

Choose a reason for hiding this comment

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

Can this function return err in any case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not right now, it will after #2520

Copy link
Member

Choose a reason for hiding this comment

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

Ah makes sense now

Copy link
Member

Choose a reason for hiding this comment

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

have created draft #2526
waiting on this one, so it's cleaner

hookFn(ctx, epochIdentifier, epochNumber)
return nil
}
// TODO: Thread info for which hook this is, may be dependent on larger hook system refactoring
err := osmoutils.ApplyFuncIfNoError(ctx, wrappedHookFn)
if err != nil {
ctx.Logger().Info("an epoch hook errored")
Copy link
Member

Choose a reason for hiding this comment

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

wdyt about logging the error itself here?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point

}
}