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.

988 lines
34 KiB

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