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

feat: make authz MsgExec emit events from all executed msgs #9522

Merged
merged 15 commits into from
Jun 22, 2021

Conversation

technicallyty
Copy link
Contributor

Description

Closes: #9501

This PR makes MsgExec emit all events from each executed message. Adds a test to check for the additional events.


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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md N/A
  • included comments for documenting Go code
  • updated the relevant documentation or specification N/A
  • 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 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)

@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Merging #9522 (e8748ad) into master (0027111) will increase coverage by 25.12%.
The diff coverage is 62.97%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #9522       +/-   ##
===========================================
+ Coverage   35.48%   60.60%   +25.12%     
===========================================
  Files         332      589      +257     
  Lines       32620    37236     +4616     
===========================================
+ Hits        11575    22567    +10992     
+ Misses      19819    12726     -7093     
- Partials     1226     1943      +717     
Impacted Files Coverage Δ
client/keys/types.go 100.00% <ø> (+100.00%) ⬆️
client/keys/utils.go 42.85% <ø> (+2.50%) ⬆️
client/query.go 16.98% <ø> (ø)
client/rpc/block.go 10.00% <ø> (ø)
client/rpc/routes.go 100.00% <ø> (ø)
client/rpc/status.go 47.72% <ø> (ø)
client/rpc/validators.go 0.00% <ø> (ø)
client/test_helpers.go 0.00% <ø> (ø)
client/tx/factory.go 28.20% <ø> (ø)
client/tx/legacy.go 68.42% <ø> (ø)
... and 700 more

@yun-yeo
Copy link
Contributor

yun-yeo commented Jun 16, 2021

Can we also emit general event attributes like sender & module from message event type??

other module messages are emitting

{"type":"message","attributes":[{"key":"action","value":"/cosmos.bank.v1beta1.MsgSend"},{"key":"sender","value":"terra1rk6tvacasnnyssfnn00zl7wz43pjnpn7vayqv6"},{"key":"module","value":"bank"}]}

but authz only is emitting

{"type":"message","attributes":[{"key":"action","value":"/cosmos.authz.v1beta1.MsgExec"}]}

@technicallyty
Copy link
Contributor Author

technicallyty commented Jun 16, 2021

Can we also emit general event attributes like sender & module from message event type??

other module messages are emitting

{"type":"message","attributes":[{"key":"action","value":"/cosmos.bank.v1beta1.MsgSend"},{"key":"sender","value":"terra1rk6tvacasnnyssfnn00zl7wz43pjnpn7vayqv6"},{"key":"module","value":"bank"}]}

Currently I have the following being emitted after a MsgExec using bank's MsgSend on my branch:

type: coin_received
attr: [receiver: cosmos139h7762ln36evfglx5fu5mreqylh4wmj3qj47k amount: 10stake]

type: coin_spent
attr: [spender: cosmos1zqupj40s8l79qxrgl9ygknxgmt5ynjlvhuplz8 amount: 10stake]

type: message
attr: [action: /cosmos.authz.v1beta1.MsgExec sender: cosmos1zqupj40s8l79qxrgl9ygknxgmt5ynjlvhuplz8 module: bank]

type: transfer
attr: [recipient: cosmos139h7762ln36evfglx5fu5mreqylh4wmj3qj47k sender: cosmos1zqupj40s8l79qxrgl9ygknxgmt5ynjlvhuplz8 amount: 10stake]

Does this cover your needs for the issue? Let me know if there is more and I'll look into it further @YunSuk-Yeo

@robert-zaremba
Copy link
Collaborator

@YunSuk-Yeo the MsgExec and MsgSend are two different events (I'm using this names to refer for events in particular messages).

This task is to make sure that the MsgSend event is triggered when doing MsgExec for the x/bank.MsgSend.

@yun-yeo
Copy link
Contributor

yun-yeo commented Jun 17, 2021

Yea actually updated events are enough, but just want to sure the consistency with other modules.

x/authz/keeper/keeper.go Outdated Show resolved Hide resolved
for i := 0; i < len(events); i++ {
sdkEvents = append(sdkEvents, sdk.Event(events[i]))
}
ctx.EventManager().EmitEvents(sdkEvents)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good to me, but I actually don't understand why the underlying Msg's events are not emitted in the first place?

L112 we call msgResult, err = handler(ctx, msg), that that should call ctx.EventManager.EmitEvents() already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because MsgExec runs its tx messages directly through tendermint/ABCI rather than the SDK handlers? Thats the gist i got from digging into it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure we dig through the logic in the router and BaseApp and understand what's happening well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked some more and looks like this code overwrites the current event manager in context, which i assume could be a culprit here. I added a nil check before allowing that code to run (it was never nil in my tests).

Curiously though, it duplicated the attributes in the events. For example a transfer event had 6 attributes instead of 3 (the 3 were just duplicates, not different key/vals) Haven't had much luck figuring out why that happens though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we removed that line in msg_service_router.go, and reverted all changes in this PR, does that still emit duplicates?

It seems to me that would be a better fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah when i ran my test i had commented out the event emission i added in DispatchEvents. For some messages though, not everything was simply a duplicate, for instance MsgExec's event only had duplicated the sender attribute, but nothing else.

also looking at this again, im noticing not every event has an exact duplicate - for example the transfer event has 2 different recipient addresses, however sender and amount are both exact copies.

@@ -565,6 +567,110 @@ func (s *IntegrationTestSuite) TestSimMultiSigTx() {
s.Require().Greater(res.GasInfo.GasUsed, uint64(0))
}

// Tests that all msg events included in an authz MsgExec tx
// Ref: https://github.com/cosmos/cosmos-sdk/issues/9501
func (s *IntegrationTestSuite) TestSim_MsgExecEvents() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be in x/authz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x/auth/tx/service_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-approving pending on Robert's comments on the test. Actual fix looks okay to me, though if we merge this we should also create an issue to understand #9522 (comment) better

@robert-zaremba
Copy link
Collaborator

[digression] Tests in SDK is a big mess - I know the fastest way is to find a similar patter and copy paste. So adding better example tests is important for future maintainability. Also tests with CLI are slower to execute.
CC: @aaronc

@github-actions github-actions bot removed the C:x/auth label Jun 22, 2021
@robert-zaremba robert-zaremba self-assigned this Jun 22, 2021
Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left few suggestions.

granterAddr := addrs[0]
granteeAddr := addrs[1]
recipientAddr := addrs[2]
s.Require().NoError(simapp.FundAccount(app.BankKeeper, s.ctx, granterAddr, sdk.NewCoins(sdk.NewInt64Coin("steak", 10000))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , thanks for using FundAccount

x/authz/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/authz/keeper/keeper_test.go Outdated Show resolved Hide resolved
@technicallyty technicallyty added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 22, 2021
@mergify mergify bot merged commit 899b097 into master Jun 22, 2021
@mergify mergify bot deleted the ty/9501-MsgExec_Events branch June 22, 2021 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:x/authz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

authz MsgExec should emit the executed msg events
7 participants