You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1191 lines
41 KiB

deps: update gogo/protobuf version from v1.2.1 to v1.3.0 (#3947) * update gogo/protobuf version from v1.2.1 to v1.3.0 Also errcheck from v1.1.0 to v1.2.0 See full diff in - https://github.com/gogo/protobuf/compare/v1.2.1...v1.3.0 - https://github.com/kisielk/errcheck/compare/v1.1.0...v1.2.0 Changelog: Tested versions: go 1.12.9 protoc 3.7.1 Improvements: plugin/stringer - Handle repeated and/or nullable types a bit better now. plugin/size - Remove the loop in sovXXX by using bit twiddling. Thanks: https://github.com/apelisse plugin/marshalto - Implemented a reverse marshal strategy which allows for faster marshalling. This now avoids a recursive (and repeated) call to Size(). Thanks: https://github.com/apelisse plugin/compare - Added support for for oneof types. Bug fixes: protoc-gen-gogo/generator - Fix assignment to entry in nil map. Thanks: https://github.com/tgulacsi protoc-gen-gogo/generator - Allows plugins to call RecordTypeUse without panicking. Thanks: https://github.com/fedenusy proto/extensions - Fixed set extension regression. We did not clear the extensions before setting. io/uint32 - fix uint32reader bug that causes ReadMsg to recreate buffer when lengths are the same. Thanks: https://github.com/SebiSujar proto/table_merge: Fix merge of non-nullable slices. Thanks: https://github.com/euroelessar Upstream commits: merged in golang/protobuf commit 318d17de72747ed1c16502681db4b2bb709a92d0 - Add UnimplementedServer for server interface merged in golang/protobuf commit b85cd75de734650db18a99a943fe351d41387800 - protoc-gen-go/grpc: inline errUnimplemented function merged in golang/protobuf commit d3c38a4eb4970272b87a425ae00ccc4548e2f9bb - protoc-gen-go/grpc: use status and code packages only if needed merged in golang/protobuf commit e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 - fix indentation in jsonpb with Any messages merged in golang/protobuf commit 8d0c54c1246661d9a51ca0ba455d22116d485eaa - protoc-gen-go: generate XXX_OneofWrappers instead of XXX_OneofFuncs Misc: extensions.md - Markdown update. Thanks: https://github.com/TennyZhuang Readme.md - Added user. go/protoc update - Updated to go1.12.x and protoc 3.7.1 Makefile update - fix go vet shadow tool reference test/mixbench - Update mixbench tool. Expose runnable benchmarks via flags. * update certstrap * update golangci-lint from v1.13.2 to v1.17.1 * update gox as well * test * comment out golangci temporary * comment out go-deadlock deps
5 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
6 years ago
  1. package config
  2. import (
  3. "encoding/hex"
  4. "errors"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. "os"
  9. "path/filepath"
  10. "time"
  11. tmjson "github.com/tendermint/tendermint/libs/json"
  12. "github.com/tendermint/tendermint/libs/log"
  13. tmos "github.com/tendermint/tendermint/libs/os"
  14. "github.com/tendermint/tendermint/types"
  15. )
  16. const (
  17. // FuzzModeDrop is a mode in which we randomly drop reads/writes, connections or sleep
  18. FuzzModeDrop = iota
  19. // FuzzModeDelay is a mode in which we randomly sleep
  20. FuzzModeDelay
  21. // DefaultLogLevel defines a default log level as INFO.
  22. DefaultLogLevel = "info"
  23. ModeFull = "full"
  24. ModeValidator = "validator"
  25. ModeSeed = "seed"
  26. MempoolV0 = "v0"
  27. MempoolV1 = "v1"
  28. )
  29. // NOTE: Most of the structs & relevant comments + the
  30. // default configuration options were used to manually
  31. // generate the config.toml. Please reflect any changes
  32. // made here in the defaultConfigTemplate constant in
  33. // config/toml.go
  34. // NOTE: libs/cli must know to look in the config dir!
  35. var (
  36. DefaultTendermintDir = ".tendermint"
  37. defaultConfigDir = "config"
  38. defaultDataDir = "data"
  39. defaultConfigFileName = "config.toml"
  40. defaultGenesisJSONName = "genesis.json"
  41. defaultMode = ModeFull
  42. defaultPrivValKeyName = "priv_validator_key.json"
  43. defaultPrivValStateName = "priv_validator_state.json"
  44. defaultNodeKeyName = "node_key.json"
  45. defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName)
  46. defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName)
  47. defaultPrivValKeyPath = filepath.Join(defaultConfigDir, defaultPrivValKeyName)
  48. defaultPrivValStatePath = filepath.Join(defaultDataDir, defaultPrivValStateName)
  49. defaultNodeKeyPath = filepath.Join(defaultConfigDir, defaultNodeKeyName)
  50. )
  51. // Config defines the top level configuration for a Tendermint node
  52. type Config struct {
  53. // Top level options use an anonymous struct
  54. BaseConfig `mapstructure:",squash"`
  55. // Options for services
  56. RPC *RPCConfig `mapstructure:"rpc"`
  57. P2P *P2PConfig `mapstructure:"p2p"`
  58. Mempool *MempoolConfig `mapstructure:"mempool"`
  59. StateSync *StateSyncConfig `mapstructure:"statesync"`
  60. Consensus *ConsensusConfig `mapstructure:"consensus"`
  61. TxIndex *TxIndexConfig `mapstructure:"tx-index"`
  62. Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
  63. PrivValidator *PrivValidatorConfig `mapstructure:"priv-validator"`
  64. }
  65. // DefaultConfig returns a default configuration for a Tendermint node
  66. func DefaultConfig() *Config {
  67. return &Config{
  68. BaseConfig: DefaultBaseConfig(),
  69. RPC: DefaultRPCConfig(),
  70. P2P: DefaultP2PConfig(),
  71. Mempool: DefaultMempoolConfig(),
  72. StateSync: DefaultStateSyncConfig(),
  73. Consensus: DefaultConsensusConfig(),
  74. TxIndex: DefaultTxIndexConfig(),
  75. Instrumentation: DefaultInstrumentationConfig(),
  76. PrivValidator: DefaultPrivValidatorConfig(),
  77. }
  78. }
  79. // DefaultValidatorConfig returns default config with mode as validator
  80. func DefaultValidatorConfig() *Config {
  81. cfg := DefaultConfig()
  82. cfg.Mode = ModeValidator
  83. return cfg
  84. }
  85. // TestConfig returns a configuration that can be used for testing
  86. func TestConfig() *Config {
  87. return &Config{
  88. BaseConfig: TestBaseConfig(),
  89. RPC: TestRPCConfig(),
  90. P2P: TestP2PConfig(),
  91. Mempool: TestMempoolConfig(),
  92. StateSync: TestStateSyncConfig(),
  93. Consensus: TestConsensusConfig(),
  94. TxIndex: TestTxIndexConfig(),
  95. Instrumentation: TestInstrumentationConfig(),
  96. PrivValidator: DefaultPrivValidatorConfig(),
  97. }
  98. }
  99. // SetRoot sets the RootDir for all Config structs
  100. func (cfg *Config) SetRoot(root string) *Config {
  101. cfg.BaseConfig.RootDir = root
  102. cfg.RPC.RootDir = root
  103. cfg.P2P.RootDir = root
  104. cfg.Mempool.RootDir = root
  105. cfg.Consensus.RootDir = root
  106. cfg.PrivValidator.RootDir = root
  107. return cfg
  108. }
  109. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  110. // returns an error if any check fails.
  111. func (cfg *Config) ValidateBasic() error {
  112. if err := cfg.BaseConfig.ValidateBasic(); err != nil {
  113. return err
  114. }
  115. if err := cfg.RPC.ValidateBasic(); err != nil {
  116. return fmt.Errorf("error in [rpc] section: %w", err)
  117. }
  118. if err := cfg.Mempool.ValidateBasic(); err != nil {
  119. return fmt.Errorf("error in [mempool] section: %w", err)
  120. }
  121. if err := cfg.StateSync.ValidateBasic(); err != nil {
  122. return fmt.Errorf("error in [statesync] section: %w", err)
  123. }
  124. if err := cfg.Consensus.ValidateBasic(); err != nil {
  125. return fmt.Errorf("error in [consensus] section: %w", err)
  126. }
  127. if err := cfg.Instrumentation.ValidateBasic(); err != nil {
  128. return fmt.Errorf("error in [instrumentation] section: %w", err)
  129. }
  130. return nil
  131. }
  132. //-----------------------------------------------------------------------------
  133. // BaseConfig
  134. // BaseConfig defines the base configuration for a Tendermint node
  135. type BaseConfig struct { //nolint: maligned
  136. // chainID is unexposed and immutable but here for convenience
  137. chainID string
  138. // The root directory for all data.
  139. // This should be set in viper so it can unmarshal into this struct
  140. RootDir string `mapstructure:"home"`
  141. // TCP or UNIX socket address of the ABCI application,
  142. // or the name of an ABCI application compiled in with the Tendermint binary
  143. ProxyApp string `mapstructure:"proxy-app"`
  144. // A custom human readable name for this node
  145. Moniker string `mapstructure:"moniker"`
  146. // Mode of Node: full | validator | seed
  147. // * validator
  148. // - all reactors
  149. // - with priv_validator_key.json, priv_validator_state.json
  150. // * full
  151. // - all reactors
  152. // - No priv_validator_key.json, priv_validator_state.json
  153. // * seed
  154. // - only P2P, PEX Reactor
  155. // - No priv_validator_key.json, priv_validator_state.json
  156. Mode string `mapstructure:"mode"`
  157. // Database backend: goleveldb | cleveldb | boltdb | rocksdb
  158. // * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
  159. // - pure go
  160. // - stable
  161. // * cleveldb (uses levigo wrapper)
  162. // - fast
  163. // - requires gcc
  164. // - use cleveldb build tag (go build -tags cleveldb)
  165. // * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
  166. // - EXPERIMENTAL
  167. // - may be faster is some use-cases (random reads - indexer)
  168. // - use boltdb build tag (go build -tags boltdb)
  169. // * rocksdb (uses github.com/tecbot/gorocksdb)
  170. // - EXPERIMENTAL
  171. // - requires gcc
  172. // - use rocksdb build tag (go build -tags rocksdb)
  173. // * badgerdb (uses github.com/dgraph-io/badger)
  174. // - EXPERIMENTAL
  175. // - use badgerdb build tag (go build -tags badgerdb)
  176. DBBackend string `mapstructure:"db-backend"`
  177. // Database directory
  178. DBPath string `mapstructure:"db-dir"`
  179. // Output level for logging
  180. LogLevel string `mapstructure:"log-level"`
  181. // Output format: 'plain' (colored text) or 'json'
  182. LogFormat string `mapstructure:"log-format"`
  183. // Path to the JSON file containing the initial validator set and other meta data
  184. Genesis string `mapstructure:"genesis-file"`
  185. // A JSON file containing the private key to use for p2p authenticated encryption
  186. NodeKey string `mapstructure:"node-key-file"`
  187. // Mechanism to connect to the ABCI application: socket | grpc
  188. ABCI string `mapstructure:"abci"`
  189. // If true, query the ABCI app on connecting to a new peer
  190. // so the app can decide if we should keep the connection or not
  191. FilterPeers bool `mapstructure:"filter-peers"` // false
  192. Other map[string]interface{} `mapstructure:",remain"`
  193. }
  194. // DefaultBaseConfig returns a default base configuration for a Tendermint node
  195. func DefaultBaseConfig() BaseConfig {
  196. return BaseConfig{
  197. Genesis: defaultGenesisJSONPath,
  198. NodeKey: defaultNodeKeyPath,
  199. Mode: defaultMode,
  200. Moniker: defaultMoniker,
  201. ProxyApp: "tcp://127.0.0.1:26658",
  202. ABCI: "socket",
  203. LogLevel: DefaultLogLevel,
  204. LogFormat: log.LogFormatPlain,
  205. FilterPeers: false,
  206. DBBackend: "goleveldb",
  207. DBPath: "data",
  208. }
  209. }
  210. // TestBaseConfig returns a base configuration for testing a Tendermint node
  211. func TestBaseConfig() BaseConfig {
  212. cfg := DefaultBaseConfig()
  213. cfg.chainID = "tendermint_test"
  214. cfg.Mode = ModeValidator
  215. cfg.ProxyApp = "kvstore"
  216. cfg.DBBackend = "memdb"
  217. return cfg
  218. }
  219. func (cfg BaseConfig) ChainID() string {
  220. return cfg.chainID
  221. }
  222. // GenesisFile returns the full path to the genesis.json file
  223. func (cfg BaseConfig) GenesisFile() string {
  224. return rootify(cfg.Genesis, cfg.RootDir)
  225. }
  226. // NodeKeyFile returns the full path to the node_key.json file
  227. func (cfg BaseConfig) NodeKeyFile() string {
  228. return rootify(cfg.NodeKey, cfg.RootDir)
  229. }
  230. // LoadNodeKey loads NodeKey located in filePath.
  231. func (cfg BaseConfig) LoadNodeKeyID() (types.NodeID, error) {
  232. jsonBytes, err := ioutil.ReadFile(cfg.NodeKeyFile())
  233. if err != nil {
  234. return "", err
  235. }
  236. nodeKey := types.NodeKey{}
  237. err = tmjson.Unmarshal(jsonBytes, &nodeKey)
  238. if err != nil {
  239. return "", err
  240. }
  241. nodeKey.ID = types.NodeIDFromPubKey(nodeKey.PubKey())
  242. return nodeKey.ID, nil
  243. }
  244. // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If
  245. // the file does not exist, it generates and saves a new NodeKey.
  246. func (cfg BaseConfig) LoadOrGenNodeKeyID() (types.NodeID, error) {
  247. if tmos.FileExists(cfg.NodeKeyFile()) {
  248. nodeKey, err := cfg.LoadNodeKeyID()
  249. if err != nil {
  250. return "", err
  251. }
  252. return nodeKey, nil
  253. }
  254. nodeKey := types.GenNodeKey()
  255. if err := nodeKey.SaveAs(cfg.NodeKeyFile()); err != nil {
  256. return "", err
  257. }
  258. return nodeKey.ID, nil
  259. }
  260. // DBDir returns the full path to the database directory
  261. func (cfg BaseConfig) DBDir() string {
  262. return rootify(cfg.DBPath, cfg.RootDir)
  263. }
  264. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  265. // returns an error if any check fails.
  266. func (cfg BaseConfig) ValidateBasic() error {
  267. switch cfg.LogFormat {
  268. case log.LogFormatJSON, log.LogFormatText, log.LogFormatPlain:
  269. default:
  270. return errors.New("unknown log format (must be 'plain', 'text' or 'json')")
  271. }
  272. switch cfg.Mode {
  273. case ModeFull, ModeValidator, ModeSeed:
  274. case "":
  275. return errors.New("no mode has been set")
  276. default:
  277. return fmt.Errorf("unknown mode: %v", cfg.Mode)
  278. }
  279. return nil
  280. }
  281. //-----------------------------------------------------------------------------
  282. // PrivValidatorConfig
  283. // PrivValidatorConfig defines the configuration parameters for running a validator
  284. type PrivValidatorConfig struct {
  285. RootDir string `mapstructure:"home"`
  286. // Path to the JSON file containing the private key to use as a validator in the consensus protocol
  287. Key string `mapstructure:"key-file"`
  288. // Path to the JSON file containing the last sign state of a validator
  289. State string `mapstructure:"state-file"`
  290. // TCP or UNIX socket address for Tendermint to listen on for
  291. // connections from an external PrivValidator process
  292. ListenAddr string `mapstructure:"laddr"`
  293. // Client certificate generated while creating needed files for secure connection.
  294. // If a remote validator address is provided but no certificate, the connection will be insecure
  295. ClientCertificate string `mapstructure:"client-certificate-file"`
  296. // Client key generated while creating certificates for secure connection
  297. ClientKey string `mapstructure:"client-key-file"`
  298. // Path Root Certificate Authority used to sign both client and server certificates
  299. RootCA string `mapstructure:"root-ca-file"`
  300. }
  301. // DefaultBaseConfig returns a default private validator configuration
  302. // for a Tendermint node.
  303. func DefaultPrivValidatorConfig() *PrivValidatorConfig {
  304. return &PrivValidatorConfig{
  305. Key: defaultPrivValKeyPath,
  306. State: defaultPrivValStatePath,
  307. }
  308. }
  309. // ClientKeyFile returns the full path to the priv_validator_key.json file
  310. func (cfg *PrivValidatorConfig) ClientKeyFile() string {
  311. return rootify(cfg.ClientKey, cfg.RootDir)
  312. }
  313. // ClientCertificateFile returns the full path to the priv_validator_key.json file
  314. func (cfg *PrivValidatorConfig) ClientCertificateFile() string {
  315. return rootify(cfg.ClientCertificate, cfg.RootDir)
  316. }
  317. // CertificateAuthorityFile returns the full path to the priv_validator_key.json file
  318. func (cfg *PrivValidatorConfig) RootCAFile() string {
  319. return rootify(cfg.RootCA, cfg.RootDir)
  320. }
  321. // KeyFile returns the full path to the priv_validator_key.json file
  322. func (cfg *PrivValidatorConfig) KeyFile() string {
  323. return rootify(cfg.Key, cfg.RootDir)
  324. }
  325. // StateFile returns the full path to the priv_validator_state.json file
  326. func (cfg *PrivValidatorConfig) StateFile() string {
  327. return rootify(cfg.State, cfg.RootDir)
  328. }
  329. func (cfg *PrivValidatorConfig) AreSecurityOptionsPresent() bool {
  330. switch {
  331. case cfg.RootCA == "":
  332. return false
  333. case cfg.ClientKey == "":
  334. return false
  335. case cfg.ClientCertificate == "":
  336. return false
  337. default:
  338. return true
  339. }
  340. }
  341. //-----------------------------------------------------------------------------
  342. // RPCConfig
  343. // RPCConfig defines the configuration options for the Tendermint RPC server
  344. type RPCConfig struct {
  345. RootDir string `mapstructure:"home"`
  346. // TCP or UNIX socket address for the RPC server to listen on
  347. ListenAddress string `mapstructure:"laddr"`
  348. // A list of origins a cross-domain request can be executed from.
  349. // If the special '*' value is present in the list, all origins will be allowed.
  350. // An origin may contain a wildcard (*) to replace 0 or more characters (i.e.: http://*.domain.com).
  351. // Only one wildcard can be used per origin.
  352. CORSAllowedOrigins []string `mapstructure:"cors-allowed-origins"`
  353. // A list of methods the client is allowed to use with cross-domain requests.
  354. CORSAllowedMethods []string `mapstructure:"cors-allowed-methods"`
  355. // A list of non simple headers the client is allowed to use with cross-domain requests.
  356. CORSAllowedHeaders []string `mapstructure:"cors-allowed-headers"`
  357. // Activate unsafe RPC commands like /dial-persistent-peers and /unsafe-flush-mempool
  358. Unsafe bool `mapstructure:"unsafe"`
  359. // Maximum number of simultaneous connections (including WebSocket).
  360. // If you want to accept a larger number than the default, make sure
  361. // you increase your OS limits.
  362. // 0 - unlimited.
  363. // Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  364. // 1024 - 40 - 10 - 50 = 924 = ~900
  365. MaxOpenConnections int `mapstructure:"max-open-connections"`
  366. // Maximum number of unique clientIDs that can /subscribe
  367. // If you're using /broadcast_tx_commit, set to the estimated maximum number
  368. // of broadcast_tx_commit calls per block.
  369. MaxSubscriptionClients int `mapstructure:"max-subscription-clients"`
  370. // Maximum number of unique queries a given client can /subscribe to
  371. // If you're using a Local RPC client and /broadcast_tx_commit, set this
  372. // to the estimated maximum number of broadcast_tx_commit calls per block.
  373. MaxSubscriptionsPerClient int `mapstructure:"max-subscriptions-per-client"`
  374. // How long to wait for a tx to be committed during /broadcast_tx_commit
  375. // WARNING: Using a value larger than 10s will result in increasing the
  376. // global HTTP write timeout, which applies to all connections and endpoints.
  377. // See https://github.com/tendermint/tendermint/issues/3435
  378. TimeoutBroadcastTxCommit time.Duration `mapstructure:"timeout-broadcast-tx-commit"`
  379. // Maximum size of request body, in bytes
  380. MaxBodyBytes int64 `mapstructure:"max-body-bytes"`
  381. // Maximum size of request header, in bytes
  382. MaxHeaderBytes int `mapstructure:"max-header-bytes"`
  383. // The path to a file containing certificate that is used to create the HTTPS server.
  384. // Might be either absolute path or path related to Tendermint's config directory.
  385. //
  386. // If the certificate is signed by a certificate authority,
  387. // the certFile should be the concatenation of the server's certificate, any intermediates,
  388. // and the CA's certificate.
  389. //
  390. // NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  391. // Otherwise, HTTP server is run.
  392. TLSCertFile string `mapstructure:"tls-cert-file"`
  393. // The path to a file containing matching private key that is used to create the HTTPS server.
  394. // Might be either absolute path or path related to tendermint's config directory.
  395. //
  396. // NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  397. // Otherwise, HTTP server is run.
  398. TLSKeyFile string `mapstructure:"tls-key-file"`
  399. // pprof listen address (https://golang.org/pkg/net/http/pprof)
  400. PprofListenAddress string `mapstructure:"pprof-laddr"`
  401. }
  402. // DefaultRPCConfig returns a default configuration for the RPC server
  403. func DefaultRPCConfig() *RPCConfig {
  404. return &RPCConfig{
  405. ListenAddress: "tcp://127.0.0.1:26657",
  406. CORSAllowedOrigins: []string{},
  407. CORSAllowedMethods: []string{http.MethodHead, http.MethodGet, http.MethodPost},
  408. CORSAllowedHeaders: []string{"Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"},
  409. Unsafe: false,
  410. MaxOpenConnections: 900,
  411. MaxSubscriptionClients: 100,
  412. MaxSubscriptionsPerClient: 5,
  413. TimeoutBroadcastTxCommit: 10 * time.Second,
  414. MaxBodyBytes: int64(1000000), // 1MB
  415. MaxHeaderBytes: 1 << 20, // same as the net/http default
  416. TLSCertFile: "",
  417. TLSKeyFile: "",
  418. }
  419. }
  420. // TestRPCConfig returns a configuration for testing the RPC server
  421. func TestRPCConfig() *RPCConfig {
  422. cfg := DefaultRPCConfig()
  423. cfg.ListenAddress = "tcp://127.0.0.1:36657"
  424. cfg.Unsafe = true
  425. return cfg
  426. }
  427. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  428. // returns an error if any check fails.
  429. func (cfg *RPCConfig) ValidateBasic() error {
  430. if cfg.MaxOpenConnections < 0 {
  431. return errors.New("max-open-connections can't be negative")
  432. }
  433. if cfg.MaxSubscriptionClients < 0 {
  434. return errors.New("max-subscription-clients can't be negative")
  435. }
  436. if cfg.MaxSubscriptionsPerClient < 0 {
  437. return errors.New("max-subscriptions-per-client can't be negative")
  438. }
  439. if cfg.TimeoutBroadcastTxCommit < 0 {
  440. return errors.New("timeout-broadcast-tx-commit can't be negative")
  441. }
  442. if cfg.MaxBodyBytes < 0 {
  443. return errors.New("max-body-bytes can't be negative")
  444. }
  445. if cfg.MaxHeaderBytes < 0 {
  446. return errors.New("max-header-bytes can't be negative")
  447. }
  448. return nil
  449. }
  450. // IsCorsEnabled returns true if cross-origin resource sharing is enabled.
  451. func (cfg *RPCConfig) IsCorsEnabled() bool {
  452. return len(cfg.CORSAllowedOrigins) != 0
  453. }
  454. func (cfg RPCConfig) KeyFile() string {
  455. path := cfg.TLSKeyFile
  456. if filepath.IsAbs(path) {
  457. return path
  458. }
  459. return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
  460. }
  461. func (cfg RPCConfig) CertFile() string {
  462. path := cfg.TLSCertFile
  463. if filepath.IsAbs(path) {
  464. return path
  465. }
  466. return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
  467. }
  468. func (cfg RPCConfig) IsTLSEnabled() bool {
  469. return cfg.TLSCertFile != "" && cfg.TLSKeyFile != ""
  470. }
  471. //-----------------------------------------------------------------------------
  472. // P2PConfig
  473. // P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer
  474. type P2PConfig struct { //nolint: maligned
  475. RootDir string `mapstructure:"home"`
  476. // Address to listen for incoming connections
  477. ListenAddress string `mapstructure:"laddr"`
  478. // Address to advertise to peers for them to dial
  479. ExternalAddress string `mapstructure:"external-address"`
  480. // Comma separated list of seed nodes to connect to
  481. // We only use these if we can’t connect to peers in the addrbook
  482. // NOTE: not used by the new PEX reactor. Please use BootstrapPeers instead.
  483. // TODO: Remove once p2p refactor is complete
  484. // ref: https://github.com/tendermint/tendermint/issues/5670
  485. Seeds string `mapstructure:"seeds"`
  486. // Comma separated list of peers to be added to the peer store
  487. // on startup. Either BootstrapPeers or PersistentPeers are
  488. // needed for peer discovery
  489. BootstrapPeers string `mapstructure:"bootstrap-peers"`
  490. // Comma separated list of nodes to keep persistent connections to
  491. PersistentPeers string `mapstructure:"persistent-peers"`
  492. // UPNP port forwarding
  493. UPNP bool `mapstructure:"upnp"`
  494. // MaxConnections defines the maximum number of connected peers (inbound and
  495. // outbound).
  496. MaxConnections uint16 `mapstructure:"max-connections"`
  497. // MaxIncomingConnectionAttempts rate limits the number of incoming connection
  498. // attempts per IP address.
  499. MaxIncomingConnectionAttempts uint `mapstructure:"max-incoming-connection-attempts"`
  500. // Set true to enable the peer-exchange reactor
  501. PexReactor bool `mapstructure:"pex"`
  502. // Comma separated list of peer IDs to keep private (will not be gossiped to
  503. // other peers)
  504. PrivatePeerIDs string `mapstructure:"private-peer-ids"`
  505. // Toggle to disable guard against peers connecting from the same ip.
  506. AllowDuplicateIP bool `mapstructure:"allow-duplicate-ip"`
  507. // Time to wait before flushing messages out on the connection
  508. FlushThrottleTimeout time.Duration `mapstructure:"flush-throttle-timeout"`
  509. // Maximum size of a message packet payload, in bytes
  510. MaxPacketMsgPayloadSize int `mapstructure:"max-packet-msg-payload-size"`
  511. // Rate at which packets can be sent, in bytes/second
  512. SendRate int64 `mapstructure:"send-rate"`
  513. // Rate at which packets can be received, in bytes/second
  514. RecvRate int64 `mapstructure:"recv-rate"`
  515. // Peer connection configuration.
  516. HandshakeTimeout time.Duration `mapstructure:"handshake-timeout"`
  517. DialTimeout time.Duration `mapstructure:"dial-timeout"`
  518. // Testing params.
  519. // Force dial to fail
  520. TestDialFail bool `mapstructure:"test-dial-fail"`
  521. // Makes it possible to configure which queue backend the p2p
  522. // layer uses. Options are: "fifo" and "priority",
  523. // with the default being "priority".
  524. QueueType string `mapstructure:"queue-type"`
  525. }
  526. // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
  527. func DefaultP2PConfig() *P2PConfig {
  528. return &P2PConfig{
  529. ListenAddress: "tcp://0.0.0.0:26656",
  530. ExternalAddress: "",
  531. UPNP: false,
  532. MaxConnections: 64,
  533. MaxIncomingConnectionAttempts: 100,
  534. FlushThrottleTimeout: 100 * time.Millisecond,
  535. // The MTU (Maximum Transmission Unit) for Ethernet is 1500 bytes.
  536. // The IP header and the TCP header take up 20 bytes each at least (unless
  537. // optional header fields are used) and thus the max for (non-Jumbo frame)
  538. // Ethernet is 1500 - 20 -20 = 1460
  539. // Source: https://stackoverflow.com/a/3074427/820520
  540. MaxPacketMsgPayloadSize: 1400,
  541. SendRate: 5120000, // 5 mB/s
  542. RecvRate: 5120000, // 5 mB/s
  543. PexReactor: true,
  544. AllowDuplicateIP: false,
  545. HandshakeTimeout: 20 * time.Second,
  546. DialTimeout: 3 * time.Second,
  547. TestDialFail: false,
  548. QueueType: "priority",
  549. }
  550. }
  551. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  552. // returns an error if any check fails.
  553. func (cfg *P2PConfig) ValidateBasic() error {
  554. if cfg.FlushThrottleTimeout < 0 {
  555. return errors.New("flush-throttle-timeout can't be negative")
  556. }
  557. if cfg.MaxPacketMsgPayloadSize < 0 {
  558. return errors.New("max-packet-msg-payload-size can't be negative")
  559. }
  560. if cfg.SendRate < 0 {
  561. return errors.New("send-rate can't be negative")
  562. }
  563. if cfg.RecvRate < 0 {
  564. return errors.New("recv-rate can't be negative")
  565. }
  566. return nil
  567. }
  568. // TestP2PConfig returns a configuration for testing the peer-to-peer layer
  569. func TestP2PConfig() *P2PConfig {
  570. cfg := DefaultP2PConfig()
  571. cfg.ListenAddress = "tcp://127.0.0.1:36656"
  572. cfg.AllowDuplicateIP = true
  573. cfg.FlushThrottleTimeout = 10 * time.Millisecond
  574. return cfg
  575. }
  576. //-----------------------------------------------------------------------------
  577. // MempoolConfig
  578. // MempoolConfig defines the configuration options for the Tendermint mempool.
  579. type MempoolConfig struct {
  580. Version string `mapstructure:"version"`
  581. RootDir string `mapstructure:"home"`
  582. Recheck bool `mapstructure:"recheck"`
  583. Broadcast bool `mapstructure:"broadcast"`
  584. // Maximum number of transactions in the mempool
  585. Size int `mapstructure:"size"`
  586. // Limit the total size of all txs in the mempool.
  587. // This only accounts for raw transactions (e.g. given 1MB transactions and
  588. // max-txs-bytes=5MB, mempool will only accept 5 transactions).
  589. MaxTxsBytes int64 `mapstructure:"max-txs-bytes"`
  590. // Size of the cache (used to filter transactions we saw earlier) in transactions
  591. CacheSize int `mapstructure:"cache-size"`
  592. // Do not remove invalid transactions from the cache (default: false)
  593. // Set to true if it's not possible for any invalid transaction to become
  594. // valid again in the future.
  595. KeepInvalidTxsInCache bool `mapstructure:"keep-invalid-txs-in-cache"`
  596. // Maximum size of a single transaction
  597. // NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
  598. MaxTxBytes int `mapstructure:"max-tx-bytes"`
  599. // Maximum size of a batch of transactions to send to a peer
  600. // Including space needed by encoding (one varint per transaction).
  601. // XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
  602. MaxBatchBytes int `mapstructure:"max-batch-bytes"`
  603. // TTLDuration, if non-zero, defines the maximum amount of time a transaction
  604. // can exist for in the mempool.
  605. //
  606. // Note, if TTLNumBlocks is also defined, a transaction will be removed if it
  607. // has existed in the mempool at least TTLNumBlocks number of blocks or if it's
  608. // insertion time into the mempool is beyond TTLDuration.
  609. TTLDuration time.Duration `mapstructure:"ttl-duration"`
  610. // TTLNumBlocks, if non-zero, defines the maximum number of blocks a transaction
  611. // can exist for in the mempool.
  612. //
  613. // Note, if TTLDuration is also defined, a transaction will be removed if it
  614. // has existed in the mempool at least TTLNumBlocks number of blocks or if
  615. // it's insertion time into the mempool is beyond TTLDuration.
  616. TTLNumBlocks int64 `mapstructure:"ttl-num-blocks"`
  617. }
  618. // DefaultMempoolConfig returns a default configuration for the Tendermint mempool.
  619. func DefaultMempoolConfig() *MempoolConfig {
  620. return &MempoolConfig{
  621. Version: MempoolV1,
  622. Recheck: true,
  623. Broadcast: true,
  624. // Each signature verification takes .5ms, Size reduced until we implement
  625. // ABCI Recheck
  626. Size: 5000,
  627. MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
  628. CacheSize: 10000,
  629. MaxTxBytes: 1024 * 1024, // 1MB
  630. TTLDuration: 0 * time.Second,
  631. TTLNumBlocks: 0,
  632. }
  633. }
  634. // TestMempoolConfig returns a configuration for testing the Tendermint mempool
  635. func TestMempoolConfig() *MempoolConfig {
  636. cfg := DefaultMempoolConfig()
  637. cfg.CacheSize = 1000
  638. return cfg
  639. }
  640. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  641. // returns an error if any check fails.
  642. func (cfg *MempoolConfig) ValidateBasic() error {
  643. if cfg.Size < 0 {
  644. return errors.New("size can't be negative")
  645. }
  646. if cfg.MaxTxsBytes < 0 {
  647. return errors.New("max-txs-bytes can't be negative")
  648. }
  649. if cfg.CacheSize < 0 {
  650. return errors.New("cache-size can't be negative")
  651. }
  652. if cfg.MaxTxBytes < 0 {
  653. return errors.New("max-tx-bytes can't be negative")
  654. }
  655. if cfg.TTLDuration < 0 {
  656. return errors.New("ttl-duration can't be negative")
  657. }
  658. if cfg.TTLNumBlocks < 0 {
  659. return errors.New("ttl-num-blocks can't be negative")
  660. }
  661. return nil
  662. }
  663. //-----------------------------------------------------------------------------
  664. // StateSyncConfig
  665. // StateSyncConfig defines the configuration for the Tendermint state sync service
  666. type StateSyncConfig struct {
  667. // State sync rapidly bootstraps a new node by discovering, fetching, and restoring a
  668. // state machine snapshot from peers instead of fetching and replaying historical
  669. // blocks. Requires some peers in the network to take and serve state machine
  670. // snapshots. State sync is not attempted if the node has any local state
  671. // (LastBlockHeight > 0). The node will have a truncated block history, starting from
  672. // the height of the snapshot.
  673. Enable bool `mapstructure:"enable"`
  674. // State sync uses light client verification to verify state. This can be done either
  675. // through the P2P layer or the RPC layer. Set this to true to use the P2P layer. If
  676. // false (default), the RPC layer will be used.
  677. UseP2P bool `mapstructure:"use-p2p"`
  678. // If using RPC, at least two addresses need to be provided. They should be compatible
  679. // with net.Dial, for example: "host.example.com:2125".
  680. RPCServers []string `mapstructure:"rpc-servers"`
  681. // The hash and height of a trusted block. Must be within the trust-period.
  682. TrustHeight int64 `mapstructure:"trust-height"`
  683. TrustHash string `mapstructure:"trust-hash"`
  684. // The trust period should be set so that Tendermint can detect and gossip
  685. // misbehavior before it is considered expired. For chains based on the Cosmos SDK,
  686. // one day less than the unbonding period should suffice.
  687. TrustPeriod time.Duration `mapstructure:"trust-period"`
  688. // Time to spend discovering snapshots before initiating a restore.
  689. DiscoveryTime time.Duration `mapstructure:"discovery-time"`
  690. // Temporary directory for state sync snapshot chunks, defaults to os.TempDir().
  691. // The synchronizer will create a new, randomly named directory within this directory
  692. // and remove it when the sync is complete.
  693. TempDir string `mapstructure:"temp-dir"`
  694. // The timeout duration before re-requesting a chunk, possibly from a different
  695. // peer (default: 15 seconds).
  696. ChunkRequestTimeout time.Duration `mapstructure:"chunk-request-timeout"`
  697. // The number of concurrent chunk and block fetchers to run (default: 4).
  698. Fetchers int32 `mapstructure:"fetchers"`
  699. }
  700. func (cfg *StateSyncConfig) TrustHashBytes() []byte {
  701. // validated in ValidateBasic, so we can safely panic here
  702. bytes, err := hex.DecodeString(cfg.TrustHash)
  703. if err != nil {
  704. panic(err)
  705. }
  706. return bytes
  707. }
  708. // DefaultStateSyncConfig returns a default configuration for the state sync service
  709. func DefaultStateSyncConfig() *StateSyncConfig {
  710. return &StateSyncConfig{
  711. TrustPeriod: 168 * time.Hour,
  712. DiscoveryTime: 15 * time.Second,
  713. ChunkRequestTimeout: 15 * time.Second,
  714. Fetchers: 4,
  715. }
  716. }
  717. // TestStateSyncConfig returns a default configuration for the state sync service
  718. func TestStateSyncConfig() *StateSyncConfig {
  719. return DefaultStateSyncConfig()
  720. }
  721. // ValidateBasic performs basic validation.
  722. func (cfg *StateSyncConfig) ValidateBasic() error {
  723. if !cfg.Enable {
  724. return nil
  725. }
  726. // If we're not using the P2P stack then we need to validate the
  727. // RPCServers
  728. if !cfg.UseP2P {
  729. if len(cfg.RPCServers) < 2 {
  730. return errors.New("at least two rpc-servers must be specified")
  731. }
  732. for _, server := range cfg.RPCServers {
  733. if server == "" {
  734. return errors.New("found empty rpc-servers entry")
  735. }
  736. }
  737. }
  738. if cfg.DiscoveryTime != 0 && cfg.DiscoveryTime < 5*time.Second {
  739. return errors.New("discovery time must be 0s or greater than five seconds")
  740. }
  741. if cfg.TrustPeriod <= 0 {
  742. return errors.New("trusted-period is required")
  743. }
  744. if cfg.TrustHeight <= 0 {
  745. return errors.New("trusted-height is required")
  746. }
  747. if len(cfg.TrustHash) == 0 {
  748. return errors.New("trusted-hash is required")
  749. }
  750. _, err := hex.DecodeString(cfg.TrustHash)
  751. if err != nil {
  752. return fmt.Errorf("invalid trusted-hash: %w", err)
  753. }
  754. if cfg.ChunkRequestTimeout < 5*time.Second {
  755. return errors.New("chunk-request-timeout must be at least 5 seconds")
  756. }
  757. if cfg.Fetchers <= 0 {
  758. return errors.New("fetchers is required")
  759. }
  760. return nil
  761. }
  762. //-----------------------------------------------------------------------------
  763. // ConsensusConfig
  764. // ConsensusConfig defines the configuration for the Tendermint consensus service,
  765. // including timeouts and details about the WAL and the block structure.
  766. type ConsensusConfig struct {
  767. RootDir string `mapstructure:"home"`
  768. WalPath string `mapstructure:"wal-file"`
  769. walFile string // overrides WalPath if set
  770. // TODO: remove timeout configs, these should be global not local
  771. // How long we wait for a proposal block before prevoting nil
  772. TimeoutPropose time.Duration `mapstructure:"timeout-propose"`
  773. // How much timeout-propose increases with each round
  774. TimeoutProposeDelta time.Duration `mapstructure:"timeout-propose-delta"`
  775. // How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
  776. TimeoutPrevote time.Duration `mapstructure:"timeout-prevote"`
  777. // How much the timeout-prevote increases with each round
  778. TimeoutPrevoteDelta time.Duration `mapstructure:"timeout-prevote-delta"`
  779. // How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
  780. TimeoutPrecommit time.Duration `mapstructure:"timeout-precommit"`
  781. // How much the timeout-precommit increases with each round
  782. TimeoutPrecommitDelta time.Duration `mapstructure:"timeout-precommit-delta"`
  783. // How long we wait after committing a block, before starting on the new
  784. // height (this gives us a chance to receive some more precommits, even
  785. // though we already have +2/3).
  786. TimeoutCommit time.Duration `mapstructure:"timeout-commit"`
  787. // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  788. SkipTimeoutCommit bool `mapstructure:"skip-timeout-commit"`
  789. // EmptyBlocks mode and possible interval between empty blocks
  790. CreateEmptyBlocks bool `mapstructure:"create-empty-blocks"`
  791. CreateEmptyBlocksInterval time.Duration `mapstructure:"create-empty-blocks-interval"`
  792. // Reactor sleep duration parameters
  793. PeerGossipSleepDuration time.Duration `mapstructure:"peer-gossip-sleep-duration"`
  794. PeerQueryMaj23SleepDuration time.Duration `mapstructure:"peer-query-maj23-sleep-duration"`
  795. DoubleSignCheckHeight int64 `mapstructure:"double-sign-check-height"`
  796. }
  797. // DefaultConsensusConfig returns a default configuration for the consensus service
  798. func DefaultConsensusConfig() *ConsensusConfig {
  799. return &ConsensusConfig{
  800. WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
  801. TimeoutPropose: 3000 * time.Millisecond,
  802. TimeoutProposeDelta: 500 * time.Millisecond,
  803. TimeoutPrevote: 1000 * time.Millisecond,
  804. TimeoutPrevoteDelta: 500 * time.Millisecond,
  805. TimeoutPrecommit: 1000 * time.Millisecond,
  806. TimeoutPrecommitDelta: 500 * time.Millisecond,
  807. TimeoutCommit: 1000 * time.Millisecond,
  808. SkipTimeoutCommit: false,
  809. CreateEmptyBlocks: true,
  810. CreateEmptyBlocksInterval: 0 * time.Second,
  811. PeerGossipSleepDuration: 100 * time.Millisecond,
  812. PeerQueryMaj23SleepDuration: 2000 * time.Millisecond,
  813. DoubleSignCheckHeight: int64(0),
  814. }
  815. }
  816. // TestConsensusConfig returns a configuration for testing the consensus service
  817. func TestConsensusConfig() *ConsensusConfig {
  818. cfg := DefaultConsensusConfig()
  819. cfg.TimeoutPropose = 40 * time.Millisecond
  820. cfg.TimeoutProposeDelta = 1 * time.Millisecond
  821. cfg.TimeoutPrevote = 10 * time.Millisecond
  822. cfg.TimeoutPrevoteDelta = 1 * time.Millisecond
  823. cfg.TimeoutPrecommit = 10 * time.Millisecond
  824. cfg.TimeoutPrecommitDelta = 1 * time.Millisecond
  825. cfg.TimeoutCommit = 10 * time.Millisecond
  826. cfg.SkipTimeoutCommit = true
  827. cfg.PeerGossipSleepDuration = 5 * time.Millisecond
  828. cfg.PeerQueryMaj23SleepDuration = 250 * time.Millisecond
  829. cfg.DoubleSignCheckHeight = int64(0)
  830. return cfg
  831. }
  832. // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step
  833. func (cfg *ConsensusConfig) WaitForTxs() bool {
  834. return !cfg.CreateEmptyBlocks || cfg.CreateEmptyBlocksInterval > 0
  835. }
  836. // Propose returns the amount of time to wait for a proposal
  837. func (cfg *ConsensusConfig) Propose(round int32) time.Duration {
  838. return time.Duration(
  839. cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round),
  840. ) * time.Nanosecond
  841. }
  842. // Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
  843. func (cfg *ConsensusConfig) Prevote(round int32) time.Duration {
  844. return time.Duration(
  845. cfg.TimeoutPrevote.Nanoseconds()+cfg.TimeoutPrevoteDelta.Nanoseconds()*int64(round),
  846. ) * time.Nanosecond
  847. }
  848. // Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
  849. func (cfg *ConsensusConfig) Precommit(round int32) time.Duration {
  850. return time.Duration(
  851. cfg.TimeoutPrecommit.Nanoseconds()+cfg.TimeoutPrecommitDelta.Nanoseconds()*int64(round),
  852. ) * time.Nanosecond
  853. }
  854. // Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits
  855. // for a single block (ie. a commit).
  856. func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
  857. return t.Add(cfg.TimeoutCommit)
  858. }
  859. // WalFile returns the full path to the write-ahead log file
  860. func (cfg *ConsensusConfig) WalFile() string {
  861. if cfg.walFile != "" {
  862. return cfg.walFile
  863. }
  864. return rootify(cfg.WalPath, cfg.RootDir)
  865. }
  866. // SetWalFile sets the path to the write-ahead log file
  867. func (cfg *ConsensusConfig) SetWalFile(walFile string) {
  868. cfg.walFile = walFile
  869. }
  870. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  871. // returns an error if any check fails.
  872. func (cfg *ConsensusConfig) ValidateBasic() error {
  873. if cfg.TimeoutPropose < 0 {
  874. return errors.New("timeout-propose can't be negative")
  875. }
  876. if cfg.TimeoutProposeDelta < 0 {
  877. return errors.New("timeout-propose-delta can't be negative")
  878. }
  879. if cfg.TimeoutPrevote < 0 {
  880. return errors.New("timeout-prevote can't be negative")
  881. }
  882. if cfg.TimeoutPrevoteDelta < 0 {
  883. return errors.New("timeout-prevote-delta can't be negative")
  884. }
  885. if cfg.TimeoutPrecommit < 0 {
  886. return errors.New("timeout-precommit can't be negative")
  887. }
  888. if cfg.TimeoutPrecommitDelta < 0 {
  889. return errors.New("timeout-precommit-delta can't be negative")
  890. }
  891. if cfg.TimeoutCommit < 0 {
  892. return errors.New("timeout-commit can't be negative")
  893. }
  894. if cfg.CreateEmptyBlocksInterval < 0 {
  895. return errors.New("create-empty-blocks-interval can't be negative")
  896. }
  897. if cfg.PeerGossipSleepDuration < 0 {
  898. return errors.New("peer-gossip-sleep-duration can't be negative")
  899. }
  900. if cfg.PeerQueryMaj23SleepDuration < 0 {
  901. return errors.New("peer-query-maj23-sleep-duration can't be negative")
  902. }
  903. if cfg.DoubleSignCheckHeight < 0 {
  904. return errors.New("double-sign-check-height can't be negative")
  905. }
  906. return nil
  907. }
  908. //-----------------------------------------------------------------------------
  909. // TxIndexConfig
  910. // Remember that Event has the following structure:
  911. // type: [
  912. // key: value,
  913. // ...
  914. // ]
  915. //
  916. // CompositeKeys are constructed by `type.key`
  917. // TxIndexConfig defines the configuration for the transaction indexer,
  918. // including composite keys to index.
  919. type TxIndexConfig struct {
  920. // The backend database list to back the indexer.
  921. // If list contains `null`, meaning no indexer service will be used.
  922. //
  923. // Options:
  924. // 1) "null" - no indexer services.
  925. // 2) "kv" (default) - the simplest possible indexer,
  926. // backed by key-value storage (defaults to levelDB; see DBBackend).
  927. // 3) "psql" - the indexer services backed by PostgreSQL.
  928. Indexer []string `mapstructure:"indexer"`
  929. // The PostgreSQL connection configuration, the connection format:
  930. // postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
  931. PsqlConn string `mapstructure:"psql-conn"`
  932. }
  933. // DefaultTxIndexConfig returns a default configuration for the transaction indexer.
  934. func DefaultTxIndexConfig() *TxIndexConfig {
  935. return &TxIndexConfig{
  936. Indexer: []string{"kv"},
  937. }
  938. }
  939. // TestTxIndexConfig returns a default configuration for the transaction indexer.
  940. func TestTxIndexConfig() *TxIndexConfig {
  941. return DefaultTxIndexConfig()
  942. }
  943. //-----------------------------------------------------------------------------
  944. // InstrumentationConfig
  945. // InstrumentationConfig defines the configuration for metrics reporting.
  946. type InstrumentationConfig struct {
  947. // When true, Prometheus metrics are served under /metrics on
  948. // PrometheusListenAddr.
  949. // Check out the documentation for the list of available metrics.
  950. Prometheus bool `mapstructure:"prometheus"`
  951. // Address to listen for Prometheus collector(s) connections.
  952. PrometheusListenAddr string `mapstructure:"prometheus-listen-addr"`
  953. // Maximum number of simultaneous connections.
  954. // If you want to accept a larger number than the default, make sure
  955. // you increase your OS limits.
  956. // 0 - unlimited.
  957. MaxOpenConnections int `mapstructure:"max-open-connections"`
  958. // Instrumentation namespace.
  959. Namespace string `mapstructure:"namespace"`
  960. }
  961. // DefaultInstrumentationConfig returns a default configuration for metrics
  962. // reporting.
  963. func DefaultInstrumentationConfig() *InstrumentationConfig {
  964. return &InstrumentationConfig{
  965. Prometheus: false,
  966. PrometheusListenAddr: ":26660",
  967. MaxOpenConnections: 3,
  968. Namespace: "tendermint",
  969. }
  970. }
  971. // TestInstrumentationConfig returns a default configuration for metrics
  972. // reporting.
  973. func TestInstrumentationConfig() *InstrumentationConfig {
  974. return DefaultInstrumentationConfig()
  975. }
  976. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  977. // returns an error if any check fails.
  978. func (cfg *InstrumentationConfig) ValidateBasic() error {
  979. if cfg.MaxOpenConnections < 0 {
  980. return errors.New("max-open-connections can't be negative")
  981. }
  982. return nil
  983. }
  984. //-----------------------------------------------------------------------------
  985. // Utils
  986. // helper function to make config creation independent of root dir
  987. func rootify(path, root string) string {
  988. if filepath.IsAbs(path) {
  989. return path
  990. }
  991. return filepath.Join(root, path)
  992. }
  993. //-----------------------------------------------------------------------------
  994. // Moniker
  995. var defaultMoniker = getDefaultMoniker()
  996. // getDefaultMoniker returns a default moniker, which is the host name. If runtime
  997. // fails to get the host name, "anonymous" will be returned.
  998. func getDefaultMoniker() string {
  999. moniker, err := os.Hostname()
  1000. if err != nil {
  1001. moniker = "anonymous"
  1002. }
  1003. return moniker
  1004. }