fix(x/group): propagate events correctly to current context (#12888)

* fix(x/groups) propagate events correctly to current context

* update to use current context on logger

* adding changelog entry

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Damian Nolan
2022-08-10 15:35:33 +02:00
committed by GitHub
co-authored by Aleksandr Bezobchuk
parent 1c16c11d5a
commit 014bfae00f
2 changed files with 9 additions and 2 deletions
+8 -2
View File
@@ -747,13 +747,14 @@ func (k Keeper) Exec(goCtx context.Context, req *group.MsgExec) (*group.MsgExecR
var logs string
if proposal.Status == group.PROPOSAL_STATUS_ACCEPTED && proposal.ExecutorResult != group.PROPOSAL_EXECUTOR_RESULT_SUCCESS {
// Caching context so that we don't update the store in case of failure.
ctx, flush := ctx.CacheContext()
cacheCtx, flush := ctx.CacheContext()
addr, err := sdk.AccAddressFromBech32(policyInfo.Address)
if err != nil {
return nil, err
}
_, err = k.doExecuteMsgs(ctx, k.router, proposal, addr)
results, err := k.doExecuteMsgs(cacheCtx, k.router, proposal, addr)
if err != nil {
proposal.ExecutorResult = group.PROPOSAL_EXECUTOR_RESULT_FAILURE
logs = fmt.Sprintf("proposal execution failed on proposal %d, because of error %s", id, err.Error())
@@ -761,6 +762,11 @@ func (k Keeper) Exec(goCtx context.Context, req *group.MsgExec) (*group.MsgExecR
} else {
proposal.ExecutorResult = group.PROPOSAL_EXECUTOR_RESULT_SUCCESS
flush()
for _, res := range results {
// NOTE: The sdk msg handler creates a new EventManager, so events must be correctly propagated back to the current context
ctx.EventManager().EmitEvents(res.GetEvents())
}
}
}