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.

1201 lines
42 KiB

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