Skip to content

Commit

Permalink
fix(x/group): propagate events correctly to current context (cosmos#1…
Browse files Browse the repository at this point in the history
…2888)

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

* update to use current context on logger

* adding changelog entry

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
damiannolan and alexanderbez authored Aug 10, 2022
1 parent 1c16c11 commit 014bfae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [#12303](https://github.com/cosmos/cosmos-sdk/pull/12303) Use bytes instead of string comparison in delete validator queue
* (x/auth/tx) [#12474](https://github.com/cosmos/cosmos-sdk/pull/12474) Remove condition in GetTxsEvent that disallowed multiple equal signs, which would break event queries with base64 strings (i.e. query by signature).
* (store/rootmulti) [#12487](https://github.com/cosmos/cosmos-sdk/pull/12487) Fix non-deterministic map iteration.
* (x/group) [#12888](https://github.com/cosmos/cosmos-sdk/pull/12888) Fix event propagation to the current context of `x/group` message execution `[]sdk.Result`.

### Deprecated

Expand Down
10 changes: 8 additions & 2 deletions x/group/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,20 +747,26 @@ 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())
k.Logger(ctx).Info("proposal execution failed", "cause", err, "proposalID", id)
} 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())
}
}
}

Expand Down

0 comments on commit 014bfae

Please sign in to comment.