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.

1182 lines
41 KiB

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