Merge branch 'develop' into jae/optimize_blockchain

This commit is contained in:
Ethan Buchman 2018-07-23 22:16:34 -04:00 committed by GitHub
commit e1b48b16c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
574 changed files with 46306 additions and 6487 deletions

View File

@ -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: |
@ -31,19 +31,18 @@ jobs:
name: binaries name: binaries
command: | command: |
export PATH="$GOBIN:$PATH" export PATH="$GOBIN:$PATH"
make install make install install_abci
cd abci && make install
- persist_to_workspace: - persist_to_workspace:
root: /tmp/workspace root: /tmp/workspace
paths: paths:
- 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
@ -53,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: |
@ -69,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: |
@ -85,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: |
@ -102,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: |
@ -117,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
@ -132,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"
@ -157,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
@ -182,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: |

3
.github/CODEOWNERS vendored
View File

@ -2,3 +2,6 @@
# Everything goes through Bucky, Anton, Alex. For now. # Everything goes through Bucky, Anton, Alex. For now.
* @ebuchman @melekes @xla * @ebuchman @melekes @xla
# Precious documentation
/docs/ @zramsay @jolesbi

View File

@ -33,7 +33,7 @@ in a case of bug.
**How to reproduce it** (as minimally and precisely as possible): **How to reproduce it** (as minimally and precisely as possible):
**Logs (you can paste a part showing an error or attach the whole file)**: **Logs (you can paste a small part showing an error or link a pastebin, gist, etc. containing more of the log file)**:
**Config (you can paste only the changes you've made)**: **Config (you can paste only the changes you've made)**:

10
.gitignore vendored
View File

@ -14,10 +14,9 @@ test/p2p/data/
test/logs test/logs
coverage.txt coverage.txt
docs/_build docs/_build
docs/tools
*.log *.log
abci-cli abci-cli
abci/types/types.pb.go docs/node_modules/
scripts/wal2json/wal2json scripts/wal2json/wal2json
scripts/cutWALUntil/cutWALUntil scripts/cutWALUntil/cutWALUntil
@ -27,3 +26,10 @@ scripts/cutWALUntil/cutWALUntil
libs/pubsub/query/fuzz_test/output libs/pubsub/query/fuzz_test/output
shunit2 shunit2
*/vendor
*/.glide
.terraform
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.d

View File

@ -1,14 +1,135 @@
# Changelog # Changelog
## TBD ## 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
*July 14th, 2018*
BREAKING CHANGES:
- [genesis] removed deprecated `app_options` field.
- [types] Genesis.AppStateJSON -> Genesis.AppState
FEATURES:
- [tools] Merged in from github.com/tendermint/tools
BUG FIXES: BUG FIXES:
- [tools/tm-bench] Various fixes
- [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.
- [rpc] limited number of HTTP/WebSocket connections ## 0.22.3
*July 10th, 2018*
IMPROVEMENTS
- Update dependencies
* pin all values in Gopkg.toml to version or commit
* update golang/protobuf to v1.1.0
## 0.22.2
*July 10th, 2018*
IMPROVEMENTS
- More cleanup post repo merge!
- [docs] Include `ecosystem.json` and `tendermint-bft.md` from deprecated `aib-data` repository.
- [config] Add `instrumentation.max_open_connections`, which limits the number
of requests in flight to Prometheus server (if enabled). Default: 3.
BUG FIXES
- [rpc] Allow unquoted integers in requests
- NOTE: this is only for URI requests. JSONRPC requests and all responses
will use quoted integers (the proto3 JSON standard).
- [consensus] Fix halt on shutdown
## 0.22.1
*July 5th, 2018*
IMPROVEMENTS
* Cleanup post repo-merge.
* [docs] Various improvements.
BUG FIXES
* [state] Return error when EndBlock returns a 0-power validator that isn't
already in the validator set.
* [consensus] Shut down WAL properly.
## 0.22.0
*July 2nd, 2018*
BREAKING CHANGES:
- [config]
* Remove `max_block_size_txs` and `max_block_size_bytes` in favor of
consensus params from the genesis file.
* Rename `skip_upnp` to `upnp`, and turn it off by default.
* Change `max_packet_msg_size` back to `max_packet_msg_payload_size`
- [rpc]
* All integers are encoded as strings (part of the update for Amino v0.10.1)
* `syncing` is now called `catching_up`
- [types] Update Amino to v0.10.1
* Amino is now fully proto3 compatible for the basic types
* JSON-encoded types now use the type name instead of the prefix bytes
* Integers are encoded as strings
- [crypto] Update go-crypto to v0.10.0 and merge into `crypto`
* privKey.Sign returns error.
* ed25519 address changed to the first 20-bytes of the SHA256 of the raw pubkey bytes
* `tmlibs/merkle` -> `crypto/merkle`. Uses SHA256 instead of RIPEMD160
- [tmlibs] Update to v0.9.0 and merge into `libs`
* remove `merkle` package (moved to `crypto/merkle`)
FEATURES
- [cmd] Added metrics (served under `/metrics` using a Prometheus client;
disabled by default). See the new `instrumentation` section in the config and
[metrics](https://tendermint.readthedocs.io/projects/tools/en/develop/metrics.html)
guide.
- [p2p] Add IPv6 support to peering.
- [p2p] Add `external_address` to config to allow specifying the address for
peers to dial
IMPROVEMENT
- [rpc/client] Supports https and wss now.
- [crypto] Make public key size into public constants
- [mempool] Log tx hash, not entire tx
- [abci] Merged in github.com/tendermint/abci
- [crypto] Merged in github.com/tendermint/go-crypto
- [libs] Merged in github.com/tendermint/tmlibs
- [docs] Move from .rst to .md
BUG FIXES:
- [rpc] Limit maximum number of HTTP/WebSocket connections
(`rpc.max_open_connections`) and gRPC connections (`rpc.max_open_connections`) and gRPC connections
(`rpc.grpc_max_open_connections`). Check out [Running In (`rpc.grpc_max_open_connections`). Check out "Running In Production" guide if
Production](https://tendermint.readthedocs.io/en/master/running-in-production.html) you want to increase them.
guide if you want to increase them. - [rpc] Limit maximum request body size to 1MB (header is limited to 1MB).
- [consensus] Fix a halting bug where `create_empty_blocks=false`
- [p2p] Fix panic in seed mode
## 0.21.0 ## 0.21.0
@ -25,13 +146,6 @@ IMPROVEMENT
- [pubsub] Set default capacity to 0 - [pubsub] Set default capacity to 0
- [docs] Various improvements - [docs] Various improvements
FEATURES
- [main] added metrics (served under `/metrics` using a Prometheus client;
disabled by default). See the new `instrumentation` section in the config and
[metrics](https://tendermint.readthedocs.io/projects/tools/en/v0.21.0/metrics.html)
guide.
BUG FIXES BUG FIXES
- [consensus] Fix an issue where we don't make blocks after `fast_sync` when `create_empty_blocks=false` - [consensus] Fix an issue where we don't make blocks after `fast_sync` when `create_empty_blocks=false`

View File

@ -17,7 +17,7 @@ Instead, we use `git remote` to add the fork as a new remote for the original re
For instance, to create a fork and work on a branch of it, I would: For instance, to create a fork and work on a branch of it, I would:
* Create the fork on github, using the fork button. * Create the fork on github, using the fork button.
* Go to the original repo checked out locally (ie. `$GOPATH/src/github.com/tendermint/tendermint`) * Go to the original repo checked out locally (i.e. `$GOPATH/src/github.com/tendermint/tendermint`)
* `git remote rename origin upstream` * `git remote rename origin upstream`
* `git remote add origin git@github.com:ebuchman/basecoin.git` * `git remote add origin git@github.com:ebuchman/basecoin.git`
@ -47,7 +47,7 @@ get_vendor_deps`). Even for dependencies under our control, dep helps us to
keep multiple repos in sync as they evolve. Anything with an executable, such keep multiple repos in sync as they evolve. Anything with an executable, such
as apps, tools, and the core, should use dep. as apps, tools, and the core, should use dep.
Run `dep status` to get a list of vendored dependencies that may not be Run `dep status` to get a list of vendor dependencies that may not be
up-to-date. up-to-date.
## Vagrant ## Vagrant
@ -85,7 +85,7 @@ especially `go-p2p` and `go-rpc`, as their versions are referenced in tendermint
- the latest state of development is on `develop` - the latest state of development is on `develop`
- `develop` must never fail `make test` - `develop` must never fail `make test`
- no --force onto `develop` (except when reverting a broken commit, which should seldom happen) - no --force onto `develop` (except when reverting a broken commit, which should seldom happen)
- create a development branch either on github.com/tendermint/tendermint, or your fork (using `git add origin`) - create a development branch either on github.com/tendermint/tendermint, or your fork (using `git remote add origin`)
- before submitting a pull request, begin `git rebase` on top of `develop` - before submitting a pull request, begin `git rebase` on top of `develop`
### Pull Merge Procedure: ### Pull Merge Procedure:
@ -110,7 +110,7 @@ especially `go-p2p` and `go-rpc`, as their versions are referenced in tendermint
- make the required changes - make the required changes
- these changes should be small and an absolute necessity - these changes should be small and an absolute necessity
- add a note to CHANGELOG.md - add a note to CHANGELOG.md
- bumb versions - bump versions
- push to hotfix-vX.X.X to run the extended integration tests on the CI - push to hotfix-vX.X.X to run the extended integration tests on the CI
- merge hotfix-vX.X.X to master - merge hotfix-vX.X.X to master
- merge hotfix-vX.X.X to develop - merge hotfix-vX.X.X to develop

93
Gopkg.lock generated
View File

@ -11,12 +11,15 @@
branch = "master" branch = "master"
name = "github.com/btcsuite/btcd" name = "github.com/btcsuite/btcd"
packages = ["btcec"] packages = ["btcec"]
revision = "86fed781132ac890ee03e906e4ecd5d6fa180c64" pruneopts = "UT"
revision = "f673a4b563b57b9a95832545c878669a7fa801d9"
[[projects]] [[projects]]
branch = "master"
name = "github.com/btcsuite/btcutil" name = "github.com/btcsuite/btcutil"
packages = ["base58"] packages = [
"base58",
"bech32"
]
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4" revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
[[projects]] [[projects]]
@ -26,16 +29,15 @@
version = "v1.1.0" version = "v1.1.0"
[[projects]] [[projects]]
branch = "master"
name = "github.com/ebuchman/fail-test" name = "github.com/ebuchman/fail-test"
packages = ["."] packages = ["."]
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4" revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
[[projects]] [[projects]]
branch = "master"
name = "github.com/fortytw2/leaktest" name = "github.com/fortytw2/leaktest"
packages = ["."] packages = ["."]
revision = "b008db64ef8daabb22ff6daa557f33b41d8f6ccd" revision = "a5ef70473c97b71626b9abeda80ee92ba2a7de9e"
version = "v1.2.0"
[[projects]] [[projects]]
name = "github.com/fsnotify/fsnotify" name = "github.com/fsnotify/fsnotify"
@ -79,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"
@ -91,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"
@ -113,7 +115,6 @@
".", ".",
"hcl/ast", "hcl/ast",
"hcl/parser", "hcl/parser",
"hcl/printer",
"hcl/scanner", "hcl/scanner",
"hcl/strconv", "hcl/strconv",
"hcl/token", "hcl/token",
@ -154,9 +155,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"
@ -182,14 +185,15 @@
"prometheus", "prometheus",
"prometheus/promhttp" "prometheus/promhttp"
] ]
revision = "c5b7fccd204277076155f10851dad72b76a49317" revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632"
version = "v0.8.0"
[[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"
@ -210,10 +214,9 @@
"nfs", "nfs",
"xfs" "xfs"
] ]
revision = "94663424ae5ae9856b40a9f170762b4197024661" revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a"
[[projects]] [[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics" name = "github.com/rcrowley/go-metrics"
packages = ["."] packages = ["."]
revision = "e2704e165165ec55d062f5919b4b29494e9fa790" revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
@ -236,8 +239,8 @@
[[projects]] [[projects]]
name = "github.com/spf13/cobra" name = "github.com/spf13/cobra"
packages = ["."] packages = ["."]
revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b"
version = "v0.0.3" version = "v0.0.1"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -254,8 +257,8 @@
[[projects]] [[projects]]
name = "github.com/spf13/viper" name = "github.com/spf13/viper"
packages = ["."] packages = ["."]
revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736" revision = "25b30aa063fc18e48662b86996252eabdcf2f0c7"
version = "v1.0.2" version = "v1.0.0"
[[projects]] [[projects]]
name = "github.com/stretchr/testify" name = "github.com/stretchr/testify"
@ -263,8 +266,8 @@
"assert", "assert",
"require" "require"
] ]
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71"
version = "v1.2.2" version = "v1.2.1"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -283,7 +286,7 @@
"leveldb/table", "leveldb/table",
"leveldb/util" "leveldb/util"
] ]
revision = "e2150783cd35f5b607daca48afd8c57ec54cc995" revision = "c4c61651e9e37fa117f53c5a906d3b63090d8445"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -301,23 +304,6 @@
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412" revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
version = "0.10.1" version = "0.10.1"
[[projects]]
name = "github.com/tendermint/tmlibs"
packages = [
"autofile",
"cli",
"cli/flags",
"clist",
"common",
"db",
"flowrate",
"log",
"merkle",
"test"
]
revision = "692f1d86a6e2c0efa698fd1e4541b68c74ffaf38"
version = "v0.8.4"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "golang.org/x/crypto" name = "golang.org/x/crypto"
@ -328,6 +314,7 @@
"curve25519", "curve25519",
"hkdf", "hkdf",
"internal/chacha20", "internal/chacha20",
"internal/subtle",
"nacl/box", "nacl/box",
"nacl/secretbox", "nacl/secretbox",
"openpgp/armor", "openpgp/armor",
@ -336,10 +323,9 @@
"ripemd160", "ripemd160",
"salsa20/salsa" "salsa20/salsa"
] ]
revision = "8ac0e0d97ce45cd83d1d7243c060cb8461dda5e9" revision = "a2144134853fc9a27a7b1e3eb4f19f1a76df13c9"
[[projects]] [[projects]]
branch = "master"
name = "golang.org/x/net" name = "golang.org/x/net"
packages = [ packages = [
"context", "context",
@ -351,7 +337,7 @@
"netutil", "netutil",
"trace" "trace"
] ]
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196" revision = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -360,7 +346,8 @@
"cpu", "cpu",
"unix" "unix"
] ]
revision = "a9e25c09b96b8870693763211309e213c6ef299d" pruneopts = "UT"
revision = "ac767d655b305d4e9612f5f6e33120b9176c4ad4"
[[projects]] [[projects]]
name = "golang.org/x/text" name = "golang.org/x/text"
@ -393,24 +380,32 @@
packages = [ packages = [
".", ".",
"balancer", "balancer",
"balancer/base",
"balancer/roundrobin",
"codes", "codes",
"connectivity", "connectivity",
"credentials", "credentials",
"grpclb/grpc_lb_v1/messages", "encoding",
"encoding/proto",
"grpclog", "grpclog",
"internal", "internal",
"internal/backoff",
"internal/channelz",
"internal/grpcrand",
"keepalive", "keepalive",
"metadata", "metadata",
"naming", "naming",
"peer", "peer",
"resolver", "resolver",
"resolver/dns",
"resolver/passthrough",
"stats", "stats",
"status", "status",
"tap", "tap",
"transport" "transport"
] ]
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e" revision = "168a6198bcb0ef175f7dacec0b8691fc141dc9b8"
version = "v1.7.5" version = "v1.13.0"
[[projects]] [[projects]]
name = "gopkg.in/yaml.v2" name = "gopkg.in/yaml.v2"
@ -421,6 +416,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "400de835ace8c8a69747afd675d1952daf750c251a02b9dac82a3c9dce4f65a8" inputs-digest = "9beb2d27dc19e3f9e2c7f416f312f7129f5441b1b53def42503fc6f7d3a54b16"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -23,65 +23,70 @@
# non-go = false # non-go = false
# go-tests = true # go-tests = true
# unused-packages = true # unused-packages = true
#
###########################################################
# NOTE: All packages should be pinned to specific versions.
# Packages without releases must pin to a commit.
[[constraint]]
name = "github.com/ebuchman/fail-test"
branch = "master"
[[constraint]]
name = "github.com/fortytw2/leaktest"
branch = "master"
[[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"
version = "~1.2.0" version = "=1.2.0"
[[constraint]] [[constraint]]
name = "github.com/pkg/errors" name = "github.com/pkg/errors"
version = "~0.8.0" version = "=0.8.0"
[[constraint]]
name = "github.com/rcrowley/go-metrics"
branch = "master"
[[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"
[[override]]
name = "github.com/tendermint/tmlibs"
version = "~0.8.4"
[[constraint]] [[constraint]]
name = "google.golang.org/grpc" name = "google.golang.org/grpc"
version = "~1.7.3" version = "=1.13.0"
# this got updated and broke, so locked to an old working commit ... [[constraint]]
name = "github.com/fortytw2/leaktest"
version = "=1.2.0"
###################################
## Some repos dont have releases.
## Pin to revision
## We can remove this one by updating protobuf to v1.1.0
## but then the grpc tests break with
#--- FAIL: TestBroadcastTx (0.01s)
#panic: message/group field common.KVPair:bytes without pointer [recovered]
# panic: message/group field common.KVPair:bytes without pointer
#
# ...
#
# github.com/tendermint/tendermint/rpc/grpc_test.TestBroadcastTx(0xc420a5ab40)
# /go/src/github.com/tendermint/tendermint/rpc/grpc/grpc_test.go:29 +0x141
[[override]] [[override]]
name = "google.golang.org/genproto" name = "google.golang.org/genproto"
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200" revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
@ -94,10 +99,28 @@
go-tests = true go-tests = true
unused-packages = true unused-packages = true
[[constraint]]
name = "github.com/ebuchman/fail-test"
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
# last revision used by go-crypto
[[constraint]]
name = "github.com/btcsuite/btcutil"
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
# Haven't made a release since 2016.
[[constraint]] [[constraint]]
name = "github.com/prometheus/client_golang" name = "github.com/prometheus/client_golang"
version = "0.8.0" revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632"
[[constraint]]
name = "github.com/rcrowley/go-metrics"
revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
[[constraint]] [[constraint]]
branch = "master"
name = "golang.org/x/net" name = "golang.org/x/net"
revision = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f"
[prune]
go-tests = true
unused-packages = true

View File

@ -1,7 +1,13 @@
GOTOOLS = \ GOTOOLS = \
github.com/mitchellh/gox \
github.com/golang/dep/cmd/dep \ github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2 gopkg.in/alecthomas/gometalinter.v2 \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto \
github.com/square/certstrap
PACKAGES=$(shell go list ./... | grep -v '/vendor/') PACKAGES=$(shell go list ./... | grep -v '/vendor/')
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`"
@ -11,7 +17,7 @@ check: check_tools ensure_deps
######################################## ########################################
### Build ### Build Tendermint
build: build:
CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o build/tendermint ./cmd/tendermint/ CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o build/tendermint ./cmd/tendermint/
@ -22,10 +28,35 @@ build_race:
install: 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
########################################
### Protobuf
protoc_all: protoc_libs protoc_abci protoc_grpc
%.pb.go: %.proto
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
protoc $(INCLUDE) $< --gogo_out=plugins=grpc:.
@echo "--> adding nolint declarations to protobuf generated files"
@awk -i inplace '/^\s*package \w+/ { print "//nolint" }1' $@
########################################
### Build ABCI
protoc_abci: abci/types/types.pb.go
build_abci:
@go build -i ./abci/cmd/...
install_abci:
@go install ./abci/cmd/...
######################################## ########################################
### Distribution ### Distribution
# dist builds binaries for all platforms and packages them for distribution # dist builds binaries for all platforms and packages them for distribution
# TODO add abci to these scripts
dist: dist:
@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'" @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
@ -59,6 +90,17 @@ ensure_deps:
@echo "--> Running dep" @echo "--> Running dep"
@dep ensure @dep ensure
#For ABCI and libs
get_protoc:
@# https://github.com/google/protobuf/releases
curl -L https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \
cd protobuf-3.4.1 && \
DIST_LANG=cpp ./configure && \
make && \
make install && \
cd .. && \
rm -rf protobuf-3.4.1
draw_deps: draw_deps:
@# requires brew install graphviz or apt-get install graphviz @# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz go get github.com/RobotsAndPencils/goviz
@ -70,6 +112,32 @@ get_deps_bin_size:
@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
@echo "Results can be found here: $(CURDIR)/deps_bin_size.log" @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
########################################
### Libs
protoc_libs: libs/common/types.pb.go
gen_certs: clean_certs
## Generating certificates for TLS testing...
certstrap init --common-name "tendermint.com" --passphrase ""
certstrap request-cert -ip "::" --passphrase ""
certstrap sign "::" --CA "tendermint.com" --passphrase ""
mv out/::.crt out/::.key db/remotedb
clean_certs:
## Cleaning TLS testing certificates...
rm -rf out
rm -f db/remotedb/::.crt db/remotedb/::.key
test_libs: gen_certs
GOCACHE=off go test -tags gcc $(PACKAGES)
make clean_certs
grpc_dbserver:
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
@ -87,6 +155,15 @@ test_apps:
# requires `abci-cli` and `tendermint` binaries installed # requires `abci-cli` and `tendermint` binaries installed
bash test/app/test.sh bash test/app/test.sh
test_abci_apps:
bash abci/tests/test_app/test.sh
test_abci_cli:
# test the cli against the examples in the tutorial at:
# ./docs/abci-cli.md
# if test fails, update the docs ^
@ bash abci/tests/test_cli/test.sh
test_persistence: test_persistence:
# run the persistence tests using bash # run the persistence tests using bash
# requires `abci-cli` installed # requires `abci-cli` installed
@ -105,17 +182,16 @@ test_p2p:
# requires 'tester' the image from above # requires 'tester' the image from above
bash test/p2p/test.sh tester bash test/p2p/test.sh tester
need_abci:
bash scripts/install_abci_apps.sh
test_integrations: test_integrations:
make build_docker_test_image make build_docker_test_image
make get_tools make get_tools
make get_vendor_deps make get_vendor_deps
make install make install
make need_abci
make test_cover make test_cover
make test_apps make test_apps
make test_abci_apps
make test_abci_cli
make test_libs
make test_persistence make test_persistence
make test_p2p make test_p2p
@ -233,4 +309,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 dist install check_tools get_tools update_tools get_vendor_deps draw_deps 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

View File

@ -50,13 +50,13 @@ Go version | Go1.9 or higher
## Install ## Install
See the [install instructions](/docs/install.rst) See the [install instructions](/docs/introduction/install.md)
## Quick Start ## Quick Start
- [Single node](/docs/using-tendermint.rst) - [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.rst) - [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
@ -72,10 +72,7 @@ Additional information about some - and eventually all - of the sub-projects bel
### Sub-projects ### Sub-projects
* [ABCI](http://github.com/tendermint/abci), the Application Blockchain Interface * [Amino](http://github.com/tendermint/go-amino), a reflection-based improvement on proto3
* [Go-Wire](http://github.com/tendermint/go-wire), a deterministic serialization library
* [Go-Crypto](http://github.com/tendermint/tendermint/crypto), an elliptic curve cryptography library
* [TmLibs](http://github.com/tendermint/tmlibs), an assortment of Go libraries used internally
* [IAVL](http://github.com/tendermint/iavl), Merkleized IAVL+ Tree implementation * [IAVL](http://github.com/tendermint/iavl), Merkleized IAVL+ Tree implementation
### Tools ### Tools
@ -119,8 +116,8 @@ CHANGELOG even if they don't lead to MINOR version bumps:
- node - node
Exported objects in these packages that are not covered by the versioning scheme Exported objects in these packages that are not covered by the versioning scheme
are explicitly marked by `// UNSTABLE` in their go doc comment and may change at any time. are explicitly marked by `// UNSTABLE` in their go doc comment and may change at any
Functions, types, and values in any other package may also change at any time. time without notice. Functions, types, and values in any other package may also change at any time.
### Upgrades ### Upgrades

View File

@ -1,174 +0,0 @@
GOTOOLS = \
github.com/mitchellh/gox \
github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto
GOTOOLS_CHECK = gox dep gometalinter.v2 protoc protoc-gen-gogo
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
all: check get_vendor_deps protoc build test install metalinter
check: check_tools
########################################
### Build
protoc:
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
protoc $(INCLUDE) --gogo_out=plugins=grpc:. types/*.proto
@echo "--> adding nolint declarations to protobuf generated files"
@awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
@mv types/types.pb.go.new types/types.pb.go
build:
@go build -i ./cmd/...
dist:
@bash scripts/dist.sh
@bash scripts/publish.sh
install:
@go install ./cmd/...
########################################
### Tools & dependencies
check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
get_tools:
@echo "--> Installing tools"
go get -u -v $(GOTOOLS)
@gometalinter.v2 --install
get_protoc:
@# https://github.com/google/protobuf/releases
curl -L https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \
cd protobuf-3.4.1 && \
DIST_LANG=cpp ./configure && \
make && \
make install && \
cd .. && \
rm -rf protobuf-3.4.1
update_tools:
@echo "--> Updating tools"
@go get -u $(GOTOOLS)
get_vendor_deps:
@rm -rf vendor/
@echo "--> Running dep ensure"
@dep ensure
########################################
### Testing
test:
@find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@echo "==> Running go test"
@go test $(PACKAGES)
test_race:
@find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@echo "==> Running go test --race"
@go test -v -race $(PACKAGES)
### three tests tested by Jenkins
test_cover:
@ bash tests/test_cover.sh
test_apps:
# test the counter using a go test script
@ bash tests/test_app/test.sh
test_cli:
# test the cli against the examples in the tutorial at:
# http://tendermint.readthedocs.io/projects/tools/en/master/abci-cli.html
#
# XXX: if this test fails, fix it and update the docs at:
# https://github.com/tendermint/tendermint/blob/develop/docs/abci-cli.rst
@ bash tests/test_cli/test.sh
########################################
### Formatting, linting, and vetting
fmt:
@go fmt ./...
metalinter:
@echo "==> Running linter"
gometalinter.v2 --vendor --deadline=600s --disable-all \
--enable=maligned \
--enable=deadcode \
--enable=goconst \
--enable=goimports \
--enable=gosimple \
--enable=ineffassign \
--enable=megacheck \
--enable=misspell \
--enable=staticcheck \
--enable=safesql \
--enable=structcheck \
--enable=unconvert \
--enable=unused \
--enable=varcheck \
--enable=vetshadow \
./...
#--enable=gas \
#--enable=dupl \
#--enable=errcheck \
#--enable=gocyclo \
#--enable=golint \ <== comments on anything exported
#--enable=gotype \
#--enable=interfacer \
#--enable=unparam \
#--enable=vet \
metalinter_all:
protoc $(INCLUDE) --lint_out=. types/*.proto
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
########################################
### Docker
DEVDOC_SAVE = docker commit `docker ps -a -n 1 -q` devdoc:local
docker_build:
docker build -t "tendermint/abci-dev" -f Dockerfile.develop .
docker_run:
docker run -it -v "$(CURDIR):/go/src/github.com/tendermint/abci" -w "/go/src/github.com/tendermint/abci" "tendermint/abci-dev" /bin/bash
docker_run_rm:
docker run -it --rm -v "$(CURDIR):/go/src/github.com/tendermint/abci" -w "/go/src/github.com/tendermint/abci" "tendermint/abci-dev" /bin/bash
devdoc_init:
docker run -it -v "$(CURDIR):/go/src/github.com/tendermint/abci" -w "/go/src/github.com/tendermint/abci" tendermint/devdoc echo
# TODO make this safer
$(call DEVDOC_SAVE)
devdoc:
docker run -it -v "$(CURDIR):/go/src/github.com/tendermint/abci" -w "/go/src/github.com/tendermint/abci" devdoc:local bash
devdoc_save:
# TODO make this safer
$(call DEVDOC_SAVE)
devdoc_clean:
docker rmi $$(docker images -f "dangling=true" -q)
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: check protoc build dist install check_tools get_tools get_protoc update_tools get_vendor_deps test test_race fmt metalinter metalinter_all docker_build docker_run docker_run_rm devdoc_init devdoc devdoc_save devdoc_clean

View File

@ -5,7 +5,7 @@ import (
"sync" "sync"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
const ( const (

View File

@ -10,7 +10,7 @@ import (
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var _ Client = (*grpcClient)(nil) var _ Client = (*grpcClient)(nil)

View File

@ -4,7 +4,7 @@ import (
"sync" "sync"
types "github.com/tendermint/tendermint/abci/types" types "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var _ Client = (*localClient)(nil) var _ Client = (*localClient)(nil)

View File

@ -11,7 +11,7 @@ import (
"time" "time"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
const reqQueueSize = 256 // TODO make configurable const reqQueueSize = 256 // TODO make configurable
@ -357,6 +357,13 @@ func (cli *socketClient) queueRequest(req *types.Request) *ReqRes {
} }
func (cli *socketClient) flushQueue() { func (cli *socketClient) flushQueue() {
// mark all in-flight messages as resolved (they will get cli.Error())
for req := cli.reqSent.Front(); req != nil; req = req.Next() {
reqres := req.Value.(*ReqRes)
reqres.Done()
}
// mark all queued messages as resolved
LOOP: LOOP:
for { for {
select { select {

View File

@ -2,10 +2,17 @@ package abcicli_test
import ( import (
"errors" "errors"
"fmt"
"testing" "testing"
"time" "time"
"github.com/tendermint/tendermint/abci/client" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/server"
"github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
) )
func TestSocketClientStopForErrorDeadlock(t *testing.T) { func TestSocketClientStopForErrorDeadlock(t *testing.T) {
@ -26,3 +33,89 @@ func TestSocketClientStopForErrorDeadlock(t *testing.T) {
t.Fatalf("Test took too long, potential deadlock still exists") t.Fatalf("Test took too long, potential deadlock still exists")
} }
} }
func TestProperSyncCalls(t *testing.T) {
app := slowApp{}
s, c := setupClientServer(t, app)
defer s.Stop()
defer c.Stop()
resp := make(chan error, 1)
go func() {
// This is BeginBlockSync unrolled....
reqres := c.BeginBlockAsync(types.RequestBeginBlock{})
c.FlushSync()
res := reqres.Response.GetBeginBlock()
require.NotNil(t, res)
resp <- c.Error()
}()
select {
case <-time.After(time.Second):
require.Fail(t, "No response arrived")
case err, ok := <-resp:
require.True(t, ok, "Must not close channel")
assert.NoError(t, err, "This should return success")
}
}
func TestHangingSyncCalls(t *testing.T) {
app := slowApp{}
s, c := setupClientServer(t, app)
defer s.Stop()
defer c.Stop()
resp := make(chan error, 1)
go func() {
// Start BeginBlock and flush it
reqres := c.BeginBlockAsync(types.RequestBeginBlock{})
flush := c.FlushAsync()
// wait 20 ms for all events to travel socket, but
// no response yet from server
time.Sleep(20 * time.Millisecond)
// kill the server, so the connections break
s.Stop()
// wait for the response from BeginBlock
reqres.Wait()
flush.Wait()
resp <- c.Error()
}()
select {
case <-time.After(time.Second):
require.Fail(t, "No response arrived")
case err, ok := <-resp:
require.True(t, ok, "Must not close channel")
assert.Error(t, err, "We should get EOF error")
}
}
func setupClientServer(t *testing.T, app types.Application) (
cmn.Service, abcicli.Client) {
// some port between 20k and 30k
port := 20000 + cmn.RandInt32()%10000
addr := fmt.Sprintf("localhost:%d", port)
s, err := server.NewServer(addr, "socket", app)
require.NoError(t, err)
err = s.Start()
require.NoError(t, err)
c := abcicli.NewSocketClient(addr, true)
err = c.Start()
require.NoError(t, err)
return s, c
}
type slowApp struct {
types.BaseApplication
}
func (slowApp) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
time.Sleep(200 * time.Millisecond)
return types.ResponseBeginBlock{}
}

View File

@ -11,8 +11,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"

View File

@ -6,7 +6,7 @@ import (
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
type CounterApplication struct { type CounterApplication struct {

View File

@ -11,8 +11,8 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"

View File

@ -2,7 +2,7 @@ package kvstore
import ( import (
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
// RandVal creates one random validator, with a key derived // RandVal creates one random validator, with a key derived

View File

@ -8,8 +8,8 @@ import (
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
) )
var ( var (

View File

@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"

View File

@ -9,9 +9,9 @@ import (
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
const ( const (

View File

@ -1,12 +0,0 @@
FROM golang:1.9.2
RUN apt-get update && apt-get install -y --no-install-recommends \
zip \
&& rm -rf /var/lib/apt/lists/*
# We want to ensure that release builds never have any cgo dependencies so we
# switch that off at the highest level.
ENV CGO_ENABLED 0
RUN mkdir -p $GOPATH/src/github.com/tendermint/abci
WORKDIR $GOPATH/src/github.com/tendermint/abci

View File

@ -1,52 +0,0 @@
#!/usr/bin/env bash
set -e
REPO_NAME="abci"
# Get the version from the environment, or try to figure it out.
if [ -z $VERSION ]; then
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
fi
if [ -z "$VERSION" ]; then
echo "Please specify a version."
exit 1
fi
echo "==> Building version $VERSION..."
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that dir because we expect that.
cd "$DIR"
# Delete the old dir
echo "==> Removing old directory..."
rm -rf build/pkg
mkdir -p build/pkg
# Do a hermetic build inside a Docker container.
docker build -t tendermint/${REPO_NAME}-builder scripts/${REPO_NAME}-builder/
docker run --rm -e "BUILD_TAGS=$BUILD_TAGS" -v "$(pwd)":/go/src/github.com/tendermint/${REPO_NAME} tendermint/${REPO_NAME}-builder ./scripts/dist_build.sh
# Add $REPO_NAME and $VERSION prefix to package name.
rm -rf ./build/dist
mkdir -p ./build/dist
for FILENAME in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type f); do
FILENAME=$(basename "$FILENAME")
cp "./build/pkg/${FILENAME}" "./build/dist/${REPO_NAME}_${VERSION}_${FILENAME}"
done
# Make the checksums.
pushd ./build/dist
shasum -a256 ./* > "./${REPO_NAME}_${VERSION}_SHA256SUMS"
popd
# Done
echo
echo "==> Results:"
ls -hl ./build/dist
exit 0

View File

@ -1,53 +0,0 @@
#!/usr/bin/env bash
set -e
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that dir because we expect that.
cd "$DIR"
# Get the git commit
GIT_COMMIT="$(git rev-parse --short HEAD)"
GIT_DESCRIBE="$(git describe --tags --always)"
GIT_IMPORT="github.com/tendermint/abci/version"
# Determine the arch/os combos we're building for
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"}
# Make sure build tools are available.
make get_tools
# Get VENDORED dependencies
make get_vendor_deps
BINARY="abci-cli"
# Build!
echo "==> Building..."
"$(which gox)" \
-os="${XC_OS}" \
-arch="${XC_ARCH}" \
-osarch="!darwin/arm !solaris/amd64 !freebsd/amd64" \
-ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \
-output "build/pkg/{{.OS}}_{{.Arch}}/$BINARY" \
-tags="${BUILD_TAGS}" \
github.com/tendermint/abci/cmd/$BINARY
# Zip all the files.
echo "==> Packaging..."
for PLATFORM in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename "${PLATFORM}")
echo "--> ${OSARCH}"
pushd "$PLATFORM" >/dev/null 2>&1
zip "../${OSARCH}.zip" ./*
popd >/dev/null 2>&1
done
exit 0

View File

@ -1,7 +0,0 @@
#! /bin/bash
# Get the version from the environment, or try to figure it out.
if [ -z $VERSION ]; then
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
fi
aws s3 cp --recursive build/dist s3://tendermint/binaries/abci/v${VERSION} --acl public-read

View File

@ -6,7 +6,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
type GRPCServer struct { type GRPCServer struct {

View File

@ -13,7 +13,7 @@ import (
"fmt" "fmt"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func NewServer(protoAddr, transport string, app types.Application) (cmn.Service, error) { func NewServer(protoAddr, transport string, app types.Application) (cmn.Service, error) {

View File

@ -8,7 +8,7 @@ import (
"sync" "sync"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
// var maxNumberConnections = 2 // var maxNumberConnections = 2

View File

@ -1,294 +0,0 @@
ABCI Specification
==================
NOTE: this file has moved to `specification.md <./specification.md>`__. It is left to prevent link breakages for the forseable future. It can safely be deleted in a few months.
Message Types
~~~~~~~~~~~~~
ABCI requests/responses are defined as simple Protobuf messages in `this
schema
file <https://github.com/tendermint/abci/blob/master/types/types.proto>`__.
TendermintCore sends the requests, and the ABCI application sends the
responses. Here, we provide an overview of the messages types and how they
are used by Tendermint. Then we describe each request-response pair as a
function with arguments and return values, and add some notes on usage.
Some messages (``Echo, Info, InitChain, BeginBlock, EndBlock, Commit``), don't
return errors because an error would indicate a critical failure in the
application and there's nothing Tendermint can do. The problem should be
addressed and both Tendermint and the application restarted. All other
messages (``SetOption, Query, CheckTx, DeliverTx``) return an
application-specific response ``Code uint32``, where only ``0`` is reserved for
``OK``.
Some messages (``SetOption, Query, CheckTx, DeliverTx``) return
non-deterministic data in the form of ``Info`` and ``Log``. The ``Log`` is
intended for the literal output from the application's logger, while the
``Info`` is any additional info that should be returned.
The first time a new blockchain is started, Tendermint calls ``InitChain``.
From then on, the Block Execution Sequence that causes the committed state to
be updated is as follows:
``BeginBlock, [DeliverTx], EndBlock, Commit``
where one ``DeliverTx`` is called for each transaction in the block.
Cryptographic commitments to the results of DeliverTx, EndBlock, and
Commit are included in the header of the next block.
Tendermint opens three connections to the application to handle the different message
types:
- ``Consensus Connection - InitChain, BeginBlock, DeliverTx, EndBlock, Commit``
- ``Mempool Connection - CheckTx``
- ``Info Connection - Info, SetOption, Query``
The ``Flush`` message is used on every connection, and the ``Echo`` message
is only used for debugging.
Note that messages may be sent concurrently across all connections -
a typical application will thus maintain a distinct state for each
connection. They may be referred to as the ``DeliverTx state``, the
``CheckTx state``, and the ``Commit state`` respectively.
See below for more details on the message types and how they are used.
Echo
^^^^
- **Arguments**:
- ``Message (string)``: A string to echo back
- **Returns**:
- ``Message (string)``: The input string
- **Usage**:
- Echo a string to test an abci client/server implementation
Flush
^^^^^
- **Usage**:
- Signals that messages queued on the client should be flushed to
the server. It is called periodically by the client implementation
to ensure asynchronous requests are actually sent, and is called
immediately to make a synchronous request, which returns when the
Flush response comes back.
Info
^^^^
- **Arguments**:
- ``Version (string)``: The Tendermint version
- **Returns**:
- ``Data (string)``: Some arbitrary information
- ``Version (Version)``: Version information
- ``LastBlockHeight (int64)``: Latest block for which the app has
called Commit
- ``LastBlockAppHash ([]byte)``: Latest result of Commit
- **Usage**:
- Return information about the application state.
- Used to sync Tendermint with the application during a handshake that
happens on startup.
- Tendermint expects ``LastBlockAppHash`` and ``LastBlockHeight`` to be
updated during ``Commit``, ensuring that ``Commit`` is never called twice
for the same block height.
SetOption
^^^^^^^^^
- **Arguments**:
- ``Key (string)``: Key to set
- ``Value (string)``: Value to set for key
- **Returns**:
- ``Code (uint32)``: Response code
- ``Log (string)``: The output of the application's logger. May be non-deterministic.
- ``Info (string)``: Additional information. May be non-deterministic.
- **Usage**:
- Set non-consensus critical application specific options.
- e.g. Key="min-fee", Value="100fermion" could set the minimum fee required for CheckTx
(but not DeliverTx - that would be consensus critical).
InitChain
^^^^^^^^^
- **Arguments**:
- ``Validators ([]Validator)``: Initial genesis validators
- ``AppStateBytes ([]byte)``: Serialized initial application state
- **Usage**:
- Called once upon genesis.
Query
^^^^^
- **Arguments**:
- ``Data ([]byte)``: Raw query bytes. Can be used with or in lieu of
Path.
- ``Path (string)``: Path of request, like an HTTP GET path. Can be
used with or in liue of Data.
- Apps MUST interpret '/store' as a query by key on the underlying
store. The key SHOULD be specified in the Data field.
- Apps SHOULD allow queries over specific types like '/accounts/...'
or '/votes/...'
- ``Height (int64)``: The block height for which you want the query
(default=0 returns data for the latest committed block). Note that
this is the height of the block containing the application's
Merkle root hash, which represents the state as it was after
committing the block at Height-1
- ``Prove (bool)``: Return Merkle proof with response if possible
- **Returns**:
- ``Code (uint32)``: Response code.
- ``Log (string)``: The output of the application's logger. May be non-deterministic.
- ``Info (string)``: Additional information. May be non-deterministic.
- ``Index (int64)``: The index of the key in the tree.
- ``Key ([]byte)``: The key of the matching data.
- ``Value ([]byte)``: The value of the matching data.
- ``Proof ([]byte)``: Proof for the data, if requested.
- ``Height (int64)``: The block height from which data was derived.
Note that this is the height of the block containing the
application's Merkle root hash, which represents the state as it
was after committing the block at Height-1
- **Usage**:
- Query for data from the application at current or past height.
- Optionally return Merkle proof.
BeginBlock
^^^^^^^^^^
- **Arguments**:
- ``Hash ([]byte)``: The block's hash. This can be derived from the
block header.
- ``Header (struct{})``: The block header
- ``AbsentValidators ([]int32)``: List of indices of validators not
included in the LastCommit
- ``ByzantineValidators ([]Evidence)``: List of evidence of
validators that acted maliciously
- **Usage**:
- Signals the beginning of a new block. Called prior to any DeliverTxs.
- The header is expected to at least contain the Height.
- The ``AbsentValidators`` and ``ByzantineValidators`` can be used to
determine rewards and punishments for the validators.
CheckTx
^^^^^^^
- **Arguments**:
- ``Tx ([]byte)``: The request transaction bytes
- **Returns**:
- ``Code (uint32)``: Response code
- ``Data ([]byte)``: Result bytes, if any.
- ``Log (string)``: The output of the application's logger. May be non-deterministic.
- ``Info (string)``: Additional information. May be non-deterministic.
- ``GasWanted (int64)``: Amount of gas request for transaction.
- ``GasUsed (int64)``: Amount of gas consumed by transaction.
- ``Tags ([]cmn.KVPair)``: Key-Value tags for filtering and indexing transactions (eg. by account).
- ``Fee (cmn.KI64Pair)``: Fee paid for the transaction.
- **Usage**: Validate a mempool transaction, prior to broadcasting or
proposing. CheckTx should perform stateful but light-weight checks
of the validity of the transaction (like checking signatures and account balances),
but need not execute in full (like running a smart contract).
Tendermint runs CheckTx and DeliverTx concurrently with eachother,
though on distinct ABCI connections - the mempool connection and the consensus
connection, respectively.
The application should maintain a separate state to support CheckTx.
This state can be reset to the latest committed state during ``Commit``,
where Tendermint ensures the mempool is locked and not sending new ``CheckTx``.
After ``Commit``, the mempool will rerun CheckTx on all remaining
transactions, throwing out any that are no longer valid.
Keys and values in Tags must be UTF-8 encoded strings (e.g. "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02")
DeliverTx
^^^^^^^^^
- **Arguments**:
- ``Tx ([]byte)``: The request transaction bytes.
- **Returns**:
- ``Code (uint32)``: Response code.
- ``Data ([]byte)``: Result bytes, if any.
- ``Log (string)``: The output of the application's logger. May be non-deterministic.
- ``Info (string)``: Additional information. May be non-deterministic.
- ``GasWanted (int64)``: Amount of gas requested for transaction.
- ``GasUsed (int64)``: Amount of gas consumed by transaction.
- ``Tags ([]cmn.KVPair)``: Key-Value tags for filtering and indexing transactions (eg. by account).
- ``Fee (cmn.KI64Pair)``: Fee paid for the transaction.
- **Usage**:
- Deliver a transaction to be executed in full by the application. If the transaction is valid,
returns CodeType.OK.
- Keys and values in Tags must be UTF-8 encoded strings (e.g. "account.owner": "Bob", "balance": "100.0", "time": "2018-01-02T12:30:00Z")
EndBlock
^^^^^^^^
- **Arguments**:
- ``Height (int64)``: Height of the block just executed.
- **Returns**:
- ``ValidatorUpdates ([]Validator)``: Changes to validator set (set
voting power to 0 to remove).
- ``ConsensusParamUpdates (ConsensusParams)``: Changes to
consensus-critical time, size, and other parameters.
- **Usage**:
- Signals the end of a block.
- Called prior to each Commit, after all transactions.
- Validator set and consensus params are updated with the result.
- Validator pubkeys are expected to be go-wire encoded.
Commit
^^^^^^
- **Returns**:
- ``Data ([]byte)``: The Merkle root hash
- **Usage**:
- Persist the application state.
- Return a Merkle root hash of the application state.
- It's critical that all application instances return the same hash. If not,
they will not be able to agree on the next block, because the hash is
included in the next block!

View File

@ -6,7 +6,7 @@ import (
"log" "log"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func main() { func main() {

View File

@ -8,7 +8,7 @@ import (
"reflect" "reflect"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func main() { func main() {

View File

@ -7,7 +7,7 @@ import (
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func InitChain(client abcicli.Client) error { func InitChain(client abcicli.Client) error {

View File

@ -7,7 +7,7 @@ import (
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
func startClient(abciType string) abcicli.Client { func startClient(abciType string) abcicli.Client {

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
set -e
echo "" > coverage.txt
echo "==> Running unit tests"
for d in $(go list ./... | grep -v vendor); do
go test -race -coverprofile=profile.out -covermode=atomic "$d"
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

View File

@ -8,7 +8,7 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func TestMarshalJSON(t *testing.T) { func TestMarshalJSON(t *testing.T) {

File diff suppressed because it is too large Load Diff

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"sort" "sort"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -6,8 +6,8 @@ import (
"github.com/tendermint/go-amino" "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
proto "github.com/tendermint/tendermint/benchmarks/proto" proto "github.com/tendermint/tendermint/benchmarks/proto"
"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"

View File

@ -3,7 +3,7 @@ package benchmarks
import ( import (
"testing" "testing"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func BenchmarkSomething(b *testing.B) { func BenchmarkSomething(b *testing.B) {

View File

@ -4,7 +4,7 @@ import (
"os" "os"
"testing" "testing"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func BenchmarkFileWrite(b *testing.B) { func BenchmarkFileWrite(b *testing.B) {

View File

@ -7,7 +7,7 @@ import (
"time" "time"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client" rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func main() { func main() {

View File

@ -8,9 +8,9 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
flow "github.com/tendermint/tmlibs/flowrate" flow "github.com/tendermint/tendermint/libs/flowrate"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"

View File

@ -1,12 +1,11 @@
package blockchain package blockchain
import ( import (
"math/rand"
"testing" "testing"
"time" "time"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -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)
}() }()

View File

@ -5,12 +5,13 @@ import (
"reflect" "reflect"
"time" "time"
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
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/tmlibs/common"
"github.com/tendermint/tmlibs/log"
) )
const ( const (
@ -176,7 +177,7 @@ func (bcR *BlockchainReactor) respondToPeer(msg *bcBlockRequestMessage,
// Receive implements Reactor by handling 4 types of messages (look below). // Receive implements Reactor by handling 4 types of messages (look below).
func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
msg, err := DecodeMessage(msgBytes) msg, err := decodeMsg(msgBytes)
if err != nil { if err != nil {
bcR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes) bcR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes)
bcR.Switch.StopPeerForError(src, err) bcR.Switch.StopPeerForError(src, err)
@ -366,17 +367,11 @@ func RegisterBlockchainMessages(cdc *amino.Codec) {
cdc.RegisterConcrete(&bcStatusRequestMessage{}, "tendermint/mempool/StatusRequest", nil) cdc.RegisterConcrete(&bcStatusRequestMessage{}, "tendermint/mempool/StatusRequest", nil)
} }
// DecodeMessage decodes BlockchainMessage. func decodeMsg(bz []byte) (msg BlockchainMessage, err error) {
// TODO: ensure that bz is completely read.
func DecodeMessage(bz []byte) (msg BlockchainMessage, err error) {
if len(bz) > maxMsgSize { if len(bz) > maxMsgSize {
return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize)
len(bz), maxMsgSize)
} }
err = cdc.UnmarshalBinaryBare(bz, &msg) err = cdc.UnmarshalBinaryBare(bz, &msg)
if err != nil {
err = cmn.ErrorWrap(err, "DecodeMessage() had bytes left over")
}
return return
} }

View File

@ -4,9 +4,9 @@ import (
"net" "net"
"testing" "testing"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
@ -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 }

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"sync" "sync"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )

View File

@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tmlibs/db" "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -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,35 +137,35 @@ 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
wantPanic: "Error reading block commit", wantPanic: "unmarshal to types.Commit failed",
}, },
{ {
block: newBlock(&header1, commitAtH10), block: newBlock(header1, commitAtH10),
parts: validPartSet, parts: validPartSet,
seenCommit: seenCommit1, seenCommit: seenCommit1,
wantPanic: "Error reading block", wantPanic: "unmarshal to types.BlockMeta failed",
corruptBlockInDB: true, // Corrupt the DB's block entry corruptBlockInDB: true, // Corrupt the DB's block entry
}, },
{ {
block: newBlock(&header1, commitAtH10), block: newBlock(header1, commitAtH10),
parts: validPartSet, parts: validPartSet,
seenCommit: seenCommit1, seenCommit: seenCommit1,
@ -174,16 +174,16 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
}, },
{ {
block: newBlock(&header1, commitAtH10), block: newBlock(header1, commitAtH10),
parts: validPartSet, parts: validPartSet,
seenCommit: seenCommit1, seenCommit: seenCommit1,
corruptSeenCommitInDB: true, corruptSeenCommitInDB: true,
wantPanic: "Error reading block seen commit", wantPanic: "unmarshal to types.Commit failed",
}, },
{ {
block: newBlock(&header1, commitAtH10), block: newBlock(header1, commitAtH10),
parts: validPartSet, parts: validPartSet,
seenCommit: seenCommit1, seenCommit: seenCommit1,
@ -287,7 +287,7 @@ func TestLoadBlockPart(t *testing.T) {
db.Set(calcBlockPartKey(height, index), []byte("Tendermint")) db.Set(calcBlockPartKey(height, index), []byte("Tendermint"))
res, _, panicErr = doFn(loadPart) res, _, panicErr = doFn(loadPart)
require.NotNil(t, panicErr, "expecting a non-nil panic") require.NotNil(t, panicErr, "expecting a non-nil panic")
require.Contains(t, panicErr.Error(), "Error reading block part") require.Contains(t, panicErr.Error(), "unmarshal to types.Part failed")
// 3. A good block serialized and saved to the DB should be retrievable // 3. A good block serialized and saved to the DB should be retrievable
db.Set(calcBlockPartKey(height, index), cdc.MustMarshalBinaryBare(part1)) db.Set(calcBlockPartKey(height, index), cdc.MustMarshalBinaryBare(part1))
@ -316,7 +316,7 @@ func TestLoadBlockMeta(t *testing.T) {
db.Set(calcBlockMetaKey(height), []byte("Tendermint-Meta")) db.Set(calcBlockMetaKey(height), []byte("Tendermint-Meta"))
res, _, panicErr = doFn(loadMeta) res, _, panicErr = doFn(loadMeta)
require.NotNil(t, panicErr, "expecting a non-nil panic") require.NotNil(t, panicErr, "expecting a non-nil panic")
require.Contains(t, panicErr.Error(), "Error reading block meta") require.Contains(t, panicErr.Error(), "unmarshal to types.BlockMeta")
// 3. A good blockMeta serialized and saved to the DB should be retrievable // 3. A good blockMeta serialized and saved to the DB should be retrievable
meta := &types.BlockMeta{} meta := &types.BlockMeta{}
@ -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,

View File

@ -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)
} }

View File

@ -4,9 +4,9 @@ import (
"flag" "flag"
"os" "os"
crypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
) )
@ -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 {

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
// GenNodeKeyCmd allows the generation of a node key. It prints node's ID to // GenNodeKeyCmd allows the generation of a node key. It prints node's ID to

View File

@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
// InitFilesCmd initialises a fresh Tendermint Core instance. // InitFilesCmd initialises a fresh Tendermint Core instance.
@ -52,8 +52,9 @@ func initFilesWithConfig(config *cfg.Config) error {
logger.Info("Found genesis file", "path", genFile) logger.Info("Found genesis file", "path", genFile)
} else { } else {
genDoc := types.GenesisDoc{ genDoc := types.GenesisDoc{
ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)), ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)),
GenesisTime: time.Now(), GenesisTime: time.Now(),
ConsensusParams: types.DefaultConsensusParams(),
} }
genDoc.Validators = []types.GenesisValidator{{ genDoc.Validators = []types.GenesisValidator{{
PubKey: pv.GetPubKey(), PubKey: pv.GetPubKey(),

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/lite/proxy" "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client"

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
// ResetAllCmd removes the database of this Tendermint core // ResetAllCmd removes the database of this Tendermint core

View File

@ -7,9 +7,9 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tendermint/libs/cli"
tmflags "github.com/tendermint/tmlibs/cli/flags" tmflags "github.com/tendermint/tendermint/libs/cli/flags"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
var ( var (

View File

@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tendermint/libs/cli"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var ( var (

View File

@ -33,7 +33,7 @@ func AddNodeFlags(cmd *cobra.Command) {
cmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)") cmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
cmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma-delimited ID@host:port seed nodes") cmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma-delimited ID@host:port seed nodes")
cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma-delimited ID@host:port persistent peers") cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma-delimited ID@host:port persistent peers")
cmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration") cmd.Flags().Bool("p2p.upnp", config.P2P.UPNP, "Enable/disable UPNP port forwarding")
cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable/disable Peer-Exchange") cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable/disable Peer-Exchange")
cmd.Flags().Bool("p2p.seed_mode", config.P2P.SeedMode, "Enable/disable seed mode") cmd.Flags().Bool("p2p.seed_mode", config.P2P.SeedMode, "Enable/disable seed mode")
cmd.Flags().String("p2p.private_peer_ids", config.P2P.PrivatePeerIDs, "Comma-delimited private peer IDs") cmd.Flags().String("p2p.private_peer_ids", config.P2P.PrivatePeerIDs, "Comma-delimited private peer IDs")

View File

@ -14,7 +14,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var ( var (

View File

@ -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)
} }

View File

@ -4,7 +4,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tendermint/libs/cli"
cmd "github.com/tendermint/tendermint/cmd/tendermint/commands" cmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"

View File

@ -21,3 +21,4 @@ ignore:
- "docs" - "docs"
- "DOCKER" - "DOCKER"
- "scripts" - "scripts"
- "**/*.pb.go"

View File

@ -276,16 +276,18 @@ type P2PConfig struct {
// Address to listen for incoming connections // Address to listen for incoming connections
ListenAddress string `mapstructure:"laddr"` ListenAddress string `mapstructure:"laddr"`
// Address to advertise to peers for them to dial
ExternalAddress string `mapstructure:"external_address"`
// Comma separated list of seed nodes to connect to // Comma separated list of seed nodes to connect to
// We only use these if we cant connect to peers in the addrbook // We only use these if we cant connect to peers in the addrbook
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"`
// Skip UPNP port forwarding // UPNP port forwarding
SkipUPNP bool `mapstructure:"skip_upnp"` UPNP bool `mapstructure:"upnp"`
// Path to address book // Path to address book
AddrBook string `mapstructure:"addr_book_file"` AddrBook string `mapstructure:"addr_book_file"`
@ -299,9 +301,8 @@ type P2PConfig struct {
// Time to wait before flushing messages out on the connection, in ms // Time to wait before flushing messages out on the connection, in ms
FlushThrottleTimeout int `mapstructure:"flush_throttle_timeout"` FlushThrottleTimeout int `mapstructure:"flush_throttle_timeout"`
// Maximum size of a message packet, in bytes // Maximum size of a message packet payload, in bytes
// Includes a header, which is ~13 bytes MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`
MaxPacketMsgSize int `mapstructure:"max_packet_msg_size"`
// Rate at which packets can be sent, in bytes/second // Rate at which packets can be sent, in bytes/second
SendRate int64 `mapstructure:"send_rate"` SendRate int64 `mapstructure:"send_rate"`
@ -340,22 +341,24 @@ type P2PConfig struct {
// DefaultP2PConfig returns a default configuration for the peer-to-peer layer // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
func DefaultP2PConfig() *P2PConfig { func DefaultP2PConfig() *P2PConfig {
return &P2PConfig{ return &P2PConfig{
ListenAddress: "tcp://0.0.0.0:26656", ListenAddress: "tcp://0.0.0.0:26656",
AddrBook: defaultAddrBookPath, ExternalAddress: "",
AddrBookStrict: true, UPNP: false,
MaxNumPeers: 50, AddrBook: defaultAddrBookPath,
FlushThrottleTimeout: 100, AddrBookStrict: true,
MaxPacketMsgSize: 1024, // 1 kB MaxNumPeers: 50,
SendRate: 512000, // 500 kB/s FlushThrottleTimeout: 100,
RecvRate: 512000, // 500 kB/s MaxPacketMsgPayloadSize: 1024, // 1 kB
PexReactor: true, SendRate: 5120000, // 5 mB/s
SeedMode: false, RecvRate: 5120000, // 5 mB/s
AllowDuplicateIP: true, // so non-breaking yet PexReactor: true,
HandshakeTimeout: 20 * time.Second, SeedMode: false,
DialTimeout: 3 * time.Second, AllowDuplicateIP: true, // so non-breaking yet
TestDialFail: false, HandshakeTimeout: 20 * time.Second,
TestFuzz: false, DialTimeout: 3 * time.Second,
TestFuzzConfig: DefaultFuzzConnConfig(), TestDialFail: false,
TestFuzz: false,
TestFuzzConfig: DefaultFuzzConnConfig(),
} }
} }
@ -363,7 +366,6 @@ func DefaultP2PConfig() *P2PConfig {
func TestP2PConfig() *P2PConfig { func TestP2PConfig() *P2PConfig {
cfg := DefaultP2PConfig() cfg := DefaultP2PConfig()
cfg.ListenAddress = "tcp://0.0.0.0:36656" cfg.ListenAddress = "tcp://0.0.0.0:36656"
cfg.SkipUPNP = true
cfg.FlushThrottleTimeout = 10 cfg.FlushThrottleTimeout = 10
cfg.AllowDuplicateIP = true cfg.AllowDuplicateIP = true
return cfg return cfg
@ -454,10 +456,6 @@ type ConsensusConfig struct {
// Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"` SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
// BlockSize
MaxBlockSizeTxs int `mapstructure:"max_block_size_txs"`
MaxBlockSizeBytes int `mapstructure:"max_block_size_bytes"`
// EmptyBlocks mode and possible interval between empty blocks in seconds // EmptyBlocks mode and possible interval between empty blocks in seconds
CreateEmptyBlocks bool `mapstructure:"create_empty_blocks"` CreateEmptyBlocks bool `mapstructure:"create_empty_blocks"`
CreateEmptyBlocksInterval int `mapstructure:"create_empty_blocks_interval"` CreateEmptyBlocksInterval int `mapstructure:"create_empty_blocks_interval"`
@ -479,8 +477,6 @@ func DefaultConsensusConfig() *ConsensusConfig {
TimeoutPrecommitDelta: 500, TimeoutPrecommitDelta: 500,
TimeoutCommit: 1000, TimeoutCommit: 1000,
SkipTimeoutCommit: false, SkipTimeoutCommit: false,
MaxBlockSizeTxs: 10000,
MaxBlockSizeBytes: 1, // TODO
CreateEmptyBlocks: true, CreateEmptyBlocks: true,
CreateEmptyBlocksInterval: 0, CreateEmptyBlocksInterval: 0,
PeerGossipSleepDuration: 100, PeerGossipSleepDuration: 100,
@ -609,6 +605,12 @@ type InstrumentationConfig struct {
// Address to listen for Prometheus collector(s) connections. // Address to listen for Prometheus collector(s) connections.
PrometheusListenAddr string `mapstructure:"prometheus_listen_addr"` PrometheusListenAddr string `mapstructure:"prometheus_listen_addr"`
// Maximum number of simultaneous connections.
// If you want to accept more significant number than the default, make sure
// you increase your OS limits.
// 0 - unlimited.
MaxOpenConnections int `mapstructure:"max_open_connections"`
} }
// DefaultInstrumentationConfig returns a default configuration for metrics // DefaultInstrumentationConfig returns a default configuration for metrics
@ -617,6 +619,7 @@ func DefaultInstrumentationConfig() *InstrumentationConfig {
return &InstrumentationConfig{ return &InstrumentationConfig{
Prometheus: false, Prometheus: false,
PrometheusListenAddr: ":26660", PrometheusListenAddr: ":26660",
MaxOpenConnections: 3,
} }
} }

View File

@ -6,7 +6,7 @@ import (
"path/filepath" "path/filepath"
"text/template" "text/template"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var configTemplate *template.Template var configTemplate *template.Template
@ -142,13 +142,21 @@ max_open_connections = {{ .RPC.MaxOpenConnections }}
# Address to listen for incoming connections # Address to listen for incoming connections
laddr = "{{ .P2P.ListenAddress }}" laddr = "{{ .P2P.ListenAddress }}"
# Address to advertise to peers for them to dial
# If empty, will use the same port as the laddr,
# and will introspect on the listener or use UPnP
# to figure out the address.
external_address = "{{ .P2P.ExternalAddress }}"
# Comma separated list of seed nodes to connect to # Comma separated list of seed nodes to connect to
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 = {{ .P2P.UPNP }}
# Path to address book # Path to address book
addr_book_file = "{{ js .P2P.AddrBook }}" addr_book_file = "{{ js .P2P.AddrBook }}"
@ -161,9 +169,8 @@ flush_throttle_timeout = {{ .P2P.FlushThrottleTimeout }}
# Maximum number of peers to connect to # Maximum number of peers to connect to
max_num_peers = {{ .P2P.MaxNumPeers }} max_num_peers = {{ .P2P.MaxNumPeers }}
# Maximum size of a message packet, in bytes # Maximum size of a message packet payload, in bytes
# Includes a header, which is ~13 bytes max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }}
max_packet_msg_size = {{ .P2P.MaxPacketMsgSize }}
# Rate at which packets can be sent, in bytes/second # Rate at which packets can be sent, in bytes/second
send_rate = {{ .P2P.SendRate }} send_rate = {{ .P2P.SendRate }}
@ -214,10 +221,6 @@ timeout_commit = {{ .Consensus.TimeoutCommit }}
# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) # Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
skip_timeout_commit = {{ .Consensus.SkipTimeoutCommit }} skip_timeout_commit = {{ .Consensus.SkipTimeoutCommit }}
# BlockSize
max_block_size_txs = {{ .Consensus.MaxBlockSizeTxs }}
max_block_size_bytes = {{ .Consensus.MaxBlockSizeBytes }}
# EmptyBlocks mode and possible interval between empty blocks in seconds # EmptyBlocks mode and possible interval between empty blocks in seconds
create_empty_blocks = {{ .Consensus.CreateEmptyBlocks }} create_empty_blocks = {{ .Consensus.CreateEmptyBlocks }}
create_empty_blocks_interval = {{ .Consensus.CreateEmptyBlocksInterval }} create_empty_blocks_interval = {{ .Consensus.CreateEmptyBlocksInterval }}
@ -258,6 +261,12 @@ prometheus = {{ .Instrumentation.Prometheus }}
# Address to listen for Prometheus collector(s) connections # Address to listen for Prometheus collector(s) connections
prometheus_listen_addr = "{{ .Instrumentation.PrometheusListenAddr }}" prometheus_listen_addr = "{{ .Instrumentation.PrometheusListenAddr }}"
# Maximum number of simultaneous connections.
# If you want to accept more significant number than the default, make sure
# you increase your OS limits.
# 0 - unlimited.
max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
` `
/****** these are for test settings ***********/ /****** these are for test settings ***********/

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
func init() { func init() {

View File

@ -22,9 +22,9 @@ import (
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
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/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/abci/example/counter" "github.com/tendermint/tendermint/abci/example/counter"
"github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/example/kvstore"

View File

@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/abci/example/code" "github.com/tendermint/tendermint/abci/example/code"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )

View File

@ -9,11 +9,11 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
amino "github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
cstypes "github.com/tendermint/tendermint/consensus/types" cstypes "github.com/tendermint/tendermint/consensus/types"
cmn "github.com/tendermint/tendermint/libs/common"
tmevents "github.com/tendermint/tendermint/libs/events" tmevents "github.com/tendermint/tendermint/libs/events"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -80,6 +80,9 @@ func (conR *ConsensusReactor) OnStop() {
conR.BaseReactor.OnStop() conR.BaseReactor.OnStop()
conR.unsubscribeFromBroadcastEvents() conR.unsubscribeFromBroadcastEvents()
conR.conS.Stop() conR.conS.Stop()
if !conR.FastSync() {
conR.conS.Wait()
}
} }
// SwitchToConsensus switches from fast_sync mode to consensus mode. // SwitchToConsensus switches from fast_sync mode to consensus mode.
@ -183,7 +186,7 @@ func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
return return
} }
msg, err := DecodeMessage(msgBytes) msg, err := decodeMsg(msgBytes)
if err != nil { if err != nil {
conR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes) conR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes)
conR.Switch.StopPeerForError(src, err) conR.Switch.StopPeerForError(src, err)
@ -1306,11 +1309,9 @@ func RegisterConsensusMessages(cdc *amino.Codec) {
cdc.RegisterConcrete(&ProposalHeartbeatMessage{}, "tendermint/ProposalHeartbeat", nil) cdc.RegisterConcrete(&ProposalHeartbeatMessage{}, "tendermint/ProposalHeartbeat", nil)
} }
// DecodeMessage decodes the given bytes into a ConsensusMessage. func decodeMsg(bz []byte) (msg ConsensusMessage, err error) {
func DecodeMessage(bz []byte) (msg ConsensusMessage, err error) {
if len(bz) > maxMsgSize { if len(bz) > maxMsgSize {
return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize)
len(bz), maxMsgSize)
} }
err = cdc.UnmarshalBinaryBare(bz, &msg) err = cdc.UnmarshalBinaryBare(bz, &msg)
return return

View File

@ -11,8 +11,8 @@ import (
"time" "time"
"github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/example/kvstore"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"

View File

@ -11,10 +11,10 @@ import (
"time" "time"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
//auto "github.com/tendermint/tmlibs/autofile" //auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
@ -273,7 +273,7 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight
ChainId: h.genDoc.ChainID, ChainId: h.genDoc.ChainID,
ConsensusParams: csParams, ConsensusParams: csParams,
Validators: validators, Validators: validators,
AppStateBytes: h.genDoc.AppStateJSON, AppStateBytes: h.genDoc.AppState,
} }
res, err := proxyApp.Consensus().InitChainSync(req) res, err := proxyApp.Consensus().InitChainSync(req)
if err != nil { if err != nil {

View File

@ -16,9 +16,9 @@ import (
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
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/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
const ( const (

View File

@ -19,16 +19,16 @@ import (
"github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/example/kvstore"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
crypto "github.com/tendermint/tendermint/crypto" crypto "github.com/tendermint/tendermint/crypto"
auto "github.com/tendermint/tmlibs/autofile" auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tendermint/libs/db"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
var consensusReplayConfig *cfg.Config var consensusReplayConfig *cfg.Config

View File

@ -10,8 +10,8 @@ import (
"time" "time"
fail "github.com/ebuchman/fail-test" fail "github.com/ebuchman/fail-test"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
cstypes "github.com/tendermint/tendermint/consensus/types" cstypes "github.com/tendermint/tendermint/consensus/types"
@ -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)
} }
@ -314,16 +314,8 @@ func (cs *ConsensusState) startRoutines(maxSteps int) {
// OnStop implements cmn.Service. It stops all routines and waits for the WAL to finish. // OnStop implements cmn.Service. It stops all routines and waits for the WAL to finish.
func (cs *ConsensusState) OnStop() { func (cs *ConsensusState) OnStop() {
cs.BaseService.OnStop()
cs.evsw.Stop() cs.evsw.Stop()
cs.timeoutTicker.Stop() cs.timeoutTicker.Stop()
// Make BaseService.Wait() wait until cs.wal.Wait()
if cs.IsRunning() {
cs.wal.Wait()
}
} }
// Wait waits for the the main routine to return. // Wait waits for the the main routine to return.
@ -579,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
@ -603,6 +595,7 @@ func (cs *ConsensusState) receiveRoutine(maxSteps int) {
// close wal now that we're done writing to it // close wal now that we're done writing to it
cs.wal.Stop() cs.wal.Stop()
cs.wal.Wait()
close(cs.done) close(cs.done)
return return
@ -624,7 +617,7 @@ func (cs *ConsensusState) handleMsg(mi msgInfo) {
err = cs.setProposal(msg.Proposal) err = cs.setProposal(msg.Proposal)
case *BlockPartMessage: case *BlockPartMessage:
// if the proposal is complete, we'll enterPrevote or tryFinalizeCommit // if the proposal is complete, we'll enterPrevote or tryFinalizeCommit
_, err = cs.addProposalBlockPart(msg.Height, msg.Part) _, err = cs.addProposalBlockPart(msg, peerID)
if err != nil && msg.Round != cs.Round { if err != nil && msg.Round != cs.Round {
cs.Logger.Debug("Received block part from wrong round", "height", cs.Height, "csRound", cs.Round, "blockRound", msg.Round) cs.Logger.Debug("Received block part from wrong round", "height", cs.Height, "csRound", cs.Round, "blockRound", msg.Round)
err = nil err = nil
@ -690,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)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -932,7 +925,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
} }
// Mempool validated transactions // Mempool validated transactions
txs := cs.mempool.Reap(cs.config.MaxBlockSizeTxs) txs := cs.mempool.Reap(cs.state.ConsensusParams.BlockSize.MaxTxs)
block, parts := cs.state.MakeBlock(cs.Height, txs, commit) block, parts := cs.state.MakeBlock(cs.Height, txs, commit)
evidence := cs.evpool.PendingEvidence() evidence := cs.evpool.PendingEvidence()
block.AddEvidence(evidence) block.AddEvidence(evidence)
@ -1399,17 +1392,22 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
// NOTE: block is not necessarily valid. // NOTE: block is not necessarily valid.
// Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, once we have the full block. // Asynchronously triggers either enterPrevote (before we timeout of propose) or tryFinalizeCommit, once we have the full block.
func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part) (added bool, err error) { func (cs *ConsensusState) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (added bool, err error) {
height, round, part := msg.Height, msg.Round, msg.Part
// Blocks might be reused, so round mismatch is OK // Blocks might be reused, so round mismatch is OK
if cs.Height != height { if cs.Height != height {
cs.Logger.Debug("Received block part from wrong height", "height", height) cs.Logger.Debug("Received block part from wrong height", "height", height, "round", round)
return false, nil return false, nil
} }
// We're not expecting a block part. // We're not expecting a block part.
if cs.ProposalBlockParts == nil { if cs.ProposalBlockParts == nil {
cs.Logger.Info("Received a block part when we're not expecting any", "height", height) // NOTE: this can happen when we've gone to a higher round and
return false, nil // TODO: bad peer? Return error? // then receive parts from the previous round - not necessarily a bad peer.
cs.Logger.Info("Received a block part when we're not expecting any",
"height", height, "round", round, "index", part.Index, "peer", peerID)
return false, nil
} }
added, err = cs.ProposalBlockParts.AddPart(part) added, err = cs.ProposalBlockParts.AddPart(part)
@ -1443,7 +1441,7 @@ func (cs *ConsensusState) addProposalBlockPart(height int64, part *types.Part) (
// procedure at this point. // procedure at this point.
} }
if cs.Step == cstypes.RoundStepPropose && cs.isProposalComplete() { if cs.Step <= cstypes.RoundStepPropose && cs.isProposalComplete() {
// Move onto the next step // Move onto the next step
cs.enterPrevote(height, cs.Round) cs.enterPrevote(height, cs.Round)
} else if cs.Step == cstypes.RoundStepCommit { } else if cs.Step == cstypes.RoundStepCommit {

View File

@ -10,8 +10,8 @@ import (
cstypes "github.com/tendermint/tendermint/consensus/types" cstypes "github.com/tendermint/tendermint/consensus/types"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub" tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
func init() { func init() {

View File

@ -3,8 +3,8 @@ package consensus
import ( import (
"time" "time"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
var ( var (

View File

@ -8,7 +8,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
type RoundVoteSet struct { type RoundVoteSet struct {

View File

@ -6,7 +6,7 @@ import (
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
var config *cfg.Config // NOTE: must be reset for each _test.go file var config *cfg.Config // NOTE: must be reset for each _test.go file

View File

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -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"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
) )
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{},

View File

@ -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)
} }

View File

@ -1,7 +1,7 @@
package consensus package consensus
import ( import (
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
// kind of arbitrary // kind of arbitrary

View File

@ -12,8 +12,8 @@ import (
amino "github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
auto "github.com/tendermint/tmlibs/autofile" auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
) )
const ( const (

View File

@ -17,10 +17,10 @@ import (
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
auto "github.com/tendermint/tmlibs/autofile" auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tmlibs/db" "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/libs/log"
) )
// WALWithNBlocks generates a consensus WAL. It does this by spining up a // WALWithNBlocks generates a consensus WAL. It does this by spining up a

View File

@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/consensus/types"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View File

@ -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)
} }

137
crypto/Gopkg.lock generated
View File

@ -1,137 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "86fed781132ac890ee03e906e4ecd5d6fa180c64"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcutil"
packages = ["base58"]
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
name = "github.com/go-kit/kit"
packages = [
"log",
"log/level",
"log/term"
]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0"
[[projects]]
name = "github.com/go-logfmt/logfmt"
packages = ["."]
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5"
version = "v0.3.0"
[[projects]]
name = "github.com/go-stack/stack"
packages = ["."]
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
version = "v1.7.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"gogoproto",
"proto",
"protoc-gen-gogo/descriptor"
]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/kr/logfmt"
packages = ["."]
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
name = "github.com/stretchr/testify"
packages = [
"assert",
"require"
]
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
branch = "master"
name = "github.com/tendermint/ed25519"
packages = [
".",
"edwards25519",
"extra25519"
]
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
[[projects]]
name = "github.com/tendermint/go-amino"
packages = ["."]
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
version = "0.10.1"
[[projects]]
name = "github.com/tendermint/tmlibs"
packages = [
"common",
"log",
"test"
]
revision = "692f1d86a6e2c0efa698fd1e4541b68c74ffaf38"
version = "v0.8.4"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"bcrypt",
"blowfish",
"chacha20poly1305",
"hkdf",
"internal/chacha20",
"internal/subtle",
"nacl/secretbox",
"openpgp/armor",
"openpgp/errors",
"poly1305",
"ripemd160",
"salsa20/salsa"
]
revision = "7f39a6fea4fe9364fb61e1def6a268a51b4f3a06"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["cpu"]
revision = "ad87a3a340fa7f3bed189293fbfa7a9b7e021ae1"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "027b22b86396a971d5d5c1d298947f531f39743975d65a22e98601140aa1b1a1"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,49 +0,0 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "github.com/btcsuite/btcutil"
branch = "master"
[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.1"
[[constraint]]
name = "github.com/tendermint/ed25519"
branch = "master"
[[constraint]]
name = "github.com/tendermint/go-amino"
version = "0.10.0-rc2"
[[constraint]]
name = "github.com/tendermint/tmlibs"
version = "0.8.1"
[prune]
go-tests = true
unused-packages = true

View File

@ -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"}

View File

@ -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)
}

View File

@ -1,4 +1,4 @@
package crypto package armor
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package crypto package armor
import ( import (
"testing" "testing"

36
crypto/crypto.go Normal file
View 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)
}

View File

@ -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
View 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
}

View 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))
}

View 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
}

Some files were not shown because too many files have changed in this diff Show More