Skip to content

Commit 843b205

Browse files
julienrbrtmergify[bot]
authored andcommitted
refactor(cosmosanalysis): proper message filtering (#4686)
* refactor(cosmosanalysis): keep only messages * updates * simplify * updates * fix * harden logic (cherry picked from commit 20a54d4)
1 parent f785e63 commit 843b205

File tree

6 files changed

+240
-72
lines changed

6 files changed

+240
-72
lines changed

changelog.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,110 @@
22

33
## Unreleased
44

5+
### Bug Fixes
6+
7+
- [#4686](https://github.com/ignite/cli/pull/4686) Filter discovered protos to only messages.
8+
9+
## [`v29.0.0-rc.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-rc.1)
10+
11+
### Features
12+
13+
- [#4509](https://github.com/ignite/cli/pull/4509) Upgrade to Go 1.24. Running `ignite doctor` migrates the scaffolded `tools.go` to the tool directive in the go.mod
14+
- [#4588](https://github.com/ignite/cli/pull/4588) Run `buf format after scaffold proto files.
15+
- [#4603](https://github.com/ignite/cli/issues/4603) Add `GetIgniteInfo` gRPC API for apps.
16+
- [#4657](https://github.com/ignite/cli/pull/4657) Upgrade to Cosmos SDK [v0.53.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.53.0).
17+
- Add x/epochs module to default template (except for minimal template).
18+
- Bump minimum compatible Cosmos SDK version to `v0.50.0`.
19+
20+
### Changes
21+
22+
- [#4596](https://github.com/ignite/cli/pull/4596) Add default `openapi.yml` when skipping proto gen.
23+
- [#4601](https://github.com/ignite/cli/pull/4601) Add `appregistry` as default plugin
24+
- [#4613](https://github.com/ignite/cli/pull/4613) Improve and simplify prompting logic by bubbletea.
25+
- [#4624](https://github.com/ignite/cli/pull/4624) Fix autocli templates for variadics.
26+
- [#4644](https://github.com/ignite/cli/pull/4644) Improve UI and UX for `testnet multi-node` command.
27+
- [#4645](https://github.com/ignite/cli/pull/4645) Refactor the xast.ModifyFunction to improve the readability.
28+
- [#4664](https://github.com/ignite/cli/pull/4664) Add verbose flags on `scaffold` and `generate` commands.
29+
- The flag displays the steps Ignite is taking to generate the code.
30+
- The verbosity only applies to the command. For full verbosity use the `IGNT_DEBUG` environment variable instead.
31+
32+
### Fixes
33+
34+
- [#4347](https://github.com/ignite/cli/pull/4347) Fix `ts-client` generation
35+
- [#4577](https://github.com/ignite/cli/pull/4577) Add proto version to query path.
36+
- [#4579](https://github.com/ignite/cli/pull/4579) Fix empty params response.
37+
- [#4585](https://github.com/ignite/cli/pull/4585) Fix faucet cmd issue.
38+
- [#4587](https://github.com/ignite/cli/pull/4587) Add missing light clients routes to IBC client keeper.
39+
- [#4595](https://github.com/ignite/cli/pull/4595) Fix wrong InterfaceRegistry for IBC modules.
40+
- [#4609](https://github.com/ignite/cli/pull/4609) Add work dir for relayer integration tests.
41+
- [#4658](https://github.com/ignite/cli/pull/4658) Fix indentation for params scaffolded into a struct.
42+
- [#4582](https://github.com/ignite/cli/issues/4582) Fix xast misplacing comments.
43+
- [#4660](https://github.com/ignite/cli/pull/4660) Fix xast test case indentation.
44+
- [#4667](https://github.com/ignite/cli/pull/4667) Harden `IsSlice`
45+
46+
## [`v29.0.0-beta.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-beta.1)
47+
48+
### Features
49+
50+
- [#3707](https://github.com/ignite/cli/pull/3707) and [#4094](https://github.com/ignite/cli/pull/4094) Add collections support.
51+
- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`
52+
- [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands
53+
- [#4001](https://github.com/ignite/cli/pull/4001) Improve `xgenny` dry run
54+
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config
55+
- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg
56+
- [#4071](https://github.com/ignite/cli/pull/4071) Support custom proto path
57+
- [#3718](https://github.com/ignite/cli/pull/3718) Add `gen-mig-diffs` tool app to compare scaffold output of two versions of ignite
58+
- [#4100](https://github.com/ignite/cli/pull/4100) Set the `proto-dir` flag only for the `scaffold chain` command and use the proto path from the config
59+
- [#4111](https://github.com/ignite/cli/pull/4111) Remove vuex generation
60+
- [#4113](https://github.com/ignite/cli/pull/4113) Generate chain config documentation automatically
61+
- [#4131](https://github.com/ignite/cli/pull/4131) Support `bytes` as data type in the `scaffold` commands
62+
- [#4300](https://github.com/ignite/cli/pull/4300) Only panics the module in the most top function level
63+
- [#4327](https://github.com/ignite/cli/pull/4327) Use the TxConfig from simState instead create a new one
64+
- [#4326](https://github.com/ignite/cli/pull/4326) Add `buf.build` version to `ignite version` command
65+
- [#4436](https://github.com/ignite/cli/pull/4436) Return tx hash to the faucet API
66+
- [#4437](https://github.com/ignite/cli/pull/4437) Remove module placeholders
67+
- [#4289](https://github.com/ignite/cli/pull/4289), [#4423](https://github.com/ignite/cli/pull/4423), [#4432](https://github.com/ignite/cli/pull/4432), [#4507](https://github.com/ignite/cli/pull/4507), [#4524](https://github.com/ignite/cli/pull/4524) Cosmos SDK v0.52 support and downgrade back to 0.50, while keeping latest improvements.
68+
- [#4480](https://github.com/ignite/cli/pull/4480) Add field max length
69+
- [#4477](https://github.com/ignite/cli/pull/4477), [#4559](https://github.com/ignite/cli/pull/4559) IBC v10 support
70+
- [#4166](https://github.com/ignite/cli/issues/4166) Migrate buf config files to v2
71+
- [#4494](https://github.com/ignite/cli/pull/4494) Automatic migrate the buf configs to v2
72+
73+
### Changes
74+
75+
- [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`.
76+
- [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler.
77+
- [#4058](https://github.com/ignite/cli/pull/4058) Use `address.Codec` instead of `AccAddressFromBech32`.
78+
- [#3993](https://github.com/ignite/cli/pull/3993) Oracle scaffolding was deprecated and has been removed
79+
- [#3962](https://github.com/ignite/cli/pull/3962) Rename all RPC endpoints and autocli commands generated for `map`/`list`/`single` types
80+
- [#3976](https://github.com/ignite/cli/pull/3976) Remove error checks for Cobra command value get calls
81+
- [#4002](https://github.com/ignite/cli/pull/4002) Bump buf build
82+
- [#4008](https://github.com/ignite/cli/pull/4008) Rename `pkg/yaml` to `pkg/xyaml`
83+
- [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2`
84+
- [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure.
85+
- [#4167](https://github.com/ignite/cli/pull/4167) Scaffold `int64` instead of `int32` when a field type is `int`
86+
- [#4159](https://github.com/ignite/cli/pull/4159) Enable gci linter
87+
- [#4160](https://github.com/ignite/cli/pull/4160) Enable copyloopvar linter
88+
- [#4162](https://github.com/ignite/cli/pull/4162) Enable errcheck linter
89+
- [#4189](https://github.com/ignite/cli/pull/4189) Deprecate `ignite node` for `ignite connect` app
90+
- [#4290](https://github.com/ignite/cli/pull/4290) Remove ignite ics logic from ignite cli (this functionality will be in the `consumer` app)
91+
- [#4295](https://github.com/ignite/cli/pull/4295) Stop scaffolding `pulsar` files
92+
- [#4317](https://github.com/ignite/cli/pull/4317) Remove xchisel dependency
93+
- [#4361](https://github.com/ignite/cli/pull/4361) Remove unused `KeyPrefix` method
94+
- [#4384](https://github.com/ignite/cli/pull/4384) Compare genesis params into chain genesis tests
95+
- [#4463](https://github.com/ignite/cli/pull/4463) Run `chain simulation` with any simulation test case
96+
- [#4533](https://github.com/ignite/cli/pull/4533) Promote GitHub codespace instead of Gitpod
97+
- [#4549](https://github.com/ignite/cli/pull/4549) Remove unused placeholder vars
98+
- [#4557](https://github.com/ignite/cli/pull/4557) Remove github.com/gookit/color
99+
100+
### Fixes
101+
102+
- [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg
103+
- [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic
104+
- [#4128](https://github.com/ignite/cli/pull/4128) Check for duplicate proto fields in config
105+
- [#4402](https://github.com/ignite/cli/pull/4402) Fix gentx parser into the cosmosutil package
106+
- [#4552](https://github.com/ignite/cli/pull/4552) Avoid direct access to proto field `perms.Account` and `perms.Permissions`
107+
- [#4555](https://github.com/ignite/cli/pull/4555) Fix buf lint issues into the chain code
108+
5109
## [`v28.10.0`](https://github.com/ignite/cli/releases/tag/v28.10.0)
6110

7111
### Features

ignite/pkg/cosmosanalysis/module/message.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

ignite/pkg/cosmosanalysis/module/module.go

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,6 @@ func RootGoImportPath(importPath string) string {
208208
return importPath
209209
}
210210

211-
func extractRelPath(pkgGoImportPath, baseGoPath string) (string, error) {
212-
// Remove the import prefix to get the relative path
213-
if strings.HasPrefix(pkgGoImportPath, baseGoPath) {
214-
return strings.TrimPrefix(pkgGoImportPath, baseGoPath), nil
215-
}
216-
217-
// When the import path prefix defined by the proto package
218-
// doesn't match the base Go import path it means that the
219-
// latter might have a version suffix and the former doesn't.
220-
if p, v := path.Split(baseGoPath); semver.IsValid(v) {
221-
// Use the import path without the version as prefix
222-
p = strings.TrimRight(p, "/")
223-
224-
return strings.TrimPrefix(pkgGoImportPath, p), nil
225-
}
226-
227-
return "", errors.Errorf("proto go import %s is not relative to %s", pkgGoImportPath, baseGoPath)
228-
}
229-
230211
// discover discovers and sdk module by a proto pkg.
231212
func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
232213
// Check if the proto package services are implemented
@@ -235,19 +216,7 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
235216
return Module{}, err
236217
}
237218

238-
pkgRelPath, err := extractRelPath(pkg.GoImportPath(), d.basegopath)
239-
if err != nil {
240-
return Module{}, err
241-
}
242-
243-
// Find the `sdk.Msg` interface implementation
244-
pkgPath := filepath.Join(d.sourcePath, pkgRelPath)
245-
msgs, err := cosmosanalysis.FindImplementation(pkgPath, messageImplementation)
246-
if err != nil {
247-
return Module{}, err
248-
}
249-
250-
if len(pkg.Services)+len(msgs) == 0 {
219+
if len(pkg.Services) == 0 {
251220
return Module{}, nil
252221
}
253222

@@ -257,22 +226,6 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
257226
Pkg: pkg,
258227
}
259228

260-
for _, msg := range msgs {
261-
pkgmsg, err := pkg.MessageByName(msg)
262-
if err != nil {
263-
// no msg found in the proto defs corresponds to discovered sdk message.
264-
// if it cannot be found, nothing to worry about, this means that it is used
265-
// only internally and not open for actual use.
266-
continue
267-
}
268-
269-
m.Msgs = append(m.Msgs, Msg{
270-
Name: msg,
271-
URI: fmt.Sprintf("%s.%s", pkg.Name, msg),
272-
FilePath: pkgmsg.Path,
273-
})
274-
}
275-
276229
// isType whether if protomsg can be added as an any Type to Module.
277230
isType := func(protomsg protoanalysis.Message) bool {
278231
// do not use GenesisState type.
@@ -315,19 +268,37 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) {
315268
})
316269
}
317270

318-
// fill queries.
271+
// fill queries & messages.
319272
for _, s := range pkg.Services {
320273
for _, q := range s.RPCFuncs {
321-
if len(q.HTTPRules) == 0 {
322-
continue
323-
}
274+
switch s.Name {
275+
case "Msg":
276+
pkgmsg, err := pkg.MessageByName(q.RequestType)
277+
if err != nil {
278+
// no msg found in the proto defs corresponds to discovered sdk message.
279+
// if it cannot be found, nothing to worry about, this means that it is used
280+
// only internally and not open for actual use.
281+
continue
282+
}
324283

325-
m.HTTPQueries = append(m.HTTPQueries, HTTPQuery{
326-
Name: q.Name,
327-
FullName: s.Name + q.Name,
328-
Rules: q.HTTPRules,
329-
Paginated: q.Paginated,
330-
})
284+
m.Msgs = append(m.Msgs, Msg{
285+
Name: q.RequestType,
286+
URI: fmt.Sprintf("%s.%s", pkg.Name, q.RequestType),
287+
FilePath: pkgmsg.Path,
288+
})
289+
case "Query":
290+
// no http rules means this query is not exposed as a REST endpoint.
291+
if len(q.HTTPRules) == 0 {
292+
continue
293+
}
294+
295+
m.HTTPQueries = append(m.HTTPQueries, HTTPQuery{
296+
Name: q.Name,
297+
FullName: s.Name + q.Name,
298+
Rules: q.HTTPRules,
299+
Paginated: q.Paginated,
300+
})
301+
}
331302
}
332303
}
333304

ignite/pkg/cosmosanalysis/module/module_test.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ func newModule(relChainPath, goImportPath string) module.Module {
2929
},
3030
GoImportName: "github.com/tendermint/planet/x/mars/types",
3131
Messages: []protoanalysis.Message{
32+
{
33+
Name: "MsgMyMessageRequest",
34+
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
35+
HighestFieldNumber: 1,
36+
Fields: map[string]string{
37+
"mytypefield": "string",
38+
},
39+
},
40+
{
41+
Name: "MsgMyMessageResponse",
42+
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
43+
HighestFieldNumber: 1,
44+
Fields: map[string]string{
45+
"mytypefield": "string",
46+
},
47+
},
48+
{
49+
Name: "MsgBarRequest",
50+
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
51+
HighestFieldNumber: 1,
52+
Fields: map[string]string{
53+
"mytypefield": "string",
54+
},
55+
},
56+
{
57+
Name: "MsgBarResponse",
58+
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
59+
HighestFieldNumber: 1,
60+
Fields: map[string]string{
61+
"mytypefield": "string",
62+
},
63+
},
3264
{
3365
Name: "QueryMyQueryRequest",
3466
Path: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
@@ -58,6 +90,21 @@ func newModule(relChainPath, goImportPath string) module.Module {
5890
},
5991
},
6092
Services: []protoanalysis.Service{
93+
{
94+
Name: "Msg",
95+
RPCFuncs: []protoanalysis.RPCFunc{
96+
{
97+
Name: "MyMessage",
98+
RequestType: "MsgMyMessageRequest",
99+
ReturnsType: "MsgMyMessageResponse",
100+
},
101+
{
102+
Name: "Bar",
103+
RequestType: "MsgBarRequest",
104+
ReturnsType: "MsgBarResponse",
105+
},
106+
},
107+
},
61108
{
62109
Name: "Query",
63110
RPCFuncs: []protoanalysis.RPCFunc{
@@ -89,7 +136,18 @@ func newModule(relChainPath, goImportPath string) module.Module {
89136
},
90137
},
91138
},
92-
Msgs: []module.Msg(nil),
139+
Msgs: []module.Msg{
140+
{
141+
Name: "MsgMyMessageRequest",
142+
URI: "tendermint.planet.mars.MsgMyMessageRequest",
143+
FilePath: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
144+
},
145+
{
146+
Name: "MsgBarRequest",
147+
URI: "tendermint.planet.mars.MsgBarRequest",
148+
FilePath: filepath.Join(relChainPath, "proto/planet/mars/mars.proto"),
149+
},
150+
},
93151
HTTPQueries: []module.HTTPQuery{
94152
{
95153
Name: "MyQuery",

ignite/pkg/cosmosanalysis/module/testdata/earth/proto/planet/mars/mars.proto

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,35 @@ import "cosmos/base/query/v1beta1/pagination.proto";
44
import "google/api/annotations.proto";
55
option go_package = "github.com/tendermint/planet/x/mars/types";
66

7+
service Msg {
8+
rpc MyMessage(MsgMyMessageRequest) returns (MsgMyMessageResponse);
9+
10+
rpc Bar(MsgBarRequest) returns (MsgBarResponse);
11+
}
12+
13+
message MsgMyMessageRequest {
14+
string mytypefield = 1;
15+
}
16+
17+
message MsgMyMessageResponse {
18+
string mytypefield = 1;
19+
}
20+
21+
message MsgBarRequest {
22+
string mytypefield = 1;
23+
}
24+
25+
message MsgBarResponse {
26+
string mytypefield = 1;
27+
}
28+
729
service Query {
830
rpc MyQuery(QueryMyQueryRequest) returns (QueryMyQueryResponse) {
9-
option (google.api.http).get = "/tendermint/mars/withoutmsg/my_query/{mytypefield}";
31+
option (google.api.http).get = "/tendermint/mars/my_query/{mytypefield}";
1032
}
1133

1234
rpc Foo(QueryFooRequest) returns (QueryFooResponse) {
13-
option (google.api.http).get = "/tendermint/mars/withoutmsg/foo/";
35+
option (google.api.http).get = "/tendermint/mars/foo/";
1436
}
1537
}
1638

ignite/pkg/cosmosanalysis/module/testdata/planet/proto/planet/mars/mars.proto

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,35 @@ import "cosmos/base/query/v1beta1/pagination.proto";
44
import "google/api/annotations.proto";
55
option go_package = "github.com/tendermint/planet/x/mars/types";
66

7+
service Msg {
8+
rpc MyMessage(MsgMyMessageRequest) returns (MsgMyMessageResponse);
9+
10+
rpc Bar(MsgBarRequest) returns (MsgBarResponse);
11+
}
12+
13+
message MsgMyMessageRequest {
14+
string mytypefield = 1;
15+
}
16+
17+
message MsgMyMessageResponse {
18+
string mytypefield = 1;
19+
}
20+
21+
message MsgBarRequest {
22+
string mytypefield = 1;
23+
}
24+
25+
message MsgBarResponse {
26+
string mytypefield = 1;
27+
}
28+
729
service Query {
830
rpc MyQuery(QueryMyQueryRequest) returns (QueryMyQueryResponse) {
9-
option (google.api.http).get = "/tendermint/mars/withoutmsg/my_query/{mytypefield}";
31+
option (google.api.http).get = "/tendermint/mars/my_query/{mytypefield}";
1032
}
1133

1234
rpc Foo(QueryFooRequest) returns (QueryFooResponse) {
13-
option (google.api.http).get = "/tendermint/mars/withoutmsg/foo/";
35+
option (google.api.http).get = "/tendermint/mars/foo/";
1436
}
1537
}
1638

0 commit comments

Comments
 (0)