remove gogoproto

This commit is contained in:
Ethan Buchman 2018-05-24 00:13:43 -04:00
parent cfdec76020
commit 01f87fd8d3
14 changed files with 399 additions and 404 deletions

40
Gopkg.lock generated
View File

@ -29,26 +29,15 @@
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
version = "v1.7.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"gogoproto",
"jsonpb",
"proto",
"protoc-gen-gogo/descriptor",
"sortkeys",
"types"
]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"jsonpb",
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/struct",
"ptypes/timestamp"
]
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
@ -58,7 +47,7 @@
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "553a641470496b2327abcac10b36396bd98e45c9"
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
[[projects]]
name = "github.com/inconshreveable/mousetrap"
@ -93,14 +82,14 @@
[[projects]]
name = "github.com/spf13/cobra"
packages = ["."]
revision = "a1f051bc3eba734da4772d60e2d677f47cf93ef4"
version = "v0.0.2"
revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385"
version = "v0.0.3"
[[projects]]
name = "github.com/spf13/pflag"
packages = ["."]
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
version = "v1.0.0"
revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
version = "v1.0.1"
[[projects]]
name = "github.com/stretchr/testify"
@ -128,31 +117,31 @@
"leveldb/table",
"leveldb/util"
]
revision = "714f901b98fdb3aa954b4193d8cbd64a28d80cad"
revision = "5d6fca44a948d2be89a9702de7717f0168403d3d"
[[projects]]
branch = "bucky/no-gogo"
name = "github.com/tendermint/tmlibs"
packages = [
"common",
"db",
"log"
]
revision = "2e24b64fc121dcdf1cabceab8dc2f7257675483c"
version = "v0.8.1"
revision = "d24a30858e23ace7aeee306e2ce652aba8021631"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"lex/httplex",
"trace"
]
revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41"
revision = "9ef9f5bb98a1fdc41f8cf6c250a4404b4085e389"
[[projects]]
name = "golang.org/x/text"
@ -176,10 +165,9 @@
version = "v0.3.0"
[[projects]]
branch = "master"
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "ce84044298496ef4b54b4a0a0909ba593cc60e30"
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[[projects]]
name = "google.golang.org/grpc"
@ -208,6 +196,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "e42d4a691fb0d0db9c717394e580dd00b36ba9e185541f99fc56689338470123"
inputs-digest = "e0b98059927fe32f1398b66d5d3464fac7d0b4c011855863a04f21b5bd8b7032"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -32,7 +32,7 @@
# Use `~` for only minor version bumps.
[[constraint]]
name = "github.com/gogo/protobuf"
name = "github.com/golang/protobuf"
version = "~1.0.0"
[[constraint]]
@ -45,12 +45,19 @@
[[constraint]]
name = "github.com/tendermint/tmlibs"
version = "0.8.1"
branch = "bucky/no-gogo"
# version = "0.8.1"
[[constraint]]
name = "google.golang.org/grpc"
version = "~1.7.3"
# this got updated and broke, so locked to an old working commit ...
[[override]]
name = "google.golang.org/genproto"
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[prune]
go-tests = true
unused-packages = true

View File

@ -2,11 +2,10 @@ GOTOOLS = \
github.com/mitchellh/gox \
github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto
GOTOOLS_CHECK = gox dep gometalinter.v2 protoc protoc-gen-gogo
github.com/golang/protobuf/protoc-gen-go \
GOTOOLS_CHECK = gox dep gometalinter.v2 protoc protoc-gen-go
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
INCLUDE = -I=. -I=${GOPATH}/src
all: check get_vendor_deps protoc build test install metalinter
@ -20,7 +19,7 @@ protoc:
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
protoc $(INCLUDE) --gogo_out=plugins=grpc:. types/*.proto
protoc $(INCLUDE) --go_out=plugins=grpc:. types/*.proto
@echo "--> adding nolint declarations to protobuf generated files"
@awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
@mv types/types.pb.go.new types/types.pb.go

View File

@ -129,7 +129,7 @@ func (app *PersistentKVStoreApplication) Validators() (validators []types.Valida
return
}
func MakeValSetChangeTx(pubkey types.PubKey, power int64) []byte {
func MakeValSetChangeTx(pubkey *types.PubKey, power int64) []byte {
return []byte(cmn.Fmt("val:%X/%d", pubkey.Data, power))
}

View File

@ -12,11 +12,12 @@ import (
func InitChain(client abcicli.Client) error {
total := 10
vals := make([]types.Validator, total)
vals := make([]*types.Validator, total)
for i := 0; i < total; i++ {
pubkey := cmn.RandBytes(33)
power := cmn.RandInt()
vals[i] = types.Ed25519Validator(pubkey, int64(power))
v := types.Ed25519Validator(pubkey, int64(power))
vals[i] = &v
}
_, err := client.InitChainSync(types.RequestInitChain{
Validators: vals,

View File

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"github.com/gogo/protobuf/jsonpb"
"github.com/golang/protobuf/jsonpb"
)
//---------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@ import (
"encoding/binary"
"io"
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/proto"
)
const (

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
cmn "github.com/tendermint/tmlibs/common"
)
@ -21,7 +21,7 @@ func TestMarshalJSON(t *testing.T) {
Code: 1,
Data: []byte("hello"),
GasWanted: 43,
Tags: []cmn.KVPair{
Tags: []*cmn.KVPair{
{[]byte("pho"), []byte("bo")},
},
}
@ -82,8 +82,8 @@ func TestWriteReadMessage2(t *testing.T) {
Data: []byte(phrase),
Log: phrase,
GasWanted: 10,
Tags: []cmn.KVPair{
cmn.KVPair{[]byte("abc"), []byte("def")},
Tags: []*cmn.KVPair{
{[]byte("abc"), []byte("def")},
},
// Fee: cmn.KI64Pair{
},

View File

@ -35,8 +35,13 @@ type ParamsInitChain struct {
}
func ToParamsInitChain(req RequestInitChain) ParamsInitChain {
vals := make([]Validator, len(req.Validators))
for i := 0; i < len(vals); i++ {
v := req.Validators[i]
vals[i] = *v
}
return ParamsInitChain{
Validators: req.Validators,
Validators: vals,
GenesisBytes: req.GenesisBytes,
}
}
@ -70,11 +75,17 @@ func ToParamsBeginBlock(req RequestBeginBlock) ParamsBeginBlock {
v := req.Validators[i]
vals[i] = *v
}
evidence := make([]Evidence, len(req.ByzantineValidators))
for i := 0; i < len(evidence); i++ {
ev := req.ByzantineValidators[i]
evidence[i] = *ev
}
return ParamsBeginBlock{
Hash: req.Hash,
Header: req.Header,
Header: *req.Header,
Validators: vals,
ByzantineValidators: req.ByzantineValidators,
ByzantineValidators: evidence,
}
}

View File

@ -1,55 +0,0 @@
// +build ignore
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
)
// This script replaces most `[]byte` with `data.Bytes` in a `.pb.go` file.
// It was written before we realized we could use `gogo/protobuf` to achieve
// this more natively. So it's here for safe keeping in case we ever need to
// abandon `gogo/protobuf`.
func main() {
bytePattern := regexp.MustCompile("[[][]]byte")
const oldPath = "types/types.pb.go"
const tmpPath = "types/types.pb.new"
content, err := ioutil.ReadFile(oldPath)
if err != nil {
panic("cannot read " + oldPath)
os.Exit(1)
}
lines := bytes.Split(content, []byte("\n"))
outFile, _ := os.Create(tmpPath)
wroteImport := false
for _, line_bytes := range lines {
line := string(line_bytes)
gotPackageLine := strings.HasPrefix(line, "package ")
writeImportTime := strings.HasPrefix(line, "import ")
containsDescriptor := strings.Contains(line, "Descriptor")
containsByteArray := strings.Contains(line, "[]byte")
if containsByteArray && !containsDescriptor {
line = string(bytePattern.ReplaceAll([]byte(line), []byte("data.Bytes")))
}
if writeImportTime && !wroteImport {
wroteImport = true
fmt.Fprintf(outFile, "import \"github.com/tendermint/go-wire/data\"\n")
}
if gotPackageLine {
fmt.Fprintf(outFile, "%s\n", "//nolint: gas")
}
fmt.Fprintf(outFile, "%s\n", line)
}
outFile.Close()
os.Remove(oldPath)
os.Rename(tmpPath, oldPath)
exec.Command("goimports", "-w", oldPath)
}

View File

@ -1,6 +1,6 @@
package types
import common "github.com/tendermint/tmlibs/common"
import cmn "github.com/tendermint/tmlibs/common"
// nondeterministic
type ResultException struct {
@ -41,7 +41,10 @@ type ResultInitChain struct {
}
func FromResultInitChain(res ResultInitChain) ResponseInitChain {
return ResponseInitChain(res)
vals := valsToPointers(res.Validators)
return ResponseInitChain{
Validators: vals,
}
}
type ResultQuery struct {
@ -61,51 +64,80 @@ func FromResultQuery(res ResultQuery) ResponseQuery {
}
type ResultBeginBlock struct {
Tags []common.KVPair `json:"tags,omitempty"`
Tags []cmn.KVPair `json:"tags,omitempty"`
}
func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock {
return ResponseBeginBlock(res)
tags := tagsToPointers(res.Tags)
return ResponseBeginBlock{
Tags: tags,
}
}
type ResultCheckTx struct {
Code uint32 `json:"code,omitempty"`
Data []byte `json:"data,omitempty"`
Log string `json:"log,omitempty"`
Info string `json:"info,omitempty"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Tags []common.KVPair `json:"tags,omitempty"`
Fee common.KI64Pair `json:"fee"`
Code uint32 `json:"code,omitempty"`
Data []byte `json:"data,omitempty"`
Log string `json:"log,omitempty"`
Info string `json:"info,omitempty"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Tags []cmn.KVPair `json:"tags,omitempty"`
Fee cmn.KI64Pair `json:"fee"`
}
func FromResultCheckTx(res ResultCheckTx) ResponseCheckTx {
return ResponseCheckTx(res)
tags := tagsToPointers(res.Tags)
return ResponseCheckTx{
Code: res.Code,
Data: res.Data,
Log: res.Log,
Info: res.Info,
GasWanted: res.GasWanted,
GasUsed: res.GasUsed,
Tags: tags,
Fee: &res.Fee,
}
}
type ResultDeliverTx struct {
Code uint32 `json:"code,omitempty"`
Data []byte `json:"data,omitempty"`
Log string `json:"log,omitempty"`
Info string `json:"info,omitempty"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Tags []common.KVPair `json:"tags,omitempty"`
Fee common.KI64Pair `json:"fee"`
Code uint32 `json:"code,omitempty"`
Data []byte `json:"data,omitempty"`
Log string `json:"log,omitempty"`
Info string `json:"info,omitempty"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Tags []cmn.KVPair `json:"tags,omitempty"`
Fee cmn.KI64Pair `json:"fee"`
}
func FromResultDeliverTx(res ResultDeliverTx) ResponseDeliverTx {
return ResponseDeliverTx(res)
tags := tagsToPointers(res.Tags)
return ResponseDeliverTx{
Code: res.Code,
Data: res.Data,
Log: res.Log,
Info: res.Info,
GasWanted: res.GasWanted,
GasUsed: res.GasUsed,
Tags: tags,
Fee: &res.Fee,
}
}
type ResultEndBlock struct {
ValidatorUpdates []Validator `json:"validator_updates"`
ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"`
Tags []common.KVPair `json:"tags,omitempty"`
Tags []cmn.KVPair `json:"tags,omitempty"`
}
func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock {
return ResponseEndBlock(res)
tags := tagsToPointers(res.Tags)
vals := valsToPointers(res.ValidatorUpdates)
return ResponseEndBlock{
ValidatorUpdates: vals,
ConsensusParamUpdates: res.ConsensusParamUpdates,
Tags: tags,
}
}
type ResultCommit struct {
@ -116,3 +148,23 @@ type ResultCommit struct {
func FromResultCommit(res ResultCommit) ResponseCommit {
return ResponseCommit(res)
}
//-------------------------------------------------------
func tagsToPointers(tags []cmn.KVPair) []*cmn.KVPair {
tagPtrs := make([]*cmn.KVPair, len(tags))
for i := 0; i < len(tags); i++ {
t := tags[i]
tagPtrs[i] = &t
}
return tagPtrs
}
func valsToPointers(vals []Validator) []*Validator {
valPtrs := make([]*Validator, len(vals))
for i := 0; i < len(vals); i++ {
v := vals[i]
valPtrs[i] = &v
}
return valPtrs
}

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,9 @@
syntax = "proto3";
package types;
// For more information on gogo.proto, see:
// https://github.com/gogo/protobuf/blob/master/extensions.md
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/tendermint/tmlibs/common/types.proto";
// This file is copied from http://github.com/tendermint/abci
// NOTE: When using custom types, mind the warnings.
// https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
//----------------------------------------
// Request types
@ -47,7 +42,7 @@ message RequestSetOption {
}
message RequestInitChain {
repeated Validator validators = 1 [(gogoproto.nullable)=false];
repeated Validator validators = 1;
bytes genesis_bytes = 2;
}
@ -60,9 +55,9 @@ message RequestQuery {
message RequestBeginBlock {
bytes hash = 1;
Header header = 2 [(gogoproto.nullable)=false];
Header header = 2;
repeated SigningValidator validators = 3;
repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false];
repeated Evidence byzantine_validators = 4;
}
message RequestCheckTx {
@ -128,7 +123,7 @@ message ResponseSetOption {
}
message ResponseInitChain {
repeated Validator validators = 1 [(gogoproto.nullable)=false];
repeated Validator validators = 1;
}
message ResponseQuery {
@ -144,7 +139,7 @@ message ResponseQuery {
}
message ResponseBeginBlock {
repeated common.KVPair tags = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
repeated common.KVPair tags = 1;
}
message ResponseCheckTx {
@ -154,8 +149,8 @@ message ResponseCheckTx {
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
repeated common.KVPair tags = 7;
common.KI64Pair fee = 8;
}
message ResponseDeliverTx {
@ -165,14 +160,14 @@ message ResponseDeliverTx {
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
repeated common.KVPair tags = 7;
common.KI64Pair fee = 8;
}
message ResponseEndBlock {
repeated Validator validator_updates = 1 [(gogoproto.nullable)=false];
repeated Validator validator_updates = 1;
ConsensusParams consensus_param_updates = 2;
repeated common.KVPair tags = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
repeated common.KVPair tags = 3;
}
message ResponseCommit {
@ -217,7 +212,7 @@ message BlockGossip {
// just the minimum the app might need
message Header {
// basics
string chain_id = 1 [(gogoproto.customname)="ChainID"];
string chain_id = 1;
int64 height = 2;
int64 time = 3;
@ -236,7 +231,7 @@ message Header {
// Validator
message Validator {
bytes address = 1;
PubKey pub_key = 2 [(gogoproto.nullable)=false];
PubKey pub_key = 2;
int64 power = 3;
}

View File

@ -15,7 +15,7 @@ const (
func Ed25519Validator(pubkey []byte, power int64) Validator {
return Validator{
// Address:
PubKey: PubKey{
PubKey: &PubKey{
Type: PubKeyEd25519,
Data: pubkey,
},