-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(orm): add query proto codegen #13438
Conversation
continue | ||
} | ||
|
||
out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644) |
Check failure
Code scanning / gosec
Expect file permissions to be 0600 or less
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to say this seems rather strange... 0644 is pretty standard 🤔
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #13438 +/- ##
==========================================
+ Coverage 54.01% 54.48% +0.46%
==========================================
Files 648 676 +28
Lines 55425 57952 +2527
==========================================
+ Hits 29940 31576 +1636
- Misses 23086 23731 +645
- Partials 2399 2645 +246
|
} | ||
|
||
func QueryProtoPluginRunner(p *protogen.Plugin) error { | ||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
@@ -17,7 +19,8 @@ | |||
ormTablePkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormtable") | |||
) | |||
|
|||
func PluginRunner(p *protogen.Plugin) error { | |||
func ORMPluginRunner(p *protogen.Plugin) error { | |||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) |
Check failure
Code scanning / gosec
Potential integer overflow by integer type conversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm.. the value of the const is 1
. gosec
should be able to statically inspect const
values...
… aaronc/orm-query-proto-gen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. are there any plans to add constructor type functions to make the ergonomics of forming the list query requests a little easier?
currently, using ListBalance
would require devs to write:
req := ListBalanceRequest{
Query: &ListBalanceRequest_PrefixQuery{
PrefixQuery: &ListBalanceRequest_IndexKey{
Key: &ListBalanceRequest_IndexKey_Denom_{
Denom: &ListBalanceRequest_IndexKey_Denom{Denom: &denom}}}},
Pagination: nil,
}
it's not too bad, but definitely a little more complex than i'd prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how come this is landing? orm is on pause till we have more time and ability to take things on.
My thought is that these are mostly for non golang clients. Which reminds me that I need to add grpc-gateway annotations to this PR. From golang it should be possible to use the ORM directly using ABCI query or something similar that supports iteration rather than this API. Longer term it'd be nice to see logical queries (eg. |
Because I have it ready and didn't want this to get lost in a pile of POC code. Do you want me to close until we have more bandwidth? |
lets merge, just somewhat confusing when its not within in the scope of things we are working right now. All good |
Sorry about that. Will give a heads up next time |
## Description This starts the implementation of approach (C) in cosmos#11774 by generating `_query.proto` files for `.proto` files which have ORM definitions. It does this using a new protoc plugin called `protoc-gen-go-cosmos-orm-proto`. Please review `bank_query.proto` and `test_schema_query.proto` as these are the outputs of the codegen. The approach taken does not attempt to do any sort of logical queries as discussed in cosmos#11774 and instead provides direct index access in the most simple and complete way that we can easily implement now. More advanced things in cosmos#11774 could be implemented later, but this should be possible to deliver relatively quickly and should allow developers to completely skip writing gRPC queries manually if they use ORM. Note that the implementation of these queries can provide merkle proofs because the mapping to state is well known. I did need to disable pulsar codegen in this PR because it doesn't support proto3 optionals which are needed here (depends on cosmos/cosmos-proto#12). Fortunately, pulsar is 100% compatible with the official google codegen and there is no problem running ORM tests against the official codegen. --- ### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Description
This starts the implementation of approach (C) in #11774 by generating
_query.proto
files for.proto
files which have ORM definitions. It does this using a new protoc plugin calledprotoc-gen-go-cosmos-orm-proto
.Please review
bank_query.proto
andtest_schema_query.proto
as these are the outputs of the codegen.The approach taken does not attempt to do any sort of logical queries as discussed in #11774 and instead provides direct index access in the most simple and complete way that we can easily implement now. More advanced things in #11774 could be implemented later, but this should be possible to deliver relatively quickly and should allow developers to completely skip writing gRPC queries manually if they use ORM.
Note that the implementation of these queries can provide merkle proofs because the mapping to state is well known.
I did need to disable pulsar codegen in this PR because it doesn't support proto3 optionals which are needed here (depends on cosmos/cosmos-proto#12). Fortunately, pulsar is 100% compatible with the official google codegen and there is no problem running ORM tests against the official codegen.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change