Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply fix from release branch #1401

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ Types of changes (Stanzas):
"Bug Fixes" for any bug fixes.
"Client Breaking" for breaking Protobuf, gRPC and REST routes used by end-users.
"CLI Breaking" for breaking CLI commands.
"Event Breaking" for breaking events.
"API Breaking" for breaking exported APIs used by developers building on SDK.
"State Machine Breaking" for any changes that result in a different AppState given same genesisState and txList.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

## [Unreleased](https://github.com/Finschia/finschia-sdk/compare/v0.47.0...HEAD)
## [Unreleased](https://github.com/Finschia/finschia-sdk/compare/v0.47.3...HEAD)

### Features

### Improvements

### Bug Fixes
* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537)

### Removed

Expand All @@ -50,4 +52,4 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Build, CI

### Document Updates

* (docs) [\#1083](https://github.com/Finschia/finschia-sdk/pull/1083) Add detailed explanation about default events
24 changes: 24 additions & 0 deletions RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## [v0.47.3](https://github.com/Finschia/finschia-sdk/releases/tag/v0.47.3) - 2023-09-08

### Bug Fixes
* (x/foundation) [\#1061](https://github.com/Finschia/finschia-sdk/pull/1061) Make x/foundation MsgExec propagate events (backport #1053)
* (baseapp) [\#1075](https://github.com/cosmos/cosmos-sdk/pull/1075) Add `events.GetAttributes` and `event.GetAttribute` methods to simplify the retrieval of an attribute from event(s) (backport cosmos/cosmos-sdk#14356)
* (baseapp) [\#1079](https://github.com/cosmos/cosmos-sdk/pull/1079) Do not add `module` attribute in case of ibc messages

### Event Breaking Changes
* (refactor) [\#1063](https://github.com/Finschia/finschia-sdk/pull/1063) Automate EventTypeMessage inclusion in every message execution (backport cosmos/cosmos-sdk#13532)
* (x/bank) [#1066](https://github.com/Finschia/finschia-sdk/pull/1066) Remove message events including `sender` attribute whose information is already present in the relevant events (backport cosmos/cosmos#17273)

### Document Updates
* (docs) [\#1081](https://github.com/Finschia/finschia-sdk/pull/1081) Document default events


## [v0.47.2](https://github.com/Finschia/finschia-sdk/releases/tag/v0.47.2) - 2023-07-18

### Features
* (server/grpc) [\#1018](https://github.com/Finschia/finschia-sdk/pull/1018) support custom r/w gRPC options (backport #1017)
* (x/auth) [\#1026](https://github.com/Finschia/finschia-sdk/pull/1026) add the api for querying next account number (backport #1011)

## [v0.47.1](https://github.com/Finschia/finschia-sdk/releases/tag/v0.47.1) - 2023-07-18
⚠️ **DEPRECATED**

## [v0.47.0](https://github.com/Finschia/finschia-sdk/releases/tag/v0.47.0) - 2023-04-24

### Features
Expand Down
38 changes: 29 additions & 9 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,23 +785,20 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg) (*sdk.Result, error
// NOTE: GasWanted is determined by the AnteHandler and GasUsed by the GasMeter.
for i, msg := range msgs {
var (
msgResult *sdk.Result
eventMsgName string // name to use as value in event `message.action`
err error
msgResult *sdk.Result
err error
)

if handler := app.msgServiceRouter.Handler(msg); handler != nil {
// ADR 031 request type routing
msgResult, err = handler(ctx, msg)
eventMsgName = sdk.MsgTypeURL(msg)
} else if legacyMsg, ok := msg.(legacytx.LegacyMsg); ok {
// legacy sdk.Msg routing
// Assuming that the app developer has migrated all their Msgs to
// proto messages and has registered all `Msg services`, then this
// path should never be called, because all those Msgs should be
// registered within the `msgServiceRouter` already.
msgRoute := legacyMsg.Route()
eventMsgName = legacyMsg.Type()
handler := app.router.Route(ctx, msgRoute)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i)
Expand All @@ -816,10 +813,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg) (*sdk.Result, error
return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i)
}

msgEvents := sdk.Events{
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)),
}
msgEvents = msgEvents.AppendEvents(msgResult.GetEvents())
// create message events
msgEvents := createEvents(msgResult.GetEvents(), msg)

// append message events, data and logs
//
Expand All @@ -842,3 +837,28 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg) (*sdk.Result, error
Events: events.ToABCIEvents(),
}, nil
}

func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events {
eventMsgName := sdk.MsgTypeURL(msg)
msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName))

// we set the signer attribute as the sender
if len(msg.GetSigners()) > 0 && !msg.GetSigners()[0].Empty() {
msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSigners()[0].String()))
}

// verify that events have no module attribute set
if _, found := events.GetAttributes(sdk.AttributeKeyModule); !found {
// here we assume that routes module name is the second element of the route
// e.g. "/cosmos.bank.v1beta1.MsgSend" => "bank"
moduleName := strings.Split(eventMsgName, ".")
if len(moduleName) > 1 {
// NOTE(0Tech): please remove this condition check after applying ibc-go v7, because it's hard coding for the ibc
if moduleName[0] != "/ibc" {
msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName[1]))
}
}
}

return sdk.Events{msgEvent}.AppendEvents(events)
}
45 changes: 45 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -229,3 +230,47 @@ func TestSetChanCheckTxSize(t *testing.T) {
app = NewBaseApp(t.Name(), logger, db, nil)
require.Equal(t, config.DefaultChanCheckTxSize, cap(app.chCheckTx))
}

func TestCreateEvents(t *testing.T) {
testCases := map[string]struct {
eventsIn sdk.Events
messageName string
eventsOut sdk.Events
}{
"cosmos": {
messageName: "cosmos.foo.v1beta1.MsgFoo",
eventsOut: sdk.Events{{Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e}, Value: []uint8{0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x66, 0x6f, 0x6f, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x46, 0x6f, 0x6f}, Index: false}, {Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x33, 0x6a, 0x6b, 0x7a, 0x65, 0x72, 0x7a, 0x76, 0x34, 0x6a, 0x6b, 0x76, 0x6b, 0x75, 0x64, 0x32, 0x63, 0x6d}, Index: false}, {Key: []uint8{0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65}, Value: []uint8{0x66, 0x6f, 0x6f}, Index: false}}}},
},
"ibc without module attribute": {
messageName: "ibc.foo.bar.v1.MsgBar",
eventsOut: sdk.Events{{Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e}, Value: []uint8{0x2f, 0x69, 0x62, 0x63, 0x2e, 0x66, 0x6f, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x61, 0x72}, Index: false}, {Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x33, 0x6a, 0x6b, 0x7a, 0x65, 0x72, 0x7a, 0x76, 0x34, 0x6a, 0x6b, 0x76, 0x6b, 0x75, 0x64, 0x32, 0x63, 0x6d}, Index: false}}}},
},
"ibc with module attribute": {
eventsIn: sdk.Events{{Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65}, Value: []uint8{0x66, 0x6f, 0x6f, 0x53, 0x62, 0x61, 0x72}, Index: false}}}},
messageName: "ibc.foo.bar.v1.MsgBar",
eventsOut: sdk.Events{{Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e}, Value: []uint8{0x2f, 0x69, 0x62, 0x63, 0x2e, 0x66, 0x6f, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x42, 0x61, 0x72}, Index: false}, {Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x33, 0x6a, 0x6b, 0x7a, 0x65, 0x72, 0x7a, 0x76, 0x34, 0x6a, 0x6b, 0x76, 0x6b, 0x75, 0x64, 0x32, 0x63, 0x6d}, Index: false}}}, {Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65}, Value: []uint8{0x66, 0x6f, 0x6f, 0x53, 0x62, 0x61, 0x72}, Index: false}}}},
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
ctrl := gomock.NewController(t)
msg := NewMockXXXMessage(ctrl)

signer := sdk.AccAddress([]byte("deadbeef"))
msg.
EXPECT().
GetSigners().
Return([]sdk.AccAddress{signer}).
AnyTimes()
msg.
EXPECT().
XXX_MessageName().
Return(tc.messageName).
AnyTimes()

eventsOut := createEvents(tc.eventsIn, msg)
require.Equal(t, tc.eventsOut, eventsOut)
})
}
}
2 changes: 1 addition & 1 deletion baseapp/testutil/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (msg *MsgCounter2) ValidateBasic() error {
var _ sdk.Msg = &MsgKeyValue{}

func (msg *MsgKeyValue) GetSigners() []sdk.AccAddress {
if msg.Signer == "" {
if len(msg.Signer) == 0 {
return []sdk.AccAddress{}
}

Expand Down
111 changes: 111 additions & 0 deletions baseapp/xxx_msg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package baseapp

import (
reflect "reflect"

types "github.com/Finschia/finschia-sdk/types"
gomock "github.com/golang/mock/gomock"
)

// MockXXXMessage is a mock of XXXMessage interface.
type MockXXXMessage struct {
ctrl *gomock.Controller
recorder *MockXXXMessageMockRecorder
}

// MockXXXMessageMockRecorder is the mock recorder for MockXXXMessage.
type MockXXXMessageMockRecorder struct {
mock *MockXXXMessage
}

// NewMockXXXMessage creates a new mock instance.
func NewMockXXXMessage(ctrl *gomock.Controller) *MockXXXMessage {
mock := &MockXXXMessage{ctrl: ctrl}
mock.recorder = &MockXXXMessageMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockXXXMessage) EXPECT() *MockXXXMessageMockRecorder {
return m.recorder
}

// GetSigners mocks base method.
func (m *MockXXXMessage) GetSigners() []types.AccAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSigners")
ret0, _ := ret[0].([]types.AccAddress)
return ret0
}

// GetSigners indicates an expected call of GetSigners.
func (mr *MockXXXMessageMockRecorder) GetSigners() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSigners", reflect.TypeOf((*MockXXXMessage)(nil).GetSigners))
}

// ProtoMessage mocks base method.
func (m *MockXXXMessage) ProtoMessage() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ProtoMessage")
}

// ProtoMessage indicates an expected call of ProtoMessage.
func (mr *MockXXXMessageMockRecorder) ProtoMessage() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProtoMessage", reflect.TypeOf((*MockXXXMessage)(nil).ProtoMessage))
}

// Reset mocks base method.
func (m *MockXXXMessage) Reset() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Reset")
}

// Reset indicates an expected call of Reset.
func (mr *MockXXXMessageMockRecorder) Reset() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reset", reflect.TypeOf((*MockXXXMessage)(nil).Reset))
}

// String mocks base method.
func (m *MockXXXMessage) String() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "String")
ret0, _ := ret[0].(string)
return ret0
}

// String indicates an expected call of String.
func (mr *MockXXXMessageMockRecorder) String() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "String", reflect.TypeOf((*MockXXXMessage)(nil).String))
}

// ValidateBasic mocks base method.
func (m *MockXXXMessage) ValidateBasic() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateBasic")
ret0, _ := ret[0].(error)
return ret0
}

// ValidateBasic indicates an expected call of ValidateBasic.
func (mr *MockXXXMessageMockRecorder) ValidateBasic() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateBasic", reflect.TypeOf((*MockXXXMessage)(nil).ValidateBasic))
}

// XXX_MessageName mocks base method.
func (m *MockXXXMessage) XXX_MessageName() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "XXX_MessageName")
ret0, _ := ret[0].(string)
return ret0
}

// XXX_MessageName indicates an expected call of XXX_MessageName.
func (mr *MockXXXMessageMockRecorder) XXX_MessageName() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "XXX_MessageName", reflect.TypeOf((*MockXXXMessage)(nil).XXX_MessageName))
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

Loading
Loading