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.

1167 lines
41 KiB

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