From 276a99976ebdead8ae6ad88837b869621d676626 Mon Sep 17 00:00:00 2001 From: Rahul Ghangas Date: Mon, 29 Aug 2022 16:45:14 +1000 Subject: [PATCH] chore: update protobuf generator (#667) * chore: update docker image tendermintdev/sdk-proto-gen to v0.7 * chore: update golang protobuf version * chore: update protocgen script to use correct flags for updated buf * chore: add config file for buf * chore: update buf generated files * chore: add empty line at end of file Co-authored-by: CHAMI Rachid * chore: use latest image for Dockerfile Co-authored-by: CHAMI Rachid --- Makefile | 2 +- go.mod | 2 +- go.sum | 3 ++- proto/buf.gen.gogo.yaml | 9 +++++++++ scripts/protocgen.sh | 18 +++++++++--------- x/payment/types/tx.pb.gw.go | 9 +++++++-- x/qgb/types/msgs.pb.gw.go | 14 +++++++++++--- 7 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 proto/buf.gen.gogo.yaml diff --git a/Makefile b/Makefile index 064aecf11c..942b5bf47f 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ test: .PHONY: test proto-gen: - $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:v0.2 sh ./scripts/protocgen.sh + $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:latest sh ./scripts/protocgen.sh proto-lint: @$(DOCKER_BUF) lint --error-format=json diff --git a/go.mod b/go.mod index 8e97d15a6f..baa91d0bc0 100644 --- a/go.mod +++ b/go.mod @@ -150,7 +150,7 @@ require ( golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect google.golang.org/api v0.81.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.0 // indirect + google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 99bb6014ac..5f1ad0ead3 100644 --- a/go.sum +++ b/go.sum @@ -1566,8 +1566,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/proto/buf.gen.gogo.yaml b/proto/buf.gen.gogo.yaml new file mode 100644 index 0000000000..8dfc016e28 --- /dev/null +++ b/proto/buf.gen.gogo.yaml @@ -0,0 +1,9 @@ +version: v1 +plugins: + - name: gocosmos + out: .. + opt: plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/celestiaorg/celestia-app/codec/types + - name: grpc-gateway + out: .. + opt: logtostderr=true,allow_colon_final_segments=true + \ No newline at end of file diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index d0b66eee2b..9b2e548041 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -13,18 +13,18 @@ protoc_gen_gocosmos() { protoc_gen_gocosmos -proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) +cd proto +proto_dirs=$(find . -path ./cosmos -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) for dir in $proto_dirs; do - buf protoc \ - -I "proto" \ - -I "third_party/proto" \ - --gocosmos_out=plugins=interfacetype+grpc,\ -Mgoogle/protobuf/any.proto=github.com/celestiaorg/celestia-app/codec/types:. \ - --grpc-gateway_out=logtostderr=true:. \ - $(find "${dir}" -maxdepth 1 -name '*.proto') - + for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do + if grep "option go_package" $file &> /dev/null ; then + buf generate --template buf.gen.gogo.yaml $file + fi + done done +cd .. + # move proto files to the right places cp -r github.com/celestiaorg/celestia-app/* ./ rm -rf github.com diff --git a/x/payment/types/tx.pb.gw.go b/x/payment/types/tx.pb.gw.go index ca1ed29254..6a6ece6f14 100644 --- a/x/payment/types/tx.pb.gw.go +++ b/x/payment/types/tx.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join var ( filter_Msg_PayForData_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -70,12 +72,14 @@ func local_request_Msg_PayForData_0(ctx context.Context, marshaler runtime.Marsh // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { mux.Handle("GET", pattern_Msg_PayForData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -83,6 +87,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_PayForData_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -158,7 +163,7 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client } var ( - pattern_Msg_PayForData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"celestia", "payment", "payfordata"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Msg_PayForData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"celestia", "payment", "payfordata"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/qgb/types/msgs.pb.gw.go b/x/qgb/types/msgs.pb.gw.go index a654b76d49..627dd386c6 100644 --- a/x/qgb/types/msgs.pb.gw.go +++ b/x/qgb/types/msgs.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join var ( filter_Msg_ValsetConfirm_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -88,12 +90,14 @@ func local_request_Msg_DataCommitmentConfirm_0(ctx context.Context, marshaler ru // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { mux.Handle("POST", pattern_Msg_ValsetConfirm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -101,6 +105,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_ValsetConfirm_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -114,6 +119,8 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server mux.Handle("POST", pattern_Msg_DataCommitmentConfirm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -121,6 +128,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_DataCommitmentConfirm_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -216,9 +224,9 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client } var ( - pattern_Msg_ValsetConfirm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"qgb", "valset_confirm"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Msg_ValsetConfirm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"qgb", "valset_confirm"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Msg_DataCommitmentConfirm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"qgb", "data_commitment_confirm"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Msg_DataCommitmentConfirm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"qgb", "data_commitment_confirm"}, "", runtime.AssumeColonVerbOpt(false))) ) var (