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.

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