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.

596 lines
23 KiB

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
  1. package config
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. "text/template"
  10. tmos "github.com/tendermint/tendermint/libs/os"
  11. )
  12. // DefaultDirPerm is the default permissions used when creating directories.
  13. const DefaultDirPerm = 0700
  14. var configTemplate *template.Template
  15. func init() {
  16. var err error
  17. tmpl := template.New("configFileTemplate").Funcs(template.FuncMap{
  18. "StringsJoin": strings.Join,
  19. })
  20. if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
  21. panic(err)
  22. }
  23. }
  24. /****** these are for production settings ***********/
  25. // EnsureRoot creates the root, config, and data directories if they don't exist,
  26. // and panics if it fails.
  27. func EnsureRoot(rootDir string) {
  28. if err := tmos.EnsureDir(rootDir, DefaultDirPerm); err != nil {
  29. panic(err.Error())
  30. }
  31. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  32. panic(err.Error())
  33. }
  34. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  35. panic(err.Error())
  36. }
  37. }
  38. // WriteConfigFile renders config using the template and writes it to configFilePath.
  39. // This function is called by cmd/tendermint/commands/init.go
  40. func WriteConfigFile(rootDir string, config *Config) {
  41. var buffer bytes.Buffer
  42. if err := configTemplate.Execute(&buffer, config); err != nil {
  43. panic(err)
  44. }
  45. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  46. mustWriteFile(configFilePath, buffer.Bytes(), 0644)
  47. }
  48. func writeDefaultConfigFileIfNone(rootDir string) {
  49. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  50. if !tmos.FileExists(configFilePath) {
  51. WriteConfigFile(rootDir, DefaultConfig())
  52. }
  53. }
  54. // Note: any changes to the comments/variables/mapstructure
  55. // must be reflected in the appropriate struct in config/config.go
  56. const defaultConfigTemplate = `# This is a TOML config file.
  57. # For more information, see https://github.com/toml-lang/toml
  58. # NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
  59. # relative to the home directory (e.g. "data"). The home directory is
  60. # "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
  61. # or --home cmd flag.
  62. #######################################################################
  63. ### Main Base Config Options ###
  64. #######################################################################
  65. # TCP or UNIX socket address of the ABCI application,
  66. # or the name of an ABCI application compiled in with the Tendermint binary
  67. proxy-app = "{{ .BaseConfig.ProxyApp }}"
  68. # A custom human readable name for this node
  69. moniker = "{{ .BaseConfig.Moniker }}"
  70. # Mode of Node: full | validator | seed
  71. # * validator node
  72. # - all reactors
  73. # - with priv_validator_key.json, priv_validator_state.json
  74. # * full node
  75. # - all reactors
  76. # - No priv_validator_key.json, priv_validator_state.json
  77. # * seed node
  78. # - only P2P, PEX Reactor
  79. # - No priv_validator_key.json, priv_validator_state.json
  80. mode = "{{ .BaseConfig.Mode }}"
  81. # Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb
  82. # * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
  83. # - pure go
  84. # - stable
  85. # * cleveldb (uses levigo wrapper)
  86. # - fast
  87. # - requires gcc
  88. # - use cleveldb build tag (go build -tags cleveldb)
  89. # * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
  90. # - EXPERIMENTAL
  91. # - may be faster is some use-cases (random reads - indexer)
  92. # - use boltdb build tag (go build -tags boltdb)
  93. # * rocksdb (uses github.com/tecbot/gorocksdb)
  94. # - EXPERIMENTAL
  95. # - requires gcc
  96. # - use rocksdb build tag (go build -tags rocksdb)
  97. # * badgerdb (uses github.com/dgraph-io/badger)
  98. # - EXPERIMENTAL
  99. # - use badgerdb build tag (go build -tags badgerdb)
  100. db-backend = "{{ .BaseConfig.DBBackend }}"
  101. # Database directory
  102. db-dir = "{{ js .BaseConfig.DBPath }}"
  103. # Output level for logging, including package level options
  104. log-level = "{{ .BaseConfig.LogLevel }}"
  105. # Output format: 'plain' (colored text) or 'json'
  106. log-format = "{{ .BaseConfig.LogFormat }}"
  107. ##### additional base config options #####
  108. # Path to the JSON file containing the initial validator set and other meta data
  109. genesis-file = "{{ js .BaseConfig.Genesis }}"
  110. # Path to the JSON file containing the private key to use for node authentication in the p2p protocol
  111. node-key-file = "{{ js .BaseConfig.NodeKey }}"
  112. # Mechanism to connect to the ABCI application: socket | grpc
  113. abci = "{{ .BaseConfig.ABCI }}"
  114. # If true, query the ABCI app on connecting to a new peer
  115. # so the app can decide if we should keep the connection or not
  116. filter-peers = {{ .BaseConfig.FilterPeers }}
  117. #######################################################
  118. ### Priv Validator Configuration ###
  119. #######################################################
  120. [priv-validator]
  121. # Path to the JSON file containing the private key to use as a validator in the consensus protocol
  122. key-file = "{{ js .PrivValidator.Key }}"
  123. # Path to the JSON file containing the last sign state of a validator
  124. state-file = "{{ js .PrivValidator.State }}"
  125. # TCP or UNIX socket address for Tendermint to listen on for
  126. # connections from an external PrivValidator process
  127. # when the listenAddr is prefixed with grpc instead of tcp it will use the gRPC Client
  128. laddr = "{{ .PrivValidator.ListenAddr }}"
  129. # Path to the client certificate generated while creating needed files for secure connection.
  130. # If a remote validator address is provided but no certificate, the connection will be insecure
  131. client-certificate-file = "{{ js .PrivValidator.ClientCertificate }}"
  132. # Client key generated while creating certificates for secure connection
  133. client-key-file = "{{ js .PrivValidator.ClientKey }}"
  134. # Path to the Root Certificate Authority used to sign both client and server certificates
  135. root-ca-file = "{{ js .PrivValidator.RootCA }}"
  136. #######################################################################
  137. ### Advanced Configuration Options ###
  138. #######################################################################
  139. #######################################################
  140. ### RPC Server Configuration Options ###
  141. #######################################################
  142. [rpc]
  143. # TCP or UNIX socket address for the RPC server to listen on
  144. laddr = "{{ .RPC.ListenAddress }}"
  145. # A list of origins a cross-domain request can be executed from
  146. # Default value '[]' disables cors support
  147. # Use '["*"]' to allow any origin
  148. cors-allowed-origins = [{{ range .RPC.CORSAllowedOrigins }}{{ printf "%q, " . }}{{end}}]
  149. # A list of methods the client is allowed to use with cross-domain requests
  150. cors-allowed-methods = [{{ range .RPC.CORSAllowedMethods }}{{ printf "%q, " . }}{{end}}]
  151. # A list of non simple headers the client is allowed to use with cross-domain requests
  152. cors-allowed-headers = [{{ range .RPC.CORSAllowedHeaders }}{{ printf "%q, " . }}{{end}}]
  153. # Activate unsafe RPC commands like /dial-seeds and /unsafe-flush-mempool
  154. unsafe = {{ .RPC.Unsafe }}
  155. # Maximum number of simultaneous connections (including WebSocket).
  156. # If you want to accept a larger number than the default, make sure
  157. # you increase your OS limits.
  158. # 0 - unlimited.
  159. # Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  160. # 1024 - 40 - 10 - 50 = 924 = ~900
  161. max-open-connections = {{ .RPC.MaxOpenConnections }}
  162. # Maximum number of unique clientIDs that can /subscribe
  163. # If you're using /broadcast_tx_commit, set to the estimated maximum number
  164. # of broadcast_tx_commit calls per block.
  165. max-subscription-clients = {{ .RPC.MaxSubscriptionClients }}
  166. # Maximum number of unique queries a given client can /subscribe to
  167. # If you're using a Local RPC client and /broadcast_tx_commit, set this
  168. # to the estimated maximum number of broadcast_tx_commit calls per block.
  169. max-subscriptions-per-client = {{ .RPC.MaxSubscriptionsPerClient }}
  170. # How long to wait for a tx to be committed during /broadcast_tx_commit.
  171. # WARNING: Using a value larger than 10s will result in increasing the
  172. # global HTTP write timeout, which applies to all connections and endpoints.
  173. # See https://github.com/tendermint/tendermint/issues/3435
  174. timeout-broadcast-tx-commit = "{{ .RPC.TimeoutBroadcastTxCommit }}"
  175. # Maximum size of request body, in bytes
  176. max-body-bytes = {{ .RPC.MaxBodyBytes }}
  177. # Maximum size of request header, in bytes
  178. max-header-bytes = {{ .RPC.MaxHeaderBytes }}
  179. # The path to a file containing certificate that is used to create the HTTPS server.
  180. # Might be either absolute path or path related to Tendermint's config directory.
  181. # If the certificate is signed by a certificate authority,
  182. # the certFile should be the concatenation of the server's certificate, any intermediates,
  183. # and the CA's certificate.
  184. # NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  185. # Otherwise, HTTP server is run.
  186. tls-cert-file = "{{ .RPC.TLSCertFile }}"
  187. # The path to a file containing matching private key that is used to create the HTTPS server.
  188. # Might be either absolute path or path related to Tendermint's config directory.
  189. # NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  190. # Otherwise, HTTP server is run.
  191. tls-key-file = "{{ .RPC.TLSKeyFile }}"
  192. # pprof listen address (https://golang.org/pkg/net/http/pprof)
  193. pprof-laddr = "{{ .RPC.PprofListenAddress }}"
  194. #######################################################
  195. ### P2P Configuration Options ###
  196. #######################################################
  197. [p2p]
  198. # Select the p2p internal queue
  199. queue-type = "{{ .P2P.QueueType }}"
  200. # Address to listen for incoming connections
  201. laddr = "{{ .P2P.ListenAddress }}"
  202. # Address to advertise to peers for them to dial
  203. # If empty, will use the same port as the laddr,
  204. # and will introspect on the listener or use UPnP
  205. # to figure out the address. ip and port are required
  206. # example: 159.89.10.97:26656
  207. external-address = "{{ .P2P.ExternalAddress }}"
  208. # Comma separated list of seed nodes to connect to
  209. # We only use these if we cant connect to peers in the addrbook
  210. # NOTE: not used by the new PEX reactor. Please use BootstrapPeers instead.
  211. # TODO: Remove once p2p refactor is complete
  212. # ref: https:#github.com/tendermint/tendermint/issues/5670
  213. seeds = "{{ .P2P.Seeds }}"
  214. # Comma separated list of peers to be added to the peer store
  215. # on startup. Either BootstrapPeers or PersistentPeers are
  216. # needed for peer discovery
  217. bootstrap-peers = "{{ .P2P.BootstrapPeers }}"
  218. # Comma separated list of nodes to keep persistent connections to
  219. persistent-peers = "{{ .P2P.PersistentPeers }}"
  220. # UPNP port forwarding
  221. upnp = {{ .P2P.UPNP }}
  222. # Maximum number of connections (inbound and outbound).
  223. max-connections = {{ .P2P.MaxConnections }}
  224. # Rate limits the number of incoming connection attempts per IP address.
  225. max-incoming-connection-attempts = {{ .P2P.MaxIncomingConnectionAttempts }}
  226. # Set true to enable the peer-exchange reactor
  227. pex = {{ .P2P.PexReactor }}
  228. # Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
  229. # Warning: IPs will be exposed at /net_info, for more information https://github.com/tendermint/tendermint/issues/3055
  230. private-peer-ids = "{{ .P2P.PrivatePeerIDs }}"
  231. # Toggle to disable guard against peers connecting from the same ip.
  232. allow-duplicate-ip = {{ .P2P.AllowDuplicateIP }}
  233. # Peer connection configuration.
  234. handshake-timeout = "{{ .P2P.HandshakeTimeout }}"
  235. dial-timeout = "{{ .P2P.DialTimeout }}"
  236. #######################################################
  237. ### Mempool Configuration Option ###
  238. #######################################################
  239. [mempool]
  240. # Mempool version to use:
  241. # 1) "v0" - The legacy non-prioritized mempool reactor.
  242. # 2) "v1" (default) - The prioritized mempool reactor.
  243. version = "{{ .Mempool.Version }}"
  244. recheck = {{ .Mempool.Recheck }}
  245. broadcast = {{ .Mempool.Broadcast }}
  246. # Maximum number of transactions in the mempool
  247. size = {{ .Mempool.Size }}
  248. # Limit the total size of all txs in the mempool.
  249. # This only accounts for raw transactions (e.g. given 1MB transactions and
  250. # max-txs-bytes=5MB, mempool will only accept 5 transactions).
  251. max-txs-bytes = {{ .Mempool.MaxTxsBytes }}
  252. # Size of the cache (used to filter transactions we saw earlier) in transactions
  253. cache-size = {{ .Mempool.CacheSize }}
  254. # Do not remove invalid transactions from the cache (default: false)
  255. # Set to true if it's not possible for any invalid transaction to become valid
  256. # again in the future.
  257. keep-invalid-txs-in-cache = {{ .Mempool.KeepInvalidTxsInCache }}
  258. # Maximum size of a single transaction.
  259. # NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
  260. max-tx-bytes = {{ .Mempool.MaxTxBytes }}
  261. # Maximum size of a batch of transactions to send to a peer
  262. # Including space needed by encoding (one varint per transaction).
  263. # XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
  264. max-batch-bytes = {{ .Mempool.MaxBatchBytes }}
  265. # ttl-duration, if non-zero, defines the maximum amount of time a transaction
  266. # can exist for in the mempool.
  267. #
  268. # Note, if ttl-num-blocks is also defined, a transaction will be removed if it
  269. # has existed in the mempool at least ttl-num-blocks number of blocks or if it's
  270. # insertion time into the mempool is beyond ttl-duration.
  271. ttl-duration = "{{ .Mempool.TTLDuration }}"
  272. # ttl-num-blocks, if non-zero, defines the maximum number of blocks a transaction
  273. # can exist for in the mempool.
  274. #
  275. # Note, if ttl-duration is also defined, a transaction will be removed if it
  276. # has existed in the mempool at least ttl-num-blocks number of blocks or if
  277. # it's insertion time into the mempool is beyond ttl-duration.
  278. ttl-num-blocks = {{ .Mempool.TTLNumBlocks }}
  279. #######################################################
  280. ### State Sync Configuration Options ###
  281. #######################################################
  282. [statesync]
  283. # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
  284. # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
  285. # the network to take and serve state machine snapshots. State sync is not attempted if the node
  286. # has any local state (LastBlockHeight > 0). The node will have a truncated block history,
  287. # starting from the height of the snapshot.
  288. enable = {{ .StateSync.Enable }}
  289. # State sync uses light client verification to verify state. This can be done either through the
  290. # P2P layer or RPC layer. Set this to true to use the P2P layer. If false (default), RPC layer
  291. # will be used.
  292. use-p2p = {{ .StateSync.UseP2P }}
  293. # If using RPC, at least two addresses need to be provided. They should be compatible with net.Dial,
  294. # for example: "host.example.com:2125"
  295. rpc-servers = "{{ StringsJoin .StateSync.RPCServers "," }}"
  296. # The hash and height of a trusted block. Must be within the trust-period.
  297. trust-height = {{ .StateSync.TrustHeight }}
  298. trust-hash = "{{ .StateSync.TrustHash }}"
  299. # The trust period should be set so that Tendermint can detect and gossip misbehavior before
  300. # it is considered expired. For chains based on the Cosmos SDK, one day less than the unbonding
  301. # period should suffice.
  302. trust-period = "{{ .StateSync.TrustPeriod }}"
  303. # Time to spend discovering snapshots before initiating a restore.
  304. discovery-time = "{{ .StateSync.DiscoveryTime }}"
  305. # Temporary directory for state sync snapshot chunks, defaults to os.TempDir().
  306. # The synchronizer will create a new, randomly named directory within this directory
  307. # and remove it when the sync is complete.
  308. temp-dir = "{{ .StateSync.TempDir }}"
  309. # The timeout duration before re-requesting a chunk, possibly from a different
  310. # peer (default: 15 seconds).
  311. chunk-request-timeout = "{{ .StateSync.ChunkRequestTimeout }}"
  312. # The number of concurrent chunk and block fetchers to run (default: 4).
  313. fetchers = "{{ .StateSync.Fetchers }}"
  314. #######################################################
  315. ### Block Sync Configuration Connections ###
  316. #######################################################
  317. [blocksync]
  318. # If this node is many blocks behind the tip of the chain, BlockSync
  319. # allows them to catchup quickly by downloading blocks in parallel
  320. # and verifying their commits
  321. enable = {{ .BlockSync.Enable }}
  322. #######################################################
  323. ### Consensus Configuration Options ###
  324. #######################################################
  325. [consensus]
  326. wal-file = "{{ js .Consensus.WalPath }}"
  327. # How long we wait for a proposal block before prevoting nil
  328. timeout-propose = "{{ .Consensus.TimeoutPropose }}"
  329. # How much timeout-propose increases with each round
  330. timeout-propose-delta = "{{ .Consensus.TimeoutProposeDelta }}"
  331. # How long we wait after receiving +2/3 prevotes for anything (ie. not a single block or nil)
  332. timeout-prevote = "{{ .Consensus.TimeoutPrevote }}"
  333. # How much the timeout-prevote increases with each round
  334. timeout-prevote-delta = "{{ .Consensus.TimeoutPrevoteDelta }}"
  335. # How long we wait after receiving +2/3 precommits for anything (ie. not a single block or nil)
  336. timeout-precommit = "{{ .Consensus.TimeoutPrecommit }}"
  337. # How much the timeout-precommit increases with each round
  338. timeout-precommit-delta = "{{ .Consensus.TimeoutPrecommitDelta }}"
  339. # How long we wait after committing a block, before starting on the new
  340. # height (this gives us a chance to receive some more precommits, even
  341. # though we already have +2/3).
  342. timeout-commit = "{{ .Consensus.TimeoutCommit }}"
  343. # How many blocks to look back to check existence of the node's consensus votes before joining consensus
  344. # When non-zero, the node will panic upon restart
  345. # if the same consensus key was used to sign {double-sign-check-height} last blocks.
  346. # So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
  347. double-sign-check-height = {{ .Consensus.DoubleSignCheckHeight }}
  348. # Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  349. skip-timeout-commit = {{ .Consensus.SkipTimeoutCommit }}
  350. # EmptyBlocks mode and possible interval between empty blocks
  351. create-empty-blocks = {{ .Consensus.CreateEmptyBlocks }}
  352. create-empty-blocks-interval = "{{ .Consensus.CreateEmptyBlocksInterval }}"
  353. # Reactor sleep duration parameters
  354. peer-gossip-sleep-duration = "{{ .Consensus.PeerGossipSleepDuration }}"
  355. peer-query-maj23-sleep-duration = "{{ .Consensus.PeerQueryMaj23SleepDuration }}"
  356. #######################################################
  357. ### Transaction Indexer Configuration Options ###
  358. #######################################################
  359. [tx-index]
  360. # The backend database list to back the indexer.
  361. # If list contains "null" or "", meaning no indexer service will be used.
  362. #
  363. # The application will set which txs to index. In some cases a node operator will be able
  364. # to decide which txs to index based on configuration set in the application.
  365. #
  366. # Options:
  367. # 1) "null"
  368. # 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  369. # 3) "psql" - the indexer services backed by PostgreSQL.
  370. # When "kv" or "psql" is chosen "tx.height" and "tx.hash" will always be indexed.
  371. indexer = [{{ range $i, $e := .TxIndex.Indexer }}{{if $i}}, {{end}}{{ printf "%q" $e}}{{end}}]
  372. # The PostgreSQL connection configuration, the connection format:
  373. # postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
  374. psql-conn = "{{ .TxIndex.PsqlConn }}"
  375. #######################################################
  376. ### Instrumentation Configuration Options ###
  377. #######################################################
  378. [instrumentation]
  379. # When true, Prometheus metrics are served under /metrics on
  380. # PrometheusListenAddr.
  381. # Check out the documentation for the list of available metrics.
  382. prometheus = {{ .Instrumentation.Prometheus }}
  383. # Address to listen for Prometheus collector(s) connections
  384. prometheus-listen-addr = "{{ .Instrumentation.PrometheusListenAddr }}"
  385. # Maximum number of simultaneous connections.
  386. # If you want to accept a larger number than the default, make sure
  387. # you increase your OS limits.
  388. # 0 - unlimited.
  389. max-open-connections = {{ .Instrumentation.MaxOpenConnections }}
  390. # Instrumentation namespace
  391. namespace = "{{ .Instrumentation.Namespace }}"
  392. `
  393. /****** these are for test settings ***********/
  394. func ResetTestRoot(testName string) *Config {
  395. return ResetTestRootWithChainID(testName, "")
  396. }
  397. func ResetTestRootWithChainID(testName string, chainID string) *Config {
  398. // create a unique, concurrency-safe test directory under os.TempDir()
  399. rootDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s_", chainID, testName))
  400. if err != nil {
  401. panic(err)
  402. }
  403. // ensure config and data subdirs are created
  404. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  405. panic(err)
  406. }
  407. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  408. panic(err)
  409. }
  410. conf := DefaultConfig()
  411. genesisFilePath := filepath.Join(rootDir, conf.Genesis)
  412. privKeyFilePath := filepath.Join(rootDir, conf.PrivValidator.Key)
  413. privStateFilePath := filepath.Join(rootDir, conf.PrivValidator.State)
  414. // Write default config file if missing.
  415. writeDefaultConfigFileIfNone(rootDir)
  416. if !tmos.FileExists(genesisFilePath) {
  417. if chainID == "" {
  418. chainID = "tendermint_test"
  419. }
  420. testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
  421. mustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
  422. }
  423. // we always overwrite the priv val
  424. mustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
  425. mustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
  426. config := TestConfig().SetRoot(rootDir)
  427. return config
  428. }
  429. func mustWriteFile(filePath string, contents []byte, mode os.FileMode) {
  430. if err := ioutil.WriteFile(filePath, contents, mode); err != nil {
  431. tmos.Exit(fmt.Sprintf("failed to write file: %v", err))
  432. }
  433. }
  434. var testGenesisFmt = `{
  435. "genesis_time": "2018-10-10T08:20:13.695936996Z",
  436. "chain_id": "%s",
  437. "initial_height": "1",
  438. "consensus_params": {
  439. "block": {
  440. "max_bytes": "22020096",
  441. "max_gas": "-1",
  442. "time_iota_ms": "10"
  443. },
  444. "evidence": {
  445. "max_age_num_blocks": "100000",
  446. "max_age_duration": "172800000000000",
  447. "max_bytes": "1048576"
  448. },
  449. "validator": {
  450. "pub_key_types": [
  451. "ed25519"
  452. ]
  453. },
  454. "version": {}
  455. },
  456. "validators": [
  457. {
  458. "pub_key": {
  459. "type": "tendermint/PubKeyEd25519",
  460. "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  461. },
  462. "power": "10",
  463. "name": ""
  464. }
  465. ],
  466. "app_hash": ""
  467. }`
  468. var testPrivValidatorKey = `{
  469. "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145",
  470. "pub_key": {
  471. "type": "tendermint/PubKeyEd25519",
  472. "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  473. },
  474. "priv_key": {
  475. "type": "tendermint/PrivKeyEd25519",
  476. "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="
  477. }
  478. }`
  479. var testPrivValidatorState = `{
  480. "height": "0",
  481. "round": 0,
  482. "step": 0
  483. }`