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.

1185 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>
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>
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>
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>
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>
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>
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>
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>
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>
5 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. // NOTE: not used by the new PEX reactor. Please use BootstrapPeers instead.
  480. // TODO: Remove once p2p refactor is complete
  481. // ref: https://github.com/tendermint/tendermint/issues/5670
  482. Seeds string `mapstructure:"seeds"`
  483. // Comma separated list of peers to be added to the peer store
  484. // on startup. Either BootstrapPeers or PersistentPeers are
  485. // needed for peer discovery
  486. BootstrapPeers string `mapstructure:"bootstrap-peers"`
  487. // Comma separated list of nodes to keep persistent connections to
  488. PersistentPeers string `mapstructure:"persistent-peers"`
  489. // UPNP port forwarding
  490. UPNP bool `mapstructure:"upnp"`
  491. // MaxConnections defines the maximum number of connected peers (inbound and
  492. // outbound).
  493. MaxConnections uint16 `mapstructure:"max-connections"`
  494. // MaxIncomingConnectionAttempts rate limits the number of incoming connection
  495. // attempts per IP address.
  496. MaxIncomingConnectionAttempts uint `mapstructure:"max-incoming-connection-attempts"`
  497. // Set true to enable the peer-exchange reactor
  498. PexReactor bool `mapstructure:"pex"`
  499. // Comma separated list of peer IDs to keep private (will not be gossiped to
  500. // other peers)
  501. PrivatePeerIDs string `mapstructure:"private-peer-ids"`
  502. // Toggle to disable guard against peers connecting from the same ip.
  503. AllowDuplicateIP bool `mapstructure:"allow-duplicate-ip"`
  504. // Time to wait before flushing messages out on the connection
  505. FlushThrottleTimeout time.Duration `mapstructure:"flush-throttle-timeout"`
  506. // Maximum size of a message packet payload, in bytes
  507. MaxPacketMsgPayloadSize int `mapstructure:"max-packet-msg-payload-size"`
  508. // Rate at which packets can be sent, in bytes/second
  509. SendRate int64 `mapstructure:"send-rate"`
  510. // Rate at which packets can be received, in bytes/second
  511. RecvRate int64 `mapstructure:"recv-rate"`
  512. // Peer connection configuration.
  513. HandshakeTimeout time.Duration `mapstructure:"handshake-timeout"`
  514. DialTimeout time.Duration `mapstructure:"dial-timeout"`
  515. // Testing params.
  516. // Force dial to fail
  517. TestDialFail bool `mapstructure:"test-dial-fail"`
  518. // Makes it possible to configure which queue backend the p2p
  519. // layer uses. Options are: "fifo" and "priority",
  520. // with the default being "priority".
  521. QueueType string `mapstructure:"queue-type"`
  522. }
  523. // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
  524. func DefaultP2PConfig() *P2PConfig {
  525. return &P2PConfig{
  526. ListenAddress: "tcp://0.0.0.0:26656",
  527. ExternalAddress: "",
  528. UPNP: false,
  529. MaxConnections: 64,
  530. MaxIncomingConnectionAttempts: 100,
  531. FlushThrottleTimeout: 100 * time.Millisecond,
  532. // The MTU (Maximum Transmission Unit) for Ethernet is 1500 bytes.
  533. // The IP header and the TCP header take up 20 bytes each at least (unless
  534. // optional header fields are used) and thus the max for (non-Jumbo frame)
  535. // Ethernet is 1500 - 20 -20 = 1460
  536. // Source: https://stackoverflow.com/a/3074427/820520
  537. MaxPacketMsgPayloadSize: 1400,
  538. SendRate: 5120000, // 5 mB/s
  539. RecvRate: 5120000, // 5 mB/s
  540. PexReactor: true,
  541. AllowDuplicateIP: false,
  542. HandshakeTimeout: 20 * time.Second,
  543. DialTimeout: 3 * time.Second,
  544. TestDialFail: false,
  545. QueueType: "priority",
  546. }
  547. }
  548. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  549. // returns an error if any check fails.
  550. func (cfg *P2PConfig) ValidateBasic() error {
  551. if cfg.FlushThrottleTimeout < 0 {
  552. return errors.New("flush-throttle-timeout can't be negative")
  553. }
  554. if cfg.MaxPacketMsgPayloadSize < 0 {
  555. return errors.New("max-packet-msg-payload-size can't be negative")
  556. }
  557. if cfg.SendRate < 0 {
  558. return errors.New("send-rate can't be negative")
  559. }
  560. if cfg.RecvRate < 0 {
  561. return errors.New("recv-rate can't be negative")
  562. }
  563. return nil
  564. }
  565. // TestP2PConfig returns a configuration for testing the peer-to-peer layer
  566. func TestP2PConfig() *P2PConfig {
  567. cfg := DefaultP2PConfig()
  568. cfg.ListenAddress = "tcp://127.0.0.1:36656"
  569. cfg.AllowDuplicateIP = true
  570. cfg.FlushThrottleTimeout = 10 * time.Millisecond
  571. return cfg
  572. }
  573. //-----------------------------------------------------------------------------
  574. // MempoolConfig
  575. // MempoolConfig defines the configuration options for the Tendermint mempool.
  576. type MempoolConfig struct {
  577. RootDir string `mapstructure:"home"`
  578. Recheck bool `mapstructure:"recheck"`
  579. Broadcast bool `mapstructure:"broadcast"`
  580. // Maximum number of transactions in the mempool
  581. Size int `mapstructure:"size"`
  582. // Limit the total size of all txs in the mempool.
  583. // This only accounts for raw transactions (e.g. given 1MB transactions and
  584. // max-txs-bytes=5MB, mempool will only accept 5 transactions).
  585. MaxTxsBytes int64 `mapstructure:"max-txs-bytes"`
  586. // Size of the cache (used to filter transactions we saw earlier) in transactions
  587. CacheSize int `mapstructure:"cache-size"`
  588. // Do not remove invalid transactions from the cache (default: false)
  589. // Set to true if it's not possible for any invalid transaction to become
  590. // valid again in the future.
  591. KeepInvalidTxsInCache bool `mapstructure:"keep-invalid-txs-in-cache"`
  592. // Maximum size of a single transaction
  593. // NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
  594. MaxTxBytes int `mapstructure:"max-tx-bytes"`
  595. // Maximum size of a batch of transactions to send to a peer
  596. // Including space needed by encoding (one varint per transaction).
  597. // XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
  598. MaxBatchBytes int `mapstructure:"max-batch-bytes"`
  599. // TTLDuration, if non-zero, defines the maximum amount of time a transaction
  600. // can exist for in the mempool.
  601. //
  602. // Note, if TTLNumBlocks is also defined, a transaction will be removed if it
  603. // has existed in the mempool at least TTLNumBlocks number of blocks or if it's
  604. // insertion time into the mempool is beyond TTLDuration.
  605. TTLDuration time.Duration `mapstructure:"ttl-duration"`
  606. // TTLNumBlocks, if non-zero, defines the maximum number of blocks a transaction
  607. // can exist for in the mempool.
  608. //
  609. // Note, if TTLDuration is also defined, a transaction will be removed if it
  610. // has existed in the mempool at least TTLNumBlocks number of blocks or if
  611. // it's insertion time into the mempool is beyond TTLDuration.
  612. TTLNumBlocks int64 `mapstructure:"ttl-num-blocks"`
  613. }
  614. // DefaultMempoolConfig returns a default configuration for the Tendermint mempool.
  615. func DefaultMempoolConfig() *MempoolConfig {
  616. return &MempoolConfig{
  617. Recheck: true,
  618. Broadcast: true,
  619. // Each signature verification takes .5ms, Size reduced until we implement
  620. // ABCI Recheck
  621. Size: 5000,
  622. MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
  623. CacheSize: 10000,
  624. MaxTxBytes: 1024 * 1024, // 1MB
  625. TTLDuration: 0 * time.Second,
  626. TTLNumBlocks: 0,
  627. }
  628. }
  629. // TestMempoolConfig returns a configuration for testing the Tendermint mempool
  630. func TestMempoolConfig() *MempoolConfig {
  631. cfg := DefaultMempoolConfig()
  632. cfg.CacheSize = 1000
  633. return cfg
  634. }
  635. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  636. // returns an error if any check fails.
  637. func (cfg *MempoolConfig) ValidateBasic() error {
  638. if cfg.Size < 0 {
  639. return errors.New("size can't be negative")
  640. }
  641. if cfg.MaxTxsBytes < 0 {
  642. return errors.New("max-txs-bytes can't be negative")
  643. }
  644. if cfg.CacheSize < 0 {
  645. return errors.New("cache-size can't be negative")
  646. }
  647. if cfg.MaxTxBytes < 0 {
  648. return errors.New("max-tx-bytes can't be negative")
  649. }
  650. if cfg.TTLDuration < 0 {
  651. return errors.New("ttl-duration can't be negative")
  652. }
  653. if cfg.TTLNumBlocks < 0 {
  654. return errors.New("ttl-num-blocks can't be negative")
  655. }
  656. return nil
  657. }
  658. //-----------------------------------------------------------------------------
  659. // StateSyncConfig
  660. // StateSyncConfig defines the configuration for the Tendermint state sync service
  661. type StateSyncConfig struct {
  662. // State sync rapidly bootstraps a new node by discovering, fetching, and restoring a
  663. // state machine snapshot from peers instead of fetching and replaying historical
  664. // blocks. Requires some peers in the network to take and serve state machine
  665. // snapshots. State sync is not attempted if the node has any local state
  666. // (LastBlockHeight > 0). The node will have a truncated block history, starting from
  667. // the height of the snapshot.
  668. Enable bool `mapstructure:"enable"`
  669. // State sync uses light client verification to verify state. This can be done either
  670. // through the P2P layer or the RPC layer. Set this to true to use the P2P layer. If
  671. // false (default), the RPC layer will be used.
  672. UseP2P bool `mapstructure:"use-p2p"`
  673. // If using RPC, at least two addresses need to be provided. They should be compatible
  674. // with net.Dial, for example: "host.example.com:2125".
  675. RPCServers []string `mapstructure:"rpc-servers"`
  676. // The hash and height of a trusted block. Must be within the trust-period.
  677. TrustHeight int64 `mapstructure:"trust-height"`
  678. TrustHash string `mapstructure:"trust-hash"`
  679. // The trust period should be set so that Tendermint can detect and gossip
  680. // misbehavior before it is considered expired. For chains based on the Cosmos SDK,
  681. // one day less than the unbonding period should suffice.
  682. TrustPeriod time.Duration `mapstructure:"trust-period"`
  683. // Time to spend discovering snapshots before initiating a restore.
  684. DiscoveryTime time.Duration `mapstructure:"discovery-time"`
  685. // Temporary directory for state sync snapshot chunks, defaults to os.TempDir().
  686. // The synchronizer will create a new, randomly named directory within this directory
  687. // and remove it when the sync is complete.
  688. TempDir string `mapstructure:"temp-dir"`
  689. // The timeout duration before re-requesting a chunk, possibly from a different
  690. // peer (default: 15 seconds).
  691. ChunkRequestTimeout time.Duration `mapstructure:"chunk-request-timeout"`
  692. // The number of concurrent chunk and block fetchers to run (default: 4).
  693. Fetchers int32 `mapstructure:"fetchers"`
  694. }
  695. func (cfg *StateSyncConfig) TrustHashBytes() []byte {
  696. // validated in ValidateBasic, so we can safely panic here
  697. bytes, err := hex.DecodeString(cfg.TrustHash)
  698. if err != nil {
  699. panic(err)
  700. }
  701. return bytes
  702. }
  703. // DefaultStateSyncConfig returns a default configuration for the state sync service
  704. func DefaultStateSyncConfig() *StateSyncConfig {
  705. return &StateSyncConfig{
  706. TrustPeriod: 168 * time.Hour,
  707. DiscoveryTime: 15 * time.Second,
  708. ChunkRequestTimeout: 15 * time.Second,
  709. Fetchers: 4,
  710. }
  711. }
  712. // TestStateSyncConfig returns a default configuration for the state sync service
  713. func TestStateSyncConfig() *StateSyncConfig {
  714. return DefaultStateSyncConfig()
  715. }
  716. // ValidateBasic performs basic validation.
  717. func (cfg *StateSyncConfig) ValidateBasic() error {
  718. if !cfg.Enable {
  719. return nil
  720. }
  721. // If we're not using the P2P stack then we need to validate the
  722. // RPCServers
  723. if !cfg.UseP2P {
  724. if len(cfg.RPCServers) < 2 {
  725. return errors.New("at least two rpc-servers must be specified")
  726. }
  727. for _, server := range cfg.RPCServers {
  728. if server == "" {
  729. return errors.New("found empty rpc-servers entry")
  730. }
  731. }
  732. }
  733. if cfg.DiscoveryTime != 0 && cfg.DiscoveryTime < 5*time.Second {
  734. return errors.New("discovery time must be 0s or greater than five seconds")
  735. }
  736. if cfg.TrustPeriod <= 0 {
  737. return errors.New("trusted-period is required")
  738. }
  739. if cfg.TrustHeight <= 0 {
  740. return errors.New("trusted-height is required")
  741. }
  742. if len(cfg.TrustHash) == 0 {
  743. return errors.New("trusted-hash is required")
  744. }
  745. _, err := hex.DecodeString(cfg.TrustHash)
  746. if err != nil {
  747. return fmt.Errorf("invalid trusted-hash: %w", err)
  748. }
  749. if cfg.ChunkRequestTimeout < 5*time.Second {
  750. return errors.New("chunk-request-timeout must be at least 5 seconds")
  751. }
  752. if cfg.Fetchers <= 0 {
  753. return errors.New("fetchers is required")
  754. }
  755. return nil
  756. }
  757. //-----------------------------------------------------------------------------
  758. // ConsensusConfig
  759. // ConsensusConfig defines the configuration for the Tendermint consensus service,
  760. // including timeouts and details about the WAL and the block structure.
  761. type ConsensusConfig struct {
  762. RootDir string `mapstructure:"home"`
  763. WalPath string `mapstructure:"wal-file"`
  764. walFile string // overrides WalPath if set
  765. // TODO: remove timeout configs, these should be global not local
  766. // How long we wait for a proposal block before prevoting nil
  767. TimeoutPropose time.Duration `mapstructure:"timeout-propose"`
  768. // How much timeout-propose increases with each round
  769. TimeoutProposeDelta time.Duration `mapstructure:"timeout-propose-delta"`
  770. // How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
  771. TimeoutPrevote time.Duration `mapstructure:"timeout-prevote"`
  772. // How much the timeout-prevote increases with each round
  773. TimeoutPrevoteDelta time.Duration `mapstructure:"timeout-prevote-delta"`
  774. // How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
  775. TimeoutPrecommit time.Duration `mapstructure:"timeout-precommit"`
  776. // How much the timeout-precommit increases with each round
  777. TimeoutPrecommitDelta time.Duration `mapstructure:"timeout-precommit-delta"`
  778. // How long we wait after committing a block, before starting on the new
  779. // height (this gives us a chance to receive some more precommits, even
  780. // though we already have +2/3).
  781. TimeoutCommit time.Duration `mapstructure:"timeout-commit"`
  782. // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  783. SkipTimeoutCommit bool `mapstructure:"skip-timeout-commit"`
  784. // EmptyBlocks mode and possible interval between empty blocks
  785. CreateEmptyBlocks bool `mapstructure:"create-empty-blocks"`
  786. CreateEmptyBlocksInterval time.Duration `mapstructure:"create-empty-blocks-interval"`
  787. // Reactor sleep duration parameters
  788. PeerGossipSleepDuration time.Duration `mapstructure:"peer-gossip-sleep-duration"`
  789. PeerQueryMaj23SleepDuration time.Duration `mapstructure:"peer-query-maj23-sleep-duration"`
  790. DoubleSignCheckHeight int64 `mapstructure:"double-sign-check-height"`
  791. }
  792. // DefaultConsensusConfig returns a default configuration for the consensus service
  793. func DefaultConsensusConfig() *ConsensusConfig {
  794. return &ConsensusConfig{
  795. WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
  796. TimeoutPropose: 3000 * time.Millisecond,
  797. TimeoutProposeDelta: 500 * time.Millisecond,
  798. TimeoutPrevote: 1000 * time.Millisecond,
  799. TimeoutPrevoteDelta: 500 * time.Millisecond,
  800. TimeoutPrecommit: 1000 * time.Millisecond,
  801. TimeoutPrecommitDelta: 500 * time.Millisecond,
  802. TimeoutCommit: 1000 * time.Millisecond,
  803. SkipTimeoutCommit: false,
  804. CreateEmptyBlocks: true,
  805. CreateEmptyBlocksInterval: 0 * time.Second,
  806. PeerGossipSleepDuration: 100 * time.Millisecond,
  807. PeerQueryMaj23SleepDuration: 2000 * time.Millisecond,
  808. DoubleSignCheckHeight: int64(0),
  809. }
  810. }
  811. // TestConsensusConfig returns a configuration for testing the consensus service
  812. func TestConsensusConfig() *ConsensusConfig {
  813. cfg := DefaultConsensusConfig()
  814. cfg.TimeoutPropose = 40 * time.Millisecond
  815. cfg.TimeoutProposeDelta = 1 * time.Millisecond
  816. cfg.TimeoutPrevote = 10 * time.Millisecond
  817. cfg.TimeoutPrevoteDelta = 1 * time.Millisecond
  818. cfg.TimeoutPrecommit = 10 * time.Millisecond
  819. cfg.TimeoutPrecommitDelta = 1 * time.Millisecond
  820. cfg.TimeoutCommit = 10 * time.Millisecond
  821. cfg.SkipTimeoutCommit = true
  822. cfg.PeerGossipSleepDuration = 5 * time.Millisecond
  823. cfg.PeerQueryMaj23SleepDuration = 250 * time.Millisecond
  824. cfg.DoubleSignCheckHeight = int64(0)
  825. return cfg
  826. }
  827. // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step
  828. func (cfg *ConsensusConfig) WaitForTxs() bool {
  829. return !cfg.CreateEmptyBlocks || cfg.CreateEmptyBlocksInterval > 0
  830. }
  831. // Propose returns the amount of time to wait for a proposal
  832. func (cfg *ConsensusConfig) Propose(round int32) time.Duration {
  833. return time.Duration(
  834. cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round),
  835. ) * time.Nanosecond
  836. }
  837. // Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
  838. func (cfg *ConsensusConfig) Prevote(round int32) time.Duration {
  839. return time.Duration(
  840. cfg.TimeoutPrevote.Nanoseconds()+cfg.TimeoutPrevoteDelta.Nanoseconds()*int64(round),
  841. ) * time.Nanosecond
  842. }
  843. // Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
  844. func (cfg *ConsensusConfig) Precommit(round int32) time.Duration {
  845. return time.Duration(
  846. cfg.TimeoutPrecommit.Nanoseconds()+cfg.TimeoutPrecommitDelta.Nanoseconds()*int64(round),
  847. ) * time.Nanosecond
  848. }
  849. // Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits
  850. // for a single block (ie. a commit).
  851. func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
  852. return t.Add(cfg.TimeoutCommit)
  853. }
  854. // WalFile returns the full path to the write-ahead log file
  855. func (cfg *ConsensusConfig) WalFile() string {
  856. if cfg.walFile != "" {
  857. return cfg.walFile
  858. }
  859. return rootify(cfg.WalPath, cfg.RootDir)
  860. }
  861. // SetWalFile sets the path to the write-ahead log file
  862. func (cfg *ConsensusConfig) SetWalFile(walFile string) {
  863. cfg.walFile = walFile
  864. }
  865. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  866. // returns an error if any check fails.
  867. func (cfg *ConsensusConfig) ValidateBasic() error {
  868. if cfg.TimeoutPropose < 0 {
  869. return errors.New("timeout-propose can't be negative")
  870. }
  871. if cfg.TimeoutProposeDelta < 0 {
  872. return errors.New("timeout-propose-delta can't be negative")
  873. }
  874. if cfg.TimeoutPrevote < 0 {
  875. return errors.New("timeout-prevote can't be negative")
  876. }
  877. if cfg.TimeoutPrevoteDelta < 0 {
  878. return errors.New("timeout-prevote-delta can't be negative")
  879. }
  880. if cfg.TimeoutPrecommit < 0 {
  881. return errors.New("timeout-precommit can't be negative")
  882. }
  883. if cfg.TimeoutPrecommitDelta < 0 {
  884. return errors.New("timeout-precommit-delta can't be negative")
  885. }
  886. if cfg.TimeoutCommit < 0 {
  887. return errors.New("timeout-commit can't be negative")
  888. }
  889. if cfg.CreateEmptyBlocksInterval < 0 {
  890. return errors.New("create-empty-blocks-interval can't be negative")
  891. }
  892. if cfg.PeerGossipSleepDuration < 0 {
  893. return errors.New("peer-gossip-sleep-duration can't be negative")
  894. }
  895. if cfg.PeerQueryMaj23SleepDuration < 0 {
  896. return errors.New("peer-query-maj23-sleep-duration can't be negative")
  897. }
  898. if cfg.DoubleSignCheckHeight < 0 {
  899. return errors.New("double-sign-check-height can't be negative")
  900. }
  901. return nil
  902. }
  903. //-----------------------------------------------------------------------------
  904. // TxIndexConfig
  905. // Remember that Event has the following structure:
  906. // type: [
  907. // key: value,
  908. // ...
  909. // ]
  910. //
  911. // CompositeKeys are constructed by `type.key`
  912. // TxIndexConfig defines the configuration for the transaction indexer,
  913. // including composite keys to index.
  914. type TxIndexConfig struct {
  915. // The backend database list to back the indexer.
  916. // If list contains `null`, meaning no indexer service will be used.
  917. //
  918. // Options:
  919. // 1) "null" - no indexer services.
  920. // 2) "kv" (default) - the simplest possible indexer,
  921. // backed by key-value storage (defaults to levelDB; see DBBackend).
  922. // 3) "psql" - the indexer services backed by PostgreSQL.
  923. Indexer []string `mapstructure:"indexer"`
  924. // The PostgreSQL connection configuration, the connection format:
  925. // postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
  926. PsqlConn string `mapstructure:"psql-conn"`
  927. }
  928. // DefaultTxIndexConfig returns a default configuration for the transaction indexer.
  929. func DefaultTxIndexConfig() *TxIndexConfig {
  930. return &TxIndexConfig{
  931. Indexer: []string{"kv"},
  932. }
  933. }
  934. // TestTxIndexConfig returns a default configuration for the transaction indexer.
  935. func TestTxIndexConfig() *TxIndexConfig {
  936. return DefaultTxIndexConfig()
  937. }
  938. //-----------------------------------------------------------------------------
  939. // InstrumentationConfig
  940. // InstrumentationConfig defines the configuration for metrics reporting.
  941. type InstrumentationConfig struct {
  942. // When true, Prometheus metrics are served under /metrics on
  943. // PrometheusListenAddr.
  944. // Check out the documentation for the list of available metrics.
  945. Prometheus bool `mapstructure:"prometheus"`
  946. // Address to listen for Prometheus collector(s) connections.
  947. PrometheusListenAddr string `mapstructure:"prometheus-listen-addr"`
  948. // Maximum number of simultaneous connections.
  949. // If you want to accept a larger number than the default, make sure
  950. // you increase your OS limits.
  951. // 0 - unlimited.
  952. MaxOpenConnections int `mapstructure:"max-open-connections"`
  953. // Instrumentation namespace.
  954. Namespace string `mapstructure:"namespace"`
  955. }
  956. // DefaultInstrumentationConfig returns a default configuration for metrics
  957. // reporting.
  958. func DefaultInstrumentationConfig() *InstrumentationConfig {
  959. return &InstrumentationConfig{
  960. Prometheus: false,
  961. PrometheusListenAddr: ":26660",
  962. MaxOpenConnections: 3,
  963. Namespace: "tendermint",
  964. }
  965. }
  966. // TestInstrumentationConfig returns a default configuration for metrics
  967. // reporting.
  968. func TestInstrumentationConfig() *InstrumentationConfig {
  969. return DefaultInstrumentationConfig()
  970. }
  971. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  972. // returns an error if any check fails.
  973. func (cfg *InstrumentationConfig) ValidateBasic() error {
  974. if cfg.MaxOpenConnections < 0 {
  975. return errors.New("max-open-connections can't be negative")
  976. }
  977. return nil
  978. }
  979. //-----------------------------------------------------------------------------
  980. // Utils
  981. // helper function to make config creation independent of root dir
  982. func rootify(path, root string) string {
  983. if filepath.IsAbs(path) {
  984. return path
  985. }
  986. return filepath.Join(root, path)
  987. }
  988. //-----------------------------------------------------------------------------
  989. // Moniker
  990. var defaultMoniker = getDefaultMoniker()
  991. // getDefaultMoniker returns a default moniker, which is the host name. If runtime
  992. // fails to get the host name, "anonymous" will be returned.
  993. func getDefaultMoniker() string {
  994. moniker, err := os.Hostname()
  995. if err != nil {
  996. moniker = "anonymous"
  997. }
  998. return moniker
  999. }