Skip to content

Commit

Permalink
Revert "chore: backport cosmos#13063 from cosmos/cosmos-sdk #323" (#327)
Browse files Browse the repository at this point in the history
This reverts commit 870132d.
  • Loading branch information
p0mvn authored Sep 14, 2022
1 parent 72af815 commit c6be459
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
11 changes: 2 additions & 9 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions types/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ 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))

write()

s.Require().Equal(v2, store.Get(k2))
s.Require().Len(ctx.EventManager().Events(), 2)
}

func (s *contextTestSuite) TestLogContext() {
Expand Down
6 changes: 6 additions & 0 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c6be459

Please sign in to comment.