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: add autocli service proto #13597

Merged
merged 12 commits into from
Oct 25, 2022
Merged

feat: add autocli service proto #13597

merged 12 commits into from
Oct 25, 2022

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Oct 19, 2022

Description

Ref: #13282
Was part of #13281.

This adds two new gRPC query endpoints which the runtime module will implement:

  • /cosmos.reflection.v1.ReflectionService/FileDescriptors - for the full file descriptor set
  • /cosmos.autocli.v1.Query/AppOptions - autocli app options for dynamic CLI generation

autocli will use both of these to build dynamic CLIs.


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
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • 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)

@aaronc aaronc marked this pull request as ready for review October 19, 2022 20:57
@aaronc aaronc requested a review from a team as a code owner October 19, 2022 20:57
@aaronc
Copy link
Member Author

aaronc commented Oct 19, 2022

Following up on #13281 (comment), the rationale for putting FileDescriptorSet into the cosmos.app query service is because the FileDescriptorSet itself along with the app config provides almost all of the reflection info needed for dynamic clients.

Some of the earlier reflection services in cosmos.base.reflection were written when less of this metadata was present in the proto files themselves. Now that we are adding more annotations, clients can get almost everything they need from the FileDescriptorSet. For autocli, the main additional pieces needed are provided by this RemoteInfoService.

Happy to consider alternate approaches.

One alternative is to just add an endpoint to list all the file descriptors and then grpc reflection can be used to query each one individually. Currently, grpc reflection doesn't have a way to list all descriptors. The downside of this approach is that it's more work on the client side to build the full FileDescriptorSet. Also, grpc reflection by default is implemented as a blackbox - we probably want to re-implement to make sure we're actually serving the right descriptors (which could be a problem with mixed gogo and proto v2 code and future semver codegen ideas).

@codecov
Copy link

codecov bot commented Oct 19, 2022

Codecov Report

Merging #13597 (59ada67) into main (9f3575a) will increase coverage by 0.07%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13597      +/-   ##
==========================================
+ Coverage   54.69%   54.76%   +0.07%     
==========================================
  Files         645      652       +7     
  Lines       55745    56023     +278     
==========================================
+ Hits        30490    30683     +193     
- Misses      22765    22833      +68     
- Partials     2490     2507      +17     
Impacted Files Coverage Δ
x/distribution/simulation/operations.go 80.64% <0.00%> (-9.68%) ⬇️
tx/textual/valuerenderer/timestamp.go 89.28% <0.00%> (ø)
tx/textual/valuerenderer/valuerenderer.go 79.59% <0.00%> (ø)
tx/textual/valuerenderer/int.go 50.00% <0.00%> (ø)
tx/textual/valuerenderer/duration.go 78.22% <0.00%> (ø)
tx/textual/valuerenderer/coins.go 73.17% <0.00%> (ø)
tx/textual/valuerenderer/bytes.go 62.50% <0.00%> (ø)
tx/textual/valuerenderer/dec.go 50.00% <0.00%> (ø)


// FileDescriptorSet returns the full FileDescriptorSet of the app in order
// to enable easier generation of dynamic clients.
rpc FileDescriptorSet(QueryFileDescriptorSetRequest) returns (QueryFileDescriptorSetResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

why not add this to

option go_package = "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1";
? seems like they go together

Copy link
Contributor

@amaury1093 amaury1093 Oct 20, 2022

Choose a reason for hiding this comment

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

Or reflection.v1beta1 (or mark it as v1).

I would put cosmos-related stuff here (e.g. chain id), and proto-related stuff (e.g. file descriptors) in cosmos.(base).reflection, even though there's only one method there to get the FileDescriptors

Copy link
Member

Choose a reason for hiding this comment

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

agree here. I would like this approach as it cleans up some random grpc services

Copy link
Member Author

Choose a reason for hiding this comment

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

So how about moving the file descriptors query to cosmos.reflection.v1 (not sure we need base) as the solo query there for now? And then we move or deprecate the stuff in the other reflection packages piece by piece?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach

Copy link
Member Author

Choose a reason for hiding this comment

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

moved to cosmos.reflection.v1. how does that look?

@aaronc
Copy link
Member Author

aaronc commented Oct 20, 2022

@tac0turtle @AmauryM one additional thing related to this PR in the context the of the presentation I gave on the ORM is that ideally the FileDescriptorSet and app config are committed to state (probably in the runtime module) whenver a chain starts or there is an upgrade. This way, if a light client wants to do proofs - first it does a proof on the app config + FileDescriptorSet and then it can prove anything else that uses the ORM. That maybe explains a bit why they're together here and the long term idea. But maybe it does make sense to put proto stuff in cosmos.reflection because it's more similar to grpc reflection.

@amaury1093
Copy link
Contributor

amaury1093 commented Oct 20, 2022

If we commit the FileDescriptorSet to state, then we're not allowed to modify the proto files between minor releases anymore, correct? Or in general how to deal with FileDescriptorSet mismatch between state and binary-embeded

@tac0turtle
Copy link
Member

I don't think its a good idea to add it to consensus. we wouldn't be able to do non breaking things to proto files going forward

@aaronc
Copy link
Member Author

aaronc commented Oct 20, 2022

Good point. What about adding app config to consensus?

Or should we say those things are to be proven out of band?

@amaury1093
Copy link
Contributor

amaury1093 commented Oct 20, 2022

Or should we say those things are to be proven out of band?

Then light clients would need 2 trusted sources: one for the initial header, and another for the filedescriptors.

What we can do is only commit the state.proto file descriptors to state. Then we couldn't do any changes in those files (e.g. not even proto comments updates), but maybe that's fine.

@aaronc
Copy link
Member Author

aaronc commented Oct 20, 2022

Or should we say those things are to be proven out of band?

Then light clients would need 2 trusted sources: one for the initial header, and another for the filedescriptors.

Yeah, but maybe that's okay?

What we can do is only commit the state.proto file descriptors to state. Then we couldn't do any changes in those files (e.g. not even proto comments updates), but maybe that's fine.

I'm fine to defer this decision till a bit later. Maybe we just do this basic query and deal with proofs when we get to that.

@aaronc
Copy link
Member Author

aaronc commented Oct 21, 2022

@tac0turtle @AmauryM does this look better? Is cosmos.reflection.v1? Okay?

@tac0turtle tac0turtle added C:CLI C: Proto Proto definition and proto release labels Oct 24, 2022
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot removed the C:CLI label Oct 24, 2022
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.

LGTM, but I would omit module_query_safe

proto/cosmos/autocli/v1/service.proto Outdated Show resolved Hide resolved
service RemoteInfoService {
// AppOptions returns the autocli options for all of the modules in an app.
rpc AppOptions(AppOptionsRequest) returns (AppOptionsResponse) {
option (cosmos.query.v1.module_query_safe) = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the benefit of adding this annotation here? I would omit if false, and add it only when true

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I don't ever expect it to be true and want to be explicit

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, maybe we can add a proto comment for this annotation why this is set to false explicitly. By scanning quickly, I initially thought it was true (because not omitted), and then I wondered why this particular query was set to false and not others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some comments. Does this look better @AmauryM ?

@aaronc
Copy link
Member Author

aaronc commented Oct 24, 2022

@AmauryM can you take another look?

@aaronc aaronc requested a review from amaury1093 October 24, 2022 16:40
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.

LGTM

@aaronc aaronc enabled auto-merge (squash) October 24, 2022 16:43
@aaronc aaronc merged commit a1b8ec2 into main Oct 25, 2022
@aaronc aaronc deleted the aaronc/autocli-service-proto branch October 25, 2022 09:17
@aaronc
Copy link
Member Author

aaronc commented Oct 25, 2022

Tagging api/v0.2.2 with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Proto Proto definition and proto release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants