Skip to content

Double Event Emit #38

@Hellobloc

Description

@Hellobloc

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
}

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

  1. https://github.com/cosmos/cosmos-sdk/blob/main/types/context.go#L358-L368
  2. EVM Events Generated twice. evmos/evmos#2312

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions