Skip to content

Commit 31fd99a

Browse files
tac0turtlemelekes
andauthored
proto: add buf and protogen script (tendermint#4369)
* proto: add buf and protogen script - add buf with minimal changes - add protogen script to easier generate proto files Signed-off-by: Marko Baricevic <[email protected]> * add protoc needs * add some needed shell cmds * remove buf from tools as it is not needed everytime * add proto lint and breakage to ci * add section in changelog and upgrading files * address pr comments * remove space in circle config * remove spaces in makefile comment * add section on contributing on how to work with proto * bump buf to 0.7 * test bufbuild image * test install make in bufbuild image * revert to tendermintdev image * Update Makefile Co-Authored-By: Anton Kaliaev <[email protected]> Co-authored-by: Anton Kaliaev <[email protected]>
1 parent aeb6cc4 commit 31fd99a

File tree

17 files changed

+512
-324
lines changed

17 files changed

+512
-324
lines changed

.circleci/config.yml

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ executors:
1414
- image: tendermintdev/docker-website-deployment
1515
environment:
1616
AWS_REGION: us-east-1
17+
protoc:
18+
docker:
19+
- image: tendermintdev/docker-protoc
1720

1821
commands:
1922
run_test:
@@ -72,6 +75,19 @@ jobs:
7275
root: "/tmp/bin"
7376
paths:
7477
- "."
78+
proto-lint:
79+
executor: protoc
80+
steps:
81+
- checkout
82+
- run:
83+
command: make proto-lint
84+
85+
proto-breakage:
86+
executor: protoc
87+
steps:
88+
- checkout
89+
- run:
90+
command: make proto-check-breaking
7591

7692
test_abci_apps:
7793
executor: golang
@@ -391,6 +407,8 @@ workflows:
391407
- test_abci_apps:
392408
requires:
393409
- setup_dependencies
410+
- proto-breakage
411+
- proto-lint
394412
- test_abci_cli:
395413
requires:
396414
- setup_dependencies

CHANGELOG_PENDING.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ program](https://hackerone.com/tendermint).
2222

2323
### IMPROVEMENTS:
2424

25+
- [proto] [\#4369] Add [buf](https://buf.build/) for usage with linting and checking if there are breaking changes with the master branch.
26+
- [proto] [\#4369] Add `make proto-gen` cmd to generate proto stubs outside of GOPATH.
27+
28+
2529
### BUG FIXES:
2630

2731
- [node] [#\4311] Use `GRPCMaxOpenConnections` when creating the gRPC server, not `MaxOpenConnections`

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ need. Instead of running `go get -u=patch`, which will update anything,
9898
specify exactly the dependency you want to update, eg.
9999
`GO111MODULE=on go get -u github.com/tendermint/go-amino@master`.
100100

101+
## Protobuf
102+
103+
When working with [protobuf](https://developers.google.com/protocol-buffers) there are a few things you should know. We use [buf](https://buf.build/) for our linting and breaking changes checking. If you would like to run linting and check if the changes you have made are breaking then you will have to install the needed dependencies with `make buf`. Then the linting cmd will be `make proto-lint` and the breaking changes check will be `make proto-check-breaking`. To generate new stubs based off of your changes you can run `make proto-gen` (you can do this outside of GOPATH).
104+
101105
## Vagrant
102106

103107
If you are a [Vagrant](https://www.vagrantup.com/) user, you can get started

Makefile

+41-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
PACKAGES=$(shell go list ./...)
22
OUTPUT?=build/tendermint
33

4-
INCLUDE = -I=${GOPATH}/src/github.com/tendermint/tendermint -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
54
BUILD_TAGS?='tendermint'
65
LD_FLAGS = -X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD` -s -w
76
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
@@ -12,8 +11,9 @@ all: check build test install
1211
include tools.mk
1312
include tests.mk
1413

15-
########################################
16-
### Build Tendermint
14+
###############################################################################
15+
### Build Tendermint ###
16+
###############################################################################
1717

1818
build:
1919
CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/
@@ -30,35 +30,41 @@ install:
3030
install_c:
3131
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint
3232

33-
########################################
34-
### Protobuf
33+
###############################################################################
34+
### Protobuf ###
35+
###############################################################################
3536

36-
protoc_all: protoc_libs protoc_merkle protoc_abci protoc_grpc protoc_proto3types
37+
proto-all: proto-gen proto-lint proto-check-breaking
3738

38-
%.pb.go: %.proto
39+
proto-gen:
3940
## If you get the following error,
4041
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
4142
## See https://stackoverflow.com/a/25518702
4243
## Note the $< here is substituted for the %.proto
4344
## Note the $@ here is substituted for the %.pb.go
44-
protoc $(INCLUDE) $< --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,plugins=grpc:../../..
45+
@sh scripts/protocgen.sh
4546

46-
########################################
47-
### Build ABCI
47+
proto-lint:
48+
@buf check lint --error-format=json
4849

49-
# see protobuf section above
50-
protoc_abci: abci/types/types.pb.go
50+
proto-check-breaking:
51+
@buf check breaking --against-input '.git#branch=master'
5152

52-
protoc_proto3types: types/proto3/block.pb.go
53+
.PHONY: proto-all proto-gen proto-lint proto-check-breaking
54+
55+
###############################################################################
56+
### Build ABCI ###
57+
###############################################################################
5358

5459
build_abci:
5560
@go build -mod=readonly -i ./abci/cmd/...
5661

5762
install_abci:
5863
@go install -mod=readonly ./abci/cmd/...
5964

60-
########################################
61-
### Distribution
65+
###############################################################################
66+
### Distribution ###
67+
###############################################################################
6268

6369
# dist builds binaries for all platforms and packages them for distribution
6470
# TODO add abci to these scripts
@@ -86,10 +92,9 @@ get_deps_bin_size:
8692
@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
8793
@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
8894

89-
########################################
90-
### Libs
91-
92-
protoc_libs: libs/kv/types.pb.go
95+
###############################################################################
96+
### Libs ###
97+
###############################################################################
9398

9499
# generates certificates for TLS testing in remotedb and RPC server
95100
gen_certs: clean_certs
@@ -105,13 +110,9 @@ clean_certs:
105110
rm -f rpc/lib/server/test.crt
106111
rm -f rpc/lib/server/test.key
107112

108-
protoc_grpc: rpc/grpc/types.pb.go
109-
110-
protoc_merkle: crypto/merkle/merkle.pb.go
111-
112-
113-
########################################
114-
### Formatting, linting, and vetting
113+
###############################################################################
114+
### Formatting, linting, and vetting ###
115+
###############################################################################
115116

116117
fmt:
117118
@go fmt ./...
@@ -122,8 +123,9 @@ lint:
122123

123124
DESTINATION = ./index.html.md
124125

125-
###########################################################
126-
### Documentation
126+
###############################################################################
127+
### Documentation ###
128+
###############################################################################
127129

128130
build-docs:
129131
cd docs && \
@@ -142,16 +144,18 @@ sync-docs:
142144
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
143145
.PHONY: sync-docs
144146

145-
###########################################################
146-
### Docker image
147+
###############################################################################
148+
### Docker image ###
149+
###############################################################################
147150

148151
build-docker:
149152
cp $(OUTPUT) DOCKER/tendermint
150153
docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
151154
rm -rf DOCKER/tendermint
152155

153-
###########################################################
154-
### Local testnet using docker
156+
###############################################################################
157+
### Local testnet using docker ###
158+
###############################################################################
155159

156160
# Build linux binary on other platforms
157161
build-linux: tools
@@ -176,8 +180,9 @@ localnet-start: localnet-stop build-docker-localnode
176180
localnet-stop:
177181
docker-compose down
178182

179-
###########################################################
180-
### Remote full-nodes (sentry) using terraform and ansible
183+
###############################################################################
184+
### Remote full-nodes (sentry) using terraform and ansible ###
185+
###############################################################################
181186

182187
# Server management
183188
sentry-start:
@@ -216,7 +221,7 @@ contract-tests:
216221
# unless there is a reason not to.
217222
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
218223
.PHONY: check build build_race build_abci dist install install_abci check_tools tools update_tools draw_deps \
219-
protoc_abci protoc_libs gen_certs clean_certs grpc_dbserver fmt build-linux localnet-start \
220-
localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop protoc_grpc protoc_all \
224+
gen_certs clean_certs grpc_dbserver fmt build-linux localnet-start \
225+
localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop \
221226
build_c install_c test_with_deadlock cleanup_after_test_with_deadlock lint build-contract-tests-hooks contract-tests \
222227
build_c-amazonlinux

UPGRADING.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
This guide provides steps to be followed when you upgrade your applications to
44
a newer version of Tendermint Core.
55

6+
## Unreleased
7+
8+
<Overview>
9+
10+
### Protobuf Changes
11+
12+
When upgrading to version <version #> you will have to fetch the `third_party` directory along with the updated proto files.
13+
614
## v0.33.0
715

816
This release is not compatible with previous blockchains due to commit becoming signatures only and fields in the header have been removed.

0 commit comments

Comments
 (0)