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.

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