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.

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