mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-31 23:21:19 +00:00
commit
05a76fb517
@ -16,7 +16,7 @@ jobs:
|
|||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- v2-pkg-cache
|
- v3-pkg-cache
|
||||||
- run:
|
- run:
|
||||||
name: tools
|
name: tools
|
||||||
command: |
|
command: |
|
||||||
@ -38,11 +38,11 @@ jobs:
|
|||||||
- bin
|
- bin
|
||||||
- profiles
|
- profiles
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
paths:
|
paths:
|
||||||
- /go/pkg
|
- /go/pkg
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
paths:
|
paths:
|
||||||
- /go/src/github.com/tendermint/tendermint
|
- /go/src/github.com/tendermint/tendermint
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: slate docs
|
name: slate docs
|
||||||
command: |
|
command: |
|
||||||
@ -68,9 +68,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: metalinter
|
name: metalinter
|
||||||
command: |
|
command: |
|
||||||
@ -84,9 +84,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: Run abci apps tests
|
name: Run abci apps tests
|
||||||
command: |
|
command: |
|
||||||
@ -101,9 +101,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: Run abci-cli tests
|
name: Run abci-cli tests
|
||||||
command: |
|
command: |
|
||||||
@ -116,9 +116,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends bsdmainutils
|
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends bsdmainutils
|
||||||
- run:
|
- run:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
@ -131,14 +131,14 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: mkdir -p /tmp/logs
|
- run: mkdir -p /tmp/logs
|
||||||
- run:
|
- run:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
command: |
|
command: |
|
||||||
for pkg in $(go list github.com/tendermint/tendermint/... | grep -v /vendor/ | circleci tests split --split-by=timings); do
|
for pkg in $(go list github.com/tendermint/tendermint/... | circleci tests split --split-by=timings); do
|
||||||
id=$(basename "$pkg")
|
id=$(basename "$pkg")
|
||||||
|
|
||||||
GOCACHE=off go test -v -timeout 5m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
|
GOCACHE=off go test -v -timeout 5m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
|
||||||
@ -156,9 +156,9 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-pkg-cache
|
key: v3-pkg-cache
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
command: bash test/persist/test_failure_indices.sh
|
command: bash test/persist/test_failure_indices.sh
|
||||||
@ -181,7 +181,7 @@ jobs:
|
|||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: /tmp/workspace
|
at: /tmp/workspace
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v2-tree-{{ .Environment.CIRCLE_SHA1 }}
|
key: v3-tree-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run:
|
- run:
|
||||||
name: gather
|
name: gather
|
||||||
command: |
|
command: |
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,7 +16,6 @@ coverage.txt
|
|||||||
docs/_build
|
docs/_build
|
||||||
*.log
|
*.log
|
||||||
abci-cli
|
abci-cli
|
||||||
abci/types/types.pb.go
|
|
||||||
docs/node_modules/
|
docs/node_modules/
|
||||||
|
|
||||||
scripts/wal2json/wal2json
|
scripts/wal2json/wal2json
|
||||||
|
24
CHANGELOG.md
24
CHANGELOG.md
@ -1,5 +1,26 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## TBA
|
||||||
|
|
||||||
|
## 0.22.5
|
||||||
|
|
||||||
|
*July 23th, 2018*
|
||||||
|
|
||||||
|
BREAKING CHANGES:
|
||||||
|
- [crypto] Refactor `tendermint/crypto` into many subpackages
|
||||||
|
- [libs/common] remove exponentially distributed random numbers
|
||||||
|
|
||||||
|
IMPROVEMENTS:
|
||||||
|
- [abci, libs/common] Generated gogoproto static marshaller methods
|
||||||
|
- [config] Increase default send/recv rates to 5 mB/s
|
||||||
|
- [p2p] allow persistent peers to be private
|
||||||
|
|
||||||
|
BUG FIXES
|
||||||
|
- [mempool] fixed a race condition when `create_empty_blocks=false` where a
|
||||||
|
transaction is published at an old height.
|
||||||
|
- [p2p] dial external IP setup by `persistent_peers`, not internal NAT IP
|
||||||
|
- [rpc] make `/status` RPC endpoint resistant to consensus halt
|
||||||
|
|
||||||
## 0.22.4
|
## 0.22.4
|
||||||
|
|
||||||
*July 14th, 2018*
|
*July 14th, 2018*
|
||||||
@ -14,7 +35,8 @@ FEATURES:
|
|||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
- [tools/tm-bench] Various fixes
|
- [tools/tm-bench] Various fixes
|
||||||
- [consensus] Wait for WAL to stop on shutdown
|
- [consensus] Wait for WAL to stop on shutdown
|
||||||
- [abci] Fix #1891, pending requests cannot hang when abci server dies. Previously a crash in BeginBlock could leave tendermint in broken state.
|
- [abci] Fix #1891, pending requests cannot hang when abci server dies.
|
||||||
|
Previously a crash in BeginBlock could leave tendermint in broken state.
|
||||||
|
|
||||||
## 0.22.3
|
## 0.22.3
|
||||||
|
|
||||||
|
34
Gopkg.lock
generated
34
Gopkg.lock
generated
@ -11,7 +11,8 @@
|
|||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/btcsuite/btcd"
|
name = "github.com/btcsuite/btcd"
|
||||||
packages = ["btcec"]
|
packages = ["btcec"]
|
||||||
revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898"
|
pruneopts = "UT"
|
||||||
|
revision = "f673a4b563b57b9a95832545c878669a7fa801d9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/btcsuite/btcutil"
|
name = "github.com/btcsuite/btcutil"
|
||||||
@ -80,8 +81,8 @@
|
|||||||
"sortkeys",
|
"sortkeys",
|
||||||
"types"
|
"types"
|
||||||
]
|
]
|
||||||
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
|
revision = "7d68e886eac4f7e34d0d82241a6273d6c304c5cf"
|
||||||
version = "v1.0.0"
|
version = "v1.1.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/golang/protobuf"
|
name = "github.com/golang/protobuf"
|
||||||
@ -92,8 +93,8 @@
|
|||||||
"ptypes/duration",
|
"ptypes/duration",
|
||||||
"ptypes/timestamp"
|
"ptypes/timestamp"
|
||||||
]
|
]
|
||||||
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
|
revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265"
|
||||||
version = "v1.0.0"
|
version = "v1.1.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -155,9 +156,11 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
digest = "1:5ab79470a1d0fb19b041a624415612f8236b3c06070161a910562f2b2d064355"
|
||||||
name = "github.com/mitchellh/mapstructure"
|
name = "github.com/mitchellh/mapstructure"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b"
|
pruneopts = "UT"
|
||||||
|
revision = "f15292f7a699fcc1a38a80977f80a046874ba8ac"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/pelletier/go-toml"
|
name = "github.com/pelletier/go-toml"
|
||||||
@ -187,9 +190,11 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
digest = "1:0f37e09b3e92aaeda5991581311f8dbf38944b36a3edec61cc2d1991f527554a"
|
||||||
name = "github.com/prometheus/client_model"
|
name = "github.com/prometheus/client_model"
|
||||||
packages = ["go"]
|
packages = ["go"]
|
||||||
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
|
pruneopts = "UT"
|
||||||
|
revision = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -319,7 +324,7 @@
|
|||||||
"ripemd160",
|
"ripemd160",
|
||||||
"salsa20/salsa"
|
"salsa20/salsa"
|
||||||
]
|
]
|
||||||
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
|
revision = "a2144134853fc9a27a7b1e3eb4f19f1a76df13c9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
@ -342,7 +347,8 @@
|
|||||||
"cpu",
|
"cpu",
|
||||||
"unix"
|
"unix"
|
||||||
]
|
]
|
||||||
revision = "1b2967e3c290b7c545b3db0deeda16e9be4f98a2"
|
pruneopts = "UT"
|
||||||
|
revision = "ac767d655b305d4e9612f5f6e33120b9176c4ad4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "golang.org/x/text"
|
name = "golang.org/x/text"
|
||||||
@ -382,9 +388,11 @@
|
|||||||
"credentials",
|
"credentials",
|
||||||
"encoding",
|
"encoding",
|
||||||
"encoding/proto",
|
"encoding/proto",
|
||||||
"grpclb/grpc_lb_v1/messages",
|
|
||||||
"grpclog",
|
"grpclog",
|
||||||
"internal",
|
"internal",
|
||||||
|
"internal/backoff",
|
||||||
|
"internal/channelz",
|
||||||
|
"internal/grpcrand",
|
||||||
"keepalive",
|
"keepalive",
|
||||||
"metadata",
|
"metadata",
|
||||||
"naming",
|
"naming",
|
||||||
@ -397,8 +405,8 @@
|
|||||||
"tap",
|
"tap",
|
||||||
"transport"
|
"transport"
|
||||||
]
|
]
|
||||||
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
|
revision = "168a6198bcb0ef175f7dacec0b8691fc141dc9b8"
|
||||||
version = "v1.11.3"
|
version = "v1.13.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "gopkg.in/yaml.v2"
|
name = "gopkg.in/yaml.v2"
|
||||||
@ -409,6 +417,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "b0718135d5ade0a75c6b8fe703f70eb9d8064ba871ec31abd9ace3c4ab944100"
|
inputs-digest = "9beb2d27dc19e3f9e2c7f416f312f7129f5441b1b53def42503fc6f7d3a54b16"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
16
Gopkg.toml
16
Gopkg.toml
@ -31,15 +31,15 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/go-kit/kit"
|
name = "github.com/go-kit/kit"
|
||||||
version = "=0.6.0"
|
version = "=0.7.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/gogo/protobuf"
|
name = "github.com/gogo/protobuf"
|
||||||
version = "=1.0.0"
|
version = "=1.1.1"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/golang/protobuf"
|
name = "github.com/golang/protobuf"
|
||||||
version = "=1.0.0"
|
version = "=1.1.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/gorilla/websocket"
|
name = "github.com/gorilla/websocket"
|
||||||
@ -51,23 +51,23 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/spf13/cobra"
|
name = "github.com/spf13/cobra"
|
||||||
version = "=0.0.1"
|
version = "=0.0.3"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/spf13/viper"
|
name = "github.com/spf13/viper"
|
||||||
version = "=1.0.0"
|
version = "=1.0.2"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/stretchr/testify"
|
name = "github.com/stretchr/testify"
|
||||||
version = "=1.2.1"
|
version = "=1.2.2"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
version = "=0.10.1"
|
version = "=v0.11.1"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
version = "=1.11.3"
|
version = "=1.13.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/fortytw2/leaktest"
|
name = "github.com/fortytw2/leaktest"
|
||||||
|
33
Makefile
33
Makefile
@ -5,7 +5,7 @@ GOTOOLS = \
|
|||||||
github.com/gogo/protobuf/protoc-gen-gogo \
|
github.com/gogo/protobuf/protoc-gen-gogo \
|
||||||
github.com/gogo/protobuf/gogoproto \
|
github.com/gogo/protobuf/gogoproto \
|
||||||
github.com/square/certstrap
|
github.com/square/certstrap
|
||||||
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
|
PACKAGES=$(shell go list ./...)
|
||||||
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
|
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
|
||||||
BUILD_TAGS?=tendermint
|
BUILD_TAGS?=tendermint
|
||||||
BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
|
BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
|
||||||
@ -28,16 +28,22 @@ install:
|
|||||||
CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/tendermint
|
CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/tendermint
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
### Build ABCI
|
### Protobuf
|
||||||
|
|
||||||
protoc_abci:
|
protoc_all: protoc_libs protoc_abci protoc_grpc
|
||||||
|
|
||||||
|
%.pb.go: %.proto
|
||||||
## If you get the following error,
|
## If you get the following error,
|
||||||
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
|
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
|
||||||
## See https://stackoverflow.com/a/25518702
|
## See https://stackoverflow.com/a/25518702
|
||||||
protoc $(INCLUDE) --gogo_out=plugins=grpc:. abci/types/*.proto
|
protoc $(INCLUDE) $< --gogo_out=plugins=grpc:.
|
||||||
@echo "--> adding nolint declarations to protobuf generated files"
|
@echo "--> adding nolint declarations to protobuf generated files"
|
||||||
@awk '/package abci/types/ { print "//nolint: gas"; print; next }1' abci/types/types.pb.go > abci/types/types.pb.go.new
|
@awk -i inplace '/^\s*package \w+/ { print "//nolint" }1' $@
|
||||||
@mv abci/types/types.pb.go.new abci/types/types.pb.go
|
|
||||||
|
########################################
|
||||||
|
### Build ABCI
|
||||||
|
|
||||||
|
protoc_abci: abci/types/types.pb.go
|
||||||
|
|
||||||
build_abci:
|
build_abci:
|
||||||
@go build -i ./abci/cmd/...
|
@go build -i ./abci/cmd/...
|
||||||
@ -108,14 +114,7 @@ get_deps_bin_size:
|
|||||||
########################################
|
########################################
|
||||||
### Libs
|
### Libs
|
||||||
|
|
||||||
protoc_libs:
|
protoc_libs: libs/common/types.pb.go
|
||||||
## 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) --go_out=plugins=grpc:. libs/common/*.proto
|
|
||||||
@echo "--> adding nolint declarations to protobuf generated files"
|
|
||||||
@awk '/package libs/common/ { print "//nolint: gas"; print; next }1' libs/common/types.pb.go > libs/common/types.pb.go.new
|
|
||||||
@mv libs/common/types.pb.go.new libs/common/types.pb.go
|
|
||||||
|
|
||||||
gen_certs: clean_certs
|
gen_certs: clean_certs
|
||||||
## Generating certificates for TLS testing...
|
## Generating certificates for TLS testing...
|
||||||
@ -130,12 +129,14 @@ clean_certs:
|
|||||||
rm -f db/remotedb/::.crt db/remotedb/::.key
|
rm -f db/remotedb/::.crt db/remotedb/::.key
|
||||||
|
|
||||||
test_libs: gen_certs
|
test_libs: gen_certs
|
||||||
GOCACHE=off go test -tags gcc $(shell go list ./... | grep -v vendor)
|
GOCACHE=off go test -tags gcc $(PACKAGES)
|
||||||
make clean_certs
|
make clean_certs
|
||||||
|
|
||||||
grpc_dbserver:
|
grpc_dbserver:
|
||||||
protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto
|
protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto
|
||||||
|
|
||||||
|
protoc_grpc: rpc/grpc/types.pb.go
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
### Testing
|
### Testing
|
||||||
|
|
||||||
@ -307,4 +308,4 @@ build-slate:
|
|||||||
# To avoid unintended conflicts with file names, always add to .PHONY
|
# To avoid unintended conflicts with file names, always add to .PHONY
|
||||||
# unless there is a reason not to.
|
# unless there is a reason not to.
|
||||||
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
|
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
|
||||||
.PHONY: check build build_race build_abci dist install install_abci check_tools get_tools update_tools get_vendor_deps 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 build-linux localnet-start localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop build-slate
|
.PHONY: check build build_race build_abci dist install install_abci check_tools get_tools update_tools get_vendor_deps 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 build-linux localnet-start localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop build-slate protoc_grpc protoc_all
|
||||||
|
@ -50,13 +50,13 @@ Go version | Go1.9 or higher
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
See the [install instructions](/docs/install.md)
|
See the [install instructions](/docs/introduction/install.md)
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
- [Single node](/docs/using-tendermint.md)
|
- [Single node](/docs/using-tendermint.md)
|
||||||
- [Local cluster using docker-compose](/networks/local)
|
- [Local cluster using docker-compose](/networks/local)
|
||||||
- [Remote cluster using terraform and ansible](/docs/terraform-and-ansible.md)
|
- [Remote cluster using terraform and ansible](/docs/networks/terraform-and-ansible.md)
|
||||||
- [Join the public testnet](https://cosmos.network/testnet)
|
- [Join the public testnet](https://cosmos.network/testnet)
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,12 +4,21 @@ package types;
|
|||||||
// For more information on gogo.proto, see:
|
// For more information on gogo.proto, see:
|
||||||
// https://github.com/gogo/protobuf/blob/master/extensions.md
|
// https://github.com/gogo/protobuf/blob/master/extensions.md
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||||
import "github.com/tendermint/tmlibs/common/types.proto";
|
import "github.com/tendermint/tendermint/libs/common/types.proto";
|
||||||
|
|
||||||
// This file is copied from http://github.com/tendermint/abci
|
// This file is copied from http://github.com/tendermint/abci
|
||||||
// NOTE: When using custom types, mind the warnings.
|
// NOTE: When using custom types, mind the warnings.
|
||||||
// https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
|
// https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
option (gogoproto.goproto_registration) = true;
|
||||||
|
// Generate tests
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
option (gogoproto.testgen_all) = true;
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
// Request types
|
// Request types
|
||||||
|
|
||||||
|
4281
abci/types/typespb_test.go
Normal file
4281
abci/types/typespb_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
|
|
||||||
proto "github.com/tendermint/tendermint/benchmarks/proto"
|
proto "github.com/tendermint/tendermint/benchmarks/proto"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
)
|
)
|
||||||
@ -16,7 +16,7 @@ func BenchmarkEncodeStatusWire(b *testing.B) {
|
|||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
cdc := amino.NewCodec()
|
cdc := amino.NewCodec()
|
||||||
ctypes.RegisterAmino(cdc)
|
ctypes.RegisterAmino(cdc)
|
||||||
nodeKey := p2p.NodeKey{PrivKey: crypto.GenPrivKeyEd25519()}
|
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
|
||||||
status := &ctypes.ResultStatus{
|
status := &ctypes.ResultStatus{
|
||||||
NodeInfo: p2p.NodeInfo{
|
NodeInfo: p2p.NodeInfo{
|
||||||
ID: nodeKey.ID(),
|
ID: nodeKey.ID(),
|
||||||
@ -52,7 +52,7 @@ func BenchmarkEncodeNodeInfoWire(b *testing.B) {
|
|||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
cdc := amino.NewCodec()
|
cdc := amino.NewCodec()
|
||||||
ctypes.RegisterAmino(cdc)
|
ctypes.RegisterAmino(cdc)
|
||||||
nodeKey := p2p.NodeKey{PrivKey: crypto.GenPrivKeyEd25519()}
|
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
|
||||||
nodeInfo := p2p.NodeInfo{
|
nodeInfo := p2p.NodeInfo{
|
||||||
ID: nodeKey.ID(),
|
ID: nodeKey.ID(),
|
||||||
Moniker: "SOMENAME",
|
Moniker: "SOMENAME",
|
||||||
@ -77,7 +77,7 @@ func BenchmarkEncodeNodeInfoBinary(b *testing.B) {
|
|||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
cdc := amino.NewCodec()
|
cdc := amino.NewCodec()
|
||||||
ctypes.RegisterAmino(cdc)
|
ctypes.RegisterAmino(cdc)
|
||||||
nodeKey := p2p.NodeKey{PrivKey: crypto.GenPrivKeyEd25519()}
|
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
|
||||||
nodeInfo := p2p.NodeInfo{
|
nodeInfo := p2p.NodeInfo{
|
||||||
ID: nodeKey.ID(),
|
ID: nodeKey.ID(),
|
||||||
Moniker: "SOMENAME",
|
Moniker: "SOMENAME",
|
||||||
@ -98,7 +98,7 @@ func BenchmarkEncodeNodeInfoBinary(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkEncodeNodeInfoProto(b *testing.B) {
|
func BenchmarkEncodeNodeInfoProto(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
nodeKey := p2p.NodeKey{PrivKey: crypto.GenPrivKeyEd25519()}
|
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
|
||||||
nodeID := string(nodeKey.ID())
|
nodeID := string(nodeKey.ID())
|
||||||
someName := "SOMENAME"
|
someName := "SOMENAME"
|
||||||
someAddr := "SOMEADDR"
|
someAddr := "SOMEADDR"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package blockchain
|
package blockchain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ func makePeers(numPeers int, minHeight, maxHeight int64) map[p2p.ID]testPeer {
|
|||||||
peers := make(map[p2p.ID]testPeer, numPeers)
|
peers := make(map[p2p.ID]testPeer, numPeers)
|
||||||
for i := 0; i < numPeers; i++ {
|
for i := 0; i < numPeers; i++ {
|
||||||
peerID := p2p.ID(cmn.RandStr(12))
|
peerID := p2p.ID(cmn.RandStr(12))
|
||||||
height := minHeight + rand.Int63n(maxHeight-minHeight)
|
height := minHeight + cmn.RandInt63n(maxHeight-minHeight)
|
||||||
peers[peerID] = testPeer{peerID, height}
|
peers[peerID] = testPeer{peerID, height}
|
||||||
}
|
}
|
||||||
return peers
|
return peers
|
||||||
@ -80,7 +79,7 @@ func TestBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// Request desired, pretend like we got the block immediately.
|
// Request desired, pretend like we got the block immediately.
|
||||||
go func() {
|
go func() {
|
||||||
block := &types.Block{Header: &types.Header{Height: request.Height}}
|
block := &types.Block{Header: types.Header{Height: request.Height}}
|
||||||
pool.AddBlock(request.PeerID, block, 123)
|
pool.AddBlock(request.PeerID, block, 123)
|
||||||
t.Logf("Added block from peer %v (height: %v)", request.PeerID, request.Height)
|
t.Logf("Added block from peer %v (height: %v)", request.PeerID, request.Height)
|
||||||
}()
|
}()
|
||||||
|
@ -206,3 +206,4 @@ func (tp *bcrTestPeer) IsPersistent() bool { return true }
|
|||||||
func (tp *bcrTestPeer) Get(s string) interface{} { return s }
|
func (tp *bcrTestPeer) Get(s string) interface{} { return s }
|
||||||
func (tp *bcrTestPeer) Set(string, interface{}) {}
|
func (tp *bcrTestPeer) Set(string, interface{}) {}
|
||||||
func (tp *bcrTestPeer) RemoteIP() net.IP { return []byte{127, 0, 0, 1} }
|
func (tp *bcrTestPeer) RemoteIP() net.IP { return []byte{127, 0, 0, 1} }
|
||||||
|
func (tp *bcrTestPeer) OriginalAddr() *p2p.NetAddress { return nil }
|
||||||
|
@ -126,7 +126,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
eraseSeenCommitInDB bool
|
eraseSeenCommitInDB bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
},
|
},
|
||||||
@ -137,19 +137,19 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header2, commitAtH10),
|
block: newBlock(header2, commitAtH10),
|
||||||
parts: uncontiguousPartSet,
|
parts: uncontiguousPartSet,
|
||||||
wantPanic: "only save contiguous blocks", // and incomplete and uncontiguous parts
|
wantPanic: "only save contiguous blocks", // and incomplete and uncontiguous parts
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: incompletePartSet,
|
parts: incompletePartSet,
|
||||||
wantPanic: "only save complete block", // incomplete parts
|
wantPanic: "only save complete block", // incomplete parts
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
corruptCommitInDB: true, // Corrupt the DB's commit entry
|
corruptCommitInDB: true, // Corrupt the DB's commit entry
|
||||||
@ -157,7 +157,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
wantPanic: "unmarshal to types.BlockMeta failed",
|
wantPanic: "unmarshal to types.BlockMeta failed",
|
||||||
@ -165,7 +165,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ func doFn(fn func() (interface{}, error)) (res interface{}, err error, panicErr
|
|||||||
return res, err, panicErr
|
return res, err, panicErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBlock(hdr *types.Header, lastCommit *types.Commit) *types.Block {
|
func newBlock(hdr types.Header, lastCommit *types.Commit) *types.Block {
|
||||||
return &types.Block{
|
return &types.Block{
|
||||||
Header: hdr,
|
Header: hdr,
|
||||||
LastCommit: lastCommit,
|
LastCommit: lastCommit,
|
||||||
|
@ -2,12 +2,12 @@ package blockchain
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterBlockchainMessages(cdc)
|
RegisterBlockchainMessages(cdc)
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func main() {
|
|||||||
*chainID,
|
*chainID,
|
||||||
*addr,
|
*addr,
|
||||||
pv,
|
pv,
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
err := rs.Start()
|
err := rs.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,11 +2,11 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -21,3 +21,4 @@ ignore:
|
|||||||
- "docs"
|
- "docs"
|
||||||
- "DOCKER"
|
- "DOCKER"
|
||||||
- "scripts"
|
- "scripts"
|
||||||
|
- "**/*.pb.go"
|
||||||
|
@ -284,7 +284,6 @@ type P2PConfig struct {
|
|||||||
Seeds string `mapstructure:"seeds"`
|
Seeds string `mapstructure:"seeds"`
|
||||||
|
|
||||||
// Comma separated list of nodes to keep persistent connections to
|
// Comma separated list of nodes to keep persistent connections to
|
||||||
// Do not add private peers to this list if you don't want them advertised
|
|
||||||
PersistentPeers string `mapstructure:"persistent_peers"`
|
PersistentPeers string `mapstructure:"persistent_peers"`
|
||||||
|
|
||||||
// UPNP port forwarding
|
// UPNP port forwarding
|
||||||
@ -350,8 +349,8 @@ func DefaultP2PConfig() *P2PConfig {
|
|||||||
MaxNumPeers: 50,
|
MaxNumPeers: 50,
|
||||||
FlushThrottleTimeout: 100,
|
FlushThrottleTimeout: 100,
|
||||||
MaxPacketMsgPayloadSize: 1024, // 1 kB
|
MaxPacketMsgPayloadSize: 1024, // 1 kB
|
||||||
SendRate: 512000, // 500 kB/s
|
SendRate: 5120000, // 5 mB/s
|
||||||
RecvRate: 512000, // 500 kB/s
|
RecvRate: 5120000, // 5 mB/s
|
||||||
PexReactor: true,
|
PexReactor: true,
|
||||||
SeedMode: false,
|
SeedMode: false,
|
||||||
AllowDuplicateIP: true, // so non-breaking yet
|
AllowDuplicateIP: true, // so non-breaking yet
|
||||||
|
@ -152,7 +152,6 @@ external_address = "{{ .P2P.ExternalAddress }}"
|
|||||||
seeds = "{{ .P2P.Seeds }}"
|
seeds = "{{ .P2P.Seeds }}"
|
||||||
|
|
||||||
# Comma separated list of nodes to keep persistent connections to
|
# Comma separated list of nodes to keep persistent connections to
|
||||||
# Do not add private peers to this list if you don't want them advertised
|
|
||||||
persistent_peers = "{{ .P2P.PersistentPeers }}"
|
persistent_peers = "{{ .P2P.PersistentPeers }}"
|
||||||
|
|
||||||
# UPNP port forwarding
|
# UPNP port forwarding
|
||||||
|
@ -81,7 +81,7 @@ type ConsensusState struct {
|
|||||||
evpool sm.EvidencePool
|
evpool sm.EvidencePool
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
mtx sync.Mutex
|
mtx sync.RWMutex
|
||||||
cstypes.RoundState
|
cstypes.RoundState
|
||||||
state sm.State // State until height-1.
|
state sm.State // State until height-1.
|
||||||
|
|
||||||
@ -192,15 +192,15 @@ func (cs *ConsensusState) String() string {
|
|||||||
|
|
||||||
// GetState returns a copy of the chain state.
|
// GetState returns a copy of the chain state.
|
||||||
func (cs *ConsensusState) GetState() sm.State {
|
func (cs *ConsensusState) GetState() sm.State {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
return cs.state.Copy()
|
return cs.state.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoundState returns a shallow copy of the internal consensus state.
|
// GetRoundState returns a shallow copy of the internal consensus state.
|
||||||
func (cs *ConsensusState) GetRoundState() *cstypes.RoundState {
|
func (cs *ConsensusState) GetRoundState() *cstypes.RoundState {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
|
|
||||||
rs := cs.RoundState // copy
|
rs := cs.RoundState // copy
|
||||||
return &rs
|
return &rs
|
||||||
@ -208,24 +208,24 @@ func (cs *ConsensusState) GetRoundState() *cstypes.RoundState {
|
|||||||
|
|
||||||
// GetRoundStateJSON returns a json of RoundState, marshalled using go-amino.
|
// GetRoundStateJSON returns a json of RoundState, marshalled using go-amino.
|
||||||
func (cs *ConsensusState) GetRoundStateJSON() ([]byte, error) {
|
func (cs *ConsensusState) GetRoundStateJSON() ([]byte, error) {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
|
|
||||||
return cdc.MarshalJSON(cs.RoundState)
|
return cdc.MarshalJSON(cs.RoundState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoundStateSimpleJSON returns a json of RoundStateSimple, marshalled using go-amino.
|
// GetRoundStateSimpleJSON returns a json of RoundStateSimple, marshalled using go-amino.
|
||||||
func (cs *ConsensusState) GetRoundStateSimpleJSON() ([]byte, error) {
|
func (cs *ConsensusState) GetRoundStateSimpleJSON() ([]byte, error) {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
|
|
||||||
return cdc.MarshalJSON(cs.RoundState.RoundStateSimple())
|
return cdc.MarshalJSON(cs.RoundState.RoundStateSimple())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidators returns a copy of the current validators.
|
// GetValidators returns a copy of the current validators.
|
||||||
func (cs *ConsensusState) GetValidators() (int64, []*types.Validator) {
|
func (cs *ConsensusState) GetValidators() (int64, []*types.Validator) {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
return cs.state.LastBlockHeight, cs.state.Validators.Copy().Validators
|
return cs.state.LastBlockHeight, cs.state.Validators.Copy().Validators
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,8 +245,8 @@ func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker) {
|
|||||||
|
|
||||||
// LoadCommit loads the commit for a given height.
|
// LoadCommit loads the commit for a given height.
|
||||||
func (cs *ConsensusState) LoadCommit(height int64) *types.Commit {
|
func (cs *ConsensusState) LoadCommit(height int64) *types.Commit {
|
||||||
cs.mtx.Lock()
|
cs.mtx.RLock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.RUnlock()
|
||||||
if height == cs.blockStore.Height() {
|
if height == cs.blockStore.Height() {
|
||||||
return cs.blockStore.LoadSeenCommit(height)
|
return cs.blockStore.LoadSeenCommit(height)
|
||||||
}
|
}
|
||||||
@ -571,8 +571,8 @@ func (cs *ConsensusState) receiveRoutine(maxSteps int) {
|
|||||||
var mi msgInfo
|
var mi msgInfo
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case height := <-cs.mempool.TxsAvailable():
|
case <-cs.mempool.TxsAvailable():
|
||||||
cs.handleTxsAvailable(height)
|
cs.handleTxsAvailable()
|
||||||
case mi = <-cs.peerMsgQueue:
|
case mi = <-cs.peerMsgQueue:
|
||||||
cs.wal.Write(mi)
|
cs.wal.Write(mi)
|
||||||
// handles proposals, block parts, votes
|
// handles proposals, block parts, votes
|
||||||
@ -683,11 +683,11 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ConsensusState) handleTxsAvailable(height int64) {
|
func (cs *ConsensusState) handleTxsAvailable() {
|
||||||
cs.mtx.Lock()
|
cs.mtx.Lock()
|
||||||
defer cs.mtx.Unlock()
|
defer cs.mtx.Unlock()
|
||||||
// we only need to do this for round 0
|
// we only need to do this for round 0
|
||||||
cs.enterPropose(height, 0)
|
cs.enterPropose(cs.Height, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -4,10 +4,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
||||||
@ -23,7 +23,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
|||||||
Hash: cmn.RandBytes(20),
|
Hash: cmn.RandBytes(20),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
sig := crypto.SignatureEd25519{}
|
sig := ed25519.SignatureEd25519{}
|
||||||
for i := 0; i < nval; i++ {
|
for i := 0; i < nval; i++ {
|
||||||
precommits[i] = &types.Vote{
|
precommits[i] = &types.Vote{
|
||||||
ValidatorAddress: types.Address(cmn.RandBytes(20)),
|
ValidatorAddress: types.Address(cmn.RandBytes(20)),
|
||||||
@ -38,7 +38,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
|||||||
}
|
}
|
||||||
// Random block
|
// Random block
|
||||||
block := &types.Block{
|
block := &types.Block{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
ChainID: cmn.RandStr(12),
|
ChainID: cmn.RandStr(12),
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
LastBlockID: blockID,
|
LastBlockID: blockID,
|
||||||
@ -50,7 +50,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
|||||||
LastResultsHash: cmn.RandBytes(20),
|
LastResultsHash: cmn.RandBytes(20),
|
||||||
EvidenceHash: cmn.RandBytes(20),
|
EvidenceHash: cmn.RandBytes(20),
|
||||||
},
|
},
|
||||||
Data: &types.Data{
|
Data: types.Data{
|
||||||
Txs: txs,
|
Txs: txs,
|
||||||
},
|
},
|
||||||
Evidence: types.EvidenceData{},
|
Evidence: types.EvidenceData{},
|
||||||
|
@ -2,11 +2,11 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package consensus
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
@ -10,5 +10,5 @@ var cdc = amino.NewCodec()
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterConsensusMessages(cdc)
|
RegisterConsensusMessages(cdc)
|
||||||
RegisterWALMessages(cdc)
|
RegisterWALMessages(cdc)
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,15 @@
|
|||||||
crypto is the cryptographic package adapted for Tendermint's uses
|
crypto is the cryptographic package adapted for Tendermint's uses
|
||||||
|
|
||||||
## Importing it
|
## Importing it
|
||||||
|
To get the interfaces,
|
||||||
`import "github.com/tendermint/tendermint/crypto"`
|
`import "github.com/tendermint/tendermint/crypto"`
|
||||||
|
|
||||||
|
For any specific algorithm, use its specific module e.g.
|
||||||
|
`import "github.com/tendermint/tendermint/crypto/ed25519"`
|
||||||
|
|
||||||
|
If you want to decode bytes into one of the types, but don't care about the specific algorithm, use
|
||||||
|
`import "github.com/tendermint/tendermint/crypto/amino"`
|
||||||
|
|
||||||
## Binary encoding
|
## Binary encoding
|
||||||
|
|
||||||
For Binary encoding, please refer to the [Tendermint encoding spec](https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/encoding.md).
|
For Binary encoding, please refer to the [Tendermint encoding spec](https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/encoding.md).
|
||||||
@ -16,9 +23,9 @@ crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
|
|||||||
```go
|
```go
|
||||||
Example Amino:JSON encodings:
|
Example Amino:JSON encodings:
|
||||||
|
|
||||||
crypto.PrivKeyEd25519 - {"type":"954568A3288910","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="}
|
ed25519.PrivKeyEd25519 - {"type":"954568A3288910","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="}
|
||||||
crypto.SignatureEd25519 - {"type":"6BF5903DA1DB28","value":"77sQNZOrf7ltExpf7AV1WaYPCHbyRLgjBsoWVzcduuLk+jIGmYk+s5R6Emm29p12HeiNAuhUJgdFGmwkpeGJCA=="}
|
crypto.SignatureEd25519 - {"type":"6BF5903DA1DB28","value":"77sQNZOrf7ltExpf7AV1WaYPCHbyRLgjBsoWVzcduuLk+jIGmYk+s5R6Emm29p12HeiNAuhUJgdFGmwkpeGJCA=="}
|
||||||
crypto.PubKeyEd25519 - {"type":"AC26791624DE60","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="}
|
ed25519.PubKeyEd25519 - {"type":"AC26791624DE60","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="}
|
||||||
crypto.PrivKeySecp256k1 - {"type":"019E82E1B0F798","value":"zx4Pnh67N+g2V+5vZbQzEyRerX9c4ccNZOVzM9RvJ0Y="}
|
crypto.PrivKeySecp256k1 - {"type":"019E82E1B0F798","value":"zx4Pnh67N+g2V+5vZbQzEyRerX9c4ccNZOVzM9RvJ0Y="}
|
||||||
crypto.SignatureSecp256k1 - {"type":"6D1EA416E1FEE8","value":"MEUCIQCIg5TqS1l7I+MKTrSPIuUN2+4m5tA29dcauqn3NhEJ2wIgICaZ+lgRc5aOTVahU/XoLopXKn8BZcl0bnuYWLvohR8="}
|
crypto.SignatureSecp256k1 - {"type":"6D1EA416E1FEE8","value":"MEUCIQCIg5TqS1l7I+MKTrSPIuUN2+4m5tA29dcauqn3NhEJ2wIgICaZ+lgRc5aOTVahU/XoLopXKn8BZcl0bnuYWLvohR8="}
|
||||||
crypto.PubKeySecp256k1 - {"type":"F8CCEAEB5AE980","value":"A8lPKJXcNl5VHt1FK8a244K9EJuS4WX1hFBnwisi0IJx"}
|
crypto.PubKeySecp256k1 - {"type":"F8CCEAEB5AE980","value":"A8lPKJXcNl5VHt1FK8a244K9EJuS4WX1hFBnwisi0IJx"}
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
amino "github.com/tendermint/go-amino"
|
|
||||||
)
|
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// NOTE: It's important that there be no conflicts here,
|
|
||||||
// as that would change the canonical representations,
|
|
||||||
// and therefore change the address.
|
|
||||||
// TODO: Add feature to go-amino to ensure that there
|
|
||||||
// are no conflicts.
|
|
||||||
RegisterAmino(cdc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterAmino registers all crypto related types in the given (amino) codec.
|
|
||||||
func RegisterAmino(cdc *amino.Codec) {
|
|
||||||
cdc.RegisterInterface((*PubKey)(nil), nil)
|
|
||||||
cdc.RegisterConcrete(PubKeyEd25519{},
|
|
||||||
"tendermint/PubKeyEd25519", nil)
|
|
||||||
cdc.RegisterConcrete(PubKeySecp256k1{},
|
|
||||||
"tendermint/PubKeySecp256k1", nil)
|
|
||||||
|
|
||||||
cdc.RegisterInterface((*PrivKey)(nil), nil)
|
|
||||||
cdc.RegisterConcrete(PrivKeyEd25519{},
|
|
||||||
"tendermint/PrivKeyEd25519", nil)
|
|
||||||
cdc.RegisterConcrete(PrivKeySecp256k1{},
|
|
||||||
"tendermint/PrivKeySecp256k1", nil)
|
|
||||||
|
|
||||||
cdc.RegisterInterface((*Signature)(nil), nil)
|
|
||||||
cdc.RegisterConcrete(SignatureEd25519{},
|
|
||||||
"tendermint/SignatureEd25519", nil)
|
|
||||||
cdc.RegisterConcrete(SignatureSecp256k1{},
|
|
||||||
"tendermint/SignatureSecp256k1", nil)
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package armor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package armor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
36
crypto/crypto.go
Normal file
36
crypto/crypto.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package crypto
|
||||||
|
|
||||||
|
import (
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PrivKey interface {
|
||||||
|
Bytes() []byte
|
||||||
|
Sign(msg []byte) (Signature, error)
|
||||||
|
PubKey() PubKey
|
||||||
|
Equals(PrivKey) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// An address is a []byte, but hex-encoded even in JSON.
|
||||||
|
// []byte leaves us the option to change the address length.
|
||||||
|
// Use an alias so Unmarshal methods (with ptr receivers) are available too.
|
||||||
|
type Address = cmn.HexBytes
|
||||||
|
|
||||||
|
type PubKey interface {
|
||||||
|
Address() Address
|
||||||
|
Bytes() []byte
|
||||||
|
VerifyBytes(msg []byte, sig Signature) bool
|
||||||
|
Equals(PubKey) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Signature interface {
|
||||||
|
Bytes() []byte
|
||||||
|
IsZero() bool
|
||||||
|
Equals(Signature) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Symmetric interface {
|
||||||
|
Keygen() []byte
|
||||||
|
Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
|
||||||
|
Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
|
||||||
|
}
|
@ -22,7 +22,7 @@
|
|||||||
// pubKey := key.PubKey()
|
// pubKey := key.PubKey()
|
||||||
|
|
||||||
// For example:
|
// For example:
|
||||||
// privKey, err := crypto.GenPrivKeyEd25519()
|
// privKey, err := ed25519.GenPrivKey()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
|
227
crypto/ed25519/ed25519.go
Normal file
227
crypto/ed25519/ed25519.go
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
package ed25519
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/subtle"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/tendermint/ed25519"
|
||||||
|
"github.com/tendermint/ed25519/extra25519"
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.PrivKey = PrivKeyEd25519{}
|
||||||
|
|
||||||
|
const (
|
||||||
|
Ed25519PrivKeyAminoRoute = "tendermint/PrivKeyEd25519"
|
||||||
|
Ed25519PubKeyAminoRoute = "tendermint/PubKeyEd25519"
|
||||||
|
Ed25519SignatureAminoRoute = "tendermint/SignatureEd25519"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(PubKeyEd25519{},
|
||||||
|
Ed25519PubKeyAminoRoute, nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(PrivKeyEd25519{},
|
||||||
|
Ed25519PrivKeyAminoRoute, nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.Signature)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(SignatureEd25519{},
|
||||||
|
Ed25519SignatureAminoRoute, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrivKeyEd25519 implements crypto.PrivKey.
|
||||||
|
type PrivKeyEd25519 [64]byte
|
||||||
|
|
||||||
|
// Bytes marshals the privkey using amino encoding.
|
||||||
|
func (privKey PrivKeyEd25519) Bytes() []byte {
|
||||||
|
return cdc.MustMarshalBinaryBare(privKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign produces a signature on the provided message.
|
||||||
|
func (privKey PrivKeyEd25519) Sign(msg []byte) (crypto.Signature, error) {
|
||||||
|
privKeyBytes := [64]byte(privKey)
|
||||||
|
signatureBytes := ed25519.Sign(&privKeyBytes, msg)
|
||||||
|
return SignatureEd25519(*signatureBytes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PubKey gets the corresponding public key from the private key.
|
||||||
|
func (privKey PrivKeyEd25519) PubKey() crypto.PubKey {
|
||||||
|
privKeyBytes := [64]byte(privKey)
|
||||||
|
initialized := false
|
||||||
|
// If the latter 32 bytes of the privkey are all zero, compute the pubkey
|
||||||
|
// otherwise privkey is initialized and we can use the cached value inside
|
||||||
|
// of the private key.
|
||||||
|
for _, v := range privKeyBytes[32:] {
|
||||||
|
if v != 0 {
|
||||||
|
initialized = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if initialized {
|
||||||
|
var pubkeyBytes [PubKeyEd25519Size]byte
|
||||||
|
copy(pubkeyBytes[:], privKeyBytes[32:])
|
||||||
|
return PubKeyEd25519(pubkeyBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
pubBytes := *ed25519.MakePublicKey(&privKeyBytes)
|
||||||
|
return PubKeyEd25519(pubBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equals - you probably don't need to use this.
|
||||||
|
// Runs in constant time based on length of the keys.
|
||||||
|
func (privKey PrivKeyEd25519) Equals(other crypto.PrivKey) bool {
|
||||||
|
if otherEd, ok := other.(PrivKeyEd25519); ok {
|
||||||
|
return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToCurve25519 takes a private key and returns its representation on
|
||||||
|
// Curve25519. Curve25519 is birationally equivalent to Edwards25519,
|
||||||
|
// which Ed25519 uses internally. This method is intended for use in
|
||||||
|
// an X25519 Diffie Hellman key exchange.
|
||||||
|
func (privKey PrivKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte {
|
||||||
|
keyCurve25519 := new([32]byte)
|
||||||
|
privKeyBytes := [64]byte(privKey)
|
||||||
|
extra25519.PrivateKeyToCurve25519(keyCurve25519, &privKeyBytes)
|
||||||
|
return keyCurve25519
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenPrivKey generates a new ed25519 private key.
|
||||||
|
// It uses OS randomness in conjunction with the current global random seed
|
||||||
|
// in tendermint/libs/common to generate the private key.
|
||||||
|
func GenPrivKey() PrivKeyEd25519 {
|
||||||
|
privKey := new([64]byte)
|
||||||
|
copy(privKey[:32], crypto.CRandBytes(32))
|
||||||
|
// ed25519.MakePublicKey(privKey) alters the last 32 bytes of privKey.
|
||||||
|
// It places the pubkey in the last 32 bytes of privKey, and returns the
|
||||||
|
// public key.
|
||||||
|
ed25519.MakePublicKey(privKey)
|
||||||
|
return PrivKeyEd25519(*privKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenPrivKeyFromSecret hashes the secret with SHA2, and uses
|
||||||
|
// that 32 byte output to create the private key.
|
||||||
|
// NOTE: secret should be the output of a KDF like bcrypt,
|
||||||
|
// if it's derived from user input.
|
||||||
|
func GenPrivKeyFromSecret(secret []byte) PrivKeyEd25519 {
|
||||||
|
privKey32 := crypto.Sha256(secret) // Not Ripemd160 because we want 32 bytes.
|
||||||
|
privKey := new([64]byte)
|
||||||
|
copy(privKey[:32], privKey32)
|
||||||
|
// ed25519.MakePublicKey(privKey) alters the last 32 bytes of privKey.
|
||||||
|
// It places the pubkey in the last 32 bytes of privKey, and returns the
|
||||||
|
// public key.
|
||||||
|
ed25519.MakePublicKey(privKey)
|
||||||
|
return PrivKeyEd25519(*privKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.PubKey = PubKeyEd25519{}
|
||||||
|
|
||||||
|
// PubKeyEd25519Size is the number of bytes in an Ed25519 signature.
|
||||||
|
const PubKeyEd25519Size = 32
|
||||||
|
|
||||||
|
// PubKeyEd25519 implements crypto.PubKey for the Ed25519 signature scheme.
|
||||||
|
type PubKeyEd25519 [PubKeyEd25519Size]byte
|
||||||
|
|
||||||
|
// Address is the SHA256-20 of the raw pubkey bytes.
|
||||||
|
func (pubKey PubKeyEd25519) Address() crypto.Address {
|
||||||
|
return crypto.Address(tmhash.Sum(pubKey[:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bytes marshals the PubKey using amino encoding.
|
||||||
|
func (pubKey PubKeyEd25519) Bytes() []byte {
|
||||||
|
bz, err := cdc.MarshalBinaryBare(pubKey)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return bz
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ crypto.Signature) bool {
|
||||||
|
// make sure we use the same algorithm to sign
|
||||||
|
sig, ok := sig_.(SignatureEd25519)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
pubKeyBytes := [PubKeyEd25519Size]byte(pubKey)
|
||||||
|
sigBytes := [SignatureEd25519Size]byte(sig)
|
||||||
|
return ed25519.Verify(&pubKeyBytes, msg, &sigBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToCurve25519 takes a public key and returns its representation on
|
||||||
|
// Curve25519. Curve25519 is birationally equivalent to Edwards25519,
|
||||||
|
// which Ed25519 uses internally. This method is intended for use in
|
||||||
|
// an X25519 Diffie Hellman key exchange.
|
||||||
|
//
|
||||||
|
// If there is an error, then this function returns nil.
|
||||||
|
func (pubKey PubKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte {
|
||||||
|
keyCurve25519, pubKeyBytes := new([PubKeyEd25519Size]byte), [PubKeyEd25519Size]byte(pubKey)
|
||||||
|
ok := extra25519.PublicKeyToCurve25519(keyCurve25519, &pubKeyBytes)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return keyCurve25519
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pubKey PubKeyEd25519) String() string {
|
||||||
|
return fmt.Sprintf("PubKeyEd25519{%X}", pubKey[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// nolint: golint
|
||||||
|
func (pubKey PubKeyEd25519) Equals(other crypto.PubKey) bool {
|
||||||
|
if otherEd, ok := other.(PubKeyEd25519); ok {
|
||||||
|
return bytes.Equal(pubKey[:], otherEd[:])
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.Signature = SignatureEd25519{}
|
||||||
|
|
||||||
|
// Size of an Edwards25519 signature. Namely the size of a compressed
|
||||||
|
// Edwards25519 point, and a field element. Both of which are 32 bytes.
|
||||||
|
const SignatureEd25519Size = 64
|
||||||
|
|
||||||
|
// SignatureEd25519 implements crypto.Signature
|
||||||
|
type SignatureEd25519 [SignatureEd25519Size]byte
|
||||||
|
|
||||||
|
func (sig SignatureEd25519) Bytes() []byte {
|
||||||
|
bz, err := cdc.MarshalBinaryBare(sig)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return bz
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
||||||
|
|
||||||
|
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", cmn.Fingerprint(sig[:])) }
|
||||||
|
|
||||||
|
func (sig SignatureEd25519) Equals(other crypto.Signature) bool {
|
||||||
|
if otherEd, ok := other.(SignatureEd25519); ok {
|
||||||
|
return subtle.ConstantTimeCompare(sig[:], otherEd[:]) == 1
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SignatureEd25519FromBytes(data []byte) crypto.Signature {
|
||||||
|
var sig SignatureEd25519
|
||||||
|
copy(sig[:], data)
|
||||||
|
return sig
|
||||||
|
}
|
31
crypto/ed25519/ed25519_test.go
Normal file
31
crypto/ed25519/ed25519_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package ed25519_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSignAndValidateEd25519(t *testing.T) {
|
||||||
|
|
||||||
|
privKey := ed25519.GenPrivKey()
|
||||||
|
pubKey := privKey.PubKey()
|
||||||
|
|
||||||
|
msg := crypto.CRandBytes(128)
|
||||||
|
sig, err := privKey.Sign(msg)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
// Test the signature
|
||||||
|
assert.True(t, pubKey.VerifyBytes(msg, sig))
|
||||||
|
|
||||||
|
// Mutate the signature, just one bit.
|
||||||
|
// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
|
||||||
|
sigEd := sig.(ed25519.SignatureEd25519)
|
||||||
|
sigEd[7] ^= byte(0x01)
|
||||||
|
sig = sigEd
|
||||||
|
|
||||||
|
assert.False(t, pubKey.VerifyBytes(msg, sig))
|
||||||
|
}
|
57
crypto/encoding/amino/amino.go
Normal file
57
crypto/encoding/amino/amino.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package cryptoAmino
|
||||||
|
|
||||||
|
import (
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// NOTE: It's important that there be no conflicts here,
|
||||||
|
// as that would change the canonical representations,
|
||||||
|
// and therefore change the address.
|
||||||
|
// TODO: Remove above note when
|
||||||
|
// https://github.com/tendermint/go-amino/issues/9
|
||||||
|
// is resolved
|
||||||
|
RegisterAmino(cdc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterAmino registers all crypto related types in the given (amino) codec.
|
||||||
|
func RegisterAmino(cdc *amino.Codec) {
|
||||||
|
// These are all written here instead of
|
||||||
|
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
|
||||||
|
"tendermint/PubKeyEd25519", nil)
|
||||||
|
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
|
||||||
|
"tendermint/PubKeySecp256k1", nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
|
||||||
|
"tendermint/PrivKeyEd25519", nil)
|
||||||
|
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
|
||||||
|
"tendermint/PrivKeySecp256k1", nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.Signature)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(ed25519.SignatureEd25519{},
|
||||||
|
"tendermint/SignatureEd25519", nil)
|
||||||
|
cdc.RegisterConcrete(secp256k1.SignatureSecp256k1{},
|
||||||
|
"tendermint/SignatureSecp256k1", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
|
||||||
|
err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
|
||||||
|
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func SignatureFromBytes(pubKeyBytes []byte) (pubKey crypto.Signature, err error) {
|
||||||
|
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
|
||||||
|
return
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package cryptoAmino
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@ -6,6 +6,9 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type byter interface {
|
type byter interface {
|
||||||
@ -56,64 +59,70 @@ func ExamplePrintRegisteredTypes() {
|
|||||||
|
|
||||||
func TestKeyEncodings(t *testing.T) {
|
func TestKeyEncodings(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
privKey PrivKey
|
privKey crypto.PrivKey
|
||||||
privSize, pubSize int // binary sizes
|
privSize, pubSize int // binary sizes
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
privKey: GenPrivKeyEd25519(),
|
privKey: ed25519.GenPrivKey(),
|
||||||
privSize: 69,
|
privSize: 69,
|
||||||
pubSize: 37,
|
pubSize: 37,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
privKey: GenPrivKeySecp256k1(),
|
privKey: secp256k1.GenPrivKey(),
|
||||||
privSize: 37,
|
privSize: 37,
|
||||||
pubSize: 38,
|
pubSize: 38,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for tcIndex, tc := range cases {
|
||||||
|
|
||||||
// Check (de/en)codings of PrivKeys.
|
// Check (de/en)codings of PrivKeys.
|
||||||
var priv2, priv3 PrivKey
|
var priv2, priv3 crypto.PrivKey
|
||||||
checkAminoBinary(t, tc.privKey, &priv2, tc.privSize)
|
checkAminoBinary(t, tc.privKey, &priv2, tc.privSize)
|
||||||
assert.EqualValues(t, tc.privKey, priv2)
|
assert.EqualValues(t, tc.privKey, priv2, "tc #%d", tcIndex)
|
||||||
checkAminoJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes.
|
checkAminoJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes.
|
||||||
assert.EqualValues(t, tc.privKey, priv3)
|
assert.EqualValues(t, tc.privKey, priv3, "tc #%d", tcIndex)
|
||||||
|
|
||||||
// Check (de/en)codings of Signatures.
|
// Check (de/en)codings of Signatures.
|
||||||
var sig1, sig2, sig3 Signature
|
var sig1, sig2, sig3 crypto.Signature
|
||||||
sig1, err := tc.privKey.Sign([]byte("something"))
|
sig1, err := tc.privKey.Sign([]byte("something"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err, "tc #%d", tcIndex)
|
||||||
checkAminoBinary(t, sig1, &sig2, -1) // Signature size changes for Secp anyways.
|
checkAminoBinary(t, sig1, &sig2, -1) // Signature size changes for Secp anyways.
|
||||||
assert.EqualValues(t, sig1, sig2)
|
assert.EqualValues(t, sig1, sig2, "tc #%d", tcIndex)
|
||||||
checkAminoJSON(t, sig1, &sig3, false) // TODO also check Prefix bytes.
|
checkAminoJSON(t, sig1, &sig3, false) // TODO also check Prefix bytes.
|
||||||
assert.EqualValues(t, sig1, sig3)
|
assert.EqualValues(t, sig1, sig3, "tc #%d", tcIndex)
|
||||||
|
|
||||||
// Check (de/en)codings of PubKeys.
|
// Check (de/en)codings of PubKeys.
|
||||||
pubKey := tc.privKey.PubKey()
|
pubKey := tc.privKey.PubKey()
|
||||||
var pub2, pub3 PubKey
|
var pub2, pub3 crypto.PubKey
|
||||||
checkAminoBinary(t, pubKey, &pub2, tc.pubSize)
|
checkAminoBinary(t, pubKey, &pub2, tc.pubSize)
|
||||||
assert.EqualValues(t, pubKey, pub2)
|
assert.EqualValues(t, pubKey, pub2, "tc #%d", tcIndex)
|
||||||
checkAminoJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes.
|
checkAminoJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes.
|
||||||
assert.EqualValues(t, pubKey, pub3)
|
assert.EqualValues(t, pubKey, pub3, "tc #%d", tcIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNilEncodings(t *testing.T) {
|
func TestNilEncodings(t *testing.T) {
|
||||||
|
|
||||||
// Check nil Signature.
|
// Check nil Signature.
|
||||||
var a, b Signature
|
var a, b crypto.Signature
|
||||||
checkAminoJSON(t, &a, &b, true)
|
checkAminoJSON(t, &a, &b, true)
|
||||||
assert.EqualValues(t, a, b)
|
assert.EqualValues(t, a, b)
|
||||||
|
|
||||||
// Check nil PubKey.
|
// Check nil PubKey.
|
||||||
var c, d PubKey
|
var c, d crypto.PubKey
|
||||||
checkAminoJSON(t, &c, &d, true)
|
checkAminoJSON(t, &c, &d, true)
|
||||||
assert.EqualValues(t, c, d)
|
assert.EqualValues(t, c, d)
|
||||||
|
|
||||||
// Check nil PrivKey.
|
// Check nil PrivKey.
|
||||||
var e, f PrivKey
|
var e, f crypto.PrivKey
|
||||||
checkAminoJSON(t, &e, &f, true)
|
checkAminoJSON(t, &e, &f, true)
|
||||||
assert.EqualValues(t, e, f)
|
assert.EqualValues(t, e, f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPubKeyInvalidDataProperReturnsEmpty(t *testing.T) {
|
||||||
|
pk, err := PubKeyFromBytes([]byte("foo"))
|
||||||
|
require.NotNil(t, err, "expecting a non-nil error")
|
||||||
|
require.Nil(t, pk, "expecting an empty public key on error")
|
||||||
|
}
|
@ -2,6 +2,7 @@ package crypto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"golang.org/x/crypto/hkdf"
|
"golang.org/x/crypto/hkdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Implements crypto.AEAD
|
||||||
type hkdfchacha20poly1305 struct {
|
type hkdfchacha20poly1305 struct {
|
||||||
key [KeySize]byte
|
key [KeySize]byte
|
||||||
}
|
}
|
||||||
|
@ -1,164 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/subtle"
|
|
||||||
|
|
||||||
secp256k1 "github.com/btcsuite/btcd/btcec"
|
|
||||||
"github.com/tendermint/ed25519"
|
|
||||||
"github.com/tendermint/ed25519/extra25519"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PrivKeyFromBytes(privKeyBytes []byte) (privKey PrivKey, err error) {
|
|
||||||
err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------
|
|
||||||
|
|
||||||
type PrivKey interface {
|
|
||||||
Bytes() []byte
|
|
||||||
Sign(msg []byte) (Signature, error)
|
|
||||||
PubKey() PubKey
|
|
||||||
Equals(PrivKey) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ PrivKey = PrivKeyEd25519{}
|
|
||||||
|
|
||||||
// Implements PrivKey
|
|
||||||
type PrivKeyEd25519 [64]byte
|
|
||||||
|
|
||||||
func (privKey PrivKeyEd25519) Bytes() []byte {
|
|
||||||
return cdc.MustMarshalBinaryBare(privKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (privKey PrivKeyEd25519) Sign(msg []byte) (Signature, error) {
|
|
||||||
privKeyBytes := [64]byte(privKey)
|
|
||||||
signatureBytes := ed25519.Sign(&privKeyBytes, msg)
|
|
||||||
return SignatureEd25519(*signatureBytes), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (privKey PrivKeyEd25519) PubKey() PubKey {
|
|
||||||
privKeyBytes := [64]byte(privKey)
|
|
||||||
pubBytes := *ed25519.MakePublicKey(&privKeyBytes)
|
|
||||||
return PubKeyEd25519(pubBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equals - you probably don't need to use this.
|
|
||||||
// Runs in constant time based on length of the keys.
|
|
||||||
func (privKey PrivKeyEd25519) Equals(other PrivKey) bool {
|
|
||||||
if otherEd, ok := other.(PrivKeyEd25519); ok {
|
|
||||||
return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte {
|
|
||||||
keyCurve25519 := new([32]byte)
|
|
||||||
privKeyBytes := [64]byte(privKey)
|
|
||||||
extra25519.PrivateKeyToCurve25519(keyCurve25519, &privKeyBytes)
|
|
||||||
return keyCurve25519
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deterministically generates new priv-key bytes from key.
|
|
||||||
func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519 {
|
|
||||||
bz, err := cdc.MarshalBinaryBare(struct {
|
|
||||||
PrivKey [64]byte
|
|
||||||
Index int
|
|
||||||
}{privKey, index})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
newBytes := Sha256(bz)
|
|
||||||
newKey := new([64]byte)
|
|
||||||
copy(newKey[:32], newBytes)
|
|
||||||
ed25519.MakePublicKey(newKey)
|
|
||||||
return PrivKeyEd25519(*newKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GenPrivKeyEd25519() PrivKeyEd25519 {
|
|
||||||
privKeyBytes := new([64]byte)
|
|
||||||
copy(privKeyBytes[:32], CRandBytes(32))
|
|
||||||
ed25519.MakePublicKey(privKeyBytes)
|
|
||||||
return PrivKeyEd25519(*privKeyBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: secret should be the output of a KDF like bcrypt,
|
|
||||||
// if it's derived from user input.
|
|
||||||
func GenPrivKeyEd25519FromSecret(secret []byte) PrivKeyEd25519 {
|
|
||||||
privKey32 := Sha256(secret) // Not Ripemd160 because we want 32 bytes.
|
|
||||||
privKeyBytes := new([64]byte)
|
|
||||||
copy(privKeyBytes[:32], privKey32)
|
|
||||||
ed25519.MakePublicKey(privKeyBytes)
|
|
||||||
return PrivKeyEd25519(*privKeyBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ PrivKey = PrivKeySecp256k1{}
|
|
||||||
|
|
||||||
// Implements PrivKey
|
|
||||||
type PrivKeySecp256k1 [32]byte
|
|
||||||
|
|
||||||
func (privKey PrivKeySecp256k1) Bytes() []byte {
|
|
||||||
return cdc.MustMarshalBinaryBare(privKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (privKey PrivKeySecp256k1) Sign(msg []byte) (Signature, error) {
|
|
||||||
priv__, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
|
|
||||||
sig__, err := priv__.Sign(Sha256(msg))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return SignatureSecp256k1(sig__.Serialize()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (privKey PrivKeySecp256k1) PubKey() PubKey {
|
|
||||||
_, pub__ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
|
|
||||||
var pub PubKeySecp256k1
|
|
||||||
copy(pub[:], pub__.SerializeCompressed())
|
|
||||||
return pub
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equals - you probably don't need to use this.
|
|
||||||
// Runs in constant time based on length of the keys.
|
|
||||||
func (privKey PrivKeySecp256k1) Equals(other PrivKey) bool {
|
|
||||||
if otherSecp, ok := other.(PrivKeySecp256k1); ok {
|
|
||||||
return subtle.ConstantTimeCompare(privKey[:], otherSecp[:]) == 1
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Deterministically generates new priv-key bytes from key.
|
|
||||||
func (key PrivKeySecp256k1) Generate(index int) PrivKeySecp256k1 {
|
|
||||||
newBytes := cdc.BinarySha256(struct {
|
|
||||||
PrivKey [64]byte
|
|
||||||
Index int
|
|
||||||
}{key, index})
|
|
||||||
var newKey [64]byte
|
|
||||||
copy(newKey[:], newBytes)
|
|
||||||
return PrivKeySecp256k1(newKey)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func GenPrivKeySecp256k1() PrivKeySecp256k1 {
|
|
||||||
privKeyBytes := [32]byte{}
|
|
||||||
copy(privKeyBytes[:], CRandBytes(32))
|
|
||||||
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKeyBytes[:])
|
|
||||||
copy(privKeyBytes[:], priv.Serialize())
|
|
||||||
return PrivKeySecp256k1(privKeyBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: secret should be the output of a KDF like bcrypt,
|
|
||||||
// if it's derived from user input.
|
|
||||||
func GenPrivKeySecp256k1FromSecret(secret []byte) PrivKeySecp256k1 {
|
|
||||||
privKey32 := Sha256(secret) // Not Ripemd160 because we want 32 bytes.
|
|
||||||
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey32)
|
|
||||||
privKeyBytes := [32]byte{}
|
|
||||||
copy(privKeyBytes[:], priv.Serialize())
|
|
||||||
return PrivKeySecp256k1(privKeyBytes)
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package crypto_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGeneratePrivKey(t *testing.T) {
|
|
||||||
testPriv := crypto.GenPrivKeyEd25519()
|
|
||||||
testGenerate := testPriv.Generate(1)
|
|
||||||
signBytes := []byte("something to sign")
|
|
||||||
pub := testGenerate.PubKey()
|
|
||||||
sig, err := testGenerate.Sign(signBytes)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, pub.VerifyBytes(signBytes, sig))
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
type BadKey struct {
|
|
||||||
PrivKeyEd25519
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReadPrivKey(t *testing.T) {
|
|
||||||
assert, require := assert.New(t), require.New(t)
|
|
||||||
|
|
||||||
// garbage in, garbage out
|
|
||||||
garbage := []byte("hjgewugfbiewgofwgewr")
|
|
||||||
XXX This test wants to register BadKey globally to crypto,
|
|
||||||
but we don't want to support that.
|
|
||||||
_, err := PrivKeyFromBytes(garbage)
|
|
||||||
require.Error(err)
|
|
||||||
|
|
||||||
edKey := GenPrivKeyEd25519()
|
|
||||||
badKey := BadKey{edKey}
|
|
||||||
|
|
||||||
cases := []struct {
|
|
||||||
key PrivKey
|
|
||||||
valid bool
|
|
||||||
}{
|
|
||||||
{edKey, true},
|
|
||||||
{badKey, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tc := range cases {
|
|
||||||
data := tc.key.Bytes()
|
|
||||||
fmt.Println(">>>", data)
|
|
||||||
key, err := PrivKeyFromBytes(data)
|
|
||||||
fmt.Printf("!!! %#v\n", key, err)
|
|
||||||
if tc.valid {
|
|
||||||
assert.NoError(err, "%d", i)
|
|
||||||
assert.Equal(tc.key, key, "%d", i)
|
|
||||||
} else {
|
|
||||||
assert.Error(err, "%d: %#v", i, key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
@ -1,153 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/ripemd160"
|
|
||||||
|
|
||||||
secp256k1 "github.com/btcsuite/btcd/btcec"
|
|
||||||
|
|
||||||
"github.com/tendermint/ed25519"
|
|
||||||
"github.com/tendermint/ed25519/extra25519"
|
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
||||||
)
|
|
||||||
|
|
||||||
// An address is a []byte, but hex-encoded even in JSON.
|
|
||||||
// []byte leaves us the option to change the address length.
|
|
||||||
// Use an alias so Unmarshal methods (with ptr receivers) are available too.
|
|
||||||
type Address = cmn.HexBytes
|
|
||||||
|
|
||||||
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey PubKey, err error) {
|
|
||||||
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------
|
|
||||||
|
|
||||||
type PubKey interface {
|
|
||||||
Address() Address
|
|
||||||
Bytes() []byte
|
|
||||||
VerifyBytes(msg []byte, sig Signature) bool
|
|
||||||
Equals(PubKey) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ PubKey = PubKeyEd25519{}
|
|
||||||
|
|
||||||
const PubKeyEd25519Size = 32
|
|
||||||
|
|
||||||
// Implements PubKeyInner
|
|
||||||
type PubKeyEd25519 [PubKeyEd25519Size]byte
|
|
||||||
|
|
||||||
// Address is the SHA256-20 of the raw pubkey bytes.
|
|
||||||
func (pubKey PubKeyEd25519) Address() Address {
|
|
||||||
return Address(tmhash.Sum(pubKey[:]))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) Bytes() []byte {
|
|
||||||
bz, err := cdc.MarshalBinaryBare(pubKey)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bz
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool {
|
|
||||||
// make sure we use the same algorithm to sign
|
|
||||||
sig, ok := sig_.(SignatureEd25519)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
pubKeyBytes := [PubKeyEd25519Size]byte(pubKey)
|
|
||||||
sigBytes := [SignatureEd25519Size]byte(sig)
|
|
||||||
return ed25519.Verify(&pubKeyBytes, msg, &sigBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// For use with golang/crypto/nacl/box
|
|
||||||
// If error, returns nil.
|
|
||||||
func (pubKey PubKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte {
|
|
||||||
keyCurve25519, pubKeyBytes := new([PubKeyEd25519Size]byte), [PubKeyEd25519Size]byte(pubKey)
|
|
||||||
ok := extra25519.PublicKeyToCurve25519(keyCurve25519, &pubKeyBytes)
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return keyCurve25519
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) String() string {
|
|
||||||
return fmt.Sprintf("PubKeyEd25519{%X}", pubKey[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeyEd25519) Equals(other PubKey) bool {
|
|
||||||
if otherEd, ok := other.(PubKeyEd25519); ok {
|
|
||||||
return bytes.Equal(pubKey[:], otherEd[:])
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ PubKey = PubKeySecp256k1{}
|
|
||||||
|
|
||||||
const PubKeySecp256k1Size = 33
|
|
||||||
|
|
||||||
// Implements PubKey.
|
|
||||||
// Compressed pubkey (just the x-cord),
|
|
||||||
// prefixed with 0x02 or 0x03, depending on the y-cord.
|
|
||||||
type PubKeySecp256k1 [PubKeySecp256k1Size]byte
|
|
||||||
|
|
||||||
// Implements Bitcoin style addresses: RIPEMD160(SHA256(pubkey))
|
|
||||||
func (pubKey PubKeySecp256k1) Address() Address {
|
|
||||||
hasherSHA256 := sha256.New()
|
|
||||||
hasherSHA256.Write(pubKey[:]) // does not error
|
|
||||||
sha := hasherSHA256.Sum(nil)
|
|
||||||
|
|
||||||
hasherRIPEMD160 := ripemd160.New()
|
|
||||||
hasherRIPEMD160.Write(sha) // does not error
|
|
||||||
return Address(hasherRIPEMD160.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeySecp256k1) Bytes() []byte {
|
|
||||||
bz, err := cdc.MarshalBinaryBare(pubKey)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bz
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool {
|
|
||||||
// and assert same algorithm to sign and verify
|
|
||||||
sig, ok := sig_.(SignatureSecp256k1)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub__, err := secp256k1.ParsePubKey(pubKey[:], secp256k1.S256())
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
sig__, err := secp256k1.ParseDERSignature(sig[:], secp256k1.S256())
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return sig__.Verify(Sha256(msg), pub__)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeySecp256k1) String() string {
|
|
||||||
return fmt.Sprintf("PubKeySecp256k1{%X}", pubKey[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pubKey PubKeySecp256k1) Equals(other PubKey) bool {
|
|
||||||
if otherSecp, ok := other.(PubKeySecp256k1); ok {
|
|
||||||
return bytes.Equal(pubKey[:], otherSecp[:])
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil/base58"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
type keyData struct {
|
|
||||||
priv string
|
|
||||||
pub string
|
|
||||||
addr string
|
|
||||||
}
|
|
||||||
|
|
||||||
var secpDataTable = []keyData{
|
|
||||||
{
|
|
||||||
priv: "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330",
|
|
||||||
pub: "02950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248c",
|
|
||||||
addr: "1CKZ9Nx4zgds8tU7nJHotKSDr4a9bYJCa3",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPubKeySecp256k1Address(t *testing.T) {
|
|
||||||
for _, d := range secpDataTable {
|
|
||||||
privB, _ := hex.DecodeString(d.priv)
|
|
||||||
pubB, _ := hex.DecodeString(d.pub)
|
|
||||||
addrBbz, _, _ := base58.CheckDecode(d.addr)
|
|
||||||
addrB := Address(addrBbz)
|
|
||||||
|
|
||||||
var priv PrivKeySecp256k1
|
|
||||||
copy(priv[:], privB)
|
|
||||||
|
|
||||||
pubKey := priv.PubKey()
|
|
||||||
pubT, _ := pubKey.(PubKeySecp256k1)
|
|
||||||
pub := pubT[:]
|
|
||||||
addr := pubKey.Address()
|
|
||||||
|
|
||||||
assert.Equal(t, pub, pubB, "Expected pub keys to match")
|
|
||||||
assert.Equal(t, addr, addrB, "Expected addresses to match")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPubKeyInvalidDataProperReturnsEmpty(t *testing.T) {
|
|
||||||
pk, err := PubKeyFromBytes([]byte("foo"))
|
|
||||||
require.NotNil(t, err, "expecting a non-nil error")
|
|
||||||
require.Nil(t, pk, "expecting an empty public key on error")
|
|
||||||
}
|
|
198
crypto/secp256k1/secp256k1.go
Normal file
198
crypto/secp256k1/secp256k1.go
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
package secp256k1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/subtle"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
secp256k1 "github.com/btcsuite/btcd/btcec"
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/libs/common"
|
||||||
|
"golang.org/x/crypto/ripemd160"
|
||||||
|
)
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
const (
|
||||||
|
Secp256k1PrivKeyAminoRoute = "tendermint/PrivKeySecp256k1"
|
||||||
|
Secp256k1PubKeyAminoRoute = "tendermint/PubKeySecp256k1"
|
||||||
|
Secp256k1SignatureAminoRoute = "tendermint/SignatureSecp256k1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(PubKeySecp256k1{},
|
||||||
|
Secp256k1PubKeyAminoRoute, nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(PrivKeySecp256k1{},
|
||||||
|
Secp256k1PrivKeyAminoRoute, nil)
|
||||||
|
|
||||||
|
cdc.RegisterInterface((*crypto.Signature)(nil), nil)
|
||||||
|
cdc.RegisterConcrete(SignatureSecp256k1{},
|
||||||
|
Secp256k1SignatureAminoRoute, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.PrivKey = PrivKeySecp256k1{}
|
||||||
|
|
||||||
|
// PrivKeySecp256k1 implements PrivKey.
|
||||||
|
type PrivKeySecp256k1 [32]byte
|
||||||
|
|
||||||
|
// Bytes marshalls the private key using amino encoding.
|
||||||
|
func (privKey PrivKeySecp256k1) Bytes() []byte {
|
||||||
|
return cdc.MustMarshalBinaryBare(privKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg.
|
||||||
|
func (privKey PrivKeySecp256k1) Sign(msg []byte) (crypto.Signature, error) {
|
||||||
|
priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
|
||||||
|
sig, err := priv.Sign(crypto.Sha256(msg))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return SignatureSecp256k1(sig.Serialize()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PubKey performs the point-scalar multiplication from the privKey on the
|
||||||
|
// generator point to get the pubkey.
|
||||||
|
func (privKey PrivKeySecp256k1) PubKey() crypto.PubKey {
|
||||||
|
_, pubkeyObject := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
|
||||||
|
var pubkeyBytes PubKeySecp256k1
|
||||||
|
copy(pubkeyBytes[:], pubkeyObject.SerializeCompressed())
|
||||||
|
return pubkeyBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equals - you probably don't need to use this.
|
||||||
|
// Runs in constant time based on length of the keys.
|
||||||
|
func (privKey PrivKeySecp256k1) Equals(other crypto.PrivKey) bool {
|
||||||
|
if otherSecp, ok := other.(PrivKeySecp256k1); ok {
|
||||||
|
return subtle.ConstantTimeCompare(privKey[:], otherSecp[:]) == 1
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenPrivKey generates a new ECDSA private key on curve secp256k1 private key.
|
||||||
|
// It uses OS randomness in conjunction with the current global random seed
|
||||||
|
// in tendermint/libs/common to generate the private key.
|
||||||
|
func GenPrivKey() PrivKeySecp256k1 {
|
||||||
|
privKeyBytes := [32]byte{}
|
||||||
|
copy(privKeyBytes[:], crypto.CRandBytes(32))
|
||||||
|
// crypto.CRandBytes is guaranteed to be 32 bytes long, so it can be
|
||||||
|
// casted to PrivKeySecp256k1.
|
||||||
|
return PrivKeySecp256k1(privKeyBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenPrivKeySecp256k1 hashes the secret with SHA2, and uses
|
||||||
|
// that 32 byte output to create the private key.
|
||||||
|
// NOTE: secret should be the output of a KDF like bcrypt,
|
||||||
|
// if it's derived from user input.
|
||||||
|
func GenPrivKeySecp256k1(secret []byte) PrivKeySecp256k1 {
|
||||||
|
privKey32 := sha256.Sum256(secret)
|
||||||
|
// sha256.Sum256() is guaranteed to be 32 bytes long, so it can be
|
||||||
|
// casted to PrivKeySecp256k1.
|
||||||
|
return PrivKeySecp256k1(privKey32)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.PubKey = PubKeySecp256k1{}
|
||||||
|
|
||||||
|
// PubKeySecp256k1Size is comprised of 32 bytes for one field element
|
||||||
|
// (the x-coordinate), plus one byte for the parity of the y-coordinate.
|
||||||
|
const PubKeySecp256k1Size = 33
|
||||||
|
|
||||||
|
// PubKeySecp256k1 implements crypto.PubKey.
|
||||||
|
// It is the compressed form of the pubkey. The first byte depends is a 0x02 byte
|
||||||
|
// if the y-coordinate is the lexicographically largest of the two associated with
|
||||||
|
// the x-coordinate. Otherwise the first byte is a 0x03.
|
||||||
|
// This prefix is followed with the x-coordinate.
|
||||||
|
type PubKeySecp256k1 [PubKeySecp256k1Size]byte
|
||||||
|
|
||||||
|
// Address returns a Bitcoin style addresses: RIPEMD160(SHA256(pubkey))
|
||||||
|
func (pubKey PubKeySecp256k1) Address() crypto.Address {
|
||||||
|
hasherSHA256 := sha256.New()
|
||||||
|
hasherSHA256.Write(pubKey[:]) // does not error
|
||||||
|
sha := hasherSHA256.Sum(nil)
|
||||||
|
|
||||||
|
hasherRIPEMD160 := ripemd160.New()
|
||||||
|
hasherRIPEMD160.Write(sha) // does not error
|
||||||
|
return crypto.Address(hasherRIPEMD160.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bytes returns the pubkey marshalled with amino encoding.
|
||||||
|
func (pubKey PubKeySecp256k1) Bytes() []byte {
|
||||||
|
bz, err := cdc.MarshalBinaryBare(pubKey)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return bz
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, interfaceSig crypto.Signature) bool {
|
||||||
|
// and assert same algorithm to sign and verify
|
||||||
|
sig, ok := interfaceSig.(SignatureSecp256k1)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub, err := secp256k1.ParsePubKey(pubKey[:], secp256k1.S256())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
parsedSig, err := secp256k1.ParseDERSignature(sig[:], secp256k1.S256())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return parsedSig.Verify(crypto.Sha256(msg), pub)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pubKey PubKeySecp256k1) String() string {
|
||||||
|
return fmt.Sprintf("PubKeySecp256k1{%X}", pubKey[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pubKey PubKeySecp256k1) Equals(other crypto.PubKey) bool {
|
||||||
|
if otherSecp, ok := other.(PubKeySecp256k1); ok {
|
||||||
|
return bytes.Equal(pubKey[:], otherSecp[:])
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
var _ crypto.Signature = SignatureSecp256k1{}
|
||||||
|
|
||||||
|
// SignatureSecp256k1 implements crypto.Signature
|
||||||
|
type SignatureSecp256k1 []byte
|
||||||
|
|
||||||
|
func (sig SignatureSecp256k1) Bytes() []byte {
|
||||||
|
bz, err := cdc.MarshalBinaryBare(sig)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return bz
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
|
||||||
|
|
||||||
|
func (sig SignatureSecp256k1) String() string {
|
||||||
|
return fmt.Sprintf("/%X.../", common.Fingerprint(sig[:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sig SignatureSecp256k1) Equals(other crypto.Signature) bool {
|
||||||
|
if otherSecp, ok := other.(SignatureSecp256k1); ok {
|
||||||
|
return subtle.ConstantTimeCompare(sig[:], otherSecp[:]) == 1
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SignatureSecp256k1FromBytes(data []byte) crypto.Signature {
|
||||||
|
sig := make(SignatureSecp256k1, len(data))
|
||||||
|
copy(sig[:], data)
|
||||||
|
return sig
|
||||||
|
}
|
88
crypto/secp256k1/secpk256k1_test.go
Normal file
88
crypto/secp256k1/secpk256k1_test.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package secp256k1_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcutil/base58"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
|
|
||||||
|
underlyingSecp256k1 "github.com/btcsuite/btcd/btcec"
|
||||||
|
)
|
||||||
|
|
||||||
|
type keyData struct {
|
||||||
|
priv string
|
||||||
|
pub string
|
||||||
|
addr string
|
||||||
|
}
|
||||||
|
|
||||||
|
var secpDataTable = []keyData{
|
||||||
|
{
|
||||||
|
priv: "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330",
|
||||||
|
pub: "02950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248c",
|
||||||
|
addr: "1CKZ9Nx4zgds8tU7nJHotKSDr4a9bYJCa3",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPubKeySecp256k1Address(t *testing.T) {
|
||||||
|
for _, d := range secpDataTable {
|
||||||
|
privB, _ := hex.DecodeString(d.priv)
|
||||||
|
pubB, _ := hex.DecodeString(d.pub)
|
||||||
|
addrBbz, _, _ := base58.CheckDecode(d.addr)
|
||||||
|
addrB := crypto.Address(addrBbz)
|
||||||
|
|
||||||
|
var priv secp256k1.PrivKeySecp256k1
|
||||||
|
copy(priv[:], privB)
|
||||||
|
|
||||||
|
pubKey := priv.PubKey()
|
||||||
|
pubT, _ := pubKey.(secp256k1.PubKeySecp256k1)
|
||||||
|
pub := pubT[:]
|
||||||
|
addr := pubKey.Address()
|
||||||
|
|
||||||
|
assert.Equal(t, pub, pubB, "Expected pub keys to match")
|
||||||
|
assert.Equal(t, addr, addrB, "Expected addresses to match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSignAndValidateSecp256k1(t *testing.T) {
|
||||||
|
privKey := secp256k1.GenPrivKey()
|
||||||
|
pubKey := privKey.PubKey()
|
||||||
|
|
||||||
|
msg := crypto.CRandBytes(128)
|
||||||
|
sig, err := privKey.Sign(msg)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
assert.True(t, pubKey.VerifyBytes(msg, sig))
|
||||||
|
|
||||||
|
// Mutate the signature, just one bit.
|
||||||
|
sigEd := sig.(secp256k1.SignatureSecp256k1)
|
||||||
|
sigEd[3] ^= byte(0x01)
|
||||||
|
sig = sigEd
|
||||||
|
|
||||||
|
assert.False(t, pubKey.VerifyBytes(msg, sig))
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test is intended to justify the removal of calls to the underlying library
|
||||||
|
// in creating the privkey.
|
||||||
|
func TestSecp256k1LoadPrivkeyAndSerializeIsIdentity(t *testing.T) {
|
||||||
|
numberOfTests := 256
|
||||||
|
for i := 0; i < numberOfTests; i++ {
|
||||||
|
// Seed the test case with some random bytes
|
||||||
|
privKeyBytes := [32]byte{}
|
||||||
|
copy(privKeyBytes[:], crypto.CRandBytes(32))
|
||||||
|
|
||||||
|
// This function creates a private and public key in the underlying libraries format.
|
||||||
|
// The private key is basically calling new(big.Int).SetBytes(pk), which removes leading zero bytes
|
||||||
|
priv, _ := underlyingSecp256k1.PrivKeyFromBytes(underlyingSecp256k1.S256(), privKeyBytes[:])
|
||||||
|
// this takes the bytes returned by `(big int).Bytes()`, and if the length is less than 32 bytes,
|
||||||
|
// pads the bytes from the left with zero bytes. Therefore these two functions composed
|
||||||
|
// result in the identity function on privKeyBytes, hence the following equality check
|
||||||
|
// always returning true.
|
||||||
|
serializedBytes := priv.Serialize()
|
||||||
|
require.Equal(t, privKeyBytes[:], serializedBytes)
|
||||||
|
}
|
||||||
|
}
|
@ -1,90 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"crypto/subtle"
|
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SignatureFromBytes(pubKeyBytes []byte) (pubKey Signature, err error) {
|
|
||||||
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------
|
|
||||||
|
|
||||||
type Signature interface {
|
|
||||||
Bytes() []byte
|
|
||||||
IsZero() bool
|
|
||||||
Equals(Signature) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ Signature = SignatureEd25519{}
|
|
||||||
|
|
||||||
const SignatureEd25519Size = 64
|
|
||||||
|
|
||||||
// Implements Signature
|
|
||||||
type SignatureEd25519 [SignatureEd25519Size]byte
|
|
||||||
|
|
||||||
func (sig SignatureEd25519) Bytes() []byte {
|
|
||||||
bz, err := cdc.MarshalBinaryBare(sig)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bz
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
|
||||||
|
|
||||||
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
|
||||||
|
|
||||||
func (sig SignatureEd25519) Equals(other Signature) bool {
|
|
||||||
if otherEd, ok := other.(SignatureEd25519); ok {
|
|
||||||
return subtle.ConstantTimeCompare(sig[:], otherEd[:]) == 1
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SignatureEd25519FromBytes(data []byte) Signature {
|
|
||||||
var sig SignatureEd25519
|
|
||||||
copy(sig[:], data)
|
|
||||||
return sig
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
|
|
||||||
var _ Signature = SignatureSecp256k1{}
|
|
||||||
|
|
||||||
// Implements Signature
|
|
||||||
type SignatureSecp256k1 []byte
|
|
||||||
|
|
||||||
func (sig SignatureSecp256k1) Bytes() []byte {
|
|
||||||
bz, err := cdc.MarshalBinaryBare(sig)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bz
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
|
|
||||||
|
|
||||||
func (sig SignatureSecp256k1) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
|
||||||
|
|
||||||
func (sig SignatureSecp256k1) Equals(other Signature) bool {
|
|
||||||
if otherSecp, ok := other.(SignatureSecp256k1); ok {
|
|
||||||
return subtle.ConstantTimeCompare(sig[:], otherSecp[:]) == 1
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SignatureSecp256k1FromBytes(data []byte) Signature {
|
|
||||||
sig := make(SignatureSecp256k1, len(data))
|
|
||||||
copy(sig[:], data)
|
|
||||||
return sig
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package crypto
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSignAndValidateEd25519(t *testing.T) {
|
|
||||||
|
|
||||||
privKey := GenPrivKeyEd25519()
|
|
||||||
pubKey := privKey.PubKey()
|
|
||||||
|
|
||||||
msg := CRandBytes(128)
|
|
||||||
sig, err := privKey.Sign(msg)
|
|
||||||
require.Nil(t, err)
|
|
||||||
|
|
||||||
// Test the signature
|
|
||||||
assert.True(t, pubKey.VerifyBytes(msg, sig))
|
|
||||||
|
|
||||||
// Mutate the signature, just one bit.
|
|
||||||
sigEd := sig.(SignatureEd25519)
|
|
||||||
sigEd[7] ^= byte(0x01)
|
|
||||||
sig = sigEd
|
|
||||||
|
|
||||||
assert.False(t, pubKey.VerifyBytes(msg, sig))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSignAndValidateSecp256k1(t *testing.T) {
|
|
||||||
privKey := GenPrivKeySecp256k1()
|
|
||||||
pubKey := privKey.PubKey()
|
|
||||||
|
|
||||||
msg := CRandBytes(128)
|
|
||||||
sig, err := privKey.Sign(msg)
|
|
||||||
require.Nil(t, err)
|
|
||||||
|
|
||||||
assert.True(t, pubKey.VerifyBytes(msg, sig))
|
|
||||||
|
|
||||||
// Mutate the signature, just one bit.
|
|
||||||
sigEd := sig.(SignatureSecp256k1)
|
|
||||||
sigEd[3] ^= byte(0x01)
|
|
||||||
sig = sigEd
|
|
||||||
|
|
||||||
assert.False(t, pubKey.VerifyBytes(msg, sig))
|
|
||||||
}
|
|
@ -1,12 +1,15 @@
|
|||||||
package crypto
|
package xsalsa20symmetric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/libs/common"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"golang.org/x/crypto/nacl/secretbox"
|
"golang.org/x/crypto/nacl/secretbox"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO, make this into a struct that implements crypto.Symmetric.
|
||||||
|
|
||||||
const nonceLen = 24
|
const nonceLen = 24
|
||||||
const secretLen = 32
|
const secretLen = 32
|
||||||
|
|
||||||
@ -15,9 +18,9 @@ const secretLen = 32
|
|||||||
// NOTE: call crypto.MixEntropy() first.
|
// NOTE: call crypto.MixEntropy() first.
|
||||||
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
|
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
|
||||||
if len(secret) != secretLen {
|
if len(secret) != secretLen {
|
||||||
PanicSanity(Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
|
cmn.PanicSanity(cmn.Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
|
||||||
}
|
}
|
||||||
nonce := CRandBytes(nonceLen)
|
nonce := crypto.CRandBytes(nonceLen)
|
||||||
nonceArr := [nonceLen]byte{}
|
nonceArr := [nonceLen]byte{}
|
||||||
copy(nonceArr[:], nonce)
|
copy(nonceArr[:], nonce)
|
||||||
secretArr := [secretLen]byte{}
|
secretArr := [secretLen]byte{}
|
||||||
@ -32,7 +35,7 @@ func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
|
|||||||
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
|
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
|
||||||
func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error) {
|
func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error) {
|
||||||
if len(secret) != secretLen {
|
if len(secret) != secretLen {
|
||||||
PanicSanity(Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
|
cmn.PanicSanity(cmn.Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
|
||||||
}
|
}
|
||||||
if len(ciphertext) <= secretbox.Overhead+nonceLen {
|
if len(ciphertext) <= secretbox.Overhead+nonceLen {
|
||||||
return nil, errors.New("Ciphertext is too short")
|
return nil, errors.New("Ciphertext is too short")
|
@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package xsalsa20symmetric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -6,12 +6,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSimple(t *testing.T) {
|
func TestSimple(t *testing.T) {
|
||||||
|
|
||||||
MixEntropy([]byte("someentropy"))
|
crypto.MixEntropy([]byte("someentropy"))
|
||||||
|
|
||||||
plaintext := []byte("sometext")
|
plaintext := []byte("sometext")
|
||||||
secret := []byte("somesecretoflengththirtytwo===32")
|
secret := []byte("somesecretoflengththirtytwo===32")
|
||||||
@ -24,7 +25,7 @@ func TestSimple(t *testing.T) {
|
|||||||
|
|
||||||
func TestSimpleWithKDF(t *testing.T) {
|
func TestSimpleWithKDF(t *testing.T) {
|
||||||
|
|
||||||
MixEntropy([]byte("someentropy"))
|
crypto.MixEntropy([]byte("someentropy"))
|
||||||
|
|
||||||
plaintext := []byte("sometext")
|
plaintext := []byte("sometext")
|
||||||
secretPass := []byte("somesecret")
|
secretPass := []byte("somesecret")
|
||||||
@ -32,7 +33,7 @@ func TestSimpleWithKDF(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
secret = Sha256(secret)
|
secret = crypto.Sha256(secret)
|
||||||
|
|
||||||
ciphertext := EncryptSymmetric(plaintext, secret)
|
ciphertext := EncryptSymmetric(plaintext, secret)
|
||||||
plaintext2, err := DecryptSymmetric(ciphertext, secret)
|
plaintext2, err := DecryptSymmetric(ciphertext, secret)
|
@ -11,6 +11,8 @@ and built using [VuePress](https://vuepress.vuejs.org/) from the tendermint webs
|
|||||||
which has a [configuration file](https://github.com/tendermint/tendermint.com/blob/develop/docs/.vuepress/config.js) for displaying
|
which has a [configuration file](https://github.com/tendermint/tendermint.com/blob/develop/docs/.vuepress/config.js) for displaying
|
||||||
the Table of Contents that lists all the documentation.
|
the Table of Contents that lists all the documentation.
|
||||||
|
|
||||||
|
Under the hood, Jenkins listens for changes in ./docs then pushes a `docs-staging` branch to the tendermint.com repo with the latest documentation. That branch must be manually PR'd to `develop` then `master` for staging then production. This process should happen in synchrony with a release.
|
||||||
|
|
||||||
The `README.md` in this directory is the landing page for
|
The `README.md` in this directory is the landing page for
|
||||||
website documentation and the following folders are intentionally
|
website documentation and the following folders are intentionally
|
||||||
ommitted:
|
ommitted:
|
||||||
|
@ -5,12 +5,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
amino "github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cdc := amino.NewCodec()
|
cdc := amino.NewCodec()
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
cdc.PrintTypes(os.Stdout)
|
cdc.PrintTypes(os.Stdout)
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,6 @@ laddr = "tcp://0.0.0.0:26656"
|
|||||||
seeds = ""
|
seeds = ""
|
||||||
|
|
||||||
# Comma separated list of nodes to keep persistent connections to
|
# Comma separated list of nodes to keep persistent connections to
|
||||||
# Do not add private peers to this list if you don't want them advertised
|
|
||||||
persistent_peers = ""
|
persistent_peers = ""
|
||||||
|
|
||||||
# UPNP port forwarding
|
# UPNP port forwarding
|
||||||
@ -121,10 +120,10 @@ max_num_peers = 50
|
|||||||
max_packet_msg_payload_size = 1024
|
max_packet_msg_payload_size = 1024
|
||||||
|
|
||||||
# Rate at which packets can be sent, in bytes/second
|
# Rate at which packets can be sent, in bytes/second
|
||||||
send_rate = 512000
|
send_rate = 5120000
|
||||||
|
|
||||||
# Rate at which packets can be received, in bytes/second
|
# Rate at which packets can be received, in bytes/second
|
||||||
recv_rate = 512000
|
recv_rate = 5120000
|
||||||
|
|
||||||
# Set true to enable the peer-exchange reactor
|
# Set true to enable the peer-exchange reactor
|
||||||
pex = true
|
pex = true
|
||||||
|
@ -2,7 +2,7 @@ package evidence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ var cdc = amino.NewCodec()
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterEvidenceMessages(cdc)
|
RegisterEvidenceMessages(cdc)
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
types.RegisterEvidences(cdc)
|
types.RegisterEvidences(cdc)
|
||||||
RegisterMockEvidences(cdc) // For testing
|
RegisterMockEvidences(cdc) // For testing
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@ package clist
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSmall(t *testing.T) {
|
func TestSmall(t *testing.T) {
|
||||||
@ -131,7 +132,7 @@ func _TestGCRandom(t *testing.T) {
|
|||||||
els = append(els, el)
|
els = append(els, el)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range rand.Perm(numElements) {
|
for _, i := range cmn.RandPerm(numElements) {
|
||||||
el := els[i]
|
el := els[i]
|
||||||
l.Remove(el)
|
l.Remove(el)
|
||||||
_ = el.Next()
|
_ = el.Next()
|
||||||
@ -189,7 +190,7 @@ func TestScanRightDeleteRandom(t *testing.T) {
|
|||||||
// Remove an element, push back an element.
|
// Remove an element, push back an element.
|
||||||
for i := 0; i < numTimes; i++ {
|
for i := 0; i < numTimes; i++ {
|
||||||
// Pick an element to remove
|
// Pick an element to remove
|
||||||
rmElIdx := rand.Intn(len(els))
|
rmElIdx := cmn.RandIntn(len(els))
|
||||||
rmEl := els[rmElIdx]
|
rmEl := els[rmElIdx]
|
||||||
|
|
||||||
// Remove it
|
// Remove it
|
||||||
@ -243,7 +244,7 @@ func TestWaitChan(t *testing.T) {
|
|||||||
for i := 1; i < 100; i++ {
|
for i := 1; i < 100; i++ {
|
||||||
l.PushBack(i)
|
l.PushBack(i)
|
||||||
pushed++
|
pushed++
|
||||||
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
|
time.Sleep(time.Duration(cmn.RandIntn(100)) * time.Millisecond)
|
||||||
}
|
}
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
@ -3,17 +3,14 @@ package common
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteFileAtomic(t *testing.T) {
|
func TestWriteFileAtomic(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
seed = rand.New(rand.NewSource(time.Now().UnixNano()))
|
data = []byte(RandStr(RandIntn(2048)))
|
||||||
data = []byte(RandStr(seed.Intn(2048)))
|
old = RandBytes(RandIntn(2048))
|
||||||
old = RandBytes(seed.Intn(2048))
|
|
||||||
perm os.FileMode = 0600
|
perm os.FileMode = 0600
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,9 +11,13 @@ const (
|
|||||||
strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters
|
strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters
|
||||||
)
|
)
|
||||||
|
|
||||||
// pseudo random number generator.
|
// Rand is a prng, that is seeded with OS randomness.
|
||||||
// seeded with OS randomness (crand)
|
// The OS randomness is obtained from crypto/rand, however none of the provided
|
||||||
|
// methods are suitable for cryptographic usage.
|
||||||
|
// They all utilize math/rand's prng internally.
|
||||||
|
//
|
||||||
|
// All of the methods here are suitable for concurrent use.
|
||||||
|
// This is achieved by using a mutex lock on all of the provided methods.
|
||||||
type Rand struct {
|
type Rand struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
rand *mrand.Rand
|
rand *mrand.Rand
|
||||||
@ -105,18 +109,6 @@ func RandInt63n(n int64) int64 {
|
|||||||
return grand.Int63n(n)
|
return grand.Int63n(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RandUint16Exp() uint16 {
|
|
||||||
return grand.Uint16Exp()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RandUint32Exp() uint32 {
|
|
||||||
return grand.Uint32Exp()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RandUint64Exp() uint64 {
|
|
||||||
return grand.Uint64Exp()
|
|
||||||
}
|
|
||||||
|
|
||||||
func RandFloat32() float32 {
|
func RandFloat32() float32 {
|
||||||
return grand.Float32()
|
return grand.Float32()
|
||||||
}
|
}
|
||||||
@ -150,8 +142,7 @@ func (r *Rand) Seed(seed int64) {
|
|||||||
r.Unlock()
|
r.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructs an alphanumeric string of given length.
|
// Str constructs a random alphanumeric string of given length.
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Str(length int) string {
|
func (r *Rand) Str(length int) string {
|
||||||
chars := []byte{}
|
chars := []byte{}
|
||||||
MAIN_LOOP:
|
MAIN_LOOP:
|
||||||
@ -175,12 +166,10 @@ MAIN_LOOP:
|
|||||||
return string(chars)
|
return string(chars)
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint16() uint16 {
|
func (r *Rand) Uint16() uint16 {
|
||||||
return uint16(r.Uint32() & (1<<16 - 1))
|
return uint16(r.Uint32() & (1<<16 - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint32() uint32 {
|
func (r *Rand) Uint32() uint32 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
u32 := r.rand.Uint32()
|
u32 := r.rand.Uint32()
|
||||||
@ -188,12 +177,10 @@ func (r *Rand) Uint32() uint32 {
|
|||||||
return u32
|
return u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint64() uint64 {
|
func (r *Rand) Uint64() uint64 {
|
||||||
return uint64(r.Uint32())<<32 + uint64(r.Uint32())
|
return uint64(r.Uint32())<<32 + uint64(r.Uint32())
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint() uint {
|
func (r *Rand) Uint() uint {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i := r.rand.Int()
|
i := r.rand.Int()
|
||||||
@ -201,22 +188,18 @@ func (r *Rand) Uint() uint {
|
|||||||
return uint(i)
|
return uint(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int16() int16 {
|
func (r *Rand) Int16() int16 {
|
||||||
return int16(r.Uint32() & (1<<16 - 1))
|
return int16(r.Uint32() & (1<<16 - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int32() int32 {
|
func (r *Rand) Int32() int32 {
|
||||||
return int32(r.Uint32())
|
return int32(r.Uint32())
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int64() int64 {
|
func (r *Rand) Int64() int64 {
|
||||||
return int64(r.Uint64())
|
return int64(r.Uint64())
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int() int {
|
func (r *Rand) Int() int {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i := r.rand.Int()
|
i := r.rand.Int()
|
||||||
@ -224,7 +207,6 @@ func (r *Rand) Int() int {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int31() int32 {
|
func (r *Rand) Int31() int32 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i31 := r.rand.Int31()
|
i31 := r.rand.Int31()
|
||||||
@ -232,7 +214,6 @@ func (r *Rand) Int31() int32 {
|
|||||||
return i31
|
return i31
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int31n(n int32) int32 {
|
func (r *Rand) Int31n(n int32) int32 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i31n := r.rand.Int31n(n)
|
i31n := r.rand.Int31n(n)
|
||||||
@ -240,7 +221,6 @@ func (r *Rand) Int31n(n int32) int32 {
|
|||||||
return i31n
|
return i31n
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int63() int64 {
|
func (r *Rand) Int63() int64 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i63 := r.rand.Int63()
|
i63 := r.rand.Int63()
|
||||||
@ -248,7 +228,6 @@ func (r *Rand) Int63() int64 {
|
|||||||
return i63
|
return i63
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Int63n(n int64) int64 {
|
func (r *Rand) Int63n(n int64) int64 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i63n := r.rand.Int63n(n)
|
i63n := r.rand.Int63n(n)
|
||||||
@ -256,43 +235,6 @@ func (r *Rand) Int63n(n int64) int64 {
|
|||||||
return i63n
|
return i63n
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distributed pseudo-exponentially to test for various cases
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint16Exp() uint16 {
|
|
||||||
bits := r.Uint32() % 16
|
|
||||||
if bits == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
n := uint16(1 << (bits - 1))
|
|
||||||
n += uint16(r.Int31()) & ((1 << (bits - 1)) - 1)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distributed pseudo-exponentially to test for various cases
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint32Exp() uint32 {
|
|
||||||
bits := r.Uint32() % 32
|
|
||||||
if bits == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
n := uint32(1 << (bits - 1))
|
|
||||||
n += uint32(r.Int31()) & ((1 << (bits - 1)) - 1)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distributed pseudo-exponentially to test for various cases
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Uint64Exp() uint64 {
|
|
||||||
bits := r.Uint32() % 64
|
|
||||||
if bits == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
n := uint64(1 << (bits - 1))
|
|
||||||
n += uint64(r.Int63()) & ((1 << (bits - 1)) - 1)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Float32() float32 {
|
func (r *Rand) Float32() float32 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
f32 := r.rand.Float32()
|
f32 := r.rand.Float32()
|
||||||
@ -300,7 +242,6 @@ func (r *Rand) Float32() float32 {
|
|||||||
return f32
|
return f32
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Float64() float64 {
|
func (r *Rand) Float64() float64 {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
f64 := r.rand.Float64()
|
f64 := r.rand.Float64()
|
||||||
@ -308,13 +249,12 @@ func (r *Rand) Float64() float64 {
|
|||||||
return f64
|
return f64
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Time() time.Time {
|
func (r *Rand) Time() time.Time {
|
||||||
return time.Unix(int64(r.Uint64Exp()), 0)
|
return time.Unix(int64(r.Uint64()), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandBytes returns n random bytes from the OS's source of entropy ie. via crypto/rand.
|
// Bytes returns n random bytes generated from the internal
|
||||||
// It is not safe for cryptographic usage.
|
// prng.
|
||||||
func (r *Rand) Bytes(n int) []byte {
|
func (r *Rand) Bytes(n int) []byte {
|
||||||
// cRandBytes isn't guaranteed to be fast so instead
|
// cRandBytes isn't guaranteed to be fast so instead
|
||||||
// use random bytes generated from the internal PRNG
|
// use random bytes generated from the internal PRNG
|
||||||
@ -325,9 +265,8 @@ func (r *Rand) Bytes(n int) []byte {
|
|||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandIntn returns, as an int, a non-negative pseudo-random number in [0, n).
|
// Intn returns, as an int, a uniform pseudo-random number in the range [0, n).
|
||||||
// It panics if n <= 0.
|
// It panics if n <= 0.
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Intn(n int) int {
|
func (r *Rand) Intn(n int) int {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
i := r.rand.Intn(n)
|
i := r.rand.Intn(n)
|
||||||
@ -335,8 +274,7 @@ func (r *Rand) Intn(n int) int {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandPerm returns a pseudo-random permutation of n integers in [0, n).
|
// Perm returns a pseudo-random permutation of n integers in [0, n).
|
||||||
// It is not safe for cryptographic usage.
|
|
||||||
func (r *Rand) Perm(n int) []int {
|
func (r *Rand) Perm(n int) []int {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
perm := r.rand.Perm(n)
|
perm := r.rand.Perm(n)
|
||||||
|
@ -73,9 +73,6 @@ func testThemAll() string {
|
|||||||
fmt.Fprintf(out, "randInt64: %d\n", RandInt64())
|
fmt.Fprintf(out, "randInt64: %d\n", RandInt64())
|
||||||
fmt.Fprintf(out, "randUint32: %d\n", RandUint32())
|
fmt.Fprintf(out, "randUint32: %d\n", RandUint32())
|
||||||
fmt.Fprintf(out, "randUint64: %d\n", RandUint64())
|
fmt.Fprintf(out, "randUint64: %d\n", RandUint64())
|
||||||
fmt.Fprintf(out, "randUint16Exp: %d\n", RandUint16Exp())
|
|
||||||
fmt.Fprintf(out, "randUint32Exp: %d\n", RandUint32Exp())
|
|
||||||
fmt.Fprintf(out, "randUint64Exp: %d\n", RandUint64Exp())
|
|
||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -131,7 +130,7 @@ func TestRepeatTimerReset(t *testing.T) {
|
|||||||
|
|
||||||
// just random calls
|
// just random calls
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
time.Sleep(time.Duration(rand.Intn(40)) * time.Millisecond)
|
time.Sleep(time.Duration(RandIntn(40)) * time.Millisecond)
|
||||||
timer.Reset()
|
timer.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,32 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: common/types.proto
|
// source: libs/common/types.proto
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package common is a generated protocol buffer package.
|
Package common is a generated protocol buffer package.
|
||||||
|
|
||||||
It is generated from these files:
|
It is generated from these files:
|
||||||
common/types.proto
|
libs/common/types.proto
|
||||||
|
|
||||||
It has these top-level messages:
|
It has these top-level messages:
|
||||||
KVPair
|
KVPair
|
||||||
KI64Pair
|
KI64Pair
|
||||||
*/
|
*/
|
||||||
//nolint: gas
|
//nolint
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
import proto "github.com/gogo/protobuf/proto"
|
||||||
|
import golang_proto "github.com/golang/protobuf/proto"
|
||||||
import fmt "fmt"
|
import fmt "fmt"
|
||||||
import math "math"
|
import math "math"
|
||||||
|
import _ "github.com/gogo/protobuf/gogoproto"
|
||||||
|
|
||||||
|
import bytes "bytes"
|
||||||
|
|
||||||
|
import io "io"
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
var _ = proto.Marshal
|
var _ = proto.Marshal
|
||||||
|
var _ = golang_proto.Marshal
|
||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
var _ = math.Inf
|
var _ = math.Inf
|
||||||
|
|
||||||
@ -27,7 +34,7 @@ var _ = math.Inf
|
|||||||
// is compatible with the proto package it is being compiled against.
|
// is compatible with the proto package it is being compiled against.
|
||||||
// A compilation error at this line likely means your copy of the
|
// A compilation error at this line likely means your copy of the
|
||||||
// proto package needs to be updated.
|
// proto package needs to be updated.
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
// Define these here for compatibility but use tmlibs/common.KVPair.
|
// Define these here for compatibility but use tmlibs/common.KVPair.
|
||||||
type KVPair struct {
|
type KVPair struct {
|
||||||
@ -38,7 +45,7 @@ type KVPair struct {
|
|||||||
func (m *KVPair) Reset() { *m = KVPair{} }
|
func (m *KVPair) Reset() { *m = KVPair{} }
|
||||||
func (m *KVPair) String() string { return proto.CompactTextString(m) }
|
func (m *KVPair) String() string { return proto.CompactTextString(m) }
|
||||||
func (*KVPair) ProtoMessage() {}
|
func (*KVPair) ProtoMessage() {}
|
||||||
func (*KVPair) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
func (*KVPair) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{0} }
|
||||||
|
|
||||||
func (m *KVPair) GetKey() []byte {
|
func (m *KVPair) GetKey() []byte {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
@ -57,13 +64,13 @@ func (m *KVPair) GetValue() []byte {
|
|||||||
// Define these here for compatibility but use tmlibs/common.KI64Pair.
|
// Define these here for compatibility but use tmlibs/common.KI64Pair.
|
||||||
type KI64Pair struct {
|
type KI64Pair struct {
|
||||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||||
Value int64 `protobuf:"varint,2,opt,name=value" json:"value,omitempty"`
|
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *KI64Pair) Reset() { *m = KI64Pair{} }
|
func (m *KI64Pair) Reset() { *m = KI64Pair{} }
|
||||||
func (m *KI64Pair) String() string { return proto.CompactTextString(m) }
|
func (m *KI64Pair) String() string { return proto.CompactTextString(m) }
|
||||||
func (*KI64Pair) ProtoMessage() {}
|
func (*KI64Pair) ProtoMessage() {}
|
||||||
func (*KI64Pair) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
func (*KI64Pair) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{1} }
|
||||||
|
|
||||||
func (m *KI64Pair) GetKey() []byte {
|
func (m *KI64Pair) GetKey() []byte {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
@ -81,18 +88,608 @@ func (m *KI64Pair) GetValue() int64 {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*KVPair)(nil), "common.KVPair")
|
proto.RegisterType((*KVPair)(nil), "common.KVPair")
|
||||||
|
golang_proto.RegisterType((*KVPair)(nil), "common.KVPair")
|
||||||
proto.RegisterType((*KI64Pair)(nil), "common.KI64Pair")
|
proto.RegisterType((*KI64Pair)(nil), "common.KI64Pair")
|
||||||
|
golang_proto.RegisterType((*KI64Pair)(nil), "common.KI64Pair")
|
||||||
|
}
|
||||||
|
func (this *KVPair) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { proto.RegisterFile("common/types.proto", fileDescriptor0) }
|
that1, ok := that.(*KVPair)
|
||||||
|
if !ok {
|
||||||
var fileDescriptor0 = []byte{
|
that2, ok := that.(KVPair)
|
||||||
// 107 bytes of a gzipped FileDescriptorProto
|
if ok {
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4a, 0xce, 0xcf, 0xcd,
|
that1 = &that2
|
||||||
0xcd, 0xcf, 0xd3, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62,
|
} else {
|
||||||
0x83, 0x88, 0x29, 0x19, 0x70, 0xb1, 0x79, 0x87, 0x05, 0x24, 0x66, 0x16, 0x09, 0x09, 0x70, 0x31,
|
return false
|
||||||
0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x04, 0x81, 0x98, 0x42, 0x22, 0x5c, 0xac,
|
}
|
||||||
0x65, 0x89, 0x39, 0xa5, 0xa9, 0x12, 0x4c, 0x60, 0x31, 0x08, 0x47, 0xc9, 0x88, 0x8b, 0xc3, 0xdb,
|
}
|
||||||
0xd3, 0xcc, 0x84, 0x18, 0x3d, 0xcc, 0x50, 0x3d, 0x49, 0x6c, 0x60, 0x4b, 0x8d, 0x01, 0x01, 0x00,
|
if that1 == nil {
|
||||||
0x00, 0xff, 0xff, 0xd8, 0xf1, 0xc3, 0x8c, 0x8a, 0x00, 0x00, 0x00,
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !bytes.Equal(this.Key, that1.Key) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !bytes.Equal(this.Value, that1.Value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (this *KI64Pair) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
that1, ok := that.(*KI64Pair)
|
||||||
|
if !ok {
|
||||||
|
that2, ok := that.(KI64Pair)
|
||||||
|
if ok {
|
||||||
|
that1 = &that2
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if that1 == nil {
|
||||||
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !bytes.Equal(this.Key, that1.Key) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if this.Value != that1.Value {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (m *KVPair) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KVPair) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
var i int
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Key) > 0 {
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(len(m.Key)))
|
||||||
|
i += copy(dAtA[i:], m.Key)
|
||||||
|
}
|
||||||
|
if len(m.Value) > 0 {
|
||||||
|
dAtA[i] = 0x12
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(len(m.Value)))
|
||||||
|
i += copy(dAtA[i:], m.Value)
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KI64Pair) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KI64Pair) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
var i int
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Key) > 0 {
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(len(m.Key)))
|
||||||
|
i += copy(dAtA[i:], m.Key)
|
||||||
|
}
|
||||||
|
if m.Value != 0 {
|
||||||
|
dAtA[i] = 0x10
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(m.Value))
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
|
||||||
|
for v >= 1<<7 {
|
||||||
|
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||||
|
v >>= 7
|
||||||
|
offset++
|
||||||
|
}
|
||||||
|
dAtA[offset] = uint8(v)
|
||||||
|
return offset + 1
|
||||||
|
}
|
||||||
|
func NewPopulatedKVPair(r randyTypes, easy bool) *KVPair {
|
||||||
|
this := &KVPair{}
|
||||||
|
v1 := r.Intn(100)
|
||||||
|
this.Key = make([]byte, v1)
|
||||||
|
for i := 0; i < v1; i++ {
|
||||||
|
this.Key[i] = byte(r.Intn(256))
|
||||||
|
}
|
||||||
|
v2 := r.Intn(100)
|
||||||
|
this.Value = make([]byte, v2)
|
||||||
|
for i := 0; i < v2; i++ {
|
||||||
|
this.Value[i] = byte(r.Intn(256))
|
||||||
|
}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPopulatedKI64Pair(r randyTypes, easy bool) *KI64Pair {
|
||||||
|
this := &KI64Pair{}
|
||||||
|
v3 := r.Intn(100)
|
||||||
|
this.Key = make([]byte, v3)
|
||||||
|
for i := 0; i < v3; i++ {
|
||||||
|
this.Key[i] = byte(r.Intn(256))
|
||||||
|
}
|
||||||
|
this.Value = int64(r.Int63())
|
||||||
|
if r.Intn(2) == 0 {
|
||||||
|
this.Value *= -1
|
||||||
|
}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
type randyTypes interface {
|
||||||
|
Float32() float32
|
||||||
|
Float64() float64
|
||||||
|
Int63() int64
|
||||||
|
Int31() int32
|
||||||
|
Uint32() uint32
|
||||||
|
Intn(n int) int
|
||||||
|
}
|
||||||
|
|
||||||
|
func randUTF8RuneTypes(r randyTypes) rune {
|
||||||
|
ru := r.Intn(62)
|
||||||
|
if ru < 10 {
|
||||||
|
return rune(ru + 48)
|
||||||
|
} else if ru < 36 {
|
||||||
|
return rune(ru + 55)
|
||||||
|
}
|
||||||
|
return rune(ru + 61)
|
||||||
|
}
|
||||||
|
func randStringTypes(r randyTypes) string {
|
||||||
|
v4 := r.Intn(100)
|
||||||
|
tmps := make([]rune, v4)
|
||||||
|
for i := 0; i < v4; i++ {
|
||||||
|
tmps[i] = randUTF8RuneTypes(r)
|
||||||
|
}
|
||||||
|
return string(tmps)
|
||||||
|
}
|
||||||
|
func randUnrecognizedTypes(r randyTypes, maxFieldNumber int) (dAtA []byte) {
|
||||||
|
l := r.Intn(5)
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
|
wire := r.Intn(4)
|
||||||
|
if wire == 3 {
|
||||||
|
wire = 5
|
||||||
|
}
|
||||||
|
fieldNumber := maxFieldNumber + r.Intn(100)
|
||||||
|
dAtA = randFieldTypes(dAtA, r, fieldNumber, wire)
|
||||||
|
}
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func randFieldTypes(dAtA []byte, r randyTypes, fieldNumber int, wire int) []byte {
|
||||||
|
key := uint32(fieldNumber)<<3 | uint32(wire)
|
||||||
|
switch wire {
|
||||||
|
case 0:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
v5 := r.Int63()
|
||||||
|
if r.Intn(2) == 0 {
|
||||||
|
v5 *= -1
|
||||||
|
}
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(v5))
|
||||||
|
case 1:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
|
||||||
|
case 2:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
ll := r.Intn(100)
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(ll))
|
||||||
|
for j := 0; j < ll; j++ {
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)))
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
|
||||||
|
}
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func encodeVarintPopulateTypes(dAtA []byte, v uint64) []byte {
|
||||||
|
for v >= 1<<7 {
|
||||||
|
dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80))
|
||||||
|
v >>= 7
|
||||||
|
}
|
||||||
|
dAtA = append(dAtA, uint8(v))
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func (m *KVPair) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
l = len(m.Key)
|
||||||
|
if l > 0 {
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
l = len(m.Value)
|
||||||
|
if l > 0 {
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *KI64Pair) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
l = len(m.Key)
|
||||||
|
if l > 0 {
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
if m.Value != 0 {
|
||||||
|
n += 1 + sovTypes(uint64(m.Value))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func sovTypes(x uint64) (n int) {
|
||||||
|
for {
|
||||||
|
n++
|
||||||
|
x >>= 7
|
||||||
|
if x == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
func sozTypes(x uint64) (n int) {
|
||||||
|
return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||||
|
}
|
||||||
|
func (m *KVPair) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: KVPair: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: KVPair: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||||
|
}
|
||||||
|
var byteLen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
byteLen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if byteLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + byteLen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||||
|
if m.Key == nil {
|
||||||
|
m.Key = []byte{}
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
|
||||||
|
}
|
||||||
|
var byteLen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
byteLen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if byteLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + byteLen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...)
|
||||||
|
if m.Value == nil {
|
||||||
|
m.Value = []byte{}
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *KI64Pair) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: KI64Pair: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: KI64Pair: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||||
|
}
|
||||||
|
var byteLen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
byteLen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if byteLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + byteLen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||||
|
if m.Key == nil {
|
||||||
|
m.Key = []byte{}
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
|
if wireType != 0 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
|
||||||
|
}
|
||||||
|
m.Value = 0
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
m.Value |= (int64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func skipTypes(dAtA []byte) (n int, err error) {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
switch wireType {
|
||||||
|
case 0:
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx++
|
||||||
|
if dAtA[iNdEx-1] < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 1:
|
||||||
|
iNdEx += 8
|
||||||
|
return iNdEx, nil
|
||||||
|
case 2:
|
||||||
|
var length int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
length |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iNdEx += length
|
||||||
|
if length < 0 {
|
||||||
|
return 0, ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 3:
|
||||||
|
for {
|
||||||
|
var innerWire uint64
|
||||||
|
var start int = iNdEx
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
innerWire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
innerWireType := int(innerWire & 0x7)
|
||||||
|
if innerWireType == 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
next, err := skipTypes(dAtA[start:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
iNdEx = start + next
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 4:
|
||||||
|
return iNdEx, nil
|
||||||
|
case 5:
|
||||||
|
iNdEx += 4
|
||||||
|
return iNdEx, nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||||
|
ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("libs/common/types.proto", fileDescriptorTypes) }
|
||||||
|
func init() { golang_proto.RegisterFile("libs/common/types.proto", fileDescriptorTypes) }
|
||||||
|
|
||||||
|
var fileDescriptorTypes = []byte{
|
||||||
|
// 174 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0xc9, 0x4c, 0x2a,
|
||||||
|
0xd6, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28,
|
||||||
|
0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x88, 0x49, 0xe9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9,
|
||||||
|
0x25, 0xe7, 0xe7, 0xea, 0xa7, 0xe7, 0xa7, 0xe7, 0xeb, 0x83, 0xa5, 0x93, 0x4a, 0xd3, 0xc0, 0x3c,
|
||||||
|
0x30, 0x07, 0xcc, 0x82, 0x68, 0x53, 0x32, 0xe0, 0x62, 0xf3, 0x0e, 0x0b, 0x48, 0xcc, 0x2c, 0x12,
|
||||||
|
0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x02, 0x31, 0x85,
|
||||||
|
0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, 0x25, 0x98, 0xc0, 0x62, 0x10, 0x8e, 0x92, 0x11,
|
||||||
|
0x17, 0x87, 0xb7, 0xa7, 0x99, 0x09, 0x31, 0x7a, 0x98, 0xa1, 0x7a, 0x9c, 0x64, 0x7e, 0x3c, 0x94,
|
||||||
|
0x63, 0x5c, 0xf1, 0x48, 0x8e, 0x71, 0xc7, 0x23, 0x39, 0xc6, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c,
|
||||||
|
0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0xf1, 0xc0, 0x63, 0x39, 0xc6, 0x24, 0x36, 0xb0, 0x53, 0x8c,
|
||||||
|
0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x39, 0xe1, 0xef, 0xdc, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package common;
|
package common;
|
||||||
|
|
||||||
|
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
option (gogoproto.goproto_registration) = true;
|
||||||
|
// Generate tests
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
option (gogoproto.testgen_all) = true;
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
// Abstract types
|
// Abstract types
|
||||||
|
|
||||||
|
280
libs/common/typespb_test.go
Normal file
280
libs/common/typespb_test.go
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
|
// source: libs/common/types.proto
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package common is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
libs/common/types.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
KVPair
|
||||||
|
KI64Pair
|
||||||
|
*/
|
||||||
|
package common
|
||||||
|
|
||||||
|
import testing "testing"
|
||||||
|
import rand "math/rand"
|
||||||
|
import time "time"
|
||||||
|
import proto "github.com/gogo/protobuf/proto"
|
||||||
|
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||||
|
import golang_proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
import _ "github.com/gogo/protobuf/gogoproto"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = golang_proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
func TestKVPairProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KVPair{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKVPairMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KVPair{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKI64PairProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KI64Pair{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKI64PairMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KI64Pair{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKVPairJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KVPair{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestKI64PairJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &KI64Pair{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestKVPairProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &KVPair{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKVPairProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &KVPair{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKI64PairProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &KI64Pair{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKI64PairProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &KI64Pair{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKVPairSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKVPair(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKI64PairSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedKI64Pair(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
@ -2,11 +2,11 @@ package events
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestAddListenerForEventFireOnce sets up an EventSwitch, subscribes a single
|
// TestAddListenerForEventFireOnce sets up an EventSwitch, subscribes a single
|
||||||
@ -306,8 +306,8 @@ func TestRemoveListenersAsync(t *testing.T) {
|
|||||||
// collect received events for event2
|
// collect received events for event2
|
||||||
go sumReceivedNumbers(numbers2, doneSum2)
|
go sumReceivedNumbers(numbers2, doneSum2)
|
||||||
addListenersStress := func() {
|
addListenersStress := func() {
|
||||||
s1 := rand.NewSource(time.Now().UnixNano())
|
r1 := cmn.NewRand()
|
||||||
r1 := rand.New(s1)
|
r1.Seed(time.Now().UnixNano())
|
||||||
for k := uint16(0); k < 400; k++ {
|
for k := uint16(0); k < 400; k++ {
|
||||||
listenerNumber := r1.Intn(100) + 3
|
listenerNumber := r1.Intn(100) + 3
|
||||||
eventNumber := r1.Intn(3) + 1
|
eventNumber := r1.Intn(3) + 1
|
||||||
@ -317,8 +317,8 @@ func TestRemoveListenersAsync(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeListenersStress := func() {
|
removeListenersStress := func() {
|
||||||
s2 := rand.NewSource(time.Now().UnixNano())
|
r2 := cmn.NewRand()
|
||||||
r2 := rand.New(s2)
|
r2.Seed(time.Now().UnixNano())
|
||||||
for k := uint16(0); k < 80; k++ {
|
for k := uint16(0); k < 80; k++ {
|
||||||
listenerNumber := r2.Intn(100) + 3
|
listenerNumber := r2.Intn(100) + 3
|
||||||
go evsw.RemoveListener(fmt.Sprintf("listener%v", listenerNumber))
|
go evsw.RemoveListener(fmt.Sprintf("listener%v", listenerNumber))
|
||||||
|
@ -2,11 +2,11 @@ package files
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -23,7 +25,7 @@ type ValKeys []crypto.PrivKey
|
|||||||
func GenValKeys(n int) ValKeys {
|
func GenValKeys(n int) ValKeys {
|
||||||
res := make(ValKeys, n)
|
res := make(ValKeys, n)
|
||||||
for i := range res {
|
for i := range res {
|
||||||
res[i] = crypto.GenPrivKeyEd25519()
|
res[i] = ed25519.GenPrivKey()
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
@ -32,7 +34,7 @@ func GenValKeys(n int) ValKeys {
|
|||||||
func (v ValKeys) Change(i int) ValKeys {
|
func (v ValKeys) Change(i int) ValKeys {
|
||||||
res := make(ValKeys, len(v))
|
res := make(ValKeys, len(v))
|
||||||
copy(res, v)
|
copy(res, v)
|
||||||
res[i] = crypto.GenPrivKeyEd25519()
|
res[i] = ed25519.GenPrivKey()
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ func (v ValKeys) Extend(n int) ValKeys {
|
|||||||
func GenSecpValKeys(n int) ValKeys {
|
func GenSecpValKeys(n int) ValKeys {
|
||||||
res := make(ValKeys, n)
|
res := make(ValKeys, n)
|
||||||
for i := range res {
|
for i := range res {
|
||||||
res[i] = crypto.GenPrivKeySecp256k1()
|
res[i] = secp256k1.GenPrivKey()
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,12 @@ package lite
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -280,7 +279,11 @@ func BenchmarkMemStoreProviderGetByHeightBinarySearch1000(b *testing.B) {
|
|||||||
benchmarkMemStoreProvidergetByHeight(b, fcs1000, h1000, binarySearch)
|
benchmarkMemStoreProvidergetByHeight(b, fcs1000, h1000, binarySearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rng = rand.New(rand.NewSource(10))
|
var rng = cmn.NewRand()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rng.Seed(10)
|
||||||
|
}
|
||||||
|
|
||||||
func benchmarkMemStoreProvidergetByHeight(b *testing.B, fcs []FullCommit, fHeights []int64, algo algo) {
|
func benchmarkMemStoreProvidergetByHeight(b *testing.B, fcs []FullCommit, fHeights []int64, algo algo) {
|
||||||
lazyGenerateFullCommits(b)
|
lazyGenerateFullCommits(b)
|
||||||
|
@ -15,14 +15,14 @@ func ValidateBlockMeta(meta *types.BlockMeta, check lite.Commit) error {
|
|||||||
return errors.New("expecting a non-nil BlockMeta")
|
return errors.New("expecting a non-nil BlockMeta")
|
||||||
}
|
}
|
||||||
// TODO: check the BlockID??
|
// TODO: check the BlockID??
|
||||||
return ValidateHeader(meta.Header, check)
|
return ValidateHeader(&meta.Header, check)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateBlock(meta *types.Block, check lite.Commit) error {
|
func ValidateBlock(meta *types.Block, check lite.Commit) error {
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
return errors.New("expecting a non-nil Block")
|
return errors.New("expecting a non-nil Block")
|
||||||
}
|
}
|
||||||
err := ValidateHeader(meta.Header, check)
|
err := ValidateHeader(&meta.Header, check)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ var (
|
|||||||
testTime2 = time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC)
|
testTime2 = time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC)
|
||||||
)
|
)
|
||||||
|
|
||||||
var hdrHeight11 = &types.Header{
|
var hdrHeight11 = types.Header{
|
||||||
Height: 11,
|
Height: 11,
|
||||||
Time: testTime1,
|
Time: testTime1,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
@ -34,21 +34,18 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
block: nil, wantErr: "non-nil Block",
|
block: nil, wantErr: "non-nil Block",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
block: &types.Block{}, wantErr: "nil Header",
|
block: &types.Block{},
|
||||||
},
|
|
||||||
{
|
|
||||||
block: &types.Block{Header: new(types.Header)},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: &types.Header{Height: 10}},
|
block: &types.Block{Header: types.Header{Height: 10}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
wantErr: "don't match - 10 vs 11",
|
wantErr: "don't match - 10 vs 11",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: &types.Header{Height: 11}},
|
block: &types.Block{Header: types.Header{Height: 11}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
},
|
},
|
||||||
// End Header.Height mismatch test
|
// End Header.Height mismatch test
|
||||||
@ -62,15 +59,15 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: hdrHeight11},
|
block: &types.Block{Header: hdrHeight11},
|
||||||
commit: lite.Commit{Header: hdrHeight11},
|
commit: lite.Commit{Header: &hdrHeight11},
|
||||||
},
|
},
|
||||||
// End Header.Hash mismatch test
|
// End Header.Hash mismatch test
|
||||||
|
|
||||||
// Start Header.Data hash mismatch test
|
// Start Header.Data hash mismatch test
|
||||||
{
|
{
|
||||||
block: &types.Block{
|
block: &types.Block{
|
||||||
Header: &types.Header{Height: 11},
|
Header: types.Header{Height: 11},
|
||||||
Data: &types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}},
|
Data: types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}},
|
||||||
},
|
},
|
||||||
commit: lite.Commit{
|
commit: lite.Commit{
|
||||||
Header: &types.Header{Height: 11},
|
Header: &types.Header{Height: 11},
|
||||||
@ -80,8 +77,8 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
block: &types.Block{
|
block: &types.Block{
|
||||||
Header: &types.Header{Height: 11, DataHash: deadBeefHash},
|
Header: types.Header{Height: 11, DataHash: deadBeefHash},
|
||||||
Data: &types.Data{Txs: deadBeefTxs},
|
Data: types.Data{Txs: deadBeefTxs},
|
||||||
},
|
},
|
||||||
commit: lite.Commit{
|
commit: lite.Commit{
|
||||||
Header: &types.Header{Height: 11},
|
Header: &types.Header{Height: 11},
|
||||||
@ -116,21 +113,18 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
meta: nil, wantErr: "non-nil BlockMeta",
|
meta: nil, wantErr: "non-nil BlockMeta",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{}, wantErr: "non-nil Header",
|
meta: &types.BlockMeta{},
|
||||||
},
|
|
||||||
{
|
|
||||||
meta: &types.BlockMeta{Header: new(types.Header)},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: &types.Header{Height: 10}},
|
meta: &types.BlockMeta{Header: types.Header{Height: 10}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
wantErr: "don't match - 10 vs 11",
|
wantErr: "don't match - 10 vs 11",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: &types.Header{Height: 11}},
|
meta: &types.BlockMeta{Header: types.Header{Height: 11}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
},
|
},
|
||||||
// End Header.Height mismatch test
|
// End Header.Height mismatch test
|
||||||
@ -144,12 +138,12 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: hdrHeight11},
|
meta: &types.BlockMeta{Header: hdrHeight11},
|
||||||
commit: lite.Commit{Header: hdrHeight11},
|
commit: lite.Commit{Header: &hdrHeight11},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11,
|
Height: 11,
|
||||||
ValidatorsHash: []byte("lite-test"),
|
ValidatorsHash: []byte("lite-test"),
|
||||||
// TODO: should be able to use empty time after Amino upgrade
|
// TODO: should be able to use empty time after Amino upgrade
|
||||||
@ -164,7 +158,7 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11, DataHash: deadBeefHash,
|
Height: 11, DataHash: deadBeefHash,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
Time: testTime1,
|
Time: testTime1,
|
||||||
@ -183,7 +177,7 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11, DataHash: deadBeefHash,
|
Height: 11, DataHash: deadBeefHash,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
Time: testTime2,
|
Time: testTime2,
|
||||||
|
@ -78,7 +78,7 @@ type Mempool struct {
|
|||||||
recheckCursor *clist.CElement // next expected response
|
recheckCursor *clist.CElement // next expected response
|
||||||
recheckEnd *clist.CElement // re-checking stops here
|
recheckEnd *clist.CElement // re-checking stops here
|
||||||
notifiedTxsAvailable bool
|
notifiedTxsAvailable bool
|
||||||
txsAvailable chan int64 // fires the next height once for each height, when the mempool is not empty
|
txsAvailable chan struct{} // fires once for each height, when the mempool is not empty
|
||||||
|
|
||||||
// Keep a cache of already-seen txs.
|
// Keep a cache of already-seen txs.
|
||||||
// This reduces the pressure on the proxyApp.
|
// This reduces the pressure on the proxyApp.
|
||||||
@ -130,7 +130,7 @@ func NewMempool(
|
|||||||
// ensuring it will trigger once every height when transactions are available.
|
// ensuring it will trigger once every height when transactions are available.
|
||||||
// NOTE: not thread safe - should only be called once, on startup
|
// NOTE: not thread safe - should only be called once, on startup
|
||||||
func (mem *Mempool) EnableTxsAvailable() {
|
func (mem *Mempool) EnableTxsAvailable() {
|
||||||
mem.txsAvailable = make(chan int64, 1)
|
mem.txsAvailable = make(chan struct{}, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLogger sets the Logger.
|
// SetLogger sets the Logger.
|
||||||
@ -348,7 +348,7 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
|
|||||||
// TxsAvailable returns a channel which fires once for every height,
|
// TxsAvailable returns a channel which fires once for every height,
|
||||||
// and only when transactions are available in the mempool.
|
// and only when transactions are available in the mempool.
|
||||||
// NOTE: the returned channel may be nil if EnableTxsAvailable was not called.
|
// NOTE: the returned channel may be nil if EnableTxsAvailable was not called.
|
||||||
func (mem *Mempool) TxsAvailable() <-chan int64 {
|
func (mem *Mempool) TxsAvailable() <-chan struct{} {
|
||||||
return mem.txsAvailable
|
return mem.txsAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,11 +358,11 @@ func (mem *Mempool) notifyTxsAvailable() {
|
|||||||
}
|
}
|
||||||
if mem.txsAvailable != nil && !mem.notifiedTxsAvailable {
|
if mem.txsAvailable != nil && !mem.notifiedTxsAvailable {
|
||||||
// channel cap is 1, so this will send once
|
// channel cap is 1, so this will send once
|
||||||
|
mem.notifiedTxsAvailable = true
|
||||||
select {
|
select {
|
||||||
case mem.txsAvailable <- mem.height + 1:
|
case mem.txsAvailable <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
mem.notifiedTxsAvailable = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func newMempoolWithApp(cc proxy.ClientCreator) *Mempool {
|
|||||||
return mempool
|
return mempool
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureNoFire(t *testing.T, ch <-chan int64, timeoutMS int) {
|
func ensureNoFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
|
||||||
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
|
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
@ -47,7 +47,7 @@ func ensureNoFire(t *testing.T, ch <-chan int64, timeoutMS int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureFire(t *testing.T, ch <-chan int64, timeoutMS int) {
|
func ensureFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
|
||||||
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
|
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
amino "github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
dbm "github.com/tendermint/tendermint/libs/db"
|
dbm "github.com/tendermint/tendermint/libs/db"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
@ -20,7 +21,6 @@ import (
|
|||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
cs "github.com/tendermint/tendermint/consensus"
|
cs "github.com/tendermint/tendermint/consensus"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
|
||||||
"github.com/tendermint/tendermint/evidence"
|
"github.com/tendermint/tendermint/evidence"
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
@ -197,7 +197,7 @@ func NewNode(config *cfg.Config,
|
|||||||
var (
|
var (
|
||||||
// TODO: persist this key so external signer
|
// TODO: persist this key so external signer
|
||||||
// can actually authenticate us
|
// can actually authenticate us
|
||||||
privKey = crypto.GenPrivKeyEd25519()
|
privKey = ed25519.GenPrivKey()
|
||||||
pvsc = privval.NewSocketPV(
|
pvsc = privval.NewSocketPV(
|
||||||
logger.With("module", "privval"),
|
logger.With("module", "privval"),
|
||||||
config.PrivValidatorListenAddr,
|
config.PrivValidatorListenAddr,
|
||||||
@ -324,7 +324,7 @@ func NewNode(config *cfg.Config,
|
|||||||
&pex.PEXReactorConfig{
|
&pex.PEXReactorConfig{
|
||||||
Seeds: cmn.SplitAndTrim(config.P2P.Seeds, ",", " "),
|
Seeds: cmn.SplitAndTrim(config.P2P.Seeds, ",", " "),
|
||||||
SeedMode: config.P2P.SeedMode,
|
SeedMode: config.P2P.SeedMode,
|
||||||
PrivatePeerIDs: cmn.SplitAndTrim(config.P2P.PrivatePeerIDs, ",", " ")})
|
})
|
||||||
pexReactor.SetLogger(p2pLogger)
|
pexReactor.SetLogger(p2pLogger)
|
||||||
sw.AddReactor("PEX", pexReactor)
|
sw.AddReactor("PEX", pexReactor)
|
||||||
}
|
}
|
||||||
@ -449,6 +449,9 @@ func (n *Node) OnStart() error {
|
|||||||
// Add ourselves to addrbook to prevent dialing ourselves
|
// Add ourselves to addrbook to prevent dialing ourselves
|
||||||
n.addrBook.AddOurAddress(nodeInfo.NetAddress())
|
n.addrBook.AddOurAddress(nodeInfo.NetAddress())
|
||||||
|
|
||||||
|
// Add private IDs to addrbook to block those peers being added
|
||||||
|
n.addrBook.AddPrivateIDs(cmn.SplitAndTrim(n.config.P2P.PrivatePeerIDs, ",", " "))
|
||||||
|
|
||||||
// Start the RPC server before the P2P server
|
// Start the RPC server before the P2P server
|
||||||
// so we can eg. receive txs for the first block
|
// so we can eg. receive txs for the first block
|
||||||
if n.config.RPC.ListenAddress != "" {
|
if n.config.RPC.ListenAddress != "" {
|
||||||
|
@ -2,11 +2,11 @@ package node
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
amino "github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ func makeKVStoreConnPair() (fooConn, barConn kvstoreConn) {
|
|||||||
func makeSecretConnPair(tb testing.TB) (fooSecConn, barSecConn *SecretConnection) {
|
func makeSecretConnPair(tb testing.TB) (fooSecConn, barSecConn *SecretConnection) {
|
||||||
|
|
||||||
var fooConn, barConn = makeKVStoreConnPair()
|
var fooConn, barConn = makeKVStoreConnPair()
|
||||||
var fooPrvKey = crypto.GenPrivKeyEd25519()
|
var fooPrvKey = ed25519.GenPrivKey()
|
||||||
var fooPubKey = fooPrvKey.PubKey()
|
var fooPubKey = fooPrvKey.PubKey()
|
||||||
var barPrvKey = crypto.GenPrivKeyEd25519()
|
var barPrvKey = ed25519.GenPrivKey()
|
||||||
var barPubKey = barPrvKey.PubKey()
|
var barPubKey = barPrvKey.PubKey()
|
||||||
|
|
||||||
// Make connections from both sides in parallel.
|
// Make connections from both sides in parallel.
|
||||||
@ -105,7 +105,7 @@ func TestSecretConnectionReadWrite(t *testing.T) {
|
|||||||
genNodeRunner := func(id string, nodeConn kvstoreConn, nodeWrites []string, nodeReads *[]string) cmn.Task {
|
genNodeRunner := func(id string, nodeConn kvstoreConn, nodeWrites []string, nodeReads *[]string) cmn.Task {
|
||||||
return func(_ int) (interface{}, error, bool) {
|
return func(_ int) (interface{}, error, bool) {
|
||||||
// Initiate cryptographic private key and secret connection trhough nodeConn.
|
// Initiate cryptographic private key and secret connection trhough nodeConn.
|
||||||
nodePrvKey := crypto.GenPrivKeyEd25519()
|
nodePrvKey := ed25519.GenPrivKey()
|
||||||
nodeSecretConn, err := MakeSecretConnection(nodeConn, nodePrvKey)
|
nodeSecretConn, err := MakeSecretConnection(nodeConn, nodePrvKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to establish SecretConnection for node: %v", err)
|
t.Errorf("Failed to establish SecretConnection for node: %v", err)
|
||||||
|
@ -2,12 +2,12 @@ package conn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc *amino.Codec = amino.NewCodec()
|
var cdc *amino.Codec = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
RegisterPacket(cdc)
|
RegisterPacket(cdc)
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package dummy
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
p2p "github.com/tendermint/tendermint/p2p"
|
p2p "github.com/tendermint/tendermint/p2p"
|
||||||
tmconn "github.com/tendermint/tendermint/p2p/conn"
|
tmconn "github.com/tendermint/tendermint/p2p/conn"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type peer struct {
|
type peer struct {
|
||||||
@ -78,3 +78,8 @@ func (p *peer) Get(key string) interface{} {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OriginalAddr always returns nil.
|
||||||
|
func (p *peer) OriginalAddr() *p2p.NetAddress {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genNodeKey(filePath string) (*NodeKey, error) {
|
func genNodeKey(filePath string) (*NodeKey, error) {
|
||||||
privKey := crypto.GenPrivKeyEd25519()
|
privKey := ed25519.GenPrivKey()
|
||||||
nodeKey := &NodeKey{
|
nodeKey := &NodeKey{
|
||||||
PrivKey: privKey,
|
PrivKey: privKey,
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@ package p2p
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -81,8 +82,8 @@ func (info NodeInfo) Validate() error {
|
|||||||
// CONTRACT: two nodes are compatible if the major version matches and network match
|
// CONTRACT: two nodes are compatible if the major version matches and network match
|
||||||
// and they have at least one channel in common.
|
// and they have at least one channel in common.
|
||||||
func (info NodeInfo) CompatibleWith(other NodeInfo) error {
|
func (info NodeInfo) CompatibleWith(other NodeInfo) error {
|
||||||
iMajor, iMinor, _, iErr := splitVersion(info.Version)
|
iMajor, _, _, iErr := splitVersion(info.Version)
|
||||||
oMajor, oMinor, _, oErr := splitVersion(other.Version)
|
oMajor, _, _, oErr := splitVersion(other.Version)
|
||||||
|
|
||||||
// if our own version number is not formatted right, we messed up
|
// if our own version number is not formatted right, we messed up
|
||||||
if iErr != nil {
|
if iErr != nil {
|
||||||
@ -99,11 +100,6 @@ func (info NodeInfo) CompatibleWith(other NodeInfo) error {
|
|||||||
return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oMajor, iMajor)
|
return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oMajor, iMajor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// minor version can differ
|
|
||||||
if iMinor != oMinor {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// nodes must be on the same network
|
// nodes must be on the same network
|
||||||
if info.Network != other.Network {
|
if info.Network != other.Network {
|
||||||
return fmt.Errorf("Peer is on a different network. Got %v, expected %v", other.Network, info.Network)
|
return fmt.Errorf("Peer is on a different network. Got %v, expected %v", other.Network, info.Network)
|
||||||
|
17
p2p/peer.go
17
p2p/peer.go
@ -26,6 +26,7 @@ type Peer interface {
|
|||||||
IsPersistent() bool // do we redial this peer when we disconnect
|
IsPersistent() bool // do we redial this peer when we disconnect
|
||||||
NodeInfo() NodeInfo // peer's info
|
NodeInfo() NodeInfo // peer's info
|
||||||
Status() tmconn.ConnectionStatus
|
Status() tmconn.ConnectionStatus
|
||||||
|
OriginalAddr() *NetAddress
|
||||||
|
|
||||||
Send(byte, []byte) bool
|
Send(byte, []byte) bool
|
||||||
TrySend(byte, []byte) bool
|
TrySend(byte, []byte) bool
|
||||||
@ -43,6 +44,7 @@ type peerConn struct {
|
|||||||
config *config.P2PConfig
|
config *config.P2PConfig
|
||||||
conn net.Conn // source connection
|
conn net.Conn // source connection
|
||||||
ip net.IP
|
ip net.IP
|
||||||
|
originalAddr *NetAddress // nil for inbound connections
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID only exists for SecretConnection.
|
// ID only exists for SecretConnection.
|
||||||
@ -139,7 +141,7 @@ func newOutboundPeerConn(
|
|||||||
return peerConn{}, cmn.ErrorWrap(err, "Error creating peer")
|
return peerConn{}, cmn.ErrorWrap(err, "Error creating peer")
|
||||||
}
|
}
|
||||||
|
|
||||||
pc, err := newPeerConn(conn, config, true, persistent, ourNodePrivKey)
|
pc, err := newPeerConn(conn, config, true, persistent, ourNodePrivKey, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if cerr := conn.Close(); cerr != nil {
|
if cerr := conn.Close(); cerr != nil {
|
||||||
return peerConn{}, cmn.ErrorWrap(err, cerr.Error())
|
return peerConn{}, cmn.ErrorWrap(err, cerr.Error())
|
||||||
@ -166,7 +168,7 @@ func newInboundPeerConn(
|
|||||||
|
|
||||||
// TODO: issue PoW challenge
|
// TODO: issue PoW challenge
|
||||||
|
|
||||||
return newPeerConn(conn, config, false, false, ourNodePrivKey)
|
return newPeerConn(conn, config, false, false, ourNodePrivKey, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeerConn(
|
func newPeerConn(
|
||||||
@ -174,6 +176,7 @@ func newPeerConn(
|
|||||||
cfg *config.P2PConfig,
|
cfg *config.P2PConfig,
|
||||||
outbound, persistent bool,
|
outbound, persistent bool,
|
||||||
ourNodePrivKey crypto.PrivKey,
|
ourNodePrivKey crypto.PrivKey,
|
||||||
|
originalAddr *NetAddress,
|
||||||
) (pc peerConn, err error) {
|
) (pc peerConn, err error) {
|
||||||
conn := rawConn
|
conn := rawConn
|
||||||
|
|
||||||
@ -204,6 +207,7 @@ func newPeerConn(
|
|||||||
outbound: outbound,
|
outbound: outbound,
|
||||||
persistent: persistent,
|
persistent: persistent,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
originalAddr: originalAddr,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +258,15 @@ func (p *peer) NodeInfo() NodeInfo {
|
|||||||
return p.nodeInfo
|
return p.nodeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OriginalAddr returns the original address, which was used to connect with
|
||||||
|
// the peer. Returns nil for inbound peers.
|
||||||
|
func (p *peer) OriginalAddr() *NetAddress {
|
||||||
|
if p.peerConn.outbound {
|
||||||
|
return p.peerConn.originalAddr
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Status returns the peer's ConnectionStatus.
|
// Status returns the peer's ConnectionStatus.
|
||||||
func (p *peer) Status() tmconn.ConnectionStatus {
|
func (p *peer) Status() tmconn.ConnectionStatus {
|
||||||
return p.mconn.Status()
|
return p.mconn.Status()
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,11 +17,11 @@ func randPeer(ip net.IP) *peer {
|
|||||||
ip = net.IP{127, 0, 0, 1}
|
ip = net.IP{127, 0, 0, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeKey := NodeKey{PrivKey: crypto.GenPrivKeyEd25519()}
|
nodeKey := NodeKey{PrivKey: ed25519.GenPrivKey()}
|
||||||
p := &peer{
|
p := &peer{
|
||||||
nodeInfo: NodeInfo{
|
nodeInfo: NodeInfo{
|
||||||
ID: nodeKey.ID(),
|
ID: nodeKey.ID(),
|
||||||
ListenAddr: cmn.Fmt("%v.%v.%v.%v:26656", rand.Int()%256, rand.Int()%256, rand.Int()%256, rand.Int()%256),
|
ListenAddr: cmn.Fmt("%v.%v.%v.%v:26656", cmn.RandInt()%256, cmn.RandInt()%256, cmn.RandInt()%256, cmn.RandInt()%256),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ func TestPeerBasic(t *testing.T) {
|
|||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
// simulate remote peer
|
// simulate remote peer
|
||||||
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: cfg}
|
rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
|
||||||
rp.Start()
|
rp.Start()
|
||||||
defer rp.Stop()
|
defer rp.Stop()
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ func TestPeerSend(t *testing.T) {
|
|||||||
config := cfg
|
config := cfg
|
||||||
|
|
||||||
// simulate remote peer
|
// simulate remote peer
|
||||||
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: config}
|
rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: config}
|
||||||
rp.Start()
|
rp.Start()
|
||||||
defer rp.Stop()
|
defer rp.Stop()
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ func createOutboundPeerAndPerformHandshake(
|
|||||||
{ID: testCh, Priority: 1},
|
{ID: testCh, Priority: 1},
|
||||||
}
|
}
|
||||||
reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)}
|
reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)}
|
||||||
pk := crypto.GenPrivKeyEd25519()
|
pk := ed25519.GenPrivKey()
|
||||||
pc, err := newOutboundPeerConn(addr, config, false, pk)
|
pc, err := newOutboundPeerConn(addr, config, false, pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
"github.com/tendermint/tendermint/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -34,6 +34,8 @@ type AddrBook interface {
|
|||||||
// Check if it is our address
|
// Check if it is our address
|
||||||
OurAddress(*p2p.NetAddress) bool
|
OurAddress(*p2p.NetAddress) bool
|
||||||
|
|
||||||
|
AddPrivateIDs([]string)
|
||||||
|
|
||||||
// Add and remove an address
|
// Add and remove an address
|
||||||
AddAddress(addr *p2p.NetAddress, src *p2p.NetAddress) error
|
AddAddress(addr *p2p.NetAddress, src *p2p.NetAddress) error
|
||||||
RemoveAddress(*p2p.NetAddress)
|
RemoveAddress(*p2p.NetAddress)
|
||||||
@ -82,6 +84,7 @@ type addrBook struct {
|
|||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
rand *cmn.Rand
|
rand *cmn.Rand
|
||||||
ourAddrs map[string]struct{}
|
ourAddrs map[string]struct{}
|
||||||
|
privateIDs map[p2p.ID]struct{}
|
||||||
addrLookup map[p2p.ID]*knownAddress // new & old
|
addrLookup map[p2p.ID]*knownAddress // new & old
|
||||||
bucketsOld []map[string]*knownAddress
|
bucketsOld []map[string]*knownAddress
|
||||||
bucketsNew []map[string]*knownAddress
|
bucketsNew []map[string]*knownAddress
|
||||||
@ -97,6 +100,7 @@ func NewAddrBook(filePath string, routabilityStrict bool) *addrBook {
|
|||||||
am := &addrBook{
|
am := &addrBook{
|
||||||
rand: cmn.NewRand(),
|
rand: cmn.NewRand(),
|
||||||
ourAddrs: make(map[string]struct{}),
|
ourAddrs: make(map[string]struct{}),
|
||||||
|
privateIDs: make(map[p2p.ID]struct{}),
|
||||||
addrLookup: make(map[p2p.ID]*knownAddress),
|
addrLookup: make(map[p2p.ID]*knownAddress),
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
routabilityStrict: routabilityStrict,
|
routabilityStrict: routabilityStrict,
|
||||||
@ -168,6 +172,14 @@ func (a *addrBook) OurAddress(addr *p2p.NetAddress) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *addrBook) AddPrivateIDs(IDs []string) {
|
||||||
|
a.mtx.Lock()
|
||||||
|
defer a.mtx.Unlock()
|
||||||
|
for _, id := range IDs {
|
||||||
|
a.privateIDs[p2p.ID(id)] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AddAddress implements AddrBook
|
// AddAddress implements AddrBook
|
||||||
// Add address to a "new" bucket. If it's already in one, only add it probabilistically.
|
// Add address to a "new" bucket. If it's already in one, only add it probabilistically.
|
||||||
// Returns error if the addr is non-routable. Does not add self.
|
// Returns error if the addr is non-routable. Does not add self.
|
||||||
@ -631,6 +643,10 @@ func (a *addrBook) addAddress(addr, src *p2p.NetAddress) error {
|
|||||||
return ErrAddrBookSelf{addr}
|
return ErrAddrBookSelf{addr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := a.privateIDs[addr.ID]; ok {
|
||||||
|
return ErrAddrBookPrivate{addr}
|
||||||
|
}
|
||||||
|
|
||||||
ka := a.addrLookup[addr.ID]
|
ka := a.addrLookup[addr.ID]
|
||||||
if ka != nil {
|
if ka != nil {
|
||||||
// If its already old and the addr is the same, ignore it.
|
// If its already old and the addr is the same, ignore it.
|
||||||
|
@ -4,14 +4,15 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
"github.com/tendermint/tendermint/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTempFileName(prefix string) string {
|
func createTempFileName(prefix string) string {
|
||||||
@ -202,12 +203,12 @@ func randNetAddressPairs(t *testing.T, n int) []netAddressPair {
|
|||||||
func randIPv4Address(t *testing.T) *p2p.NetAddress {
|
func randIPv4Address(t *testing.T) *p2p.NetAddress {
|
||||||
for {
|
for {
|
||||||
ip := fmt.Sprintf("%v.%v.%v.%v",
|
ip := fmt.Sprintf("%v.%v.%v.%v",
|
||||||
rand.Intn(254)+1,
|
cmn.RandIntn(254)+1,
|
||||||
rand.Intn(255),
|
cmn.RandIntn(255),
|
||||||
rand.Intn(255),
|
cmn.RandIntn(255),
|
||||||
rand.Intn(255),
|
cmn.RandIntn(255),
|
||||||
)
|
)
|
||||||
port := rand.Intn(65535-1) + 1
|
port := cmn.RandIntn(65535-1) + 1
|
||||||
id := p2p.ID(hex.EncodeToString(cmn.RandBytes(p2p.IDByteLength)))
|
id := p2p.ID(hex.EncodeToString(cmn.RandBytes(p2p.IDByteLength)))
|
||||||
idAddr := p2p.IDAddressString(id, fmt.Sprintf("%v:%v", ip, port))
|
idAddr := p2p.IDAddressString(id, fmt.Sprintf("%v:%v", ip, port))
|
||||||
addr, err := p2p.NewNetAddressString(idAddr)
|
addr, err := p2p.NewNetAddressString(idAddr)
|
||||||
@ -354,3 +355,29 @@ func TestAddrBookHasAddress(t *testing.T) {
|
|||||||
|
|
||||||
assert.False(t, book.HasAddress(addr))
|
assert.False(t, book.HasAddress(addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrivatePeers(t *testing.T) {
|
||||||
|
fname := createTempFileName("addrbook_test")
|
||||||
|
defer deleteTempFile(fname)
|
||||||
|
|
||||||
|
book := NewAddrBook(fname, true)
|
||||||
|
book.SetLogger(log.TestingLogger())
|
||||||
|
|
||||||
|
addrs := make([]*p2p.NetAddress, 10)
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
addrs[i] = randIPv4Address(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
private := make([]string, 10)
|
||||||
|
for i, addr := range addrs {
|
||||||
|
private[i] = string(addr.ID)
|
||||||
|
}
|
||||||
|
book.AddPrivateIDs(private)
|
||||||
|
|
||||||
|
for _, addr := range addrs {
|
||||||
|
err := book.AddAddress(addr, addr)
|
||||||
|
require.Error(t, err, "AddAddress should have failed with private peer %s", addr)
|
||||||
|
_, ok := err.(ErrAddrBookPrivate)
|
||||||
|
require.True(t, ok, "Wrong error type, wanted ErrAddrBookPrivate, got error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,6 +22,14 @@ func (err ErrAddrBookSelf) Error() string {
|
|||||||
return fmt.Sprintf("Cannot add ourselves with address %v", err.Addr)
|
return fmt.Sprintf("Cannot add ourselves with address %v", err.Addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrAddrBookPrivate struct {
|
||||||
|
Addr *p2p.NetAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrAddrBookPrivate) Error() string {
|
||||||
|
return fmt.Sprintf("Cannot add private peer with address %v", err.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
type ErrAddrBookNilAddr struct {
|
type ErrAddrBookNilAddr struct {
|
||||||
Addr *p2p.NetAddress
|
Addr *p2p.NetAddress
|
||||||
Src *p2p.NetAddress
|
Src *p2p.NetAddress
|
||||||
|
@ -91,10 +91,6 @@ type PEXReactorConfig struct {
|
|||||||
// Seeds is a list of addresses reactor may use
|
// Seeds is a list of addresses reactor may use
|
||||||
// if it can't connect to peers in the addrbook.
|
// if it can't connect to peers in the addrbook.
|
||||||
Seeds []string
|
Seeds []string
|
||||||
|
|
||||||
// PrivatePeerIDs is a list of peer IDs, which must not be gossiped to other
|
|
||||||
// peers.
|
|
||||||
PrivatePeerIDs []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type _attemptsToDial struct {
|
type _attemptsToDial struct {
|
||||||
@ -173,11 +169,6 @@ func (r *PEXReactor) AddPeer(p Peer) {
|
|||||||
addr := p.NodeInfo().NetAddress()
|
addr := p.NodeInfo().NetAddress()
|
||||||
src := addr
|
src := addr
|
||||||
|
|
||||||
// ignore private addrs
|
|
||||||
if isAddrPrivate(addr, r.config.PrivatePeerIDs) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// add to book. dont RequestAddrs right away because
|
// add to book. dont RequestAddrs right away because
|
||||||
// we don't trust inbound as much - let ensurePeersRoutine handle it.
|
// we don't trust inbound as much - let ensurePeersRoutine handle it.
|
||||||
err := r.book.AddAddress(addr, src)
|
err := r.book.AddAddress(addr, src)
|
||||||
@ -191,7 +182,7 @@ func (r *PEXReactor) logErrAddrBook(err error) {
|
|||||||
case ErrAddrBookNilAddr:
|
case ErrAddrBookNilAddr:
|
||||||
r.Logger.Error("Failed to add new address", "err", err)
|
r.Logger.Error("Failed to add new address", "err", err)
|
||||||
default:
|
default:
|
||||||
// non-routable, self, full book, etc.
|
// non-routable, self, full book, private, etc.
|
||||||
r.Logger.Debug("Failed to add new address", "err", err)
|
r.Logger.Debug("Failed to add new address", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,14 +299,6 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
|
|||||||
return cmn.NewError("received nil addr")
|
return cmn.NewError("received nil addr")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore private peers
|
|
||||||
// TODO: give private peers to AddrBook so it can enforce this on AddAddress.
|
|
||||||
// We'd then have to check for ErrPrivatePeer on AddAddress here, which is
|
|
||||||
// an error we just ignore (maybe peer is probing us for our private peers :P)
|
|
||||||
if isAddrPrivate(netAddr, r.config.PrivatePeerIDs) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err := r.book.AddAddress(netAddr, srcAddr)
|
err := r.book.AddAddress(netAddr, srcAddr)
|
||||||
r.logErrAddrBook(err)
|
r.logErrAddrBook(err)
|
||||||
}
|
}
|
||||||
@ -647,16 +630,6 @@ func (r *PEXReactor) attemptDisconnects() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isAddrPrivate returns true if addr.ID is a private ID.
|
|
||||||
func isAddrPrivate(addr *p2p.NetAddress, privatePeerIDs []string) bool {
|
|
||||||
for _, id := range privatePeerIDs {
|
|
||||||
if string(addr.ID) == id {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Messages
|
// Messages
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -295,7 +296,8 @@ func TestPEXReactorCrawlStatus(t *testing.T) {
|
|||||||
func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) {
|
func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) {
|
||||||
peer := p2p.CreateRandomPeer(false)
|
peer := p2p.CreateRandomPeer(false)
|
||||||
|
|
||||||
pexR, book := createReactor(&PEXReactorConfig{PrivatePeerIDs: []string{string(peer.NodeInfo().ID)}})
|
pexR, book := createReactor(&PEXReactorConfig{})
|
||||||
|
book.AddPrivateIDs([]string{string(peer.NodeInfo().ID)})
|
||||||
defer teardownReactor(book)
|
defer teardownReactor(book)
|
||||||
|
|
||||||
// we have to send a request to receive responses
|
// we have to send a request to receive responses
|
||||||
@ -355,7 +357,7 @@ func newMockPeer() mockPeer {
|
|||||||
_, netAddr := p2p.CreateRoutableAddr()
|
_, netAddr := p2p.CreateRoutableAddr()
|
||||||
mp := mockPeer{
|
mp := mockPeer{
|
||||||
addr: netAddr,
|
addr: netAddr,
|
||||||
pubKey: crypto.GenPrivKeyEd25519().PubKey(),
|
pubKey: ed25519.GenPrivKey().PubKey(),
|
||||||
}
|
}
|
||||||
mp.BaseService = cmn.NewBaseService(nil, "MockPeer", mp)
|
mp.BaseService = cmn.NewBaseService(nil, "MockPeer", mp)
|
||||||
mp.Start()
|
mp.Start()
|
||||||
@ -371,12 +373,13 @@ func (mp mockPeer) NodeInfo() p2p.NodeInfo {
|
|||||||
ListenAddr: mp.addr.DialString(),
|
ListenAddr: mp.addr.DialString(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (mp mockPeer) RemoteIP() net.IP { return net.ParseIP("127.0.0.1") }
|
func (mockPeer) RemoteIP() net.IP { return net.ParseIP("127.0.0.1") }
|
||||||
func (mp mockPeer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} }
|
func (mockPeer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} }
|
||||||
func (mp mockPeer) Send(byte, []byte) bool { return false }
|
func (mockPeer) Send(byte, []byte) bool { return false }
|
||||||
func (mp mockPeer) TrySend(byte, []byte) bool { return false }
|
func (mockPeer) TrySend(byte, []byte) bool { return false }
|
||||||
func (mp mockPeer) Set(string, interface{}) {}
|
func (mockPeer) Set(string, interface{}) {}
|
||||||
func (mp mockPeer) Get(string) interface{} { return nil }
|
func (mockPeer) Get(string) interface{} { return nil }
|
||||||
|
func (mockPeer) OriginalAddr() *p2p.NetAddress { return nil }
|
||||||
|
|
||||||
func assertPeersWithTimeout(
|
func assertPeersWithTimeout(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config"
|
"github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p/conn"
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
"github.com/tendermint/tendermint/p2p/conn"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -281,8 +281,13 @@ func (sw *Switch) StopPeerForError(peer Peer, reason interface{}) {
|
|||||||
sw.stopAndRemovePeer(peer, reason)
|
sw.stopAndRemovePeer(peer, reason)
|
||||||
|
|
||||||
if peer.IsPersistent() {
|
if peer.IsPersistent() {
|
||||||
// NOTE: this is the self-reported addr, not the original we dialed
|
addr := peer.OriginalAddr()
|
||||||
go sw.reconnectToPeer(peer.NodeInfo().NetAddress())
|
if addr == nil {
|
||||||
|
// FIXME: persistent peers can't be inbound right now.
|
||||||
|
// self-reported address for inbound persistent peers
|
||||||
|
addr = peer.NodeInfo().NetAddress()
|
||||||
|
}
|
||||||
|
go sw.reconnectToPeer(addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config"
|
"github.com/tendermint/tendermint/config"
|
||||||
@ -259,7 +259,7 @@ func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) {
|
|||||||
defer sw.Stop()
|
defer sw.Stop()
|
||||||
|
|
||||||
// simulate remote peer
|
// simulate remote peer
|
||||||
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: cfg}
|
rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
|
||||||
rp.Start()
|
rp.Start()
|
||||||
defer rp.Stop()
|
defer rp.Stop()
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
|
|||||||
defer sw.Stop()
|
defer sw.Stop()
|
||||||
|
|
||||||
// simulate remote peer
|
// simulate remote peer
|
||||||
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: cfg}
|
rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
|
||||||
rp.Start()
|
rp.Start()
|
||||||
defer rp.Stop()
|
defer rp.Stop()
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
|
|||||||
|
|
||||||
// simulate another remote peer
|
// simulate another remote peer
|
||||||
rp = &remotePeer{
|
rp = &remotePeer{
|
||||||
PrivKey: crypto.GenPrivKeyEd25519(),
|
PrivKey: ed25519.GenPrivKey(),
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
// Use different interface to prevent duplicate IP filter, this will break
|
// Use different interface to prevent duplicate IP filter, this will break
|
||||||
// beyond two peers.
|
// beyond two peers.
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ func MakeSwitch(cfg *config.P2PConfig, i int, network, version string, initSwitc
|
|||||||
// new switch, add reactors
|
// new switch, add reactors
|
||||||
// TODO: let the config be passed in?
|
// TODO: let the config be passed in?
|
||||||
nodeKey := &NodeKey{
|
nodeKey := &NodeKey{
|
||||||
PrivKey: crypto.GenPrivKeyEd25519(),
|
PrivKey: ed25519.GenPrivKey(),
|
||||||
}
|
}
|
||||||
sw := NewSwitch(cfg)
|
sw := NewSwitch(cfg)
|
||||||
sw.SetLogger(log.TestingLogger())
|
sw.SetLogger(log.TestingLogger())
|
||||||
|
@ -2,11 +2,11 @@ package p2p
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -67,7 +68,7 @@ func (pv *FilePV) GetPubKey() crypto.PubKey {
|
|||||||
// GenFilePV generates a new validator with randomly generated private key
|
// GenFilePV generates a new validator with randomly generated private key
|
||||||
// and sets the filePath, but does not call Save().
|
// and sets the filePath, but does not call Save().
|
||||||
func GenFilePV(filePath string) *FilePV {
|
func GenFilePV(filePath string) *FilePV {
|
||||||
privKey := crypto.GenPrivKeyEd25519()
|
privKey := ed25519.GenPrivKey()
|
||||||
return &FilePV{
|
return &FilePV{
|
||||||
Address: privKey.PubKey().Address(),
|
Address: privKey.PubKey().Address(),
|
||||||
PubKey: privKey.PubKey(),
|
PubKey: privKey.PubKey(),
|
||||||
|
@ -10,8 +10,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenLoadValidator(t *testing.T) {
|
func TestGenLoadValidator(t *testing.T) {
|
||||||
@ -47,10 +48,10 @@ func TestUnmarshalValidator(t *testing.T) {
|
|||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
// create some fixed values
|
// create some fixed values
|
||||||
privKey := crypto.GenPrivKeyEd25519()
|
privKey := ed25519.GenPrivKey()
|
||||||
pubKey := privKey.PubKey()
|
pubKey := privKey.PubKey()
|
||||||
addr := pubKey.Address()
|
addr := pubKey.Address()
|
||||||
pubArray := [32]byte(pubKey.(crypto.PubKeyEd25519))
|
pubArray := [32]byte(pubKey.(ed25519.PubKeyEd25519))
|
||||||
pubBytes := pubArray[:]
|
pubBytes := pubArray[:]
|
||||||
privArray := [64]byte(privKey)
|
privArray := [64]byte(privKey)
|
||||||
privBytes := privArray[:]
|
privBytes := privArray[:]
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ type SocketPV struct {
|
|||||||
connDeadline time.Duration
|
connDeadline time.Duration
|
||||||
connHeartbeat time.Duration
|
connHeartbeat time.Duration
|
||||||
connWaitTimeout time.Duration
|
connWaitTimeout time.Duration
|
||||||
privKey crypto.PrivKeyEd25519
|
privKey ed25519.PrivKeyEd25519
|
||||||
|
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
@ -87,7 +88,7 @@ var _ types.PrivValidator = (*SocketPV)(nil)
|
|||||||
func NewSocketPV(
|
func NewSocketPV(
|
||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
socketAddr string,
|
socketAddr string,
|
||||||
privKey crypto.PrivKeyEd25519,
|
privKey ed25519.PrivKeyEd25519,
|
||||||
) *SocketPV {
|
) *SocketPV {
|
||||||
sc := &SocketPV{
|
sc := &SocketPV{
|
||||||
addr: socketAddr,
|
addr: socketAddr,
|
||||||
@ -343,7 +344,7 @@ type RemoteSigner struct {
|
|||||||
chainID string
|
chainID string
|
||||||
connDeadline time.Duration
|
connDeadline time.Duration
|
||||||
connRetries int
|
connRetries int
|
||||||
privKey crypto.PrivKeyEd25519
|
privKey ed25519.PrivKeyEd25519
|
||||||
privVal types.PrivValidator
|
privVal types.PrivValidator
|
||||||
|
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
@ -354,7 +355,7 @@ func NewRemoteSigner(
|
|||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
chainID, socketAddr string,
|
chainID, socketAddr string,
|
||||||
privVal types.PrivValidator,
|
privVal types.PrivValidator,
|
||||||
privKey crypto.PrivKeyEd25519,
|
privKey ed25519.PrivKeyEd25519,
|
||||||
) *RemoteSigner {
|
) *RemoteSigner {
|
||||||
rs := &RemoteSigner{
|
rs := &RemoteSigner{
|
||||||
addr: socketAddr,
|
addr: socketAddr,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ func TestSocketPVAcceptDeadline(t *testing.T) {
|
|||||||
sc = NewSocketPV(
|
sc = NewSocketPV(
|
||||||
log.TestingLogger(),
|
log.TestingLogger(),
|
||||||
"127.0.0.1:0",
|
"127.0.0.1:0",
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
defer sc.Stop()
|
defer sc.Stop()
|
||||||
@ -129,7 +129,7 @@ func TestSocketPVDeadline(t *testing.T) {
|
|||||||
sc = NewSocketPV(
|
sc = NewSocketPV(
|
||||||
log.TestingLogger(),
|
log.TestingLogger(),
|
||||||
addr,
|
addr,
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func TestSocketPVDeadline(t *testing.T) {
|
|||||||
|
|
||||||
_, err = p2pconn.MakeSecretConnection(
|
_, err = p2pconn.MakeSecretConnection(
|
||||||
conn,
|
conn,
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
@ -172,7 +172,7 @@ func TestSocketPVWait(t *testing.T) {
|
|||||||
sc := NewSocketPV(
|
sc := NewSocketPV(
|
||||||
log.TestingLogger(),
|
log.TestingLogger(),
|
||||||
"127.0.0.1:0",
|
"127.0.0.1:0",
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
defer sc.Stop()
|
defer sc.Stop()
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ func TestRemoteSignerRetry(t *testing.T) {
|
|||||||
cmn.RandStr(12),
|
cmn.RandStr(12),
|
||||||
ln.Addr().String(),
|
ln.Addr().String(),
|
||||||
types.NewMockPV(),
|
types.NewMockPV(),
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
defer rs.Stop()
|
defer rs.Stop()
|
||||||
|
|
||||||
@ -245,12 +245,12 @@ func testSetupSocketPair(
|
|||||||
chainID,
|
chainID,
|
||||||
addr,
|
addr,
|
||||||
privVal,
|
privVal,
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
sc = NewSocketPV(
|
sc = NewSocketPV(
|
||||||
logger,
|
logger,
|
||||||
addr,
|
addr,
|
||||||
crypto.GenPrivKeyEd25519(),
|
ed25519.GenPrivKey(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ package privval
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
RegisterSocketPVMsg(cdc)
|
RegisterSocketPVMsg(cdc)
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||||
nm "github.com/tendermint/tendermint/node"
|
nm "github.com/tendermint/tendermint/node"
|
||||||
"github.com/tendermint/tendermint/rpc/core"
|
"github.com/tendermint/tendermint/rpc/core"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,10 +3,10 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get block headers for minHeight <= height <= maxHeight.
|
// Get block headers for minHeight <= height <= maxHeight.
|
||||||
@ -288,12 +288,12 @@ func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) {
|
|||||||
// use a non-canonical commit
|
// use a non-canonical commit
|
||||||
if height == storeHeight {
|
if height == storeHeight {
|
||||||
commit := blockStore.LoadSeenCommit(height)
|
commit := blockStore.LoadSeenCommit(height)
|
||||||
return ctypes.NewResultCommit(header, commit, false), nil
|
return ctypes.NewResultCommit(&header, commit, false), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the canonical commit (comes from the block at height+1)
|
// Return the canonical commit (comes from the block at height+1)
|
||||||
commit := blockStore.LoadBlockCommit(height)
|
commit := blockStore.LoadBlockCommit(height)
|
||||||
return ctypes.NewResultCommit(header, commit, true), nil
|
return ctypes.NewResultCommit(&header, commit, true), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockResults gets ABCIResults at a given height.
|
// BlockResults gets ABCIResults at a given height.
|
||||||
|
@ -39,8 +39,6 @@ curl 'localhost:26657/broadcast_tx_sync?tx="abc"'
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The first entry in the result-array (`96`) is the method this response correlates with. `96` refers to "ResultTypeBroadcastTx", see [responses.go](https://github.com/tendermint/tendermint/blob/master/rpc/core/types/responses.go) for a complete overview.
|
|
||||||
|
|
||||||
## JSONRPC/HTTP
|
## JSONRPC/HTTP
|
||||||
|
|
||||||
JSONRPC requests can be POST'd to the root RPC endpoint via HTTP (e.g. `http://localhost:26657/`).
|
JSONRPC requests can be POST'd to the root RPC endpoint via HTTP (e.g. `http://localhost:26657/`).
|
||||||
|
@ -4,10 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get Tendermint status including node info, pubkey, latest block
|
// Get Tendermint status including node info, pubkey, latest block
|
||||||
@ -104,8 +104,17 @@ func Status() (*ctypes.ResultStatus, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const consensusTimeout = time.Second
|
||||||
|
|
||||||
func validatorAtHeight(h int64) *types.Validator {
|
func validatorAtHeight(h int64) *types.Validator {
|
||||||
lastBlockHeight, vals := consensusState.GetValidators()
|
lastBlockHeight, vals := getValidatorsWithTimeout(
|
||||||
|
consensusState,
|
||||||
|
consensusTimeout,
|
||||||
|
)
|
||||||
|
|
||||||
|
if lastBlockHeight == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
privValAddress := pubKey.Address()
|
privValAddress := pubKey.Address()
|
||||||
|
|
||||||
@ -131,3 +140,32 @@ func validatorAtHeight(h int64) *types.Validator {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type validatorRetriever interface {
|
||||||
|
GetValidators() (int64, []*types.Validator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Consensus might halt, but we still need to process RPC requests (at
|
||||||
|
// least for endpoints whole output does not depend on consensus state).
|
||||||
|
func getValidatorsWithTimeout(
|
||||||
|
vr validatorRetriever,
|
||||||
|
t time.Duration,
|
||||||
|
) (int64, []*types.Validator) {
|
||||||
|
resultCh := make(chan struct {
|
||||||
|
lastBlockHeight int64
|
||||||
|
vals []*types.Validator
|
||||||
|
})
|
||||||
|
go func() {
|
||||||
|
h, v := vr.GetValidators()
|
||||||
|
resultCh <- struct {
|
||||||
|
lastBlockHeight int64
|
||||||
|
vals []*types.Validator
|
||||||
|
}{h, v}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case res := <-resultCh:
|
||||||
|
return res.lastBlockHeight, res.vals
|
||||||
|
case <-time.After(t):
|
||||||
|
return -1, []*types.Validator{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
39
rpc/core/status_test.go
Normal file
39
rpc/core/status_test.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetValidatorsWithTimeout(t *testing.T) {
|
||||||
|
height, vs := getValidatorsWithTimeout(
|
||||||
|
testValidatorReceiver{},
|
||||||
|
time.Millisecond,
|
||||||
|
)
|
||||||
|
|
||||||
|
if height != -1 {
|
||||||
|
t.Errorf("expected negative height")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(vs) != 0 {
|
||||||
|
t.Errorf("expected no validators")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type testValidatorReceiver struct{}
|
||||||
|
|
||||||
|
func (tr testValidatorReceiver) GetValidators() (int64, []*types.Validator) {
|
||||||
|
vs := []*types.Validator{}
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
v, _ := types.RandValidator(true, 10)
|
||||||
|
|
||||||
|
vs = append(vs, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
|
||||||
|
return 10, vs
|
||||||
|
}
|
@ -2,12 +2,12 @@ package core_types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterAmino(cdc *amino.Codec) {
|
func RegisterAmino(cdc *amino.Codec) {
|
||||||
types.RegisterEventDatas(cdc)
|
types.RegisterEventDatas(cdc)
|
||||||
types.RegisterEvidences(cdc)
|
types.RegisterEvidences(cdc)
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
protoc --go_out=plugins=grpc:. -I $GOPATH/src/ -I . types.proto
|
|
@ -1,12 +1,11 @@
|
|||||||
// Code generated by protoc-gen-go.
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
// source: types.proto
|
// source: rpc/grpc/types.proto
|
||||||
// DO NOT EDIT!
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package core_grpc is a generated protocol buffer package.
|
Package core_grpc is a generated protocol buffer package.
|
||||||
|
|
||||||
It is generated from these files:
|
It is generated from these files:
|
||||||
types.proto
|
rpc/grpc/types.proto
|
||||||
|
|
||||||
It has these top-level messages:
|
It has these top-level messages:
|
||||||
RequestPing
|
RequestPing
|
||||||
@ -14,21 +13,26 @@ It has these top-level messages:
|
|||||||
ResponsePing
|
ResponsePing
|
||||||
ResponseBroadcastTx
|
ResponseBroadcastTx
|
||||||
*/
|
*/
|
||||||
|
//nolint
|
||||||
package core_grpc
|
package core_grpc
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
import proto "github.com/gogo/protobuf/proto"
|
||||||
|
import golang_proto "github.com/golang/protobuf/proto"
|
||||||
import fmt "fmt"
|
import fmt "fmt"
|
||||||
import math "math"
|
import math "math"
|
||||||
|
import _ "github.com/gogo/protobuf/gogoproto"
|
||||||
import types "github.com/tendermint/tendermint/abci/types"
|
import types "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
import (
|
import bytes "bytes"
|
||||||
"context"
|
|
||||||
|
|
||||||
grpc "google.golang.org/grpc"
|
import context "golang.org/x/net/context"
|
||||||
)
|
import grpc "google.golang.org/grpc"
|
||||||
|
|
||||||
|
import io "io"
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
var _ = proto.Marshal
|
var _ = proto.Marshal
|
||||||
|
var _ = golang_proto.Marshal
|
||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
var _ = math.Inf
|
var _ = math.Inf
|
||||||
|
|
||||||
@ -36,7 +40,7 @@ var _ = math.Inf
|
|||||||
// is compatible with the proto package it is being compiled against.
|
// is compatible with the proto package it is being compiled against.
|
||||||
// A compilation error at this line likely means your copy of the
|
// A compilation error at this line likely means your copy of the
|
||||||
// proto package needs to be updated.
|
// proto package needs to be updated.
|
||||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
type RequestPing struct {
|
type RequestPing struct {
|
||||||
}
|
}
|
||||||
@ -44,7 +48,7 @@ type RequestPing struct {
|
|||||||
func (m *RequestPing) Reset() { *m = RequestPing{} }
|
func (m *RequestPing) Reset() { *m = RequestPing{} }
|
||||||
func (m *RequestPing) String() string { return proto.CompactTextString(m) }
|
func (m *RequestPing) String() string { return proto.CompactTextString(m) }
|
||||||
func (*RequestPing) ProtoMessage() {}
|
func (*RequestPing) ProtoMessage() {}
|
||||||
func (*RequestPing) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
func (*RequestPing) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{0} }
|
||||||
|
|
||||||
type RequestBroadcastTx struct {
|
type RequestBroadcastTx struct {
|
||||||
Tx []byte `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"`
|
Tx []byte `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"`
|
||||||
@ -53,7 +57,7 @@ type RequestBroadcastTx struct {
|
|||||||
func (m *RequestBroadcastTx) Reset() { *m = RequestBroadcastTx{} }
|
func (m *RequestBroadcastTx) Reset() { *m = RequestBroadcastTx{} }
|
||||||
func (m *RequestBroadcastTx) String() string { return proto.CompactTextString(m) }
|
func (m *RequestBroadcastTx) String() string { return proto.CompactTextString(m) }
|
||||||
func (*RequestBroadcastTx) ProtoMessage() {}
|
func (*RequestBroadcastTx) ProtoMessage() {}
|
||||||
func (*RequestBroadcastTx) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
func (*RequestBroadcastTx) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{1} }
|
||||||
|
|
||||||
func (m *RequestBroadcastTx) GetTx() []byte {
|
func (m *RequestBroadcastTx) GetTx() []byte {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
@ -68,7 +72,7 @@ type ResponsePing struct {
|
|||||||
func (m *ResponsePing) Reset() { *m = ResponsePing{} }
|
func (m *ResponsePing) Reset() { *m = ResponsePing{} }
|
||||||
func (m *ResponsePing) String() string { return proto.CompactTextString(m) }
|
func (m *ResponsePing) String() string { return proto.CompactTextString(m) }
|
||||||
func (*ResponsePing) ProtoMessage() {}
|
func (*ResponsePing) ProtoMessage() {}
|
||||||
func (*ResponsePing) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
func (*ResponsePing) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{2} }
|
||||||
|
|
||||||
type ResponseBroadcastTx struct {
|
type ResponseBroadcastTx struct {
|
||||||
CheckTx *types.ResponseCheckTx `protobuf:"bytes,1,opt,name=check_tx,json=checkTx" json:"check_tx,omitempty"`
|
CheckTx *types.ResponseCheckTx `protobuf:"bytes,1,opt,name=check_tx,json=checkTx" json:"check_tx,omitempty"`
|
||||||
@ -78,7 +82,7 @@ type ResponseBroadcastTx struct {
|
|||||||
func (m *ResponseBroadcastTx) Reset() { *m = ResponseBroadcastTx{} }
|
func (m *ResponseBroadcastTx) Reset() { *m = ResponseBroadcastTx{} }
|
||||||
func (m *ResponseBroadcastTx) String() string { return proto.CompactTextString(m) }
|
func (m *ResponseBroadcastTx) String() string { return proto.CompactTextString(m) }
|
||||||
func (*ResponseBroadcastTx) ProtoMessage() {}
|
func (*ResponseBroadcastTx) ProtoMessage() {}
|
||||||
func (*ResponseBroadcastTx) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
func (*ResponseBroadcastTx) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{3} }
|
||||||
|
|
||||||
func (m *ResponseBroadcastTx) GetCheckTx() *types.ResponseCheckTx {
|
func (m *ResponseBroadcastTx) GetCheckTx() *types.ResponseCheckTx {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
@ -96,9 +100,106 @@ func (m *ResponseBroadcastTx) GetDeliverTx() *types.ResponseDeliverTx {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*RequestPing)(nil), "core_grpc.RequestPing")
|
proto.RegisterType((*RequestPing)(nil), "core_grpc.RequestPing")
|
||||||
|
golang_proto.RegisterType((*RequestPing)(nil), "core_grpc.RequestPing")
|
||||||
proto.RegisterType((*RequestBroadcastTx)(nil), "core_grpc.RequestBroadcastTx")
|
proto.RegisterType((*RequestBroadcastTx)(nil), "core_grpc.RequestBroadcastTx")
|
||||||
|
golang_proto.RegisterType((*RequestBroadcastTx)(nil), "core_grpc.RequestBroadcastTx")
|
||||||
proto.RegisterType((*ResponsePing)(nil), "core_grpc.ResponsePing")
|
proto.RegisterType((*ResponsePing)(nil), "core_grpc.ResponsePing")
|
||||||
|
golang_proto.RegisterType((*ResponsePing)(nil), "core_grpc.ResponsePing")
|
||||||
proto.RegisterType((*ResponseBroadcastTx)(nil), "core_grpc.ResponseBroadcastTx")
|
proto.RegisterType((*ResponseBroadcastTx)(nil), "core_grpc.ResponseBroadcastTx")
|
||||||
|
golang_proto.RegisterType((*ResponseBroadcastTx)(nil), "core_grpc.ResponseBroadcastTx")
|
||||||
|
}
|
||||||
|
func (this *RequestPing) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
that1, ok := that.(*RequestPing)
|
||||||
|
if !ok {
|
||||||
|
that2, ok := that.(RequestPing)
|
||||||
|
if ok {
|
||||||
|
that1 = &that2
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if that1 == nil {
|
||||||
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (this *RequestBroadcastTx) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
that1, ok := that.(*RequestBroadcastTx)
|
||||||
|
if !ok {
|
||||||
|
that2, ok := that.(RequestBroadcastTx)
|
||||||
|
if ok {
|
||||||
|
that1 = &that2
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if that1 == nil {
|
||||||
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !bytes.Equal(this.Tx, that1.Tx) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (this *ResponsePing) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
that1, ok := that.(*ResponsePing)
|
||||||
|
if !ok {
|
||||||
|
that2, ok := that.(ResponsePing)
|
||||||
|
if ok {
|
||||||
|
that1 = &that2
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if that1 == nil {
|
||||||
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (this *ResponseBroadcastTx) Equal(that interface{}) bool {
|
||||||
|
if that == nil {
|
||||||
|
return this == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
that1, ok := that.(*ResponseBroadcastTx)
|
||||||
|
if !ok {
|
||||||
|
that2, ok := that.(ResponseBroadcastTx)
|
||||||
|
if ok {
|
||||||
|
that1 = &that2
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if that1 == nil {
|
||||||
|
return this == nil
|
||||||
|
} else if this == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !this.CheckTx.Equal(that1.CheckTx) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !this.DeliverTx.Equal(that1.DeliverTx) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
@ -203,28 +304,702 @@ var _BroadcastAPI_serviceDesc = grpc.ServiceDesc{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{},
|
Streams: []grpc.StreamDesc{},
|
||||||
Metadata: "types.proto",
|
Metadata: "rpc/grpc/types.proto",
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { proto.RegisterFile("types.proto", fileDescriptor0) }
|
func (m *RequestPing) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
var fileDescriptor0 = []byte{
|
dAtA = make([]byte, size)
|
||||||
// 264 bytes of a gzipped FileDescriptorProto
|
n, err := m.MarshalTo(dAtA)
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xa9, 0x2c, 0x48,
|
if err != nil {
|
||||||
0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4c, 0xce, 0x2f, 0x4a, 0x8d, 0x4f, 0x2f,
|
return nil, err
|
||||||
0x2a, 0x48, 0x96, 0xd2, 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x2f,
|
}
|
||||||
0x49, 0xcd, 0x4b, 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4f, 0x4c, 0x4a, 0xce, 0xd4, 0x07,
|
return dAtA[:n], nil
|
||||||
0x6b, 0xd1, 0x47, 0xd2, 0xa8, 0xc4, 0xcb, 0xc5, 0x1d, 0x94, 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0x12,
|
}
|
||||||
0x90, 0x99, 0x97, 0xae, 0xa4, 0xc2, 0x25, 0x04, 0xe5, 0x3a, 0x15, 0xe5, 0x27, 0xa6, 0x24, 0x27,
|
|
||||||
0x16, 0x97, 0x84, 0x54, 0x08, 0xf1, 0x71, 0x31, 0x95, 0x54, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xf0,
|
func (m *RequestPing) MarshalTo(dAtA []byte) (int, error) {
|
||||||
0x04, 0x31, 0x95, 0x54, 0x28, 0xf1, 0x71, 0xf1, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7,
|
var i int
|
||||||
0x82, 0x75, 0x35, 0x32, 0x72, 0x09, 0xc3, 0x04, 0x90, 0xf5, 0x19, 0x72, 0x71, 0x24, 0x67, 0xa4,
|
_ = i
|
||||||
0x26, 0x67, 0xc7, 0x43, 0x75, 0x73, 0x1b, 0x89, 0xe9, 0x41, 0x2c, 0x87, 0xa9, 0x76, 0x06, 0x49,
|
var l int
|
||||||
0x87, 0x54, 0x04, 0xb1, 0x27, 0x43, 0x18, 0x42, 0xe6, 0x5c, 0x5c, 0x29, 0xa9, 0x39, 0x99, 0x65,
|
_ = l
|
||||||
0xa9, 0x45, 0x20, 0x4d, 0x4c, 0x60, 0x4d, 0x12, 0x68, 0x9a, 0x5c, 0x20, 0x0a, 0x42, 0x2a, 0x82,
|
return i, nil
|
||||||
0x38, 0x53, 0x60, 0x4c, 0xa3, 0xa9, 0x8c, 0x5c, 0x3c, 0x70, 0xbb, 0x1d, 0x03, 0x3c, 0x85, 0xcc,
|
}
|
||||||
0xb9, 0x58, 0x40, 0x8e, 0x13, 0x12, 0xd3, 0x83, 0x87, 0x8d, 0x1e, 0x92, 0x57, 0xa5, 0xc4, 0x51,
|
|
||||||
0xc4, 0x11, 0xbe, 0x11, 0xf2, 0xe1, 0xe2, 0x46, 0xf6, 0x84, 0x2c, 0xa6, 0x7e, 0x24, 0x69, 0x29,
|
func (m *RequestBroadcastTx) Marshal() (dAtA []byte, err error) {
|
||||||
0x39, 0x2c, 0xc6, 0x20, 0xc9, 0x27, 0xb1, 0x81, 0xc3, 0xd9, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff,
|
size := m.Size()
|
||||||
0x92, 0x29, 0xd9, 0x42, 0xaf, 0x01, 0x00, 0x00,
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *RequestBroadcastTx) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
var i int
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Tx) > 0 {
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(len(m.Tx)))
|
||||||
|
i += copy(dAtA[i:], m.Tx)
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponsePing) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponsePing) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
var i int
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseBroadcastTx) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseBroadcastTx) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
var i int
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if m.CheckTx != nil {
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(m.CheckTx.Size()))
|
||||||
|
n1, err := m.CheckTx.MarshalTo(dAtA[i:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i += n1
|
||||||
|
}
|
||||||
|
if m.DeliverTx != nil {
|
||||||
|
dAtA[i] = 0x12
|
||||||
|
i++
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(m.DeliverTx.Size()))
|
||||||
|
n2, err := m.DeliverTx.MarshalTo(dAtA[i:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i += n2
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
|
||||||
|
for v >= 1<<7 {
|
||||||
|
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||||
|
v >>= 7
|
||||||
|
offset++
|
||||||
|
}
|
||||||
|
dAtA[offset] = uint8(v)
|
||||||
|
return offset + 1
|
||||||
|
}
|
||||||
|
func NewPopulatedRequestPing(r randyTypes, easy bool) *RequestPing {
|
||||||
|
this := &RequestPing{}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPopulatedRequestBroadcastTx(r randyTypes, easy bool) *RequestBroadcastTx {
|
||||||
|
this := &RequestBroadcastTx{}
|
||||||
|
v1 := r.Intn(100)
|
||||||
|
this.Tx = make([]byte, v1)
|
||||||
|
for i := 0; i < v1; i++ {
|
||||||
|
this.Tx[i] = byte(r.Intn(256))
|
||||||
|
}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPopulatedResponsePing(r randyTypes, easy bool) *ResponsePing {
|
||||||
|
this := &ResponsePing{}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPopulatedResponseBroadcastTx(r randyTypes, easy bool) *ResponseBroadcastTx {
|
||||||
|
this := &ResponseBroadcastTx{}
|
||||||
|
if r.Intn(10) != 0 {
|
||||||
|
this.CheckTx = types.NewPopulatedResponseCheckTx(r, easy)
|
||||||
|
}
|
||||||
|
if r.Intn(10) != 0 {
|
||||||
|
this.DeliverTx = types.NewPopulatedResponseDeliverTx(r, easy)
|
||||||
|
}
|
||||||
|
if !easy && r.Intn(10) != 0 {
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
type randyTypes interface {
|
||||||
|
Float32() float32
|
||||||
|
Float64() float64
|
||||||
|
Int63() int64
|
||||||
|
Int31() int32
|
||||||
|
Uint32() uint32
|
||||||
|
Intn(n int) int
|
||||||
|
}
|
||||||
|
|
||||||
|
func randUTF8RuneTypes(r randyTypes) rune {
|
||||||
|
ru := r.Intn(62)
|
||||||
|
if ru < 10 {
|
||||||
|
return rune(ru + 48)
|
||||||
|
} else if ru < 36 {
|
||||||
|
return rune(ru + 55)
|
||||||
|
}
|
||||||
|
return rune(ru + 61)
|
||||||
|
}
|
||||||
|
func randStringTypes(r randyTypes) string {
|
||||||
|
v2 := r.Intn(100)
|
||||||
|
tmps := make([]rune, v2)
|
||||||
|
for i := 0; i < v2; i++ {
|
||||||
|
tmps[i] = randUTF8RuneTypes(r)
|
||||||
|
}
|
||||||
|
return string(tmps)
|
||||||
|
}
|
||||||
|
func randUnrecognizedTypes(r randyTypes, maxFieldNumber int) (dAtA []byte) {
|
||||||
|
l := r.Intn(5)
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
|
wire := r.Intn(4)
|
||||||
|
if wire == 3 {
|
||||||
|
wire = 5
|
||||||
|
}
|
||||||
|
fieldNumber := maxFieldNumber + r.Intn(100)
|
||||||
|
dAtA = randFieldTypes(dAtA, r, fieldNumber, wire)
|
||||||
|
}
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func randFieldTypes(dAtA []byte, r randyTypes, fieldNumber int, wire int) []byte {
|
||||||
|
key := uint32(fieldNumber)<<3 | uint32(wire)
|
||||||
|
switch wire {
|
||||||
|
case 0:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
v3 := r.Int63()
|
||||||
|
if r.Intn(2) == 0 {
|
||||||
|
v3 *= -1
|
||||||
|
}
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(v3))
|
||||||
|
case 1:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
|
||||||
|
case 2:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
ll := r.Intn(100)
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(ll))
|
||||||
|
for j := 0; j < ll; j++ {
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)))
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
dAtA = encodeVarintPopulateTypes(dAtA, uint64(key))
|
||||||
|
dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
|
||||||
|
}
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func encodeVarintPopulateTypes(dAtA []byte, v uint64) []byte {
|
||||||
|
for v >= 1<<7 {
|
||||||
|
dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80))
|
||||||
|
v >>= 7
|
||||||
|
}
|
||||||
|
dAtA = append(dAtA, uint8(v))
|
||||||
|
return dAtA
|
||||||
|
}
|
||||||
|
func (m *RequestPing) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *RequestBroadcastTx) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
l = len(m.Tx)
|
||||||
|
if l > 0 {
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponsePing) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ResponseBroadcastTx) Size() (n int) {
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if m.CheckTx != nil {
|
||||||
|
l = m.CheckTx.Size()
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
if m.DeliverTx != nil {
|
||||||
|
l = m.DeliverTx.Size()
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func sovTypes(x uint64) (n int) {
|
||||||
|
for {
|
||||||
|
n++
|
||||||
|
x >>= 7
|
||||||
|
if x == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
func sozTypes(x uint64) (n int) {
|
||||||
|
return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||||
|
}
|
||||||
|
func (m *RequestPing) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: RequestPing: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: RequestPing: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *RequestBroadcastTx) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: RequestBroadcastTx: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: RequestBroadcastTx: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Tx", wireType)
|
||||||
|
}
|
||||||
|
var byteLen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
byteLen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if byteLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + byteLen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Tx = append(m.Tx[:0], dAtA[iNdEx:postIndex]...)
|
||||||
|
if m.Tx == nil {
|
||||||
|
m.Tx = []byte{}
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *ResponsePing) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: ResponsePing: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: ResponsePing: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *ResponseBroadcastTx) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: ResponseBroadcastTx: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: ResponseBroadcastTx: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field CheckTx", wireType)
|
||||||
|
}
|
||||||
|
var msglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
msglen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msglen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + msglen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if m.CheckTx == nil {
|
||||||
|
m.CheckTx = &types.ResponseCheckTx{}
|
||||||
|
}
|
||||||
|
if err := m.CheckTx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field DeliverTx", wireType)
|
||||||
|
}
|
||||||
|
var msglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
msglen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msglen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + msglen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if m.DeliverTx == nil {
|
||||||
|
m.DeliverTx = &types.ResponseDeliverTx{}
|
||||||
|
}
|
||||||
|
if err := m.DeliverTx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func skipTypes(dAtA []byte) (n int, err error) {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
switch wireType {
|
||||||
|
case 0:
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx++
|
||||||
|
if dAtA[iNdEx-1] < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 1:
|
||||||
|
iNdEx += 8
|
||||||
|
return iNdEx, nil
|
||||||
|
case 2:
|
||||||
|
var length int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
length |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iNdEx += length
|
||||||
|
if length < 0 {
|
||||||
|
return 0, ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 3:
|
||||||
|
for {
|
||||||
|
var innerWire uint64
|
||||||
|
var start int = iNdEx
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return 0, ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
innerWire |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
innerWireType := int(innerWire & 0x7)
|
||||||
|
if innerWireType == 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
next, err := skipTypes(dAtA[start:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
iNdEx = start + next
|
||||||
|
}
|
||||||
|
return iNdEx, nil
|
||||||
|
case 4:
|
||||||
|
return iNdEx, nil
|
||||||
|
case 5:
|
||||||
|
iNdEx += 4
|
||||||
|
return iNdEx, nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||||
|
ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("rpc/grpc/types.proto", fileDescriptorTypes) }
|
||||||
|
func init() { golang_proto.RegisterFile("rpc/grpc/types.proto", fileDescriptorTypes) }
|
||||||
|
|
||||||
|
var fileDescriptorTypes = []byte{
|
||||||
|
// 321 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x29, 0x2a, 0x48, 0xd6,
|
||||||
|
0x4f, 0x07, 0x11, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x9c,
|
||||||
|
0xc9, 0xf9, 0x45, 0xa9, 0xf1, 0x20, 0x61, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd,
|
||||||
|
0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xfc, 0xf4, 0x7c, 0x7d, 0xb0, 0x8a, 0xa4, 0xd2, 0x34, 0x30, 0x0f,
|
||||||
|
0xcc, 0x01, 0xb3, 0x20, 0x3a, 0xa5, 0xcc, 0x91, 0x94, 0x97, 0xa4, 0xe6, 0xa5, 0xa4, 0x16, 0xe5,
|
||||||
|
0x66, 0xe6, 0x95, 0x20, 0x33, 0x13, 0x93, 0x92, 0x33, 0x21, 0x96, 0x21, 0x5b, 0xa9, 0xc4, 0xcb,
|
||||||
|
0xc5, 0x1d, 0x94, 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0x12, 0x90, 0x99, 0x97, 0xae, 0xa4, 0xc2, 0x25,
|
||||||
|
0x04, 0xe5, 0x3a, 0x15, 0xe5, 0x27, 0xa6, 0x24, 0x27, 0x16, 0x97, 0x84, 0x54, 0x08, 0xf1, 0x71,
|
||||||
|
0x31, 0x95, 0x54, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x04, 0x31, 0x95, 0x54, 0x28, 0xf1, 0x71,
|
||||||
|
0xf1, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x82, 0x75, 0x35, 0x32, 0x72, 0x09, 0xc3,
|
||||||
|
0x04, 0x90, 0xf5, 0x19, 0x72, 0x71, 0x24, 0x67, 0xa4, 0x26, 0x67, 0xc7, 0x43, 0x75, 0x73, 0x1b,
|
||||||
|
0x89, 0xe9, 0x41, 0x2c, 0x87, 0xa9, 0x76, 0x06, 0x49, 0x87, 0x54, 0x04, 0xb1, 0x27, 0x43, 0x18,
|
||||||
|
0x42, 0xe6, 0x5c, 0x5c, 0x29, 0xa9, 0x39, 0x99, 0x65, 0xa9, 0x45, 0x20, 0x4d, 0x4c, 0x60, 0x4d,
|
||||||
|
0x12, 0x68, 0x9a, 0x5c, 0x20, 0x0a, 0x42, 0x2a, 0x82, 0x38, 0x53, 0x60, 0x4c, 0xa3, 0xa9, 0x8c,
|
||||||
|
0x5c, 0x3c, 0x70, 0xbb, 0x1d, 0x03, 0x3c, 0x85, 0xcc, 0xb9, 0x58, 0x40, 0x8e, 0x13, 0x12, 0xd3,
|
||||||
|
0x83, 0x87, 0xaa, 0x1e, 0x92, 0x57, 0xa5, 0xc4, 0x51, 0xc4, 0x11, 0xbe, 0x11, 0xf2, 0xe1, 0xe2,
|
||||||
|
0x46, 0xf6, 0x84, 0x2c, 0xa6, 0x7e, 0x24, 0x69, 0x29, 0x39, 0x2c, 0xc6, 0x20, 0xc9, 0x3b, 0xc9,
|
||||||
|
0xfc, 0x78, 0x28, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x8e, 0x47, 0x72, 0x8c, 0x27, 0x1e, 0xc9,
|
||||||
|
0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x81, 0xc7, 0x72, 0x8c, 0x49, 0x6c,
|
||||||
|
0xe0, 0x58, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xd5, 0xa8, 0xe4, 0xd9, 0x10, 0x02, 0x00,
|
||||||
|
0x00,
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package core_grpc;
|
package core_grpc;
|
||||||
|
|
||||||
|
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||||
import "github.com/tendermint/tendermint/abci/types/types.proto";
|
import "github.com/tendermint/tendermint/abci/types/types.proto";
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
option (gogoproto.goproto_registration) = true;
|
||||||
|
// Generate tests
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
option (gogoproto.testgen_all) = true;
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
// Message types
|
// Message types
|
||||||
|
|
||||||
|
531
rpc/grpc/typespb_test.go
Normal file
531
rpc/grpc/typespb_test.go
Normal file
@ -0,0 +1,531 @@
|
|||||||
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
|
// source: rpc/grpc/types.proto
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package core_grpc is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
rpc/grpc/types.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
RequestPing
|
||||||
|
RequestBroadcastTx
|
||||||
|
ResponsePing
|
||||||
|
ResponseBroadcastTx
|
||||||
|
*/
|
||||||
|
package core_grpc
|
||||||
|
|
||||||
|
import testing "testing"
|
||||||
|
import rand "math/rand"
|
||||||
|
import time "time"
|
||||||
|
import proto "github.com/gogo/protobuf/proto"
|
||||||
|
import jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||||
|
import golang_proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
import _ "github.com/gogo/protobuf/gogoproto"
|
||||||
|
import _ "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = golang_proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
func TestRequestPingProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestPing{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestPingMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestPing{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestBroadcastTxProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestBroadcastTx{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestBroadcastTxMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestBroadcastTx{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponsePingProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponsePing{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponsePingMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponsePing{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponseBroadcastTxProto(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, false)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponseBroadcastTx{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
littlefuzz := make([]byte, len(dAtA))
|
||||||
|
copy(littlefuzz, dAtA)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
if len(littlefuzz) > 0 {
|
||||||
|
fuzzamount := 100
|
||||||
|
for i := 0; i < fuzzamount; i++ {
|
||||||
|
littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
|
||||||
|
littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
|
||||||
|
}
|
||||||
|
// shouldn't panic
|
||||||
|
_ = proto.Unmarshal(littlefuzz, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponseBroadcastTxMarshalTo(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, false)
|
||||||
|
size := p.Size()
|
||||||
|
dAtA := make([]byte, size)
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
_, err := p.MarshalTo(dAtA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponseBroadcastTx{}
|
||||||
|
if err := proto.Unmarshal(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
for i := range dAtA {
|
||||||
|
dAtA[i] = byte(popr.Intn(256))
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestPingJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestPing{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestRequestBroadcastTxJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &RequestBroadcastTx{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestResponsePingJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponsePing{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestResponseBroadcastTxJSON(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, true)
|
||||||
|
marshaler := jsonpb.Marshaler{}
|
||||||
|
jsondata, err := marshaler.MarshalToString(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
msg := &ResponseBroadcastTx{}
|
||||||
|
err = jsonpb.UnmarshalString(jsondata, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestRequestPingProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &RequestPing{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestPingProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &RequestPing{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestBroadcastTxProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &RequestBroadcastTx{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestBroadcastTxProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &RequestBroadcastTx{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponsePingProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &ResponsePing{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponsePingProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &ResponsePing{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponseBroadcastTxProtoText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, true)
|
||||||
|
dAtA := proto.MarshalTextString(p)
|
||||||
|
msg := &ResponseBroadcastTx{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponseBroadcastTxProtoCompactText(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, true)
|
||||||
|
dAtA := proto.CompactTextString(p)
|
||||||
|
msg := &ResponseBroadcastTx{}
|
||||||
|
if err := proto.UnmarshalText(dAtA, msg); err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
if !p.Equal(msg) {
|
||||||
|
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestPingSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestPing(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRequestBroadcastTxSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedRequestBroadcastTx(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponsePingSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponsePing(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResponseBroadcastTxSize(t *testing.T) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
popr := rand.New(rand.NewSource(seed))
|
||||||
|
p := NewPopulatedResponseBroadcastTx(popr, true)
|
||||||
|
size2 := proto.Size(p)
|
||||||
|
dAtA, err := proto.Marshal(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed = %d, err = %v", seed, err)
|
||||||
|
}
|
||||||
|
size := p.Size()
|
||||||
|
if len(dAtA) != size {
|
||||||
|
t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
|
||||||
|
}
|
||||||
|
if size2 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
|
||||||
|
}
|
||||||
|
size3 := proto.Size(p)
|
||||||
|
if size3 != size {
|
||||||
|
t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user