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.

1120 lines
39 KiB

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