From 6a5a2de798d4e61302783ae84ecfe2958c7088d5 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 18 Jun 2021 21:06:10 +0200 Subject: [PATCH] fix: collect all responses from authz/MsgExec (#9538) ## Description Closes: #9536 ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- docs/core/proto-docs.md | 2 +- proto/cosmos/authz/v1beta1/tx.proto | 2 +- x/authz/keeper/keeper.go | 14 ++-- x/authz/keeper/msg_server.go | 4 +- x/authz/tx.pb.go | 118 +++++++++++++--------------- 5 files changed, 67 insertions(+), 73 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index b5dc37dae..1f6a1dd02 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -1308,7 +1308,7 @@ MsgExecResponse defines the Msg/MsgExecResponse response type. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `result` | [cosmos.base.abci.v1beta1.Result](#cosmos.base.abci.v1beta1.Result) | | | +| `results` | [bytes](#bytes) | repeated | | diff --git a/proto/cosmos/authz/v1beta1/tx.proto b/proto/cosmos/authz/v1beta1/tx.proto index ffff46340..dd68984e9 100644 --- a/proto/cosmos/authz/v1beta1/tx.proto +++ b/proto/cosmos/authz/v1beta1/tx.proto @@ -40,7 +40,7 @@ message MsgGrant { // MsgExecResponse defines the Msg/MsgExecResponse response type. message MsgExecResponse { - cosmos.base.abci.v1beta1.Result result = 1; + repeated bytes results = 1; } // MsgExec attempts to execute the provided messages using diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 10d516040..7d541c374 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -72,10 +72,9 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA // DispatchActions attempts to execute the provided messages via authorization // grants from the message signer to the grantee. -func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) (*sdk.Result, error) { - var msgResult *sdk.Result - var err error - for _, msg := range msgs { +func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) ([][]byte, error) { + var results = make([][]byte, len(msgs)) + for i, msg := range msgs { signers := msg.GetSigners() if len(signers) != 1 { return nil, sdkerrors.ErrInvalidRequest.Wrap("authorization can be given to msg with only one signer") @@ -103,19 +102,20 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs [] return nil, sdkerrors.ErrUnauthorized } } - handler := k.router.Handler(msg) + handler := k.router.Handler(msg) if handler == nil { return nil, sdkerrors.ErrUnknownRequest.Wrapf("unrecognized message route: %s", sdk.MsgTypeURL(msg)) } - msgResult, err = handler(ctx, msg) + msgResp, err := handler(ctx, msg) if err != nil { return nil, sdkerrors.Wrapf(err, "failed to execute message; message %v", msg) } + results[i] = msgResp.Data } - return msgResult, nil + return results, nil } // SaveGrant method grants the provided authorization to the grantee on the granter's account diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 0d9659908..e13b29fbd 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -70,9 +70,9 @@ func (k Keeper) Exec(goCtx context.Context, msg *authz.MsgExec) (*authz.MsgExecR if err != nil { return nil, err } - result, err := k.DispatchActions(ctx, grantee, msgs) + results, err := k.DispatchActions(ctx, grantee, msgs) if err != nil { return nil, err } - return &authz.MsgExecResponse{Result: result}, nil + return &authz.MsgExecResponse{Results: results}, nil } diff --git a/x/authz/tx.pb.go b/x/authz/tx.pb.go index cac4f3b3c..9f75a1936 100644 --- a/x/authz/tx.pb.go +++ b/x/authz/tx.pb.go @@ -6,8 +6,8 @@ package authz import ( context "context" fmt "fmt" - types1 "github.com/cosmos/cosmos-sdk/codec/types" - types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -75,7 +75,7 @@ var xxx_messageInfo_MsgGrant proto.InternalMessageInfo // MsgExecResponse defines the Msg/MsgExecResponse response type. type MsgExecResponse struct { - Result *types.Result `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` + Results [][]byte `protobuf:"bytes,1,rep,name=results,proto3" json:"results,omitempty"` } func (m *MsgExecResponse) Reset() { *m = MsgExecResponse{} } @@ -119,7 +119,7 @@ type MsgExec struct { // Authorization Msg requests to execute. Each msg must implement Authorization interface // The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg)) // triple and validate it. - Msgs []*types1.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` + Msgs []*types.Any `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs,omitempty"` } func (m *MsgExec) Reset() { *m = MsgExec{} } @@ -282,39 +282,38 @@ func init() { func init() { proto.RegisterFile("cosmos/authz/v1beta1/tx.proto", fileDescriptor_3ceddab7d8589ad1) } var fileDescriptor_3ceddab7d8589ad1 = []byte{ - // 498 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0xb5, 0x9b, 0x34, 0x25, 0x13, 0x24, 0xc0, 0x64, 0xe1, 0x1a, 0xea, 0x58, 0xe6, 0x95, 0x05, - 0x1d, 0xab, 0x61, 0x01, 0xdb, 0x46, 0x42, 0x48, 0x80, 0x85, 0x64, 0xc1, 0x86, 0x4d, 0x64, 0xa7, - 0xc3, 0xc4, 0x4a, 0xec, 0xb1, 0x7c, 0xc7, 0x25, 0xe9, 0x57, 0xf0, 0x31, 0x7c, 0x44, 0xc4, 0xaa, - 0x4b, 0x56, 0x08, 0x92, 0x9f, 0x60, 0x89, 0x3c, 0x8f, 0x50, 0x50, 0x5a, 0x24, 0x56, 0x99, 0x3b, - 0xe7, 0xe4, 0xdc, 0x73, 0xcf, 0xf5, 0xa0, 0x83, 0x31, 0x83, 0x8c, 0x41, 0x10, 0x57, 0x7c, 0x72, - 0x16, 0x9c, 0x1e, 0x25, 0x84, 0xc7, 0x47, 0x01, 0x9f, 0xe3, 0xa2, 0x64, 0x9c, 0x59, 0x5d, 0x09, - 0x63, 0x01, 0x63, 0x05, 0x3b, 0xfb, 0xf2, 0x76, 0x24, 0x38, 0x81, 0xa2, 0x88, 0xc2, 0xe9, 0x52, - 0x46, 0x99, 0xbc, 0xaf, 0x4f, 0xea, 0xb6, 0x47, 0x19, 0xa3, 0x33, 0x12, 0x88, 0x2a, 0xa9, 0x3e, - 0x04, 0x3c, 0xcd, 0x08, 0xf0, 0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x6e, 0xea, 0xd8, 0xb4, - 0x7d, 0x3f, 0x46, 0xed, 0x10, 0x68, 0x44, 0x4e, 0xd9, 0x94, 0xfc, 0x57, 0x96, 0x1e, 0xba, 0x9e, - 0x01, 0x1d, 0xf1, 0x45, 0x41, 0x46, 0x55, 0x39, 0x13, 0x91, 0xb6, 0x23, 0x94, 0x01, 0x7d, 0xbb, - 0x28, 0xc8, 0xbb, 0x72, 0xe6, 0xdf, 0x46, 0xb7, 0x36, 0x2d, 0x74, 0xdf, 0xc1, 0x4f, 0x13, 0x35, - 0x42, 0xa0, 0xd6, 0x1b, 0xb4, 0x2b, 0xf7, 0xe8, 0x6e, 0x5f, 0x82, 0x36, 0xec, 0x3c, 0xbc, 0x1a, - 0xdf, 0xec, 0xe3, 0x35, 0x6a, 0x8a, 0x48, 0x0f, 0x2e, 0xe5, 0xd7, 0xb0, 0xf3, 0xe0, 0x4a, 0x78, - 0xa3, 0x16, 0xa1, 0x96, 0xca, 0xa6, 0x77, 0xe9, 0x1f, 0x24, 0xc1, 0x79, 0xf4, 0x0f, 0x82, 0xd6, - 0x1c, 0x0e, 0x97, 0x3f, 0x5c, 0x63, 0xb9, 0x72, 0xcd, 0xf3, 0x95, 0x6b, 0x7e, 0x5f, 0xb9, 0xe6, - 0xa7, 0xb5, 0x6b, 0x9c, 0xaf, 0x5d, 0xe3, 0xeb, 0xda, 0x35, 0xde, 0xdf, 0xa7, 0x29, 0x9f, 0x54, - 0x09, 0x1e, 0xb3, 0x4c, 0xbd, 0x46, 0xf5, 0x73, 0x08, 0x27, 0xd3, 0x60, 0x2e, 0xdf, 0x41, 0xd2, - 0x12, 0x1f, 0xc0, 0x93, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4a, 0xa9, 0xb0, 0x59, 0xf3, 0x03, - 0x00, 0x00, + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xcf, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0xb3, 0x4d, 0xda, 0x92, 0x6d, 0x25, 0xc0, 0xe4, 0xe0, 0x1a, 0xea, 0x58, 0xe6, 0x5f, + 0x24, 0xe8, 0x5a, 0x0d, 0x07, 0xce, 0x8d, 0x84, 0x90, 0x10, 0x16, 0x92, 0x05, 0x17, 0x2e, 0xd1, + 0x3a, 0x5d, 0x36, 0x56, 0x62, 0xaf, 0xe5, 0x59, 0x97, 0xa4, 0x4f, 0xc1, 0xc3, 0xf0, 0x10, 0x11, + 0xa7, 0x1e, 0x39, 0x21, 0x48, 0x5e, 0x82, 0x23, 0xf2, 0xee, 0x3a, 0x14, 0x94, 0x16, 0x89, 0x53, + 0x76, 0xe6, 0xfb, 0x65, 0xe6, 0xf3, 0xe7, 0x35, 0x3e, 0x1c, 0x09, 0x48, 0x05, 0x04, 0xb4, 0x94, + 0xe3, 0xf3, 0xe0, 0xec, 0x38, 0x66, 0x92, 0x1e, 0x07, 0x72, 0x46, 0xf2, 0x42, 0x48, 0x61, 0x75, + 0xb4, 0x4c, 0x94, 0x4c, 0x8c, 0xec, 0x1c, 0xe8, 0xee, 0x50, 0x31, 0x81, 0x41, 0x54, 0xe1, 0x74, + 0xb8, 0xe0, 0x42, 0xf7, 0xab, 0x93, 0xe9, 0x76, 0xb9, 0x10, 0x7c, 0xca, 0x02, 0x55, 0xc5, 0xe5, + 0x87, 0x40, 0x26, 0x29, 0x03, 0x49, 0xd3, 0xdc, 0x00, 0x07, 0x7f, 0x03, 0x34, 0x9b, 0x1b, 0xe9, + 0xbe, 0x71, 0x18, 0x53, 0x60, 0x01, 0x8d, 0x47, 0xc9, 0xda, 0x65, 0x55, 0x18, 0xc8, 0xdb, 0xf8, + 0x18, 0xda, 0xb5, 0x22, 0xfc, 0x8f, 0xf8, 0x46, 0x08, 0xfc, 0x65, 0x41, 0x33, 0x69, 0xd9, 0x78, + 0x97, 0x57, 0x07, 0x56, 0xd8, 0xc8, 0x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0x77, 0x73, 0xc8, + 0xb5, 0x61, 0xe7, 0xd1, 0xf5, 0xfa, 0x3a, 0xef, 0xd7, 0xb8, 0xa5, 0x22, 0x3d, 0xbc, 0x92, 0xaf, + 0x64, 0xe7, 0xe1, 0xb5, 0xf2, 0x7a, 0x5a, 0x84, 0x77, 0x4c, 0x36, 0xdd, 0x2b, 0xff, 0xa0, 0x01, + 0xe7, 0xf1, 0x3f, 0x80, 0x7a, 0xe6, 0x60, 0xb0, 0xf8, 0xe1, 0x36, 0x16, 0x4b, 0x17, 0x5d, 0x2c, + 0x5d, 0xf4, 0x7d, 0xe9, 0xa2, 0x4f, 0x2b, 0xb7, 0x71, 0xb1, 0x72, 0x1b, 0x5f, 0x57, 0x6e, 0xe3, + 0xfd, 0x03, 0x9e, 0xc8, 0x71, 0x19, 0x93, 0x91, 0x48, 0xcd, 0xd7, 0x66, 0x7e, 0x8e, 0xe0, 0x74, + 0x12, 0xcc, 0xf4, 0x3d, 0x8f, 0x77, 0xd4, 0x05, 0x78, 0xf6, 0x2b, 0x00, 0x00, 0xff, 0xff, 0xe3, + 0x02, 0xf3, 0xbe, 0xd3, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -554,17 +553,14 @@ func (m *MsgExecResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Result != nil { - { - size, err := m.Result.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + if len(m.Results) > 0 { + for iNdEx := len(m.Results) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Results[iNdEx]) + copy(dAtA[i:], m.Results[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Results[iNdEx]))) + i-- + dAtA[i] = 0xa } - i-- - dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -739,9 +735,11 @@ func (m *MsgExecResponse) Size() (n int) { } var l int _ = l - if m.Result != nil { - l = m.Result.Size() - n += 1 + l + sovTx(uint64(l)) + if len(m.Results) > 0 { + for _, b := range m.Results { + l = len(b) + n += 1 + l + sovTx(uint64(l)) + } } return n } @@ -988,9 +986,9 @@ func (m *MsgExecResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Results", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1000,27 +998,23 @@ func (m *MsgExecResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Result == nil { - m.Result = &types.Result{} - } - if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Results = append(m.Results, make([]byte, postIndex-iNdEx)) + copy(m.Results[len(m.Results)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1133,7 +1127,7 @@ func (m *MsgExec) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Msgs = append(m.Msgs, &types1.Any{}) + m.Msgs = append(m.Msgs, &types.Any{}) if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err }