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.

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