Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobuf Encoding Migration #5456

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3f8778e
Makefile cleanup
alexanderbez Dec 30, 2019
f55bdf3
Add buf targets to makefile
alexanderbez Dec 30, 2019
f0da7fc
Fix buf version var
alexanderbez Dec 30, 2019
3f6fd6d
GOLANGCI_LINT_HASHSUM
alexanderbez Dec 30, 2019
5be0645
Update go.{mod,sum}
alexanderbez Dec 31, 2019
75fbebc
Add buf config file
alexanderbez Dec 31, 2019
ff570d9
Add proto targets and script
alexanderbez Dec 31, 2019
04d1834
Update types/
alexanderbez Dec 31, 2019
2c58592
Add newlines
alexanderbez Dec 31, 2019
dac3b5e
Fix MarshalTo for nil case
alexanderbez Dec 31, 2019
1623ac5
Update proto types
alexanderbez Dec 31, 2019
1dca276
Define and enforce custom type interface
alexanderbez Dec 31, 2019
fc5b049
Migrate Dec type to proto
alexanderbez Jan 1, 2020
3bc73b2
Proto lint
alexanderbez Jan 1, 2020
cafabf6
Remove old decimal amino tests
alexanderbez Jan 1, 2020
f48e8fd
Remove compare methods
alexanderbez Jan 1, 2020
b723ac5
Fix sim
alexanderbez Jan 2, 2020
2c92e06
Remove TODO
alexanderbez Jan 2, 2020
fa841fc
Rename types.proto to codec.proto
alexanderbez Jan 2, 2020
b990a10
remove old codec.go
alexanderbez Jan 2, 2020
dae8941
Fix linting
alexanderbez Jan 2, 2020
d87b7c6
Add todo
alexanderbez Jan 2, 2020
a2828f8
Merge branch 'master' into bez/5444-proto-encoding
alexanderbez Jan 2, 2020
58441cf
Squash
alexanderbez Jan 2, 2020
4c884c3
Update GH action
alexanderbez Jan 2, 2020
2f50122
Change package name and add version suffix
alexanderbez Jan 2, 2020
616a10d
Initial commit
alexanderbez Jan 3, 2020
3af9449
Fix protocgen script
alexanderbez Jan 3, 2020
3866d73
Merge branch 'bez/5444-proto-encoding' into bez/5444-proto-encoding-auth
alexanderbez Jan 3, 2020
f62cc36
Update types codec package name
alexanderbez Jan 3, 2020
3f7f490
Merge branch 'bez/5444-proto-encoding' into bez/5444-proto-encoding-auth
alexanderbez Jan 3, 2020
b7a67fe
Start integrating cosmos-proto (#5473)
aaronc Jan 3, 2020
7bd0171
Update auth codec
alexanderbez Jan 3, 2020
c77de68
Merge branch 'bez/5444-proto-encoding-auth' of github.com:cosmos/cosm…
alexanderbez Jan 3, 2020
e28fc09
Rebase changes from bez/5444-proto-encoding-auth
alexanderbez Jan 3, 2020
10ae78a
Merge branch 'bez/5444-proto-encoding' into bez/5444-proto-encoding-auth
alexanderbez Jan 3, 2020
3338487
Update go.mod
alexanderbez Jan 3, 2020
806ecf0
Update go.{mod,sum}
alexanderbez Jan 3, 2020
726ea57
Support multisig in crypto proto
alexanderbez Jan 3, 2020
27a3fa2
Updates to crypto proto API
alexanderbez Jan 3, 2020
1c07bc0
Move crypto proto to types
alexanderbez Jan 3, 2020
17b6ac4
Move crypto proto to types
alexanderbez Jan 3, 2020
4b5c766
Merge branch 'bez/5444-proto-encoding' into bez/5444-proto-encoding-auth
alexanderbez Jan 3, 2020
9f07f11
Move install to contrib
alexanderbez Jan 3, 2020
120da39
Update types pubkey
alexanderbez Jan 4, 2020
2218efd
Add JSON serialization from interface utils
alexanderbez Jan 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 60 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ MOCKS_DIR = $(CURDIR)/tests/mocks

export GO111MODULE = on

all: tools build lint test

# The below include contains the tools and runsim targets.
include contrib/devtools/Makefile

########################################
### Build
all: tools build lint test

###############################################################################
### Build ###
###############################################################################

build: go.sum
@go build -mod=readonly ./...
.PHONY: build

update-swagger-docs: statik
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi
.PHONY: update-swagger-docs

mocks: $(MOCKS_DIR)
mockgen -source=x/auth/types/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go
.PHONY: mocks

$(MOCKS_DIR):
mkdir -p $(MOCKS_DIR)

########################################
### Tools & dependencies
distclean:
rm -rf \
gitian-build-darwin/ \
gitian-build-linux/ \
gitian-build-windows/ \
.gitian-builder-cache/
.PHONY: distclean

###############################################################################
### Tools & Dependencies ###
###############################################################################

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
Expand All @@ -53,16 +53,19 @@ go.sum: go.mod
@go mod verify
@go mod tidy

distclean:
rm -rf \
gitian-build-darwin/ \
gitian-build-linux/ \
gitian-build-windows/ \
.gitian-builder-cache/
.PHONY: distclean
###############################################################################
### Documentation ###
###############################################################################

########################################
### Documentation
update-swagger-docs: statik
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi
.PHONY: update-swagger-docs

godocs:
@echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/cosmos-sdk/types"
Expand All @@ -85,8 +88,9 @@ sync-docs:
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
.PHONY: sync-docs

########################################
### Testing
###############################################################################
### Tests & Simulation ###
###############################################################################

test: test-unit
test-all: test-unit test-ledger-mock test-race test-cover
Expand Down Expand Up @@ -173,6 +177,14 @@ test-cover:
@export VERSION=$(VERSION); bash -x tests/test_cover.sh
.PHONY: test-cover

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
.PHONY: benchmark

###############################################################################
### Linting ###
###############################################################################

lint: golangci-lint
$(BINDIR)/golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
Expand All @@ -185,12 +197,9 @@ format: tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk
.PHONY: format

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
.PHONY: benchmark

########################################
### Devdoc
###############################################################################
### Devdoc ###
###############################################################################

DEVDOC_SAVE = docker commit `docker ps -a -n 1 -q` devdoc:local

Expand All @@ -213,3 +222,21 @@ devdoc-update:
docker pull tendermint/devdoc

.PHONY: devdoc devdoc-clean devdoc-init devdoc-save devdoc-update

###############################################################################
### Protobuf ###
###############################################################################

proto-all: proto-lint proto-check-breaking proto-gen

proto-gen:
@go mod vendor
@./scripts/protocgen.sh

proto-lint:
@buf check lint --error-format=json

proto-check-breaking:
@buf check breaking --against-input '.git#branch=master'

.PHONY: proto-all proto-gen proto-lint proto-check-breaking
19 changes: 19 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build:
roots:
- .
excludes:
- vendor/github.com/tendermint
lint:
use:
- DEFAULT
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
- UNARY_RPC
- PACKAGE_VERSION_SUFFIX
- COMMENT_FIELD
ignore:
- vendor
breaking:
use:
- FILE
60 changes: 44 additions & 16 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.PHONY: all tools tools-clean statik runsim golangci-lint \
buf protoc-gen-buf-check-breaking protoc-gen-buf-check-lint

###
# Find OS and Go environment
# GO contains the Go binary
Expand All @@ -15,13 +18,11 @@ ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif

GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
GOLANGCI_LINT_HASHSUM := 8d21cc95da8d3daf8321ac40091456fc26123c964d7c2281d339d431f2f4c840
all: tools

###
# Functions
###
###############################################################################
### Functions ###
###############################################################################

go_get = $(if $(findstring Windows_NT,$(OS)),\
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
Expand All @@ -35,17 +36,25 @@ cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)

###
# tools
###

TOOLS_DESTDIR ?= $(GOPATH)/bin
###############################################################################
### Tools ###
###############################################################################

GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint
STATIK = $(TOOLS_DESTDIR)/statik
RUNSIM = $(TOOLS_DESTDIR)/runsim
BIN ?= /usr/local/bin
OS ?= $(shell uname -s)
HD ?= $(shell uname -m)

all: tools
GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
GOLANGCI_LINT_HASHSUM := f11179f445385a4a6d5079d67de63fe48a9113cee8e9ee0ced19327a83a4394b

BUF_VERSION ?= 0.4.0

TOOLS_DESTDIR ?= $(GOPATH)/bin
GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint
STATIK = $(TOOLS_DESTDIR)/statik
RUNSIM = $(TOOLS_DESTDIR)/runsim

tools: statik runsim golangci-lint

Expand Down Expand Up @@ -74,8 +83,27 @@ $(RUNSIM):
@echo "Installing runsim..."
@(cd /tmp && go get github.com/cosmos/tools/cmd/runsim@v1.0.0)

buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint
@echo "Installing buf..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${OS}-${HD}" \
-o "${BIN}/buf" && \
chmod +x "${BIN}/buf"

protoc-gen-buf-check-breaking:
@echo "Installing protoc-gen-buf-check-breaking..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-breaking-${OS}-${HD}" \
-o "${BIN}/protoc-gen-buf-check-breaking" && \
chmod +x "${BIN}/protoc-gen-buf-check-breaking"

protoc-gen-buf-check-lint:
@echo "Installing protoc-gen-buf-check-lint..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-lint-${OS}-${HD}" \
-o "${BIN}/protoc-gen-buf-check-lint" && \
chmod +x "${BIN}/protoc-gen-buf-check-lint"

tools-clean:
rm -f $(STATIK) $(GOLANGCI_LINT) $(RUNSIM)
rm -f tools-stamp

.PHONY: all tools tools-clean
4 changes: 2 additions & 2 deletions contrib/devtools/install-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ get_latest_release() {

VERSION="$(get_latest_release golangci/golangci-lint)"

echo "Downloading golangci-lint ${VERSION} installer ..." >&2
echo "Downloading golangci-lint ${VERSION} installer..." >&2
"${CURL}" -sfL "https://raw.githubusercontent.com/golangci/golangci-lint/${VERSION}/install.sh" > "${installer}"

echo "Checking hashsum ..." >&2
echo "Checking hashsum..." >&2
[ "${HASHSUM}" = "$(f_sha256 ${installer})" ]
chmod +x "${installer}"

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
github.com/golang/protobuf v1.3.2
github.com/gorilla/mux v1.7.3
github.com/hashicorp/golang-lru v0.5.3
github.com/mattn/go-isatty v0.0.11
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand All @@ -132,6 +133,7 @@ github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM=
Expand All @@ -154,8 +156,6 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
Expand Down Expand Up @@ -206,7 +206,9 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down Expand Up @@ -316,8 +318,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
13 changes: 13 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eo pipefail

proto_dirs=$(find . -path ./vendor -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
protoc -I/usr/local/include \
-I. \
-I${GOPATH}/src \
-Ivendor/github.com/gogo/protobuf/gogoproto \
--gofast_out=. \
$(find "${dir}" -name '*.proto')
done
Loading