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.

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