From d74d102fbcdcbd56b06a7c40a32576a3a61925cc Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 10 Aug 2022 16:16:53 +0200 Subject: [PATCH] fix(x/group): propagate events correctly to current context (backport #12888) (#12890) * 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 (cherry picked from commit 014bfae00faf18a519a3ad7f3174cdff913e2db7) # Conflicts: # CHANGELOG.md * fix conflicts Co-authored-by: Damian Nolan Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ x/group/keeper/msg_server.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ba054337fd..aadb987d3581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/bank) [#12674](https://github.com/cosmos/cosmos-sdk/pull/12674) Add convenience function `CreatePrefixedAccountStoreKey()` to construct key to access account's balance for a given denom. * [#12877](https://github.com/cosmos/cosmos-sdk/pull/12877) Bumped cosmossdk.io/math to v1.0.0-beta.3 +### Bug Fixes + +* (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`. + ## [v0.46.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0) - 2022-07-26 ### Features diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index a4f7fe2e2a84..cfd2dbfbfc8e 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -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()) + } } }