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.

1224 lines
42 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
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. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "net/http"
  8. "os"
  9. "path/filepath"
  10. "time"
  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 = json.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. // If true, disable the websocket interface to the RPC service. This has
  372. // the effect of disabling the /subscribe, /unsubscribe, and /unsubscribe_all
  373. // methods for event subscription.
  374. //
  375. // EXPERIMENTAL: This setting will be removed in Tendermint v0.37.
  376. ExperimentalDisableWebsocket bool `mapstructure:"experimental-disable-websocket"`
  377. // The time window size for the event log. All events up to this long before
  378. // the latest (up to EventLogMaxItems) will be available for subscribers to
  379. // fetch via the /events method. If 0 (the default) the event log and the
  380. // /events RPC method are disabled.
  381. EventLogWindowSize time.Duration `mapstructure:"event-log-window-size"`
  382. // The maxiumum number of events that may be retained by the event log. If
  383. // this value is 0, no upper limit is set. Otherwise, items in excess of
  384. // this number will be discarded from the event log.
  385. //
  386. // Warning: This setting is a safety valve. Setting it too low may cause
  387. // subscribers to miss events. Try to choose a value higher than the
  388. // maximum worst-case expected event load within the chosen window size in
  389. // ordinary operation.
  390. //
  391. // For example, if the window size is 10 minutes and the node typically
  392. // averages 1000 events per ten minutes, but with occasional known spikes of
  393. // up to 2000, choose a value > 2000.
  394. EventLogMaxItems int `mapstructure:"event-log-max-items"`
  395. // How long to wait for a tx to be committed during /broadcast_tx_commit
  396. // WARNING: Using a value larger than 10s will result in increasing the
  397. // global HTTP write timeout, which applies to all connections and endpoints.
  398. // See https://github.com/tendermint/tendermint/issues/3435
  399. TimeoutBroadcastTxCommit time.Duration `mapstructure:"timeout-broadcast-tx-commit"`
  400. // Maximum size of request body, in bytes
  401. MaxBodyBytes int64 `mapstructure:"max-body-bytes"`
  402. // Maximum size of request header, in bytes
  403. MaxHeaderBytes int `mapstructure:"max-header-bytes"`
  404. // The path to a file containing certificate that is used to create the HTTPS server.
  405. // Might be either absolute path or path related to Tendermint's config directory.
  406. //
  407. // If the certificate is signed by a certificate authority,
  408. // the certFile should be the concatenation of the server's certificate, any intermediates,
  409. // and the CA's certificate.
  410. //
  411. // NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  412. // Otherwise, HTTP server is run.
  413. TLSCertFile string `mapstructure:"tls-cert-file"`
  414. // The path to a file containing matching private key that is used to create the HTTPS server.
  415. // Might be either absolute path or path related to tendermint's config directory.
  416. //
  417. // NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  418. // Otherwise, HTTP server is run.
  419. TLSKeyFile string `mapstructure:"tls-key-file"`
  420. // pprof listen address (https://golang.org/pkg/net/http/pprof)
  421. PprofListenAddress string `mapstructure:"pprof-laddr"`
  422. }
  423. // DefaultRPCConfig returns a default configuration for the RPC server
  424. func DefaultRPCConfig() *RPCConfig {
  425. return &RPCConfig{
  426. ListenAddress: "tcp://127.0.0.1:26657",
  427. CORSAllowedOrigins: []string{},
  428. CORSAllowedMethods: []string{http.MethodHead, http.MethodGet, http.MethodPost},
  429. CORSAllowedHeaders: []string{"Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"},
  430. Unsafe: false,
  431. MaxOpenConnections: 900,
  432. // Settings for event subscription.
  433. MaxSubscriptionClients: 100,
  434. MaxSubscriptionsPerClient: 5,
  435. ExperimentalDisableWebsocket: false, // compatible with TM v0.35 and earlier
  436. EventLogWindowSize: 0, // disables /events RPC by default
  437. EventLogMaxItems: 0,
  438. TimeoutBroadcastTxCommit: 10 * time.Second,
  439. MaxBodyBytes: int64(1000000), // 1MB
  440. MaxHeaderBytes: 1 << 20, // same as the net/http default
  441. TLSCertFile: "",
  442. TLSKeyFile: "",
  443. }
  444. }
  445. // TestRPCConfig returns a configuration for testing the RPC server
  446. func TestRPCConfig() *RPCConfig {
  447. cfg := DefaultRPCConfig()
  448. cfg.ListenAddress = "tcp://127.0.0.1:36657"
  449. cfg.Unsafe = true
  450. return cfg
  451. }
  452. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  453. // returns an error if any check fails.
  454. func (cfg *RPCConfig) ValidateBasic() error {
  455. if cfg.MaxOpenConnections < 0 {
  456. return errors.New("max-open-connections can't be negative")
  457. }
  458. if cfg.MaxSubscriptionClients < 0 {
  459. return errors.New("max-subscription-clients can't be negative")
  460. }
  461. if cfg.MaxSubscriptionsPerClient < 0 {
  462. return errors.New("max-subscriptions-per-client can't be negative")
  463. }
  464. if cfg.EventLogWindowSize < 0 {
  465. return errors.New("event-log-window-size must not be negative")
  466. }
  467. if cfg.EventLogMaxItems < 0 {
  468. return errors.New("event-log-max-items must not be negative")
  469. }
  470. if cfg.TimeoutBroadcastTxCommit < 0 {
  471. return errors.New("timeout-broadcast-tx-commit can't be negative")
  472. }
  473. if cfg.MaxBodyBytes < 0 {
  474. return errors.New("max-body-bytes can't be negative")
  475. }
  476. if cfg.MaxHeaderBytes < 0 {
  477. return errors.New("max-header-bytes can't be negative")
  478. }
  479. return nil
  480. }
  481. // IsCorsEnabled returns true if cross-origin resource sharing is enabled.
  482. func (cfg *RPCConfig) IsCorsEnabled() bool {
  483. return len(cfg.CORSAllowedOrigins) != 0
  484. }
  485. func (cfg RPCConfig) KeyFile() string {
  486. path := cfg.TLSKeyFile
  487. if filepath.IsAbs(path) {
  488. return path
  489. }
  490. return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
  491. }
  492. func (cfg RPCConfig) CertFile() string {
  493. path := cfg.TLSCertFile
  494. if filepath.IsAbs(path) {
  495. return path
  496. }
  497. return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
  498. }
  499. func (cfg RPCConfig) IsTLSEnabled() bool {
  500. return cfg.TLSCertFile != "" && cfg.TLSKeyFile != ""
  501. }
  502. //-----------------------------------------------------------------------------
  503. // P2PConfig
  504. // P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer
  505. type P2PConfig struct { //nolint: maligned
  506. RootDir string `mapstructure:"home"`
  507. // Address to listen for incoming connections
  508. ListenAddress string `mapstructure:"laddr"`
  509. // Address to advertise to peers for them to dial
  510. ExternalAddress string `mapstructure:"external-address"`
  511. // Comma separated list of seed nodes to connect to
  512. // We only use these if we can’t connect to peers in the addrbook
  513. //
  514. // Deprecated: This value is not used by the new PEX reactor. Use
  515. // BootstrapPeers instead.
  516. //
  517. // TODO(#5670): Remove once the p2p refactor is complete.
  518. Seeds string `mapstructure:"seeds"`
  519. // Comma separated list of peers to be added to the peer store
  520. // on startup. Either BootstrapPeers or PersistentPeers are
  521. // needed for peer discovery
  522. BootstrapPeers string `mapstructure:"bootstrap-peers"`
  523. // Comma separated list of nodes to keep persistent connections to
  524. PersistentPeers string `mapstructure:"persistent-peers"`
  525. // UPNP port forwarding
  526. UPNP bool `mapstructure:"upnp"`
  527. // MaxConnections defines the maximum number of connected peers (inbound and
  528. // outbound).
  529. MaxConnections uint16 `mapstructure:"max-connections"`
  530. // MaxIncomingConnectionAttempts rate limits the number of incoming connection
  531. // attempts per IP address.
  532. MaxIncomingConnectionAttempts uint `mapstructure:"max-incoming-connection-attempts"`
  533. // Set true to enable the peer-exchange reactor
  534. PexReactor bool `mapstructure:"pex"`
  535. // Comma separated list of peer IDs to keep private (will not be gossiped to
  536. // other peers)
  537. PrivatePeerIDs string `mapstructure:"private-peer-ids"`
  538. // Toggle to disable guard against peers connecting from the same ip.
  539. AllowDuplicateIP bool `mapstructure:"allow-duplicate-ip"`
  540. // Time to wait before flushing messages out on the connection
  541. FlushThrottleTimeout time.Duration `mapstructure:"flush-throttle-timeout"`
  542. // Maximum size of a message packet payload, in bytes
  543. MaxPacketMsgPayloadSize int `mapstructure:"max-packet-msg-payload-size"`
  544. // Rate at which packets can be sent, in bytes/second
  545. SendRate int64 `mapstructure:"send-rate"`
  546. // Rate at which packets can be received, in bytes/second
  547. RecvRate int64 `mapstructure:"recv-rate"`
  548. // Peer connection configuration.
  549. HandshakeTimeout time.Duration `mapstructure:"handshake-timeout"`
  550. DialTimeout time.Duration `mapstructure:"dial-timeout"`
  551. // Testing params.
  552. // Force dial to fail
  553. TestDialFail bool `mapstructure:"test-dial-fail"`
  554. // Makes it possible to configure which queue backend the p2p
  555. // layer uses. Options are: "fifo" and "priority",
  556. // with the default being "priority".
  557. QueueType string `mapstructure:"queue-type"`
  558. }
  559. // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
  560. func DefaultP2PConfig() *P2PConfig {
  561. return &P2PConfig{
  562. ListenAddress: "tcp://0.0.0.0:26656",
  563. ExternalAddress: "",
  564. UPNP: false,
  565. MaxConnections: 64,
  566. MaxIncomingConnectionAttempts: 100,
  567. FlushThrottleTimeout: 100 * time.Millisecond,
  568. // The MTU (Maximum Transmission Unit) for Ethernet is 1500 bytes.
  569. // The IP header and the TCP header take up 20 bytes each at least (unless
  570. // optional header fields are used) and thus the max for (non-Jumbo frame)
  571. // Ethernet is 1500 - 20 -20 = 1460
  572. // Source: https://stackoverflow.com/a/3074427/820520
  573. MaxPacketMsgPayloadSize: 1400,
  574. SendRate: 5120000, // 5 mB/s
  575. RecvRate: 5120000, // 5 mB/s
  576. PexReactor: true,
  577. AllowDuplicateIP: false,
  578. HandshakeTimeout: 20 * time.Second,
  579. DialTimeout: 3 * time.Second,
  580. TestDialFail: false,
  581. QueueType: "priority",
  582. }
  583. }
  584. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  585. // returns an error if any check fails.
  586. func (cfg *P2PConfig) ValidateBasic() error {
  587. if cfg.FlushThrottleTimeout < 0 {
  588. return errors.New("flush-throttle-timeout can't be negative")
  589. }
  590. if cfg.MaxPacketMsgPayloadSize < 0 {
  591. return errors.New("max-packet-msg-payload-size can't be negative")
  592. }
  593. if cfg.SendRate < 0 {
  594. return errors.New("send-rate can't be negative")
  595. }
  596. if cfg.RecvRate < 0 {
  597. return errors.New("recv-rate can't be negative")
  598. }
  599. return nil
  600. }
  601. // TestP2PConfig returns a configuration for testing the peer-to-peer layer
  602. func TestP2PConfig() *P2PConfig {
  603. cfg := DefaultP2PConfig()
  604. cfg.ListenAddress = "tcp://127.0.0.1:36656"
  605. cfg.AllowDuplicateIP = true
  606. cfg.FlushThrottleTimeout = 10 * time.Millisecond
  607. return cfg
  608. }
  609. //-----------------------------------------------------------------------------
  610. // MempoolConfig
  611. // MempoolConfig defines the configuration options for the Tendermint mempool.
  612. type MempoolConfig struct {
  613. RootDir string `mapstructure:"home"`
  614. Recheck bool `mapstructure:"recheck"`
  615. Broadcast bool `mapstructure:"broadcast"`
  616. // Maximum number of transactions in the mempool
  617. Size int `mapstructure:"size"`
  618. // Limit the total size of all txs in the mempool.
  619. // This only accounts for raw transactions (e.g. given 1MB transactions and
  620. // max-txs-bytes=5MB, mempool will only accept 5 transactions).
  621. MaxTxsBytes int64 `mapstructure:"max-txs-bytes"`
  622. // Size of the cache (used to filter transactions we saw earlier) in transactions
  623. CacheSize int `mapstructure:"cache-size"`
  624. // Do not remove invalid transactions from the cache (default: false)
  625. // Set to true if it's not possible for any invalid transaction to become
  626. // valid again in the future.
  627. KeepInvalidTxsInCache bool `mapstructure:"keep-invalid-txs-in-cache"`
  628. // Maximum size of a single transaction
  629. // NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
  630. MaxTxBytes int `mapstructure:"max-tx-bytes"`
  631. // Maximum size of a batch of transactions to send to a peer
  632. // Including space needed by encoding (one varint per transaction).
  633. // XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
  634. MaxBatchBytes int `mapstructure:"max-batch-bytes"`
  635. // TTLDuration, if non-zero, defines the maximum amount of time a transaction
  636. // can exist for in the mempool.
  637. //
  638. // Note, if TTLNumBlocks is also defined, a transaction will be removed if it
  639. // has existed in the mempool at least TTLNumBlocks number of blocks or if it's
  640. // insertion time into the mempool is beyond TTLDuration.
  641. TTLDuration time.Duration `mapstructure:"ttl-duration"`
  642. // TTLNumBlocks, if non-zero, defines the maximum number of blocks a transaction
  643. // can exist for in the mempool.
  644. //
  645. // Note, if TTLDuration is also defined, a transaction will be removed if it
  646. // has existed in the mempool at least TTLNumBlocks number of blocks or if
  647. // it's insertion time into the mempool is beyond TTLDuration.
  648. TTLNumBlocks int64 `mapstructure:"ttl-num-blocks"`
  649. }
  650. // DefaultMempoolConfig returns a default configuration for the Tendermint mempool.
  651. func DefaultMempoolConfig() *MempoolConfig {
  652. return &MempoolConfig{
  653. Recheck: true,
  654. Broadcast: true,
  655. // Each signature verification takes .5ms, Size reduced until we implement
  656. // ABCI Recheck
  657. Size: 5000,
  658. MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
  659. CacheSize: 10000,
  660. MaxTxBytes: 1024 * 1024, // 1MB
  661. TTLDuration: 0 * time.Second,
  662. TTLNumBlocks: 0,
  663. }
  664. }
  665. // TestMempoolConfig returns a configuration for testing the Tendermint mempool
  666. func TestMempoolConfig() *MempoolConfig {
  667. cfg := DefaultMempoolConfig()
  668. cfg.CacheSize = 1000
  669. return cfg
  670. }
  671. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  672. // returns an error if any check fails.
  673. func (cfg *MempoolConfig) ValidateBasic() error {
  674. if cfg.Size < 0 {
  675. return errors.New("size can't be negative")
  676. }
  677. if cfg.MaxTxsBytes < 0 {
  678. return errors.New("max-txs-bytes can't be negative")
  679. }
  680. if cfg.CacheSize < 0 {
  681. return errors.New("cache-size can't be negative")
  682. }
  683. if cfg.MaxTxBytes < 0 {
  684. return errors.New("max-tx-bytes can't be negative")
  685. }
  686. if cfg.TTLDuration < 0 {
  687. return errors.New("ttl-duration can't be negative")
  688. }
  689. if cfg.TTLNumBlocks < 0 {
  690. return errors.New("ttl-num-blocks can't be negative")
  691. }
  692. return nil
  693. }
  694. //-----------------------------------------------------------------------------
  695. // StateSyncConfig
  696. // StateSyncConfig defines the configuration for the Tendermint state sync service
  697. type StateSyncConfig struct {
  698. // State sync rapidly bootstraps a new node by discovering, fetching, and restoring a
  699. // state machine snapshot from peers instead of fetching and replaying historical
  700. // blocks. Requires some peers in the network to take and serve state machine
  701. // snapshots. State sync is not attempted if the node has any local state
  702. // (LastBlockHeight > 0). The node will have a truncated block history, starting from
  703. // the height of the snapshot.
  704. Enable bool `mapstructure:"enable"`
  705. // State sync uses light client verification to verify state. This can be done either
  706. // through the P2P layer or the RPC layer. Set this to true to use the P2P layer. If
  707. // false (default), the RPC layer will be used.
  708. UseP2P bool `mapstructure:"use-p2p"`
  709. // If using RPC, at least two addresses need to be provided. They should be compatible
  710. // with net.Dial, for example: "host.example.com:2125".
  711. RPCServers []string `mapstructure:"rpc-servers"`
  712. // The hash and height of a trusted block. Must be within the trust-period.
  713. TrustHeight int64 `mapstructure:"trust-height"`
  714. TrustHash string `mapstructure:"trust-hash"`
  715. // The trust period should be set so that Tendermint can detect and gossip
  716. // misbehavior before it is considered expired. For chains based on the Cosmos SDK,
  717. // one day less than the unbonding period should suffice.
  718. TrustPeriod time.Duration `mapstructure:"trust-period"`
  719. // Time to spend discovering snapshots before initiating a restore.
  720. DiscoveryTime time.Duration `mapstructure:"discovery-time"`
  721. // Temporary directory for state sync snapshot chunks, defaults to os.TempDir().
  722. // The synchronizer will create a new, randomly named directory within this directory
  723. // and remove it when the sync is complete.
  724. TempDir string `mapstructure:"temp-dir"`
  725. // The timeout duration before re-requesting a chunk, possibly from a different
  726. // peer (default: 15 seconds).
  727. ChunkRequestTimeout time.Duration `mapstructure:"chunk-request-timeout"`
  728. // The number of concurrent chunk and block fetchers to run (default: 4).
  729. Fetchers int32 `mapstructure:"fetchers"`
  730. }
  731. func (cfg *StateSyncConfig) TrustHashBytes() []byte {
  732. // validated in ValidateBasic, so we can safely panic here
  733. bytes, err := hex.DecodeString(cfg.TrustHash)
  734. if err != nil {
  735. panic(err)
  736. }
  737. return bytes
  738. }
  739. // DefaultStateSyncConfig returns a default configuration for the state sync service
  740. func DefaultStateSyncConfig() *StateSyncConfig {
  741. return &StateSyncConfig{
  742. TrustPeriod: 168 * time.Hour,
  743. DiscoveryTime: 15 * time.Second,
  744. ChunkRequestTimeout: 15 * time.Second,
  745. Fetchers: 4,
  746. }
  747. }
  748. // TestStateSyncConfig returns a default configuration for the state sync service
  749. func TestStateSyncConfig() *StateSyncConfig {
  750. return DefaultStateSyncConfig()
  751. }
  752. // ValidateBasic performs basic validation.
  753. func (cfg *StateSyncConfig) ValidateBasic() error {
  754. if !cfg.Enable {
  755. return nil
  756. }
  757. // If we're not using the P2P stack then we need to validate the
  758. // RPCServers
  759. if !cfg.UseP2P {
  760. if len(cfg.RPCServers) < 2 {
  761. return errors.New("at least two rpc-servers must be specified")
  762. }
  763. for _, server := range cfg.RPCServers {
  764. if server == "" {
  765. return errors.New("found empty rpc-servers entry")
  766. }
  767. }
  768. }
  769. if cfg.DiscoveryTime != 0 && cfg.DiscoveryTime < 5*time.Second {
  770. return errors.New("discovery time must be 0s or greater than five seconds")
  771. }
  772. if cfg.TrustPeriod <= 0 {
  773. return errors.New("trusted-period is required")
  774. }
  775. if cfg.TrustHeight <= 0 {
  776. return errors.New("trusted-height is required")
  777. }
  778. if len(cfg.TrustHash) == 0 {
  779. return errors.New("trusted-hash is required")
  780. }
  781. _, err := hex.DecodeString(cfg.TrustHash)
  782. if err != nil {
  783. return fmt.Errorf("invalid trusted-hash: %w", err)
  784. }
  785. if cfg.ChunkRequestTimeout < 5*time.Second {
  786. return errors.New("chunk-request-timeout must be at least 5 seconds")
  787. }
  788. if cfg.Fetchers <= 0 {
  789. return errors.New("fetchers is required")
  790. }
  791. return nil
  792. }
  793. //-----------------------------------------------------------------------------
  794. // ConsensusConfig
  795. // ConsensusConfig defines the configuration for the Tendermint consensus service,
  796. // including timeouts and details about the WAL and the block structure.
  797. type ConsensusConfig struct {
  798. RootDir string `mapstructure:"home"`
  799. WalPath string `mapstructure:"wal-file"`
  800. walFile string // overrides WalPath if set
  801. // TODO: remove timeout configs, these should be global not local
  802. // How long we wait for a proposal block before prevoting nil
  803. TimeoutPropose time.Duration `mapstructure:"timeout-propose"`
  804. // How much timeout-propose increases with each round
  805. TimeoutProposeDelta time.Duration `mapstructure:"timeout-propose-delta"`
  806. // How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
  807. TimeoutPrevote time.Duration `mapstructure:"timeout-prevote"`
  808. // How much the timeout-prevote increases with each round
  809. TimeoutPrevoteDelta time.Duration `mapstructure:"timeout-prevote-delta"`
  810. // How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
  811. TimeoutPrecommit time.Duration `mapstructure:"timeout-precommit"`
  812. // How much the timeout-precommit increases with each round
  813. TimeoutPrecommitDelta time.Duration `mapstructure:"timeout-precommit-delta"`
  814. // How long we wait after committing a block, before starting on the new
  815. // height (this gives us a chance to receive some more precommits, even
  816. // though we already have +2/3).
  817. TimeoutCommit time.Duration `mapstructure:"timeout-commit"`
  818. // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  819. SkipTimeoutCommit bool `mapstructure:"skip-timeout-commit"`
  820. // EmptyBlocks mode and possible interval between empty blocks
  821. CreateEmptyBlocks bool `mapstructure:"create-empty-blocks"`
  822. CreateEmptyBlocksInterval time.Duration `mapstructure:"create-empty-blocks-interval"`
  823. // Reactor sleep duration parameters
  824. PeerGossipSleepDuration time.Duration `mapstructure:"peer-gossip-sleep-duration"`
  825. PeerQueryMaj23SleepDuration time.Duration `mapstructure:"peer-query-maj23-sleep-duration"`
  826. DoubleSignCheckHeight int64 `mapstructure:"double-sign-check-height"`
  827. }
  828. // DefaultConsensusConfig returns a default configuration for the consensus service
  829. func DefaultConsensusConfig() *ConsensusConfig {
  830. return &ConsensusConfig{
  831. WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
  832. TimeoutPropose: 3000 * time.Millisecond,
  833. TimeoutProposeDelta: 500 * time.Millisecond,
  834. TimeoutPrevote: 1000 * time.Millisecond,
  835. TimeoutPrevoteDelta: 500 * time.Millisecond,
  836. TimeoutPrecommit: 1000 * time.Millisecond,
  837. TimeoutPrecommitDelta: 500 * time.Millisecond,
  838. TimeoutCommit: 1000 * time.Millisecond,
  839. SkipTimeoutCommit: false,
  840. CreateEmptyBlocks: true,
  841. CreateEmptyBlocksInterval: 0 * time.Second,
  842. PeerGossipSleepDuration: 100 * time.Millisecond,
  843. PeerQueryMaj23SleepDuration: 2000 * time.Millisecond,
  844. DoubleSignCheckHeight: int64(0),
  845. }
  846. }
  847. // TestConsensusConfig returns a configuration for testing the consensus service
  848. func TestConsensusConfig() *ConsensusConfig {
  849. cfg := DefaultConsensusConfig()
  850. cfg.TimeoutPropose = 40 * time.Millisecond
  851. cfg.TimeoutProposeDelta = 1 * time.Millisecond
  852. cfg.TimeoutPrevote = 10 * time.Millisecond
  853. cfg.TimeoutPrevoteDelta = 1 * time.Millisecond
  854. cfg.TimeoutPrecommit = 10 * time.Millisecond
  855. cfg.TimeoutPrecommitDelta = 1 * time.Millisecond
  856. cfg.TimeoutCommit = 10 * time.Millisecond
  857. cfg.SkipTimeoutCommit = true
  858. cfg.PeerGossipSleepDuration = 5 * time.Millisecond
  859. cfg.PeerQueryMaj23SleepDuration = 250 * time.Millisecond
  860. cfg.DoubleSignCheckHeight = int64(0)
  861. return cfg
  862. }
  863. // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step
  864. func (cfg *ConsensusConfig) WaitForTxs() bool {
  865. return !cfg.CreateEmptyBlocks || cfg.CreateEmptyBlocksInterval > 0
  866. }
  867. // Propose returns the amount of time to wait for a proposal
  868. func (cfg *ConsensusConfig) Propose(round int32) time.Duration {
  869. return time.Duration(
  870. cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round),
  871. ) * time.Nanosecond
  872. }
  873. // Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
  874. func (cfg *ConsensusConfig) Prevote(round int32) time.Duration {
  875. return time.Duration(
  876. cfg.TimeoutPrevote.Nanoseconds()+cfg.TimeoutPrevoteDelta.Nanoseconds()*int64(round),
  877. ) * time.Nanosecond
  878. }
  879. // Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
  880. func (cfg *ConsensusConfig) Precommit(round int32) time.Duration {
  881. return time.Duration(
  882. cfg.TimeoutPrecommit.Nanoseconds()+cfg.TimeoutPrecommitDelta.Nanoseconds()*int64(round),
  883. ) * time.Nanosecond
  884. }
  885. // Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits
  886. // for a single block (ie. a commit).
  887. func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
  888. return t.Add(cfg.TimeoutCommit)
  889. }
  890. // WalFile returns the full path to the write-ahead log file
  891. func (cfg *ConsensusConfig) WalFile() string {
  892. if cfg.walFile != "" {
  893. return cfg.walFile
  894. }
  895. return rootify(cfg.WalPath, cfg.RootDir)
  896. }
  897. // SetWalFile sets the path to the write-ahead log file
  898. func (cfg *ConsensusConfig) SetWalFile(walFile string) {
  899. cfg.walFile = walFile
  900. }
  901. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  902. // returns an error if any check fails.
  903. func (cfg *ConsensusConfig) ValidateBasic() error {
  904. if cfg.TimeoutPropose < 0 {
  905. return errors.New("timeout-propose can't be negative")
  906. }
  907. if cfg.TimeoutProposeDelta < 0 {
  908. return errors.New("timeout-propose-delta can't be negative")
  909. }
  910. if cfg.TimeoutPrevote < 0 {
  911. return errors.New("timeout-prevote can't be negative")
  912. }
  913. if cfg.TimeoutPrevoteDelta < 0 {
  914. return errors.New("timeout-prevote-delta can't be negative")
  915. }
  916. if cfg.TimeoutPrecommit < 0 {
  917. return errors.New("timeout-precommit can't be negative")
  918. }
  919. if cfg.TimeoutPrecommitDelta < 0 {
  920. return errors.New("timeout-precommit-delta can't be negative")
  921. }
  922. if cfg.TimeoutCommit < 0 {
  923. return errors.New("timeout-commit can't be negative")
  924. }
  925. if cfg.CreateEmptyBlocksInterval < 0 {
  926. return errors.New("create-empty-blocks-interval can't be negative")
  927. }
  928. if cfg.PeerGossipSleepDuration < 0 {
  929. return errors.New("peer-gossip-sleep-duration can't be negative")
  930. }
  931. if cfg.PeerQueryMaj23SleepDuration < 0 {
  932. return errors.New("peer-query-maj23-sleep-duration can't be negative")
  933. }
  934. if cfg.DoubleSignCheckHeight < 0 {
  935. return errors.New("double-sign-check-height can't be negative")
  936. }
  937. return nil
  938. }
  939. //-----------------------------------------------------------------------------
  940. // TxIndexConfig
  941. // Remember that Event has the following structure:
  942. // type: [
  943. // key: value,
  944. // ...
  945. // ]
  946. //
  947. // CompositeKeys are constructed by `type.key`
  948. // TxIndexConfig defines the configuration for the transaction indexer,
  949. // including composite keys to index.
  950. type TxIndexConfig struct {
  951. // The backend database list to back the indexer.
  952. // If list contains `null`, meaning no indexer service will be used.
  953. //
  954. // Options:
  955. // 1) "null" - no indexer services.
  956. // 2) "kv" (default) - the simplest possible indexer,
  957. // backed by key-value storage (defaults to levelDB; see DBBackend).
  958. // 3) "psql" - the indexer services backed by PostgreSQL.
  959. Indexer []string `mapstructure:"indexer"`
  960. // The PostgreSQL connection configuration, the connection format:
  961. // postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
  962. PsqlConn string `mapstructure:"psql-conn"`
  963. }
  964. // DefaultTxIndexConfig returns a default configuration for the transaction indexer.
  965. func DefaultTxIndexConfig() *TxIndexConfig {
  966. return &TxIndexConfig{
  967. Indexer: []string{"kv"},
  968. }
  969. }
  970. // TestTxIndexConfig returns a default configuration for the transaction indexer.
  971. func TestTxIndexConfig() *TxIndexConfig {
  972. return DefaultTxIndexConfig()
  973. }
  974. //-----------------------------------------------------------------------------
  975. // InstrumentationConfig
  976. // InstrumentationConfig defines the configuration for metrics reporting.
  977. type InstrumentationConfig struct {
  978. // When true, Prometheus metrics are served under /metrics on
  979. // PrometheusListenAddr.
  980. // Check out the documentation for the list of available metrics.
  981. Prometheus bool `mapstructure:"prometheus"`
  982. // Address to listen for Prometheus collector(s) connections.
  983. PrometheusListenAddr string `mapstructure:"prometheus-listen-addr"`
  984. // Maximum number of simultaneous connections.
  985. // If you want to accept a larger number than the default, make sure
  986. // you increase your OS limits.
  987. // 0 - unlimited.
  988. MaxOpenConnections int `mapstructure:"max-open-connections"`
  989. // Instrumentation namespace.
  990. Namespace string `mapstructure:"namespace"`
  991. }
  992. // DefaultInstrumentationConfig returns a default configuration for metrics
  993. // reporting.
  994. func DefaultInstrumentationConfig() *InstrumentationConfig {
  995. return &InstrumentationConfig{
  996. Prometheus: false,
  997. PrometheusListenAddr: ":26660",
  998. MaxOpenConnections: 3,
  999. Namespace: "tendermint",
  1000. }
  1001. }
  1002. // TestInstrumentationConfig returns a default configuration for metrics
  1003. // reporting.
  1004. func TestInstrumentationConfig() *InstrumentationConfig {
  1005. return DefaultInstrumentationConfig()
  1006. }
  1007. // ValidateBasic performs basic validation (checking param bounds, etc.) and
  1008. // returns an error if any check fails.
  1009. func (cfg *InstrumentationConfig) ValidateBasic() error {
  1010. if cfg.MaxOpenConnections < 0 {
  1011. return errors.New("max-open-connections can't be negative")
  1012. }
  1013. return nil
  1014. }
  1015. //-----------------------------------------------------------------------------
  1016. // Utils
  1017. // helper function to make config creation independent of root dir
  1018. func rootify(path, root string) string {
  1019. if filepath.IsAbs(path) {
  1020. return path
  1021. }
  1022. return filepath.Join(root, path)
  1023. }
  1024. //-----------------------------------------------------------------------------
  1025. // Moniker
  1026. var defaultMoniker = getDefaultMoniker()
  1027. // getDefaultMoniker returns a default moniker, which is the host name. If runtime
  1028. // fails to get the host name, "anonymous" will be returned.
  1029. func getDefaultMoniker() string {
  1030. moniker, err := os.Hostname()
  1031. if err != nil {
  1032. moniker = "anonymous"
  1033. }
  1034. return moniker
  1035. }