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.

920 lines
32 KiB

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