Merge branch 'master' into brapse/blockchain-v2-riri-routine

This commit is contained in:
Sean Braithwaite 2019-09-18 15:46:29 -04:00 committed by GitHub
commit 211bd64355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 198 additions and 48 deletions

View File

@ -21,6 +21,7 @@ program](https://hackerone.com/tendermint).
- [rpc] \#2010 Add NewHTTPWithClient and NewJSONRPCClientWithHTTPClient (note these and NewHTTP, NewJSONRPCClient functions panic if remote is invalid) (@gracenoah)
- [rpc] \#3984 Add `MempoolClient` interface to `Client` interface
- [rpc] \#3882 Add custom marshalers to proto messages to disable `omitempty`
### BUG FIXES:

View File

@ -15,7 +15,7 @@ BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
all: check build test install
# The below include contains the tools.
include scripts/devtools/Makefile
include tools.mk
include tests.mk
########################################
@ -153,10 +153,6 @@ lint:
DESTINATION = ./index.html.md
rpc-docs:
cat rpc/core/slate_header.txt > $(DESTINATION)
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)
###########################################################
### Docker image

View File

@ -15,9 +15,8 @@ import (
func TestMarshalJSON(t *testing.T) {
b, err := json.Marshal(&ResponseDeliverTx{})
assert.Nil(t, err)
// Do not include empty fields.
assert.False(t, strings.Contains(string(b), "code"))
// include empty fields.
assert.True(t, strings.Contains(string(b), "code"))
r1 := ResponseCheckTx{
Code: 1,
Data: []byte("hello"),

View File

@ -42,14 +42,12 @@ func (r ResponseQuery) IsErr() bool {
}
//---------------------------------------------------------------------------
// override JSON marshalling so we dont emit defaults (ie. disable omitempty)
// note we need Unmarshal functions too because protobuf had the bright idea
// to marshal int64->string. cool. cool, cool, cool: https://developers.google.com/protocol-buffers/docs/proto3#json
// override JSON marshalling so we emit defaults (ie. disable omitempty)
var (
jsonpbMarshaller = jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: false,
EmitDefaults: true,
}
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
)

53
crypto/merkle/result.go Normal file
View File

@ -0,0 +1,53 @@
// nolint: dupl
package merkle
import (
"bytes"
"encoding/json"
"github.com/gogo/protobuf/jsonpb"
)
//---------------------------------------------------------------------------
// override JSON marshalling so we emit defaults (ie. disable omitempty)
var (
jsonpbMarshaller = jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: true,
}
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
)
func (r *ProofOp) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *ProofOp) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Proof) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Proof) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*ProofOp)(nil)
var _ jsonRoundTripper = (*Proof)(nil)

54
libs/common/result.go Normal file
View File

@ -0,0 +1,54 @@
// nolint: dupl
// dupl is reading this as the same file as crypto/merkle/result.go
package common
import (
"bytes"
"encoding/json"
"github.com/gogo/protobuf/jsonpb"
)
//---------------------------------------------------------------------------
// override JSON marshalling so we emit defaults (ie. disable omitempty)
var (
jsonpbMarshaller = jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: true,
}
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
)
func (r *KVPair) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *KVPair) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *KI64Pair) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *KI64Pair) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*KVPair)(nil)
var _ jsonRoundTripper = (*KI64Pair)(nil)

View File

@ -1,15 +1,5 @@
# Tendermint RPC
We are using [Slate](https://github.com/lord/slate) to power our RPC
documentation. For generating markdown use:
```shell
go get github.com/davecheney/godoc2md
# from root of this repo
make rpc-docs
```
## Pagination
Requests that return multiple items will be paginated to 30 items by default.

View File

@ -1,13 +0,0 @@
---
title: RPC Reference
language_tabs: # must be one of https://git.io/vQNgJ
- shell
- go
toc_footers:
- <a href='https://tendermint.com/'>Tendermint</a>
- <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a>
search: true
---

View File

@ -40,7 +40,6 @@ mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
TOOLS_DESTDIR ?= $(GOPATH)/bin
GOIMPORTS = $(TOOLS_DESTDIR)/goimports
CERTSTRAP = $(TOOLS_DESTDIR)/certstrap
PROTOBUF = $(TOOLS_DESTDIR)/protoc
GOX = $(TOOLS_DESTDIR)/gox
@ -48,7 +47,7 @@ GOODMAN = $(TOOLS_DESTDIR)/goodman
all: tools
tools: goimports certstrap protobuf gox goodman
tools: certstrap protobuf gox goodman
check: check_tools
@ -57,11 +56,6 @@ check_tools:
@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
goimports: $(GOIMPORTS)
$(GOIMPORTS):
@echo "Get goimports@v0.0.0-20190628034336-212fb13d595e"
@go get golang.org/x/tools/cmd/goimports@v0.0.0-20190628034336-212fb13d595e
certstrap: $(CERTSTRAP)
$(CERTSTRAP):
@echo "Get Certstrap"
@ -86,7 +80,7 @@ $(GOODMAN):
@go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
tools-clean:
rm -f $(CERTSTRAP) $(GOIMPORTS) $(PROTOBUF) $(GOX) $(GOODMAN)
rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
rm -f tools-stamp
.PHONY: all tools tools-clean

View File

@ -1,4 +1,8 @@
# tm-bench
# tm-bench (Deprecated)
> ## **Deprecation Warning**
### This tool will be depreacted in favor of [tm-load-test](https://github.com/interchainio/tm-load-test).
Tendermint blockchain benchmarking tool:

View File

@ -432,7 +432,7 @@ func (h *Header) StringIndented(indent string) string {
%s Validators: %v
%s NextValidators: %v
%s App: %v
%s Consensus: %v
%s Consensus: %v
%s Results: %v
%s Evidence: %v
%s Proposer: %v

74
types/proto3/result.go Normal file
View File

@ -0,0 +1,74 @@
package proto3
import (
"bytes"
"encoding/json"
"github.com/gogo/protobuf/jsonpb"
)
//---------------------------------------------------------------------------
// override JSON marshalling so we emit defaults (ie. disable omitempty)
var (
jsonpbMarshaller = jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: true,
}
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
)
func (r *PartSetHeader) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *PartSetHeader) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Header) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Header) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Version) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Version) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Timestamp) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Timestamp) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*PartSetHeader)(nil)
var _ jsonRoundTripper = (*Header)(nil)
var _ jsonRoundTripper = (*Version)(nil)
var _ jsonRoundTripper = (*Timestamp)(nil)

View File

@ -83,9 +83,9 @@ func (txs Txs) Proof(i int) TxProof {
// TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.
type TxProof struct {
RootHash cmn.HexBytes
Data Tx
Proof merkle.SimpleProof
RootHash cmn.HexBytes `json:"root_hash"`
Data Tx `json:"data"`
Proof merkle.SimpleProof `json:"proof"`
}
// Leaf returns the hash(tx), which is the leaf in the merkle tree which this proof refers to.