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.

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