Skip to content

Commit f61a2e7

Browse files
authored
Automate and fix ProtocolBuffer generation across all sub modules (#2462)
Consolidate and modernise the protobuf setup across the codebase. All Buf configurations have been aggregated and migrated to v2, providing a single, unified configuration for consistent generation and linting. Duplicate third-party protos have been removed following the unification, reducing maintenance overhead and eliminating redundancy. Several fixes have been applied to improve stability and code quality — including correcting grpc-gateway import path requirements, resolving warnings for nullable field options, and addressing various lint issues. Non-critical lint rules have been suppressed to minimise noise and simplify future reviews. Additionally, the PR integrates proto generation into the standard go generate workflow and introduces continuous integration checks to validate all Buf configurations automatically. These updates ensure a cleaner developer experience, more consistent code generation, and tighter CI enforcement. Updated modules: sei-chain, sei-cosmos, sei-tendermint, sei-wasmd. One critical inconsistency was detected which is fixed in this PR and bubbled up to the next release. See: #2461
1 parent 2198b81 commit f61a2e7

401 files changed

Lines changed: 6476 additions & 46744 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/buf-check.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Buf
2+
on:
3+
pull_request:
4+
types: [ opened, synchronize, reopened, labeled, unlabeled ]
5+
permissions:
6+
contents: read
7+
pull-requests: write
8+
jobs:
9+
buf:
10+
name: Check
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: bufbuild/buf-action@v1
15+
with:
16+
version: 1.58.0

buf.gen.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: v2
2+
inputs:
3+
- directory: proto
4+
- directory: sei-cosmos/proto
5+
- directory: sei-tendermint/proto
6+
- directory: sei-wasmd/proto
7+
plugins:
8+
- local:
9+
- ./build/proto/gocosmos/protoc-gen-gocosmos
10+
opt:
11+
- plugins=interfacetype+grpc
12+
- Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types
13+
- Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types
14+
- Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types
15+
- Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types
16+
- Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
17+
out: ./build/proto/gocosmos
18+
- local:
19+
# The version used is consistent with the grp-gateway version in go.mod.
20+
- go
21+
- run
22+
- github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.16.0
23+
out: ./build/proto/gocosmos
24+
opt:
25+
- logtostderr=true
26+
- allow_colon_final_segments=true
27+
28+
# Note that buf v2 does not support using generator per input directory.
29+
# As a workaround, we generate all the code in a separate output directory.
30+
# Then we copy the generated code to the desired location for tendermint only.
31+
# This is because tendermint uses gogofaster while cosmos-sdk and wasmd use gocosmos
32+
# (a fork of gogo/protobuf maintained by cosmos).
33+
# In the future we should consider using a single generator for all of them.
34+
- local:
35+
# The version used is consistent with the gogofaster version used by tendermint.
36+
- go
37+
- run
38+
- github.com/gogo/protobuf/protoc-gen-gogofaster@v1.3.2
39+
out: ./build/proto/gogofaster
40+
opt:
41+
- Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types
42+
- Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration
43+
- plugins=grpc

buf.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v2

buf.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
2+
version: v2
3+
modules:
4+
- path: proto
5+
name: buf.build/sei-protocol/sei-chain
6+
- path: sei-cosmos/proto
7+
- path: sei-cosmos/third_party/proto
8+
- path: sei-tendermint/proto
9+
- path: sei-wasmd/proto
10+
- path: sei-wasmd/third_party/proto
11+
12+
lint:
13+
use:
14+
- BASIC
15+
- FILE_LOWER_SNAKE_CASE
16+
- UNARY_RPC
17+
except:
18+
- COMMENT_FIELD
19+
- PACKAGE_VERSION_SUFFIX
20+
- PACKAGE_SAME_DIRECTORY
21+
- PACKAGE_DIRECTORY_MATCH
22+
- PACKAGE_SAME_GO_PACKAGE
23+
ignore:
24+
- sei-wasmd/third_party/proto
25+
- sei-cosmos/third_party/proto
26+
27+
breaking:
28+
use:
29+
- FILE

gen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package sei
2+
3+
//go:generate ./scripts/protoc.sh

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ require (
4747
golang.org/x/time v0.13.0
4848
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38
4949
google.golang.org/grpc v1.67.1
50-
google.golang.org/protobuf v1.36.8
5150
gopkg.in/yaml.v2 v2.4.0
5251
gopkg.in/yaml.v3 v3.0.1
5352
)
@@ -332,6 +331,7 @@ require (
332331
golang.org/x/tools v0.29.0 // indirect
333332
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect
334333
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
334+
google.golang.org/protobuf v1.36.8 // indirect
335335
gopkg.in/ini.v1 v1.67.0 // indirect
336336
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
337337
honnef.co/go/tools v0.3.1 // indirect

proto/epoch/epoch.proto

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,34 @@ syntax = "proto3";
22
package seiprotocol.seichain.epoch;
33

44
import "gogoproto/gogo.proto";
5-
import "google/protobuf/timestamp.proto";
65
import "google/protobuf/duration.proto";
6+
import "google/protobuf/timestamp.proto";
77

88
option go_package = "github.com/sei-protocol/sei-chain/x/epoch/types";
99

1010
message Epoch {
11-
12-
google.protobuf.Timestamp genesis_time = 1 [
13-
(gogoproto.stdtime) = true,
14-
(gogoproto.nullable) = false,
15-
(gogoproto.moretags) = "yaml:\"genesis_time\""
16-
];
17-
google.protobuf.Duration epoch_duration = 2 [
18-
(gogoproto.nullable) = false,
19-
(gogoproto.stdduration) = true,
20-
(gogoproto.jsontag) = "duration,omitempty",
21-
(gogoproto.moretags) = "yaml:\"epoch_duration\""
22-
];
23-
uint64 current_epoch = 3 [
24-
(gogoproto.jsontag) = "current_epoch",
25-
(gogoproto.moretags) = "yaml:\"current_epoch\""
26-
];
27-
google.protobuf.Timestamp current_epoch_start_time = 4 [
28-
(gogoproto.stdtime) = true,
29-
(gogoproto.nullable) = false,
30-
(gogoproto.moretags) = "yaml:\"current_epoch_start_time\""
31-
];
32-
int64 current_epoch_height = 5 [
33-
(gogoproto.jsontag) = "current_epoch_height",
34-
(gogoproto.moretags) = "yaml:\"current_epoch_height\""
35-
];
11+
google.protobuf.Timestamp genesis_time = 1 [
12+
(gogoproto.stdtime) = true,
13+
(gogoproto.nullable) = false,
14+
(gogoproto.moretags) = "yaml:\"genesis_time\""
15+
];
16+
google.protobuf.Duration epoch_duration = 2 [
17+
(gogoproto.nullable) = false,
18+
(gogoproto.stdduration) = true,
19+
(gogoproto.jsontag) = "duration,omitempty",
20+
(gogoproto.moretags) = "yaml:\"epoch_duration\""
21+
];
22+
uint64 current_epoch = 3 [
23+
(gogoproto.jsontag) = "current_epoch",
24+
(gogoproto.moretags) = "yaml:\"current_epoch\""
25+
];
26+
google.protobuf.Timestamp current_epoch_start_time = 4 [
27+
(gogoproto.stdtime) = true,
28+
(gogoproto.nullable) = false,
29+
(gogoproto.moretags) = "yaml:\"current_epoch_start_time\""
30+
];
31+
int64 current_epoch_height = 5 [
32+
(gogoproto.jsontag) = "current_epoch_height",
33+
(gogoproto.moretags) = "yaml:\"current_epoch_height\""
34+
];
3635
}

proto/epoch/genesis.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22
package seiprotocol.seichain.epoch;
33

4-
import "gogoproto/gogo.proto";
5-
import "epoch/params.proto";
64
import "epoch/epoch.proto";
5+
import "epoch/params.proto";
6+
import "gogoproto/gogo.proto";
77
// this line is used by starport scaffolding # genesis/proto/import
88

99
option go_package = "github.com/sei-protocol/sei-chain/x/epoch/types";

proto/epoch/params.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ option go_package = "github.com/sei-protocol/sei-chain/x/epoch/types";
88
// Params defines the parameters for the module.
99
message Params {
1010
option (gogoproto.goproto_stringer) = false;
11-
12-
}
11+
}

proto/epoch/query.proto

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
syntax = "proto3";
22
package seiprotocol.seichain.epoch;
33

4+
import "epoch/epoch.proto";
5+
import "epoch/params.proto";
46
import "gogoproto/gogo.proto";
57
import "google/api/annotations.proto";
6-
import "cosmos/base/query/v1beta1/pagination.proto";
7-
import "epoch/params.proto";
8-
import "epoch/epoch.proto";
98
// this line is used by starport scaffolding # 1
109

1110
option go_package = "github.com/sei-protocol/sei-chain/x/epoch/types";

0 commit comments

Comments
 (0)