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.

1107 lines
39 KiB

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