You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
12 KiB

6 years ago
9 years ago
[RPC] Static swagger (#3880) * manually swagging Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * three definitions with polymorphism Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * added blockchain and block Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * low quality generation, commit, block_response and validators Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * genesis and consensus states endpoints Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * fix indentation Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * consensus parameters Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * fix indentation Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * add height to consensus parameters endpoint Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * unconfirmed_txs and num_unconfirmed_txs Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * add missing query parameter Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * add ABCI queries Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * added index document for swagger documentation Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * add missing routes Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * contract tests added on CCI Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * contract tests job should be in the test suite Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * simplify requirements to test Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * typo Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * build is a prerequisite to start localnet Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * reduce nodejs size, move goodman to get_tools, add docs, fix comments Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * Update scripts/get_tools.sh That's cleaner, thanks! Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * xz not supported by cci image, let's keep it simple Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * REMOVE-indirect debug of CCI paths Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * dirty experiment, volume is empty but binary has been produced Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * dirty experiment, volume is empty but binary has been produced Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * dirty experiment going on Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * locally works, CCI have difficulties with second layaer containers volumes Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * restore experiment, use machine instead of docker for contract tests Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * simplify a bit Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * rollback on machine golang Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * Document the changes Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * Changelog Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com> * comments Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
5 years ago
  1. GOTOOLS = \
  2. github.com/mitchellh/gox \
  3. github.com/golangci/golangci-lint/cmd/golangci-lint \
  4. github.com/gogo/protobuf/protoc-gen-gogo \
  5. github.com/square/certstrap
  6. GOBIN?=${GOPATH}/bin
  7. PACKAGES=$(shell go list ./...)
  8. OUTPUT?=build/tendermint
  9. export GO111MODULE = on
  10. INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
  11. BUILD_TAGS?='tendermint'
  12. LD_FLAGS = -X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD` -s -w
  13. BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
  14. all: check build test install
  15. check: check_tools
  16. ########################################
  17. ### Build Tendermint
  18. build:
  19. CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/
  20. build_c:
  21. CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" -o $(OUTPUT) ./cmd/tendermint/
  22. # Runs `make build_c` from within an Amazon Linux (v2)-based Docker build
  23. # container in order to build an Amazon Linux-compatible binary. Produces a
  24. # compatible binary at ./build/tendermint
  25. build_c-amazonlinux:
  26. $(MAKE) -C ./DOCKER build_amazonlinux_buildimage
  27. docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux
  28. build_race:
  29. CGO_ENABLED=1 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint
  30. install:
  31. CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
  32. install_c:
  33. CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint
  34. ########################################
  35. ### Protobuf
  36. protoc_all: protoc_libs protoc_merkle protoc_abci protoc_grpc protoc_proto3types
  37. %.pb.go: %.proto
  38. ## If you get the following error,
  39. ## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
  40. ## See https://stackoverflow.com/a/25518702
  41. ## Note the $< here is substituted for the %.proto
  42. ## Note the $@ here is substituted for the %.pb.go
  43. protoc $(INCLUDE) $< --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,plugins=grpc:.
  44. ########################################
  45. ### Build ABCI
  46. # see protobuf section above
  47. protoc_abci: abci/types/types.pb.go
  48. protoc_proto3types: types/proto3/block.pb.go
  49. build_abci:
  50. @go build -mod=readonly -i ./abci/cmd/...
  51. install_abci:
  52. @go install -mod=readonly ./abci/cmd/...
  53. ########################################
  54. ### Distribution
  55. # dist builds binaries for all platforms and packages them for distribution
  56. # TODO add abci to these scripts
  57. dist:
  58. @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
  59. ########################################
  60. ### Tools & dependencies
  61. check_tools:
  62. @# https://stackoverflow.com/a/25668869
  63. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  64. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  65. get_tools:
  66. @echo "--> Installing tools"
  67. ./scripts/get_tools.sh
  68. update_tools:
  69. @echo "--> Updating tools"
  70. ./scripts/get_tools.sh
  71. #For ABCI and libs
  72. get_protoc:
  73. @# https://github.com/google/protobuf/releases
  74. curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.tar.gz | tar xvz && \
  75. cd protobuf-3.6.1 && \
  76. DIST_LANG=cpp ./configure && \
  77. make && \
  78. make check && \
  79. sudo make install && \
  80. sudo ldconfig && \
  81. cd .. && \
  82. rm -rf protobuf-3.6.1
  83. draw_deps:
  84. @# requires brew install graphviz or apt-get install graphviz
  85. go get github.com/RobotsAndPencils/goviz
  86. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  87. get_deps_bin_size:
  88. @# Copy of build recipe with additional flags to perform binary size analysis
  89. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
  90. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  91. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  92. ########################################
  93. ### Libs
  94. protoc_libs: libs/common/types.pb.go
  95. # generates certificates for TLS testing in remotedb and RPC server
  96. gen_certs: clean_certs
  97. certstrap init --common-name "tendermint.com" --passphrase ""
  98. certstrap request-cert --common-name "remotedb" -ip "127.0.0.1" --passphrase ""
  99. certstrap sign "remotedb" --CA "tendermint.com" --passphrase ""
  100. mv out/remotedb.crt libs/db/remotedb/test.crt
  101. mv out/remotedb.key libs/db/remotedb/test.key
  102. certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
  103. certstrap sign "server" --CA "tendermint.com" --passphrase ""
  104. mv out/server.crt rpc/lib/server/test.crt
  105. mv out/server.key rpc/lib/server/test.key
  106. rm -rf out
  107. # deletes generated certificates
  108. clean_certs:
  109. rm -f libs/db/remotedb/test.crt
  110. rm -f libs/db/remotedb/test.key
  111. rm -f rpc/lib/server/test.crt
  112. rm -f rpc/lib/server/test.key
  113. test_libs:
  114. go test -tags clevedb boltdb $(PACKAGES)
  115. grpc_dbserver:
  116. protoc -I libs/db/remotedb/proto/ libs/db/remotedb/proto/defs.proto --go_out=plugins=grpc:libs/db/remotedb/proto
  117. protoc_grpc: rpc/grpc/types.pb.go
  118. protoc_merkle: crypto/merkle/merkle.pb.go
  119. ########################################
  120. ### Testing
  121. ## required to be run first by most tests
  122. build_docker_test_image:
  123. docker build -t tester -f ./test/docker/Dockerfile .
  124. ### coverage, app, persistence, and libs tests
  125. test_cover:
  126. # run the go unit tests with coverage
  127. bash test/test_cover.sh
  128. test_apps:
  129. # run the app tests using bash
  130. # requires `abci-cli` and `tendermint` binaries installed
  131. bash test/app/test.sh
  132. test_abci_apps:
  133. bash abci/tests/test_app/test.sh
  134. test_abci_cli:
  135. # test the cli against the examples in the tutorial at:
  136. # ./docs/abci-cli.md
  137. # if test fails, update the docs ^
  138. @ bash abci/tests/test_cli/test.sh
  139. test_persistence:
  140. # run the persistence tests using bash
  141. # requires `abci-cli` installed
  142. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  143. # TODO undockerize
  144. # bash test/persist/test_failure_indices.sh
  145. test_p2p:
  146. docker rm -f rsyslog || true
  147. rm -rf test/logs || true
  148. mkdir test/logs
  149. cd test/
  150. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  151. cd ..
  152. # requires 'tester' the image from above
  153. bash test/p2p/test.sh tester
  154. # the `docker cp` takes a really long time; uncomment for debugging
  155. #
  156. # mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
  157. test_integrations:
  158. make build_docker_test_image
  159. make get_tools
  160. make install
  161. make test_cover
  162. make test_apps
  163. make test_abci_apps
  164. make test_abci_cli
  165. make test_libs
  166. make test_persistence
  167. make test_p2p
  168. test_release:
  169. @go test -tags release $(PACKAGES)
  170. test100:
  171. @for i in {1..100}; do make test; done
  172. vagrant_test:
  173. vagrant up
  174. vagrant ssh -c 'make test_integrations'
  175. ### go tests
  176. test:
  177. @echo "--> Running go test"
  178. @go test -p 1 $(PACKAGES)
  179. test_race:
  180. @echo "--> Running go test --race"
  181. @go test -p 1 -v -race $(PACKAGES)
  182. # uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
  183. test_with_deadlock:
  184. make set_with_deadlock
  185. make test
  186. make cleanup_after_test_with_deadlock
  187. set_with_deadlock:
  188. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/'
  189. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/'
  190. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  191. # cleanes up after you ran test_with_deadlock
  192. cleanup_after_test_with_deadlock:
  193. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/'
  194. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/'
  195. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  196. ########################################
  197. ### Formatting, linting, and vetting
  198. fmt:
  199. @go fmt ./...
  200. lint:
  201. @echo "--> Running linter"
  202. @golangci-lint run
  203. DESTINATION = ./index.html.md
  204. rpc-docs:
  205. cat rpc/core/slate_header.txt > $(DESTINATION)
  206. godoc2md -template rpc/core/doc_template.txt github.com/tendermint/tendermint/rpc/core | grep -v -e "pipe.go" -e "routes.go" -e "dev.go" | sed 's,/src/target,https://github.com/tendermint/tendermint/tree/master/rpc/core,' >> $(DESTINATION)
  207. ###########################################################
  208. ### Docker image
  209. build-docker:
  210. cp $(OUTPUT) DOCKER/tendermint
  211. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  212. rm -rf DOCKER/tendermint
  213. ###########################################################
  214. ### Local testnet using docker
  215. # Build linux binary on other platforms
  216. build-linux: get_tools
  217. GOOS=linux GOARCH=amd64 $(MAKE) build
  218. build-docker-localnode:
  219. @cd networks/local && make
  220. # Run a 4-node testnet locally
  221. localnet-start: localnet-stop build-docker-localnode
  222. @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --config /etc/tendermint/config-template.toml --v 4 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2; fi
  223. docker-compose up
  224. # Stop testnet
  225. localnet-stop:
  226. docker-compose down
  227. ###########################################################
  228. ### Remote full-nodes (sentry) using terraform and ansible
  229. # Server management
  230. sentry-start:
  231. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  232. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  233. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  234. @if ! [ -f $(CURDIR)/build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 0 --n 4 --o . ; fi
  235. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  236. @echo "Next step: Add your validator setup in the genesis.json and config.tml files and run \"make sentry-config\". (Public key of validator, chain ID, peer IP and node ID.)"
  237. # Configuration management
  238. sentry-config:
  239. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  240. sentry-stop:
  241. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  242. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  243. # meant for the CI, inspect script & adapt accordingly
  244. build-slate:
  245. bash scripts/slate.sh
  246. # Build hooks for dredd, to skip or add information on some steps
  247. build-contract-tests-hooks:
  248. ifeq ($(OS),Windows_NT)
  249. go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests
  250. else
  251. go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests
  252. endif
  253. # Run a nodejs tool to test endpoints against a localnet
  254. # The command takes care of starting and stopping the network
  255. # prerequisits: build-contract-tests-hooks build-linux
  256. # the two build commands were not added to let this command run from generic containers or machines.
  257. # The binaries should be built beforehand
  258. contract-tests:
  259. dredd
  260. # To avoid unintended conflicts with file names, always add to .PHONY
  261. # unless there is a reason not to.
  262. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  263. .PHONY: check build build_race build_abci dist install install_abci check_tools get_tools update_tools draw_deps get_protoc protoc_abci protoc_libs gen_certs clean_certs grpc_dbserver test_cover test_apps test_persistence test_p2p test test_race test_integrations test_release test100 vagrant_test fmt rpc-docs build-linux localnet-start localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop build-slate protoc_grpc protoc_all build_c install_c test_with_deadlock cleanup_after_test_with_deadlock lint build-contract-tests-hooks contract-tests build_c-amazonlinux