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.

1099 lines
39 KiB

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