From 64532340730aa1095a157c8343b368ed1cc06b99 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 31 May 2023 09:33:26 +0200 Subject: [PATCH] build: optimize proto-builder (#16343) --- .github/workflows/proto-registry.yml | 2 +- .github/workflows/proto.yml | 4 ++-- Makefile | 2 +- baseapp/testutil/buf.lock | 4 +++- contrib/devtools/Dockerfile | 5 +++-- proto/buf.lock | 7 +++++-- proto/cosmos/circuit/v1/query.proto | 2 +- proto/cosmos/circuit/v1/tx.proto | 2 +- scripts/protocgen-pulsar.sh | 10 +--------- scripts/protocgen.sh | 4 ++-- testutil/testdata/buf.lock | 14 +++++++++++++- testutil/testdata/buf.yaml | 1 + x/circuit/keeper/genesis.go | 2 +- x/circuit/keeper/msg_server.go | 2 +- x/circuit/keeper/query.go | 2 +- x/circuit/module.go | 9 ++------- x/circuit/types/codec.go | 2 +- x/tx/Makefile | 2 +- x/tx/internal/testpb/buf.lock | 14 +++++++++++++- x/tx/internal/testpb/buf.yaml | 1 + x/tx/signing/aminojson/internal/Makefile | 1 + x/tx/signing/aminojson/internal/buf.lock | 14 +++++++++++++- x/tx/signing/aminojson/internal/buf.yaml | 1 + 23 files changed, 70 insertions(+), 37 deletions(-) diff --git a/.github/workflows/proto-registry.yml b/.github/workflows/proto-registry.yml index 5ab302ae2b..9936227409 100644 --- a/.github/workflows/proto-registry.yml +++ b/.github/workflows/proto-registry.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: bufbuild/buf-setup-action@v1.19.0 + - uses: bufbuild/buf-setup-action@v1.20.0 - uses: bufbuild/buf-push-action@v1 with: input: "proto" diff --git a/.github/workflows/proto.yml b/.github/workflows/proto.yml index e0dfb1b043..4f84a13ded 100644 --- a/.github/workflows/proto.yml +++ b/.github/workflows/proto.yml @@ -15,7 +15,7 @@ jobs: timeout-minutes: 5 steps: - uses: actions/checkout@v3 - - uses: bufbuild/buf-setup-action@v1.19.0 + - uses: bufbuild/buf-setup-action@v1.20.0 - uses: bufbuild/buf-lint-action@v1 with: input: "proto" @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: bufbuild/buf-setup-action@v1.19.0 + - uses: bufbuild/buf-setup-action@v1.20.0 - uses: bufbuild/buf-breaking-action@v1 with: input: "proto" diff --git a/Makefile b/Makefile index 87cb1de4d6..cbbbcebbe7 100644 --- a/Makefile +++ b/Makefile @@ -398,7 +398,7 @@ lint-fix: ### Protobuf ### ############################################################################### -protoVer=0.13.1 +protoVer=0.13.2 protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) diff --git a/baseapp/testutil/buf.lock b/baseapp/testutil/buf.lock index 259bd9ce82..1bc0a2429e 100644 --- a/baseapp/testutil/buf.lock +++ b/baseapp/testutil/buf.lock @@ -5,7 +5,9 @@ deps: owner: cosmos repository: cosmos-proto commit: 1935555c206d4afb9e94615dfd0fad31 + digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 - remote: buf.build owner: cosmos repository: gogo-proto - commit: 6652e3443c3b4504bb3bf82e73a7e409 + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 + digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 diff --git a/contrib/devtools/Dockerfile b/contrib/devtools/Dockerfile index 616758f7fd..3a38f5f148 100644 --- a/contrib/devtools/Dockerfile +++ b/contrib/devtools/Dockerfile @@ -2,7 +2,7 @@ # docker build --pull --rm -f "contrib/devtools/Dockerfile" -t cosmossdk-proto:latest "contrib/devtools" # docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh -FROM bufbuild/buf:1.19.0 as BUILDER +FROM bufbuild/buf:1.20.0 as BUILDER FROM golang:1.20-alpine RUN apk add --no-cache \ @@ -27,7 +27,8 @@ RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest && go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} && \ go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} && \ - go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@v1.0.0-beta.3 + go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@v1.0.0-beta.3 && \ + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest # install all gogo protobuf binaries RUN git clone https://github.com/cosmos/gogoproto.git; \ diff --git a/proto/buf.lock b/proto/buf.lock index 4391403a59..ddc6786a25 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -5,11 +5,14 @@ deps: owner: cosmos repository: cosmos-proto commit: 1935555c206d4afb9e94615dfd0fad31 + digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 - remote: buf.build owner: cosmos repository: gogo-proto - commit: 34d970b699f84aa382f3c29773a60836 + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 + digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 - remote: buf.build owner: googleapis repository: googleapis - commit: 5ae7f88519b04fe1965da0f8a375a088 + commit: cc916c31859748a68fd229a3c8d7a2e8 + digest: shake256:469b049d0eb04203d5272062636c078decefc96fec69739159c25d85349c50c34c7706918a8b216c5c27f76939df48452148cff8c5c3ae77fa6ba5c25c1b8bf8 diff --git a/proto/cosmos/circuit/v1/query.proto b/proto/cosmos/circuit/v1/query.proto index 69bdb11edf..1b952020d1 100644 --- a/proto/cosmos/circuit/v1/query.proto +++ b/proto/cosmos/circuit/v1/query.proto @@ -8,7 +8,7 @@ import "cosmos/circuit/v1/types.proto"; import "google/api/annotations.proto"; import "cosmos/query/v1/query.proto"; -// Msg defines the crisis Msg service. +// Query defines the circuit Msg service. service Query { // Account returns account permissions. rpc Account(QueryAccountRequest) returns (AccountResponse) { diff --git a/proto/cosmos/circuit/v1/tx.proto b/proto/cosmos/circuit/v1/tx.proto index 44e55a9f67..c0684316d0 100644 --- a/proto/cosmos/circuit/v1/tx.proto +++ b/proto/cosmos/circuit/v1/tx.proto @@ -6,7 +6,7 @@ option go_package = "cosmossdk.io/x/circuit/types"; import "cosmos/msg/v1/msg.proto"; import "cosmos/circuit/v1/types.proto"; -// Msg defines the crisis Msg service. +// Msg defines the circuit Msg service. service Msg { option (cosmos.msg.v1.service) = true; diff --git a/scripts/protocgen-pulsar.sh b/scripts/protocgen-pulsar.sh index c859c71fc8..43b0c386ba 100755 --- a/scripts/protocgen-pulsar.sh +++ b/scripts/protocgen-pulsar.sh @@ -1,14 +1,6 @@ # this script is for generating protobuf files for the new google.golang.org/protobuf API - set -eo pipefail -protoc_install_gopulsar() { - go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest -} - -protoc_install_gopulsar - echo "Cleaning API directory" (cd api; find ./ -type f \( -iname \*.pulsar.go -o -iname \*.pb.go -o -iname \*.cosmos_orm.go -o -iname \*.pb.gw.go \) -delete; find . -empty -type d -delete; cd ..) @@ -16,7 +8,7 @@ echo "Generating API module" (cd proto; buf generate --template buf.gen.pulsar.yaml) echo "Generate Pulsar Test Data" -(cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml) +(cd testutil/testdata; buf mod update; buf generate --template buf.gen.pulsar.yaml) echo "Generate x/tx" (cd x/tx; make codegen) \ No newline at end of file diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index b1a4428e85..01c4349bd2 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -23,10 +23,10 @@ done cd .. # generate codec/testdata proto code -(cd testutil/testdata; buf generate) +(cd testutil/testdata; buf mod update; buf generate) # generate baseapp test messages -(cd baseapp/testutil; buf generate) +(cd baseapp/testutil; buf mod update; buf generate) # move proto files to the right places cp -r github.com/cosmos/cosmos-sdk/* ./ diff --git a/testutil/testdata/buf.lock b/testutil/testdata/buf.lock index 259bd9ce82..a2cdec427a 100644 --- a/testutil/testdata/buf.lock +++ b/testutil/testdata/buf.lock @@ -5,7 +5,19 @@ deps: owner: cosmos repository: cosmos-proto commit: 1935555c206d4afb9e94615dfd0fad31 + digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 + - remote: buf.build + owner: cosmos + repository: cosmos-sdk + commit: e0dcb5ad221c4c3b8166c04751084b9d + digest: shake256:31ac8086ce294d2e388d266f9a867789710109b7e7ce647fad404569f5b57af407607d5ff85e609e9bc32f5abf7acdc9ec94c053865bd1f6d9f1ac0d58a99ebb - remote: buf.build owner: cosmos repository: gogo-proto - commit: 6652e3443c3b4504bb3bf82e73a7e409 + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 + digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 5ae7f88519b04fe1965da0f8a375a088 + digest: shake256:27d9fcdc0e3eb957449dc3d17e2d24c7ce59c3c483ecf128818183c336dfd28595ecd13771fb3172247775caf7707c4076dd8e70c5ac2cbcac170df35e4d0028 diff --git a/testutil/testdata/buf.yaml b/testutil/testdata/buf.yaml index e6f82c0cdc..b0edfb59a9 100644 --- a/testutil/testdata/buf.yaml +++ b/testutil/testdata/buf.yaml @@ -1,4 +1,5 @@ version: v1 deps: + - buf.build/cosmos/cosmos-sdk - buf.build/cosmos/gogo-proto - buf.build/cosmos/cosmos-proto diff --git a/x/circuit/keeper/genesis.go b/x/circuit/keeper/genesis.go index af7735fe89..bb8b2b2930 100644 --- a/x/circuit/keeper/genesis.go +++ b/x/circuit/keeper/genesis.go @@ -36,7 +36,7 @@ func (k *Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) { } } -// InitGenesis initializes the bank module's state from a given genesis state. +// InitGenesis initializes the circuit module's state from a given genesis state. func (k *Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { for _, accounts := range genState.AccountPermissions { add, err := k.addressCodec.StringToBytes(accounts.Address) diff --git a/x/circuit/keeper/msg_server.go b/x/circuit/keeper/msg_server.go index ce74cee5df..d2aeafaddf 100644 --- a/x/circuit/keeper/msg_server.go +++ b/x/circuit/keeper/msg_server.go @@ -19,7 +19,7 @@ type msgServer struct { var _ types.MsgServer = msgServer{} -// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// NewMsgServerImpl returns an implementation of the circuit MsgServer interface // for the provided Keeper. func NewMsgServerImpl(keeper Keeper) types.MsgServer { return &msgServer{Keeper: keeper} diff --git a/x/circuit/keeper/query.go b/x/circuit/keeper/query.go index 59dfaf8cdc..4b8f505f67 100644 --- a/x/circuit/keeper/query.go +++ b/x/circuit/keeper/query.go @@ -17,7 +17,7 @@ type QueryServer struct { keeper Keeper } -// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// NewMsgServerImpl returns an implementation of the circuit MsgServer interface // for the provided Keeper. func NewQueryServer(keeper Keeper) types.QueryServer { return &QueryServer{keeper: keeper} diff --git a/x/circuit/module.go b/x/circuit/module.go index 8107197bd1..3b95da6045 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -117,16 +117,11 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { } } -// Name returns the circuit module's name. -func (AppModule) Name() string { return types.ModuleName } - -// RegisterInvariants registers the circuit module invariants. -func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { -} - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } +// InitGenesis performs genesis initialization for the circuit module. It returns +// no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { start := time.Now() var genesisState types.GenesisState diff --git a/x/circuit/types/codec.go b/x/circuit/types/codec.go index 2afe054d80..ceddf62543 100644 --- a/x/circuit/types/codec.go +++ b/x/circuit/types/codec.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types +// RegisterLegacyAminoCodec registers the necessary circuit interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgAuthorizeCircuitBreaker{}, "cosmos-sdk/MsgAuthorizeCircuitBreaker") diff --git a/x/tx/Makefile b/x/tx/Makefile index 7fd7077787..1d33ef29c0 100644 --- a/x/tx/Makefile +++ b/x/tx/Makefile @@ -1,3 +1,3 @@ codegen: - @(cd internal/testpb; buf generate) + @(cd internal/testpb; buf mod update; buf generate) @(cd signing/aminojson/internal; make codegen) \ No newline at end of file diff --git a/x/tx/internal/testpb/buf.lock b/x/tx/internal/testpb/buf.lock index 259bd9ce82..a2cdec427a 100644 --- a/x/tx/internal/testpb/buf.lock +++ b/x/tx/internal/testpb/buf.lock @@ -5,7 +5,19 @@ deps: owner: cosmos repository: cosmos-proto commit: 1935555c206d4afb9e94615dfd0fad31 + digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 + - remote: buf.build + owner: cosmos + repository: cosmos-sdk + commit: e0dcb5ad221c4c3b8166c04751084b9d + digest: shake256:31ac8086ce294d2e388d266f9a867789710109b7e7ce647fad404569f5b57af407607d5ff85e609e9bc32f5abf7acdc9ec94c053865bd1f6d9f1ac0d58a99ebb - remote: buf.build owner: cosmos repository: gogo-proto - commit: 6652e3443c3b4504bb3bf82e73a7e409 + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 + digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 5ae7f88519b04fe1965da0f8a375a088 + digest: shake256:27d9fcdc0e3eb957449dc3d17e2d24c7ce59c3c483ecf128818183c336dfd28595ecd13771fb3172247775caf7707c4076dd8e70c5ac2cbcac170df35e4d0028 diff --git a/x/tx/internal/testpb/buf.yaml b/x/tx/internal/testpb/buf.yaml index 5aee45ac2b..02f98c1563 100644 --- a/x/tx/internal/testpb/buf.yaml +++ b/x/tx/internal/testpb/buf.yaml @@ -1,5 +1,6 @@ version: v1 deps: + - buf.build/cosmos/cosmos-sdk - buf.build/cosmos/cosmos-proto - buf.build/cosmos/gogo-proto lint: diff --git a/x/tx/signing/aminojson/internal/Makefile b/x/tx/signing/aminojson/internal/Makefile index 6eb4420b60..465057e261 100644 --- a/x/tx/signing/aminojson/internal/Makefile +++ b/x/tx/signing/aminojson/internal/Makefile @@ -1,3 +1,4 @@ codegen: @echo "Generating proto files" + @buf mod update @buf generate \ No newline at end of file diff --git a/x/tx/signing/aminojson/internal/buf.lock b/x/tx/signing/aminojson/internal/buf.lock index 88709c98ef..a2cdec427a 100644 --- a/x/tx/signing/aminojson/internal/buf.lock +++ b/x/tx/signing/aminojson/internal/buf.lock @@ -5,7 +5,19 @@ deps: owner: cosmos repository: cosmos-proto commit: 1935555c206d4afb9e94615dfd0fad31 + digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 + - remote: buf.build + owner: cosmos + repository: cosmos-sdk + commit: e0dcb5ad221c4c3b8166c04751084b9d + digest: shake256:31ac8086ce294d2e388d266f9a867789710109b7e7ce647fad404569f5b57af407607d5ff85e609e9bc32f5abf7acdc9ec94c053865bd1f6d9f1ac0d58a99ebb - remote: buf.build owner: cosmos repository: gogo-proto - commit: 34d970b699f84aa382f3c29773a60836 + commit: 5e5b9fdd01804356895f8f79a6f1ddc1 + digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 5ae7f88519b04fe1965da0f8a375a088 + digest: shake256:27d9fcdc0e3eb957449dc3d17e2d24c7ce59c3c483ecf128818183c336dfd28595ecd13771fb3172247775caf7707c4076dd8e70c5ac2cbcac170df35e4d0028 diff --git a/x/tx/signing/aminojson/internal/buf.yaml b/x/tx/signing/aminojson/internal/buf.yaml index ab3dff3940..a18820022f 100644 --- a/x/tx/signing/aminojson/internal/buf.yaml +++ b/x/tx/signing/aminojson/internal/buf.yaml @@ -1,5 +1,6 @@ version: v1 deps: + - buf.build/cosmos/cosmos-sdk - buf.build/cosmos/gogo-proto - buf.build/cosmos/cosmos-proto lint: