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.

654 lines
25 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
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. # If true, disable the websocket interface to the RPC service. This has
  177. # the effect of disabling the /subscribe, /unsubscribe, and /unsubscribe_all
  178. # methods for event subscription.
  179. #
  180. # EXPERIMENTAL: This setting will be removed in Tendermint v0.37.
  181. experimental-disable-websocket = {{ .RPC.ExperimentalDisableWebsocket }}
  182. # The time window size for the event log. All events up to this long before
  183. # the latest (up to EventLogMaxItems) will be available for subscribers to
  184. # fetch via the /events method. If 0 (the default) the event log and the
  185. # /events RPC method are disabled.
  186. event-log-window-size = "{{ .RPC.EventLogWindowSize }}"
  187. # The maxiumum number of events that may be retained by the event log. If
  188. # this value is 0, no upper limit is set. Otherwise, items in excess of
  189. # this number will be discarded from the event log.
  190. #
  191. # Warning: This setting is a safety valve. Setting it too low may cause
  192. # subscribers to miss events. Try to choose a value higher than the
  193. # maximum worst-case expected event load within the chosen window size in
  194. # ordinary operation.
  195. #
  196. # For example, if the window size is 10 minutes and the node typically
  197. # averages 1000 events per ten minutes, but with occasional known spikes of
  198. # up to 2000, choose a value > 2000.
  199. event-log-max-items = {{ .RPC.EventLogMaxItems }}
  200. # How long to wait for a tx to be committed during /broadcast_tx_commit.
  201. # WARNING: Using a value larger than 10s will result in increasing the
  202. # global HTTP write timeout, which applies to all connections and endpoints.
  203. # See https://github.com/tendermint/tendermint/issues/3435
  204. timeout-broadcast-tx-commit = "{{ .RPC.TimeoutBroadcastTxCommit }}"
  205. # Maximum size of request body, in bytes
  206. max-body-bytes = {{ .RPC.MaxBodyBytes }}
  207. # Maximum size of request header, in bytes
  208. max-header-bytes = {{ .RPC.MaxHeaderBytes }}
  209. # The path to a file containing certificate that is used to create the HTTPS server.
  210. # Might be either absolute path or path related to Tendermint's config directory.
  211. # If the certificate is signed by a certificate authority,
  212. # the certFile should be the concatenation of the server's certificate, any intermediates,
  213. # and the CA's certificate.
  214. # NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  215. # Otherwise, HTTP server is run.
  216. tls-cert-file = "{{ .RPC.TLSCertFile }}"
  217. # The path to a file containing matching private key that is used to create the HTTPS server.
  218. # Might be either absolute path or path related to Tendermint's config directory.
  219. # NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
  220. # Otherwise, HTTP server is run.
  221. tls-key-file = "{{ .RPC.TLSKeyFile }}"
  222. # pprof listen address (https://golang.org/pkg/net/http/pprof)
  223. pprof-laddr = "{{ .RPC.PprofListenAddress }}"
  224. #######################################################
  225. ### P2P Configuration Options ###
  226. #######################################################
  227. [p2p]
  228. # Select the p2p internal queue
  229. queue-type = "{{ .P2P.QueueType }}"
  230. # Address to listen for incoming connections
  231. laddr = "{{ .P2P.ListenAddress }}"
  232. # Address to advertise to peers for them to dial
  233. # If empty, will use the same port as the laddr,
  234. # and will introspect on the listener or use UPnP
  235. # to figure out the address. ip and port are required
  236. # example: 159.89.10.97:26656
  237. external-address = "{{ .P2P.ExternalAddress }}"
  238. # Comma separated list of seed nodes to connect to
  239. # We only use these if we cant connect to peers in the addrbook
  240. # NOTE: not used by the new PEX reactor. Please use BootstrapPeers instead.
  241. # TODO: Remove once p2p refactor is complete
  242. # ref: https:#github.com/tendermint/tendermint/issues/5670
  243. seeds = "{{ .P2P.Seeds }}"
  244. # Comma separated list of peers to be added to the peer store
  245. # on startup. Either BootstrapPeers or PersistentPeers are
  246. # needed for peer discovery
  247. bootstrap-peers = "{{ .P2P.BootstrapPeers }}"
  248. # Comma separated list of nodes to keep persistent connections to
  249. persistent-peers = "{{ .P2P.PersistentPeers }}"
  250. # UPNP port forwarding
  251. upnp = {{ .P2P.UPNP }}
  252. # Maximum number of connections (inbound and outbound).
  253. max-connections = {{ .P2P.MaxConnections }}
  254. # Rate limits the number of incoming connection attempts per IP address.
  255. max-incoming-connection-attempts = {{ .P2P.MaxIncomingConnectionAttempts }}
  256. # Set true to enable the peer-exchange reactor
  257. pex = {{ .P2P.PexReactor }}
  258. # Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
  259. # Warning: IPs will be exposed at /net_info, for more information https://github.com/tendermint/tendermint/issues/3055
  260. private-peer-ids = "{{ .P2P.PrivatePeerIDs }}"
  261. # Toggle to disable guard against peers connecting from the same ip.
  262. allow-duplicate-ip = {{ .P2P.AllowDuplicateIP }}
  263. # Peer connection configuration.
  264. handshake-timeout = "{{ .P2P.HandshakeTimeout }}"
  265. dial-timeout = "{{ .P2P.DialTimeout }}"
  266. # Time to wait before flushing messages out on the connection
  267. # TODO: Remove once MConnConnection is removed.
  268. flush-throttle-timeout = "{{ .P2P.FlushThrottleTimeout }}"
  269. # Maximum size of a message packet payload, in bytes
  270. # TODO: Remove once MConnConnection is removed.
  271. max-packet-msg-payload-size = {{ .P2P.MaxPacketMsgPayloadSize }}
  272. # Rate at which packets can be sent, in bytes/second
  273. # TODO: Remove once MConnConnection is removed.
  274. send-rate = {{ .P2P.SendRate }}
  275. # Rate at which packets can be received, in bytes/second
  276. # TODO: Remove once MConnConnection is removed.
  277. recv-rate = {{ .P2P.RecvRate }}
  278. #######################################################
  279. ### Mempool Configuration Option ###
  280. #######################################################
  281. [mempool]
  282. recheck = {{ .Mempool.Recheck }}
  283. broadcast = {{ .Mempool.Broadcast }}
  284. # Maximum number of transactions in the mempool
  285. size = {{ .Mempool.Size }}
  286. # Limit the total size of all txs in the mempool.
  287. # This only accounts for raw transactions (e.g. given 1MB transactions and
  288. # max-txs-bytes=5MB, mempool will only accept 5 transactions).
  289. max-txs-bytes = {{ .Mempool.MaxTxsBytes }}
  290. # Size of the cache (used to filter transactions we saw earlier) in transactions
  291. cache-size = {{ .Mempool.CacheSize }}
  292. # Do not remove invalid transactions from the cache (default: false)
  293. # Set to true if it's not possible for any invalid transaction to become valid
  294. # again in the future.
  295. keep-invalid-txs-in-cache = {{ .Mempool.KeepInvalidTxsInCache }}
  296. # Maximum size of a single transaction.
  297. # NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
  298. max-tx-bytes = {{ .Mempool.MaxTxBytes }}
  299. # Maximum size of a batch of transactions to send to a peer
  300. # Including space needed by encoding (one varint per transaction).
  301. # XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
  302. max-batch-bytes = {{ .Mempool.MaxBatchBytes }}
  303. # ttl-duration, if non-zero, defines the maximum amount of time a transaction
  304. # can exist for in the mempool.
  305. #
  306. # Note, if ttl-num-blocks is also defined, a transaction will be removed if it
  307. # has existed in the mempool at least ttl-num-blocks number of blocks or if it's
  308. # insertion time into the mempool is beyond ttl-duration.
  309. ttl-duration = "{{ .Mempool.TTLDuration }}"
  310. # ttl-num-blocks, if non-zero, defines the maximum number of blocks a transaction
  311. # can exist for in the mempool.
  312. #
  313. # Note, if ttl-duration is also defined, a transaction will be removed if it
  314. # has existed in the mempool at least ttl-num-blocks number of blocks or if
  315. # it's insertion time into the mempool is beyond ttl-duration.
  316. ttl-num-blocks = {{ .Mempool.TTLNumBlocks }}
  317. #######################################################
  318. ### State Sync Configuration Options ###
  319. #######################################################
  320. [statesync]
  321. # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
  322. # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
  323. # the network to take and serve state machine snapshots. State sync is not attempted if the node
  324. # has any local state (LastBlockHeight > 0). The node will have a truncated block history,
  325. # starting from the height of the snapshot.
  326. enable = {{ .StateSync.Enable }}
  327. # State sync uses light client verification to verify state. This can be done either through the
  328. # P2P layer or RPC layer. Set this to true to use the P2P layer. If false (default), RPC layer
  329. # will be used.
  330. use-p2p = {{ .StateSync.UseP2P }}
  331. # If using RPC, at least two addresses need to be provided. They should be compatible with net.Dial,
  332. # for example: "host.example.com:2125"
  333. rpc-servers = "{{ StringsJoin .StateSync.RPCServers "," }}"
  334. # The hash and height of a trusted block. Must be within the trust-period.
  335. trust-height = {{ .StateSync.TrustHeight }}
  336. trust-hash = "{{ .StateSync.TrustHash }}"
  337. # The trust period should be set so that Tendermint can detect and gossip misbehavior before
  338. # it is considered expired. For chains based on the Cosmos SDK, one day less than the unbonding
  339. # period should suffice.
  340. trust-period = "{{ .StateSync.TrustPeriod }}"
  341. # Time to spend discovering snapshots before initiating a restore.
  342. discovery-time = "{{ .StateSync.DiscoveryTime }}"
  343. # Temporary directory for state sync snapshot chunks, defaults to os.TempDir().
  344. # The synchronizer will create a new, randomly named directory within this directory
  345. # and remove it when the sync is complete.
  346. temp-dir = "{{ .StateSync.TempDir }}"
  347. # The timeout duration before re-requesting a chunk, possibly from a different
  348. # peer (default: 15 seconds).
  349. chunk-request-timeout = "{{ .StateSync.ChunkRequestTimeout }}"
  350. # The number of concurrent chunk and block fetchers to run (default: 4).
  351. fetchers = "{{ .StateSync.Fetchers }}"
  352. #######################################################
  353. ### Consensus Configuration Options ###
  354. #######################################################
  355. [consensus]
  356. wal-file = "{{ js .Consensus.WalPath }}"
  357. # How long we wait for a proposal block before prevoting nil
  358. timeout-propose = "{{ .Consensus.TimeoutPropose }}"
  359. # How much timeout-propose increases with each round
  360. timeout-propose-delta = "{{ .Consensus.TimeoutProposeDelta }}"
  361. # How long we wait after receiving +2/3 prevotes for anything (ie. not a single block or nil)
  362. timeout-prevote = "{{ .Consensus.TimeoutPrevote }}"
  363. # How much the timeout-prevote increases with each round
  364. timeout-prevote-delta = "{{ .Consensus.TimeoutPrevoteDelta }}"
  365. # How long we wait after receiving +2/3 precommits for anything (ie. not a single block or nil)
  366. timeout-precommit = "{{ .Consensus.TimeoutPrecommit }}"
  367. # How much the timeout-precommit increases with each round
  368. timeout-precommit-delta = "{{ .Consensus.TimeoutPrecommitDelta }}"
  369. # How long we wait after committing a block, before starting on the new
  370. # height (this gives us a chance to receive some more precommits, even
  371. # though we already have +2/3).
  372. timeout-commit = "{{ .Consensus.TimeoutCommit }}"
  373. # How many blocks to look back to check existence of the node's consensus votes before joining consensus
  374. # When non-zero, the node will panic upon restart
  375. # if the same consensus key was used to sign {double-sign-check-height} last blocks.
  376. # So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
  377. double-sign-check-height = {{ .Consensus.DoubleSignCheckHeight }}
  378. # Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  379. skip-timeout-commit = {{ .Consensus.SkipTimeoutCommit }}
  380. # EmptyBlocks mode and possible interval between empty blocks
  381. create-empty-blocks = {{ .Consensus.CreateEmptyBlocks }}
  382. create-empty-blocks-interval = "{{ .Consensus.CreateEmptyBlocksInterval }}"
  383. # Reactor sleep duration parameters
  384. peer-gossip-sleep-duration = "{{ .Consensus.PeerGossipSleepDuration }}"
  385. peer-query-maj23-sleep-duration = "{{ .Consensus.PeerQueryMaj23SleepDuration }}"
  386. #######################################################
  387. ### Transaction Indexer Configuration Options ###
  388. #######################################################
  389. [tx-index]
  390. # The backend database list to back the indexer.
  391. # If list contains "null" or "", meaning no indexer service will be used.
  392. #
  393. # The application will set which txs to index. In some cases a node operator will be able
  394. # to decide which txs to index based on configuration set in the application.
  395. #
  396. # Options:
  397. # 1) "null"
  398. # 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  399. # 3) "psql" - the indexer services backed by PostgreSQL.
  400. # When "kv" or "psql" is chosen "tx.height" and "tx.hash" will always be indexed.
  401. indexer = [{{ range $i, $e := .TxIndex.Indexer }}{{if $i}}, {{end}}{{ printf "%q" $e}}{{end}}]
  402. # The PostgreSQL connection configuration, the connection format:
  403. # postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
  404. psql-conn = "{{ .TxIndex.PsqlConn }}"
  405. #######################################################
  406. ### Instrumentation Configuration Options ###
  407. #######################################################
  408. [instrumentation]
  409. # When true, Prometheus metrics are served under /metrics on
  410. # PrometheusListenAddr.
  411. # Check out the documentation for the list of available metrics.
  412. prometheus = {{ .Instrumentation.Prometheus }}
  413. # Address to listen for Prometheus collector(s) connections
  414. prometheus-listen-addr = "{{ .Instrumentation.PrometheusListenAddr }}"
  415. # Maximum number of simultaneous connections.
  416. # If you want to accept a larger number than the default, make sure
  417. # you increase your OS limits.
  418. # 0 - unlimited.
  419. max-open-connections = {{ .Instrumentation.MaxOpenConnections }}
  420. # Instrumentation namespace
  421. namespace = "{{ .Instrumentation.Namespace }}"
  422. `
  423. /****** these are for test settings ***********/
  424. func ResetTestRoot(dir, testName string) (*Config, error) {
  425. return ResetTestRootWithChainID(dir, testName, "")
  426. }
  427. func ResetTestRootWithChainID(dir, testName string, chainID string) (*Config, error) {
  428. // create a unique, concurrency-safe test directory under os.TempDir()
  429. rootDir, err := os.MkdirTemp(dir, fmt.Sprintf("%s-%s_", chainID, testName))
  430. if err != nil {
  431. return nil, err
  432. }
  433. // ensure config and data subdirs are created
  434. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  435. return nil, err
  436. }
  437. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  438. return nil, err
  439. }
  440. conf := DefaultConfig()
  441. genesisFilePath := filepath.Join(rootDir, conf.Genesis)
  442. privKeyFilePath := filepath.Join(rootDir, conf.PrivValidator.Key)
  443. privStateFilePath := filepath.Join(rootDir, conf.PrivValidator.State)
  444. // Write default config file if missing.
  445. if err := writeDefaultConfigFileIfNone(rootDir); err != nil {
  446. return nil, err
  447. }
  448. if !tmos.FileExists(genesisFilePath) {
  449. if chainID == "" {
  450. chainID = "tendermint_test"
  451. }
  452. testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
  453. if err := writeFile(genesisFilePath, []byte(testGenesis), 0644); err != nil {
  454. return nil, err
  455. }
  456. }
  457. // we always overwrite the priv val
  458. if err := writeFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644); err != nil {
  459. return nil, err
  460. }
  461. if err := writeFile(privStateFilePath, []byte(testPrivValidatorState), 0644); err != nil {
  462. return nil, err
  463. }
  464. config := TestConfig().SetRoot(rootDir)
  465. config.Instrumentation.Namespace = fmt.Sprintf("%s_%s_%s", testName, chainID, tmrand.Str(16))
  466. return config, nil
  467. }
  468. func writeFile(filePath string, contents []byte, mode os.FileMode) error {
  469. if err := os.WriteFile(filePath, contents, mode); err != nil {
  470. return fmt.Errorf("failed to write file: %w", err)
  471. }
  472. return nil
  473. }
  474. var testGenesisFmt = `{
  475. "genesis_time": "2018-10-10T08:20:13.695936996Z",
  476. "chain_id": "%s",
  477. "initial_height": "1",
  478. "consensus_params": {
  479. "block": {
  480. "max_bytes": "22020096",
  481. "max_gas": "-1",
  482. "time_iota_ms": "10"
  483. },
  484. "synchrony": {
  485. "message_delay": "500000000",
  486. "precision": "10000000"
  487. },
  488. "timeout": {
  489. "propose": "30000000000",
  490. "propose_delta": "50000000",
  491. "vote": "30000000000",
  492. "vote_delta": "50000000",
  493. "commit": "10000000000",
  494. "bypass_commit_timeout": false
  495. },
  496. "evidence": {
  497. "max_age_num_blocks": "100000",
  498. "max_age_duration": "172800000000000",
  499. "max_bytes": "1048576"
  500. },
  501. "validator": {
  502. "pub_key_types": [
  503. "ed25519"
  504. ]
  505. },
  506. "version": {}
  507. },
  508. "validators": [
  509. {
  510. "pub_key": {
  511. "type": "tendermint/PubKeyEd25519",
  512. "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  513. },
  514. "power": "10",
  515. "name": ""
  516. }
  517. ],
  518. "app_hash": ""
  519. }`
  520. var testPrivValidatorKey = `{
  521. "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145",
  522. "pub_key": {
  523. "type": "tendermint/PubKeyEd25519",
  524. "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  525. },
  526. "priv_key": {
  527. "type": "tendermint/PrivKeyEd25519",
  528. "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="
  529. }
  530. }`
  531. var testPrivValidatorState = `{
  532. "height": "0",
  533. "round": 0,
  534. "step": 0
  535. }`