From b101c4eaadc52439371d76e961dac99217a7ff66 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 13 Sep 2022 20:49:59 -0400 Subject: [PATCH] Revert "chore: backport #13063 from cosmos/cosmos-sdk #323" (#327) This reverts commit 870132d311d162fdbe0e92fcc0a42ee3889afd0d. --- types/context.go | 11 ++--------- types/context_test.go | 5 ----- x/gov/abci.go | 6 ++++++ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/types/context.go b/types/context.go index da69c129cff1..e3604df954ba 100644 --- a/types/context.go +++ b/types/context.go @@ -262,18 +262,11 @@ func (c Context) TransientStore(key StoreKey) KVStore { // 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. +// is called. 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 + return cc, cms.Write } // ContextKey defines a type alias for a stdlib Context key. diff --git a/types/context_test.go b/types/context_test.go index 2fb1025ee200..9533a52ee2e3 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -42,10 +42,6 @@ func (s *contextTestSuite) TestCacheContext() { s.Require().Equal(v1, cstore.Get(k1)) s.Require().Nil(cstore.Get(k2)) - // emit some events - cctx.EventManager().EmitEvent(types.NewEvent("foo", types.NewAttribute("key", "value"))) - cctx.EventManager().EmitEvent(types.NewEvent("bar", types.NewAttribute("key", "value"))) - cstore.Set(k2, v2) s.Require().Equal(v2, cstore.Get(k2)) s.Require().Nil(store.Get(k2)) @@ -53,7 +49,6 @@ func (s *contextTestSuite) TestCacheContext() { write() s.Require().Equal(v2, store.Get(k2)) - s.Require().Len(ctx.EventManager().Events(), 2) } func (s *contextTestSuite) TestLogContext() { diff --git a/x/gov/abci.go b/x/gov/abci.go index 4d5ec074d46b..8749fc7f685e 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -77,6 +77,12 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { tagValue = types.AttributeValueProposalPassed logMsg = "passed" + // The cached context is created with a new EventManager. However, since + // the proposal handler execution was successful, we want to track/keep + // any events emitted, so we re-emit to "merge" the events into the + // original Context's EventManager. + ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) + // write state to the underlying multi-store writeCache() } else {