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

refactor(x/bank): remove message events including sender attribute whose information is already present in the relevant events (backport cosmos/cosmos#17273) #1066

Merged
merged 8 commits into from
Aug 17, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### 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)

### Build, CI

Expand Down
2 changes: 1 addition & 1 deletion client/grpc/tmservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (s IntegrationTestSuite) TestQueryBlockResultsByHeight() {
s.Require().Equal(0, len(txResult))

beginBlock := blockResultsRes.GetResBeginBlock()
s.Require().Equal(11, len(beginBlock.Events)) // coinbase event (6) + transfer mintModule to feeCollectorName(5)
s.Require().Equal(9, len(beginBlock.Events)) // coinbase event (6) + transfer mintModule to feeCollectorName(3)

endBlock := blockResultsRes.GetResEndBlock()
s.Require().Equal(0, len(endBlock.Events))
Expand Down
2 changes: 1 addition & 1 deletion types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func toBytes(i interface{}) []byte {
}

// Common event types and attribute keys
var (
const (
EventTypeTx = "tx"

AttributeKeyAccountSequence = "acc_seq"
Expand Down
8 changes: 4 additions & 4 deletions x/auth/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPC() {
// Check the result and gas used are correct.
//
// NOTE(0Tech): This comment should be updated after applying #11985.
// Events from the antehandlers would not be included in the simulation. The 5 events are:
// - Sending Amount to recipient: coin_spent, coin_received, transfer and message.sender=<val1>
// Events from the antehandlers would not be included in the simulation. The 4 events are:
// - Sending Amount to recipient: coin_spent, coin_received and transfer
// - Msg events: message.module=bank, message.action=/cosmos.bank.v1beta1.MsgSend and message.sender=<val1> (in one message)
s.Require().Equal(5, len(res.GetResult().GetEvents()))
s.Require().Equal(4, len(res.GetResult().GetEvents()))
s.Require().True(res.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty.
}
})
Expand Down Expand Up @@ -191,7 +191,7 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPCGateway() {
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
// Check the result and gas used are correct.
s.Require().Equal(5, len(result.GetResult().GetEvents())) // See TestSimulateTx_GRPC for the 5 events.
s.Require().Equal(4, len(result.GetResult().GetEvents())) // See TestSimulateTx_GRPC for the 4 events.
s.Require().True(result.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty.
}
})
Expand Down
5 changes: 2 additions & 3 deletions x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,13 @@ func (s *TestSuite) TestDispatchedEvents() {

events := s.ctx.EventManager().Events()

// get last 5 events (events that occur *after* the grant)
events = events[len(events)-5:]
// get last 3 events (events that occur *after* the grant)
events = events[len(events)-3:]

requiredEvents := map[string]bool{
"coin_spent": false,
"coin_received": false,
"transfer": false,
"message": false,
}
for _, e := range events {
requiredEvents[e.Type] = true
Expand Down
62 changes: 16 additions & 46 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,10 @@ func (suite *IntegrationTestSuite) TestMsgSendEvents() {
abci.EventAttribute{Key: []byte(sdk.AttributeKeyAmount), Value: []byte(newCoins.String())},
)

event2 := sdk.Event{
Type: sdk.EventTypeMessage,
Attributes: []abci.EventAttribute{},
}
event2.Attributes = append(
event2.Attributes,
abci.EventAttribute{Key: []byte(types.AttributeKeySender), Value: []byte(addr.String())},
)

// events are shifted due to the funding account events
events := ctx.EventManager().ABCIEvents()
suite.Require().Equal(10, len(events))
suite.Require().Equal(abci.Event(event1), events[8])
suite.Require().Equal(abci.Event(event2), events[9])
suite.Require().Equal(8, len(events))
suite.Require().Equal(abci.Event(event1), events[7])
}

func (suite *IntegrationTestSuite) TestMsgMultiSendEvents() {
Expand Down Expand Up @@ -636,17 +626,7 @@ func (suite *IntegrationTestSuite) TestMsgMultiSendEvents() {
suite.Require().Error(app.BankKeeper.InputOutputCoins(ctx, inputs, outputs))

events = ctx.EventManager().ABCIEvents()
suite.Require().Equal(8, len(events)) // 7 events because account funding causes extra minting + coin_spent + coin_recv events

event1 := sdk.Event{
Type: sdk.EventTypeMessage,
Attributes: []abci.EventAttribute{},
}
event1.Attributes = append(
event1.Attributes,
abci.EventAttribute{Key: []byte(types.AttributeKeySender), Value: []byte(addr.String())},
)
suite.Require().Equal(abci.Event(event1), events[7])
suite.Require().Equal(6, len(events)) // 6 events because account funding causes extra minting + coin_spent + coin_recv events

// Set addr's coins and addr2's coins
suite.Require().NoError(simapp.FundAccount(app, ctx, addr, sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))))
Expand All @@ -658,44 +638,34 @@ func (suite *IntegrationTestSuite) TestMsgMultiSendEvents() {
suite.Require().NoError(app.BankKeeper.InputOutputCoins(ctx, inputs, outputs))

events = ctx.EventManager().ABCIEvents()
suite.Require().Equal(28, len(events)) // 25 due to account funding + coin_spent + coin_recv events
suite.Require().Equal(22, len(events)) // 22 due to account funding + coin_spent + coin_recv events

event2 := sdk.Event{
Type: sdk.EventTypeMessage,
Attributes: []abci.EventAttribute{},
}
event2.Attributes = append(
event2.Attributes,
abci.EventAttribute{Key: []byte(types.AttributeKeySender), Value: []byte(addr2.String())},
)
event3 := sdk.Event{
event1 := sdk.Event{
Type: types.EventTypeTransfer,
Attributes: []abci.EventAttribute{},
}
event3.Attributes = append(
event3.Attributes,
event1.Attributes = append(
event1.Attributes,
abci.EventAttribute{Key: []byte(types.AttributeKeyRecipient), Value: []byte(addr3.String())},
)
event3.Attributes = append(
event3.Attributes,
event1.Attributes = append(
event1.Attributes,
abci.EventAttribute{Key: []byte(sdk.AttributeKeyAmount), Value: []byte(newCoins.String())})
event4 := sdk.Event{
event2 := sdk.Event{
Type: types.EventTypeTransfer,
Attributes: []abci.EventAttribute{},
}
event4.Attributes = append(
event4.Attributes,
event2.Attributes = append(
event2.Attributes,
abci.EventAttribute{Key: []byte(types.AttributeKeyRecipient), Value: []byte(addr4.String())},
)
event4.Attributes = append(
event4.Attributes,
event2.Attributes = append(
event2.Attributes,
abci.EventAttribute{Key: []byte(sdk.AttributeKeyAmount), Value: []byte(newCoins2.String())},
)
// events are shifted due to the funding account events
suite.Require().Equal(abci.Event(event1), events[21])
suite.Require().Equal(abci.Event(event2), events[23])
suite.Require().Equal(abci.Event(event3), events[25])
suite.Require().Equal(abci.Event(event4), events[27])
suite.Require().Equal(abci.Event(event1), events[19])
suite.Require().Equal(abci.Event(event2), events[21])
}

func (suite *IntegrationTestSuite) TestSpendableCoins() {
Expand Down
15 changes: 2 additions & 13 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input,
if err != nil {
return err
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, in.Address),
),
)
}

for _, out := range outputs {
Expand Down Expand Up @@ -150,18 +143,14 @@ func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAd
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr))
}

ctx.EventManager().EmitEvents(sdk.Events{
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, toAddr.String()),
sdk.NewAttribute(types.AttributeKeySender, fromAddr.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, amt.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, fromAddr.String()),
),
})
)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const (
EventTypeTransfer = "transfer"

AttributeKeyRecipient = "recipient"
AttributeKeySender = "sender"
AttributeKeySender = sdk.AttributeKeySender

// supply and balance tracking events name and attributes
EventTypeCoinSpent = "coin_spent"
Expand Down
2 changes: 1 addition & 1 deletion x/foundation/keeper/internal/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *KeeperTestSuite) TestBeginBlocker() {
s.Require().NotPanics(testing)

if s.deterministic {
expectedEvents := sdk.Events{sdk.Event{Type: "coin_spent", Attributes: []abci.EventAttribute{{Key: []uint8{0x73, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x37, 0x78, 0x70, 0x66, 0x76, 0x61, 0x6b, 0x6d, 0x32, 0x61, 0x6d, 0x67, 0x39, 0x36, 0x32, 0x79, 0x6c, 0x73, 0x36, 0x66, 0x38, 0x34, 0x7a, 0x33, 0x6b, 0x65, 0x6c, 0x6c, 0x38, 0x63, 0x35, 0x6c, 0x39, 0x68, 0x72, 0x7a, 0x73, 0x34}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}, sdk.Event{Type: "coin_received", Attributes: []abci.EventAttribute{{Key: []uint8{0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x6d, 0x61, 0x66, 0x6c, 0x38, 0x66, 0x33, 0x73, 0x36, 0x75, 0x75, 0x7a, 0x77, 0x6e, 0x78, 0x6b, 0x71, 0x7a, 0x30, 0x65, 0x7a, 0x61, 0x34, 0x37, 0x76, 0x36, 0x65, 0x63, 0x6e, 0x30, 0x74, 0x75, 0x77, 0x72, 0x36, 0x79, 0x6b}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}, sdk.Event{Type: "transfer", Attributes: []abci.EventAttribute{{Key: []uint8{0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x6d, 0x61, 0x66, 0x6c, 0x38, 0x66, 0x33, 0x73, 0x36, 0x75, 0x75, 0x7a, 0x77, 0x6e, 0x78, 0x6b, 0x71, 0x7a, 0x30, 0x65, 0x7a, 0x61, 0x34, 0x37, 0x76, 0x36, 0x65, 0x63, 0x6e, 0x30, 0x74, 0x75, 0x77, 0x72, 0x36, 0x79, 0x6b}, Index: false}, {Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x37, 0x78, 0x70, 0x66, 0x76, 0x61, 0x6b, 0x6d, 0x32, 0x61, 0x6d, 0x67, 0x39, 0x36, 0x32, 0x79, 0x6c, 0x73, 0x36, 0x66, 0x38, 0x34, 0x7a, 0x33, 0x6b, 0x65, 0x6c, 0x6c, 0x38, 0x63, 0x35, 0x6c, 0x39, 0x68, 0x72, 0x7a, 0x73, 0x34}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}, sdk.Event{Type: "message", Attributes: []abci.EventAttribute{{Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x37, 0x78, 0x70, 0x66, 0x76, 0x61, 0x6b, 0x6d, 0x32, 0x61, 0x6d, 0x67, 0x39, 0x36, 0x32, 0x79, 0x6c, 0x73, 0x36, 0x66, 0x38, 0x34, 0x7a, 0x33, 0x6b, 0x65, 0x6c, 0x6c, 0x38, 0x63, 0x35, 0x6c, 0x39, 0x68, 0x72, 0x7a, 0x73, 0x34}, Index: false}}}}
expectedEvents := sdk.Events{sdk.Event{Type: "coin_spent", Attributes: []abci.EventAttribute{{Key: []uint8{0x73, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x37, 0x78, 0x70, 0x66, 0x76, 0x61, 0x6b, 0x6d, 0x32, 0x61, 0x6d, 0x67, 0x39, 0x36, 0x32, 0x79, 0x6c, 0x73, 0x36, 0x66, 0x38, 0x34, 0x7a, 0x33, 0x6b, 0x65, 0x6c, 0x6c, 0x38, 0x63, 0x35, 0x6c, 0x39, 0x68, 0x72, 0x7a, 0x73, 0x34}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}, sdk.Event{Type: "coin_received", Attributes: []abci.EventAttribute{{Key: []uint8{0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x6d, 0x61, 0x66, 0x6c, 0x38, 0x66, 0x33, 0x73, 0x36, 0x75, 0x75, 0x7a, 0x77, 0x6e, 0x78, 0x6b, 0x71, 0x7a, 0x30, 0x65, 0x7a, 0x61, 0x34, 0x37, 0x76, 0x36, 0x65, 0x63, 0x6e, 0x30, 0x74, 0x75, 0x77, 0x72, 0x36, 0x79, 0x6b}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}, sdk.Event{Type: "transfer", Attributes: []abci.EventAttribute{{Key: []uint8{0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x76, 0x6d, 0x61, 0x66, 0x6c, 0x38, 0x66, 0x33, 0x73, 0x36, 0x75, 0x75, 0x7a, 0x77, 0x6e, 0x78, 0x6b, 0x71, 0x7a, 0x30, 0x65, 0x7a, 0x61, 0x34, 0x37, 0x76, 0x36, 0x65, 0x63, 0x6e, 0x30, 0x74, 0x75, 0x77, 0x72, 0x36, 0x79, 0x6b}, Index: false}, {Key: []uint8{0x73, 0x65, 0x6e, 0x64, 0x65, 0x72}, Value: []uint8{0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x37, 0x78, 0x70, 0x66, 0x76, 0x61, 0x6b, 0x6d, 0x32, 0x61, 0x6d, 0x67, 0x39, 0x36, 0x32, 0x79, 0x6c, 0x73, 0x36, 0x66, 0x38, 0x34, 0x7a, 0x33, 0x6b, 0x65, 0x6c, 0x6c, 0x38, 0x63, 0x35, 0x6c, 0x39, 0x68, 0x72, 0x7a, 0x73, 0x34}, Index: false}, {Key: []uint8{0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74}, Value: []uint8{0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x73, 0x74, 0x61, 0x6b, 0x65}, Index: false}}}}
s.Require().Equal(expectedEvents, ctx.EventManager().Events())
}
})
Expand Down
Loading