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

Automate EventTypeMessage inclusion in every message execution #11868

Closed
4 tasks
Tracked by #13085
ValarDragon opened this issue May 3, 2022 · 12 comments · Fixed by #13532
Closed
4 tasks
Tracked by #13085

Automate EventTypeMessage inclusion in every message execution #11868

ValarDragon opened this issue May 3, 2022 · 12 comments · Fixed by #13532
Assignees
Labels
T: Dev UX UX for SDK developers (i.e. how to call our code)

Comments

@ValarDragon
Copy link
Contributor

ValarDragon commented May 3, 2022

Summary

Many modules define ad-hoc events in the message server, that (in a boilerplate fashion) encode the message type, source module, and sender. These are not standardized by code.

Problem Definition

~Every message has the following event defined in the message server
Staking Redelegate:

		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.DelegatorAddress),
		),

Gov vote

	ctx.EventManager().EmitEvent(
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Voter),
		),
	)

Osmosis swap

	ctx.EventManager().EmitEvents(sdk.Events{
		sdk.NewEvent(
			sdk.EventTypeMessage,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
			sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
		),
	})

The only exception I can see for where this isn't done is authz exec txs.

Proposal

Notice that in ~all cases checked types.AttributeValueCategory = types.ModuleName. The abstraction over msg.Sender, msg.Voter, and msg.DelegatorAddress is basically msg.GetSigners()[0].

We should adapt the event defined here: https://github.com/cosmos/cosmos-sdk/blob/main/x/auth/middleware/run_msgs.go#L91-L93 in the case that this is a non-legacy message. I believe that types.ModuleName is metadata that should be communicatable in the message service registration, and retrievable there.

Then we can delete this event from every msg server.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@aaronc
Copy link
Member

aaronc commented May 4, 2022

Yes, these should probably get removed and just handled in the tx middleware

@ValarDragon ValarDragon added the T: Dev UX UX for SDK developers (i.e. how to call our code) label May 30, 2022
@tac0turtle tac0turtle mentioned this issue Aug 30, 2022
18 tasks
@julienrbrt julienrbrt self-assigned this Sep 27, 2022
@julienrbrt julienrbrt moved this to 📝 Todo in Cosmos-SDK Sep 27, 2022
@julienrbrt julienrbrt moved this from 📝 Todo to 💪 In Progress in Cosmos-SDK Sep 27, 2022
@julienrbrt
Copy link
Member

I am trying to implement this issue, but I wonder what is the use of these events?

@alexanderbez
Copy link
Contributor

We kind of already do this here in BaseApp#runMsgs:

		msgEvents := sdk.Events{
			sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)),
		}

We can just expand upon this.

I am trying to implement this issue, but I wonder what is the use of these events?

Clients might want to query for all txs that had messages of type X, e.g. delegations.

@aaronc
Copy link
Member

aaronc commented Sep 29, 2022

Clients might want to query for all txs that had messages of type X, e.g. delegations.

Why can't they do that by just looking at the messages in the transaction? Isn't this sort of redundant?

@alexanderbez
Copy link
Contributor

I don't follow. The point of these events is to query for blocks/txs that have specific messages/actions. No, it's not redundant.

@aaronc
Copy link
Member

aaronc commented Sep 29, 2022

I don't follow. The point of these events is to query for blocks/txs that have specific messages/actions. No, it's not redundant.

I'm just saying that the type of message is already present in the transaction itself. The information is there it just needs to be indexed. Emitting the event seems like it's just a work around for poor indexing. I think it makes more sense to improve indexing.

@alexanderbez
Copy link
Contributor

alexanderbez commented Sep 30, 2022

I'm not following. The indexer uses events themselves to index. Specifically, I'm referring to Tendermint's KV indexer and solutions like Numia which use events to index.

Inspecting the transaction itself requires parsing it which not all indexers and post-processing tools can or want to do.

@aaronc
Copy link
Member

aaronc commented Oct 1, 2022

Yeah, I understand that those indexers don't know how to inspect the transaction and I see the motivation to deal with it this way. I'm just pointing out that this is an indexer deficiency rather than some new useful data that the state machine is producing. So if we need this for now then whatever it's fine, but IMHO we should work towards better indexers.

@alexanderbez
Copy link
Contributor

But better indexers aren't really the issue per se. Imagine you have an indexer that is completely chain agnostic -- i.e. you don't have a codec so you can't decode and inspect the tx. You have to rely on on events and state streaming. In fact, this is how Numia works.

@aaronc
Copy link
Member

aaronc commented Oct 3, 2022

But better indexers aren't really the issue per se. Imagine you have an indexer that is completely chain agnostic -- i.e. you don't have a codec so you can't decode and inspect the tx. You have to rely on on events and state streaming. In fact, this is how Numia works.

In my mind, a lot of the value in migrating to protobuf was to make it easier for clients to inspect things like tx contents. So maybe an indexer wants to take the position of not knowing whether a chain uses the Cosmos SDK protobuf or not... I don't think that ultimately means we should duplicate data just to accommodate that use case. Short term maybe it makes sense, but really, it's not that hard at all to parse the tx - there are endpoints which return JSON and protobuf isn't really even needed at that point. We have a similar situation with some secondary indexes - sometimes we add indexes just to support queries when that index will never be needed by the state machine itself. Short term yes this is the easiest thing to do, but IMHO long term we want better off-chain indexers and a leaner state machine. Maybe some of this comes down to philosophy of how we use events. As we've discussed there needs to be some bigger discussion around events as I think we all agree there are lots of improvements to be made.

@aaronc
Copy link
Member

aaronc commented Oct 3, 2022

So if this is a standardized way to separate which events came from which Msg's in a multi-Msg tx which is what it seems like it actually does looking at the code, then it has value and isn't redundant

@alexanderbez
Copy link
Contributor

Ok, let's get this in a PR soon. Thanks @julienrbrt 🙏

@julienrbrt julienrbrt moved this from 💪 In Progress to 👀 Needs Review in Cosmos-SDK Oct 16, 2022
Repository owner moved this from 👀 Needs Review to 👏 Done in Cosmos-SDK Oct 16, 2022
@tac0turtle tac0turtle removed this from Cosmos-SDK Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Dev UX UX for SDK developers (i.e. how to call our code)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants