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.

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