Skip to content

Duplicated Event Emit #12632

@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
}

cacheCtx, writeCache := origCtx.CacheContext()
for i, msg := range msgs {
protoAny, err := k.executeMsg(cacheCtx, msg)
if err != nil {
return nil, err
}
if err = k.cdc.UnpackAny(protoAny, &resps[i]); err != nil {
return nil, err
}
}
// NOTE: The context returned by CacheContext() creates a new EventManager, so events must be correctly propagated back to the current context
origCtx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
writeCache()

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions