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

ADR 32: Typed Events #7474

Merged
merged 21 commits into from
Oct 13, 2020
Merged

ADR 32: Typed Events #7474

merged 21 commits into from
Oct 13, 2020

Conversation

jackzampolin
Copy link
Member

@jackzampolin jackzampolin commented Oct 7, 2020

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

ACK

I'm not sure the detailed code example at the bottom is necessary (it's hard to assess correctness) but I guess it could be useful to some people.

docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
@aaronc aaronc added T: ADR An issue or PR relating to an architectural decision record T: Dev UX UX for SDK developers (i.e. how to call our code) C:baseapp C:Types labels Oct 8, 2020
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.

Very clear and well structured proposal. I left few comments to:

  • add abstract
  • see if Message subscription mechanism would be better / more powerful
  • validate the JSON usage.


As the SDK gets used more extensively for apps like `peggy`, other peg zones, IBC, DeFi, etc... there will be an exploding demand for event driven applications to support new features desired by users. We propose upstreaming our findings into the SDK to enable all SDK applications to quickly and easily build event driven apps to aid their core application. Wallets, exchanges, explorers, and defi protocols all stand to benefit from this work.

If this proposal is accepted, users will be able to build event driven SDK apps in go by just writing `EventHandler`s for their specific event types and passing them to `EventEmitters` that are defined in the SDK.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree, event driven API is very useful for app developers.
That being said, I'm wondering if designing a subscription mechanism for messages (emitted when a Msg lands into the blockchain) would solve it in a better way? Msgs already have a well defined structure and an "url" (type).

Copy link
Member

Choose a reason for hiding this comment

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

There does seem to be a lot of redundancy I agree, but events are already used pretty widely in the ecosystem and sometimes communicate things not covered in Msgs. For instance a cosmwasm contract could have the side effect of creating a gov proposal, even if the Msg submitted to the blockchain was just to call a contract.

Copy link
Contributor

@amaury1093 amaury1093 Oct 9, 2020

Choose a reason for hiding this comment

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

For instance a cosmwasm contract could have the side effect of creating a gov proposal, even if the Msg submitted to the blockchain was just to call a contract.

If we go with Msg-based OCAPS (i.e. assuming both ADR031 and ADR033 get merged), this contract would need to send a MsgSubmitProposal, which in turn will emit the corresponding Msg Response.

I'd like to see a use-case in this ADR where a message subscription mechanism is not enough, as I feel ADR031 and ADR033 can get to the same goal in a more elegant way. We could of course still emit events, because of inertia in the ecosystem, but they will be Msg Responses and not typed events.

Copy link
Member

@aaronc aaronc Oct 9, 2020

Choose a reason for hiding this comment

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

I'd like to see a use-case in this ADR where a message subscription mechanism is not enough, as I feel ADR031 and ADR033 can get to the same goal in a more elegant way. We could of course still emit events, because of inertia in the ecosystem, but they will be Msg Responses and not typed events.

I don't think it's just inertia. Does the cosmwasm use case I mentioned above not seem like something unaddressed by Msg responses?

Copy link
Member

Choose a reason for hiding this comment

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

Possibly with ADR 033 though, we can capture all of the nested Msgs that get sent between different modules and maybe it would have the same result...

Copy link
Member Author

@jackzampolin jackzampolin Oct 9, 2020

Choose a reason for hiding this comment

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

Can someone link to ADR 33? I don't see the open PR...

Also this is a basic improvement to the current event system that is really low impact. It can be additive with other changes, but will make using the tendermint websocket easier for developers. I would also personally like this change for the relayer and the IBC code specifically.

Copy link
Member Author

Choose a reason for hiding this comment

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

One thing that isn't covered by Msg subscription is the emission of events in EndBlock. See the band protocol example: https://blog.cosmos.network/guide-to-building-defi-using-band-protocol-oracle-and-cosmos-ibc-fa5348832f84

Copy link
Contributor

Choose a reason for hiding this comment

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

If this proposal is accepted, users will be able to build event driven SDK apps

To clarify, these typed events are designed for external/client-side applications? I think it is very good to provide the best event support possible for them... working on consuming this since early 2018 and it has been rough getting much working out of it... almost never well tested or structured. I am very happy for such improvements.

If you are saying, as I believe some are interpreting, of using Events to communicate between modules in the SDK, then I have some hesitation. Not that it is bad, but adds a lot of potentials that need to be considered.

Anyway the use of "SDK apps" can be interpretted two ways. I would prefer "SDK modules" or "SDK clients" (and we have strong support for such clients in JS/TS... not just Go.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jackzampolin , could you add a note that subscription to Msg doesn't solve all use cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ethanfrey this work would also allow for better TS/JS libs around events as well.

docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
@robert-zaremba
Copy link
Collaborator

Improving DevX for better event driven API is really desirable. As I wrote in the comment, I would like to see if adding Msg subscription mechanism wouldn't surpass this proposal.

docs/architecture/adr-032-typed-events.md Outdated Show resolved Hide resolved

As the SDK gets used more extensively for apps like `peggy`, other peg zones, IBC, DeFi, etc... there will be an exploding demand for event driven applications to support new features desired by users. We propose upstreaming our findings into the SDK to enable all SDK applications to quickly and easily build event driven apps to aid their core application. Wallets, exchanges, explorers, and defi protocols all stand to benefit from this work.

If this proposal is accepted, users will be able to build event driven SDK apps in go by just writing `EventHandler`s for their specific event types and passing them to `EventEmitters` that are defined in the SDK.
Copy link
Contributor

@amaury1093 amaury1093 Oct 9, 2020

Choose a reason for hiding this comment

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

For instance a cosmwasm contract could have the side effect of creating a gov proposal, even if the Msg submitted to the blockchain was just to call a contract.

If we go with Msg-based OCAPS (i.e. assuming both ADR031 and ADR033 get merged), this contract would need to send a MsgSubmitProposal, which in turn will emit the corresponding Msg Response.

I'd like to see a use-case in this ADR where a message subscription mechanism is not enough, as I feel ADR031 and ADR033 can get to the same goal in a more elegant way. We could of course still emit events, because of inertia in the ecosystem, but they will be Msg Responses and not typed events.

@aaronc aaronc requested a review from ethanfrey October 9, 2020 15:04
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Okay, the encoding of proto -> json events and json event -> proto makes sense to me. That does seem very clean.

The one question I have is how the tendermint indexer handles these matches. How to search for 1 (uint64) vs. "1" (string). And how to search for addresses. I have no idea how this works now. I remember logs being string/string at some point now attributes are bytes/bytes. I am not the best one to answer how or if it works, it would just be good if this was tested (ideally with unit tests). No need to implement this ADR to do so. Just write some events and see how to search.

docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
docs/architecture/adr-032-typed-events.md Show resolved Hide resolved
@jackzampolin
Copy link
Member Author

jackzampolin commented Oct 9, 2020

@amaurymartiny one usecase, Band Protocol's IBC oracle implementation that emits events in EndBlock comes to mind immediately in terms of usecases that wouldn't be met by just Msg subscriptions. I think Msg subscriptions would be useful, and a good thing. I also don't think they would replace the current event system. That will remain. We should endeavor to make it much easier to use for devs for the reason outlined in this proposal.

@aaronc
Copy link
Member

aaronc commented Oct 9, 2020

I think Msg subscriptions would be useful, and a good thing. I also don't think they would replace the current event system. That will remain. We should endeavor to make it much easier to use for devs for the reason outlined in this proposal.

One thing we could do in the SDK, is just automatically emit typed events for every Msg that gets processed. Whether it's from a transaction or under the hood in the Ocaps layer (#7459). And modules can emit additional typed events if needed. What do you think @jackzampolin @amaurymartiny ?

@alessio
Copy link
Contributor

alessio commented Oct 10, 2020

This is indeed a great proposal!

@robert-zaremba dixit:

event driven API is very useful for app developers

I very much agree with that. and as long as we don't aim to

@ethanfrey dixit:

using Events to communicate between modules in the SDK

which this proposal doesn't seem to be about anyway (there would loads of implications that we should account for in that case) then +1 from me.

@jackzampolin thoughts? If you are OK with this, would you mind clarifying the ADR and explicitly exclude such a use case (events as inter-module communications means) from its scope?

@jackzampolin
Copy link
Member Author

jackzampolin commented Oct 10, 2020

@aaronc that could work. What I need is one interface I can subscribe to and get all those events as types. Currently that place is the tendermint websocket and this ADR offers an affordance for doing that. The other changes seem to be for a different purpose.

@alessio I've added the following:

This proposal is specifically about how to consume these events as a client of the blockchain, not for intermodule communication.

Also reading ADR 31, it seems like the concerns here are seprate.

Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

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

Nihil obstat from me.

Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Thanks for the clarifications

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.

One thing we could do in the SDK, is just automatically emit typed events for every Msg that gets processed. Whether it's from a transaction or under the hood in the Ocaps layer (#7459). And modules can emit additional typed events if needed. What do you think @jackzampolin @amaurymartiny ?

Yes this should cover all use cases.

Pre-approving, but I'd like to see #7474 (comment)

Comment on lines +124 to +128
message EventSubmitProposal {
string from_address = 1;
uint64 proposal_id = 2;
TextProposal proposal = 3;
}
Copy link
Contributor

@amaury1093 amaury1093 Oct 12, 2020

Choose a reason for hiding this comment

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

EventSubmitProposal is typically a use-case where I believe a Msg response makes more sense. With ADR031+ADR033, I would call this struct MsgSubmitProposalResponse.

Could we maybe put an example that's not directly a response from a Msg?

Copy link
Member

Choose a reason for hiding this comment

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

I think MsgSubmitProposalResponse would only include proposal_id in ADR 031. There's overlap for sure. Combining MsgSubmitProposal + MsgSubmitProposalResponse would give the same info but is maybe more cumbersome.

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

@jackzampolin please add an entry to docs/architecture/README.md

@jackzampolin
Copy link
Member Author

Ok @aaronc thanks for catching that. Ready to roll!

@jackzampolin
Copy link
Member Author

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:baseapp C:Types T: ADR An issue or PR relating to an architectural decision record T: Dev UX UX for SDK developers (i.e. how to call our code)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants