diff --git a/CHANGELOG.md b/CHANGELOG.md index 6373910850b9..47dad7bb0b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,19 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +<<<<<<< HEAD +======= +* [#12668](https://github.com/cosmos/cosmos-sdk/pull/12668) Add `authz_msg_index` event attribute to message events emitted when executing via `MsgExec` through `x/authz`. +* [#12634](https://github.com/cosmos/cosmos-sdk/pull/12634) Move `sdk.Dec` to math package. +* [#12596](https://github.com/cosmos/cosmos-sdk/pull/12596) Remove all imports of the non-existent gogo/protobuf v1.3.3 to ease downstream use and go workspaces. +* [#12589](https://github.com/cosmos/cosmos-sdk/pull/12589) Allow zero gas in simulation mode. +* [#12576](https://github.com/cosmos/cosmos-sdk/pull/12576) Remove dependency on cosmos/keyring and upgrade to 99designs/keyring v1.2.1 +* [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default. +* [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring. +* [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. +* [#12453](https://github.com/cosmos/cosmos-sdk/pull/12453) Add `NewInMemoryWithKeyring` function which allows the creation of in memory `keystore` instances with a specified set of existing items. +* [#11390](https://github.com/cosmos/cosmos-sdk/pull/11390) `LatestBlockResponse` & `BlockByHeightResponse` types' `Block` filed has been deprecated and they now contains new field `sdk_block` with `proposer_address` as `string` +>>>>>>> afab2f348 (feat: add message index event attribute to authz message execution (#12668)) * [#12626](https://github.com/cosmos/cosmos-sdk/pull/12626) Upgrade IAVL to v0.19.0 with fast index and error propagation. NOTE: first start will take a while to propagate into new model. * [#12649](https://github.com/cosmos/cosmos-sdk/pull/12649) Bump tendermint to v0.34.20. diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 137e07dc9444..75f2a061fbc8 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -2,10 +2,11 @@ package keeper import ( "fmt" + "strconv" "time" "github.com/gogo/protobuf/proto" - + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/baseapp" @@ -85,14 +86,17 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) ([][]byte, error) { results := make([][]byte, len(msgs)) now := ctx.BlockTime() + for i, msg := range msgs { signers := msg.GetSigners() if len(signers) != 1 { return nil, authz.ErrAuthorizationNumOfSigners } + granter := signers[0] - // if granter != grantee then check authorization.Accept, otherwise we implicitly accept. + // If granter != grantee then check authorization.Accept, otherwise we + // implicitly accept. if !granter.Equals(grantee) { skey := grantStoreKey(grantee, granter, sdk.MsgTypeURL(msg)) @@ -114,6 +118,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] if err != nil { return nil, err } + if resp.Delete { err = k.DeleteGrant(ctx, grantee, granter, sdk.MsgTypeURL(msg)) } else if resp.Updated != nil { @@ -122,6 +127,7 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] if err != nil { return nil, err } + if !resp.Accept { return nil, sdkerrors.ErrUnauthorized } @@ -136,14 +142,19 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] if err != nil { return nil, sdkerrors.Wrapf(err, "failed to execute message; message %v", msg) } + results[i] = msgResp.Data // emit the events from the dispatched actions events := msgResp.Events sdkEvents := make([]sdk.Event, 0, len(events)) - for i := 0; i < len(events); i++ { - sdkEvents = append(sdkEvents, sdk.Event(events[i])) + for _, event := range events { + e := event + e.Attributes = append(e.Attributes, abci.EventAttribute{Key: "authz_msg_index", Value: strconv.Itoa(i)}) + + sdkEvents = append(sdkEvents, sdk.Event(e)) } + ctx.EventManager().EmitEvents(sdkEvents) } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 6674d95c7863..645aab5dfd25 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -300,9 +300,12 @@ func (s *TestSuite) TestDispatchedEvents() { result, err := app.AuthzKeeper.DispatchActions(s.ctx, granteeAddr, executeMsgs) require.NoError(err) require.NotNil(result) + events := s.ctx.EventManager().Events() + // get last 5 events (events that occur *after* the grant) events = events[len(events)-5:] + requiredEvents := map[string]bool{ "coin_spent": false, "coin_received": false, diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 24047e921c8a..7f3ff113d10e 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -17,6 +17,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra if err != nil { return nil, err } + // create the account if it is not in account state granteeAcc := k.authKeeper.GetAccount(ctx, grantee) if granteeAcc == nil { @@ -33,6 +34,7 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra if err != nil { return nil, err } + t := authorization.MsgTypeURL() if k.router.HandlerByTypeURL(t) == nil { return nil, sdkerrors.ErrInvalidType.Wrapf("%s doesn't exist.", t) @@ -73,13 +75,16 @@ func (k Keeper) Exec(goCtx context.Context, msg *authz.MsgExec) (*authz.MsgExecR if err != nil { return nil, err } + msgs, err := msg.GetMessages() if err != nil { return nil, err } + results, err := k.DispatchActions(ctx, grantee, msgs) if err != nil { return nil, err } + return &authz.MsgExecResponse{Results: results}, nil }