Skip to content

Double Event Emit due to Misuse of CacheContext #628

@Hellobloc

Description

@Hellobloc

it's seem that you repo update the cosmos-sdk version in this repo but missing fix some API CHANGE Issue like Cachecontext double event emit issue.

This issue will make your project emit Cosmos Event twice.

Specifically, we can see that CacheContext has been modified in version 0.46.7 of cosmos, which would emit event internally.

func (c Context) CacheContext() (cc Context, writeCache func()) {
	cms := c.MultiStore().CacheMultiStore()
	cc = c.WithMultiStore(cms).WithEventManager(NewEventManager())

	writeCache = func() {
		c.EventManager().EmitEvents(cc.EventManager().Events())
		cms.Write()
	}

	return cc, writeCache
}
https://github.com/cosmos/cosmos-sdk/blob/v0.47.10/types/context.go#L294-L304

but in your repo, this event already emit by yourself, which would make double event emit issue if you use PostTxProcessing.

		} else {
			if commitFn != nil {
				commitFn()
			}

			// Since the post-processing can alter the log, we need to update the result
			if res.Failed() {
				res.Logs = nil
				receipt.Logs = nil
				receipt.Bloom = ethtypes.Bloom{}
			} else {
				res.Logs = types.NewLogsFromEth(receipt.Logs)
			}

			events := tmpCtx.EventManager().Events()
			if len(events) > eventsLen {
				ctx.EventManager().EmitEvents(events[eventsLen:])
			}
		}
	}

https://github.com/cosmos/evm/blob/main/x/vm/keeper/state_transition.go#L252-L271

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