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.

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