-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Introduction
In the following code, your Project emit cachecontext twice which is not necessary and allowing emit same event twice.
// CacheContext returns a new Context with the multi-store cached and a new
// EventManager. The cached context is written to the context when writeCache
// is called. Note, events are automatically emitted on the parent context's
// EventManager when the caller executes the write.
func (c Context) CacheContext() (cc Context, writeCache func()) {
cms := c.ms.CacheMultiStore()
cc = c.WithMultiStore(cms).WithEventManager(NewEventManager())
writeCache = func() {
c.EventManager().EmitEvents(cc.EventManager().Events())
cms.Write()
}
return cc, writeCache
}Lines 61 to 80 in e4d2dd7
| func applyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error) { | |
| // Add a panic safeguard | |
| defer func() { | |
| if recoveryError := recover(); recoveryError != nil { | |
| printPanicRecoveryError(ctx, recoveryError) | |
| err = errors.New("panic occurred during execution") | |
| } | |
| }() | |
| // makes a new cache context, which all state changes get wrapped inside of. | |
| cacheCtx, write := ctx.CacheContext() | |
| err = f(cacheCtx) | |
| if err != nil { | |
| ctx.Logger().Error(err.Error()) | |
| } else { | |
| // no error, write the output of f | |
| write() | |
| ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) | |
| } | |
| return err | |
| } |
The following code uses related function functions, which will cause all events in the hook to appear repeatedly. Bring risks to off-chain monitoring, especially considering that the event contains Send events
https://github.com/sagaxyz/ssc/blob/main/x/billing/keeper/hooks.go#L190
Related Refs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels