Skip to content

Commit

Permalink
Unify cache_ctx wraps (#2519)
Browse files Browse the repository at this point in the history
* Unify cache_ctx wraps

* Apply matt suggested fix
  • Loading branch information
ValarDragon authored Aug 29, 2022
1 parent 75728ea commit 5e0b914
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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
20 changes: 11 additions & 9 deletions x/epochs/types/hooks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
fmt "fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v11/osmoutils"
Expand Down Expand Up @@ -42,13 +44,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 {
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().Error(fmt.Sprintf("error in epoch hook %v", err))
}
}

0 comments on commit 5e0b914

Please sign in to comment.