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.

656 lines
22 KiB

  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "time"
  7. )
  8. const (
  9. // FuzzModeDrop is a mode in which we randomly drop reads/writes, connections or sleep
  10. FuzzModeDrop = iota
  11. // FuzzModeDelay is a mode in which we randomly sleep
  12. FuzzModeDelay
  13. )
  14. // NOTE: Most of the structs & relevant comments + the
  15. // default configuration options were used to manually
  16. // generate the config.toml. Please reflect any changes
  17. // made here in the defaultConfigTemplate constant in
  18. // config/toml.go
  19. // NOTE: tmlibs/cli must know to look in the config dir!
  20. var (
  21. DefaultTendermintDir = ".tendermint"
  22. defaultConfigDir = "config"
  23. defaultDataDir = "data"
  24. defaultConfigFileName = "config.toml"
  25. defaultGenesisJSONName = "genesis.json"
  26. defaultPrivValName = "priv_validator.json"
  27. defaultNodeKeyName = "node_key.json"
  28. defaultAddrBookName = "addrbook.json"
  29. defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName)
  30. defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName)
  31. defaultPrivValPath = filepath.Join(defaultConfigDir, defaultPrivValName)
  32. defaultNodeKeyPath = filepath.Join(defaultConfigDir, defaultNodeKeyName)
  33. defaultAddrBookPath = filepath.Join(defaultConfigDir, defaultAddrBookName)
  34. )
  35. // Config defines the top level configuration for a Tendermint node
  36. type Config struct {
  37. // Top level options use an anonymous struct
  38. BaseConfig `mapstructure:",squash"`
  39. // Options for services
  40. RPC *RPCConfig `mapstructure:"rpc"`
  41. P2P *P2PConfig `mapstructure:"p2p"`
  42. Mempool *MempoolConfig `mapstructure:"mempool"`
  43. Consensus *ConsensusConfig `mapstructure:"consensus"`
  44. TxIndex *TxIndexConfig `mapstructure:"tx_index"`
  45. Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
  46. }
  47. // DefaultConfig returns a default configuration for a Tendermint node
  48. func DefaultConfig() *Config {
  49. return &Config{
  50. BaseConfig: DefaultBaseConfig(),
  51. RPC: DefaultRPCConfig(),
  52. P2P: DefaultP2PConfig(),
  53. Mempool: DefaultMempoolConfig(),
  54. Consensus: DefaultConsensusConfig(),
  55. TxIndex: DefaultTxIndexConfig(),
  56. Instrumentation: DefaultInstrumentationConfig(),
  57. }
  58. }
  59. // TestConfig returns a configuration that can be used for testing
  60. func TestConfig() *Config {
  61. return &Config{
  62. BaseConfig: TestBaseConfig(),
  63. RPC: TestRPCConfig(),
  64. P2P: TestP2PConfig(),
  65. Mempool: TestMempoolConfig(),
  66. Consensus: TestConsensusConfig(),
  67. TxIndex: TestTxIndexConfig(),
  68. Instrumentation: TestInstrumentationConfig(),
  69. }
  70. }
  71. // SetRoot sets the RootDir for all Config structs
  72. func (cfg *Config) SetRoot(root string) *Config {
  73. cfg.BaseConfig.RootDir = root
  74. cfg.RPC.RootDir = root
  75. cfg.P2P.RootDir = root
  76. cfg.Mempool.RootDir = root
  77. cfg.Consensus.RootDir = root
  78. return cfg
  79. }
  80. //-----------------------------------------------------------------------------
  81. // BaseConfig
  82. // BaseConfig defines the base configuration for a Tendermint node
  83. type BaseConfig struct {
  84. // chainID is unexposed and immutable but here for convenience
  85. chainID string
  86. // The root directory for all data.
  87. // This should be set in viper so it can unmarshal into this struct
  88. RootDir string `mapstructure:"home"`
  89. // Path to the JSON file containing the initial validator set and other meta data
  90. Genesis string `mapstructure:"genesis_file"`
  91. // Path to the JSON file containing the private key to use as a validator in the consensus protocol
  92. PrivValidator string `mapstructure:"priv_validator_file"`
  93. // A JSON file containing the private key to use for p2p authenticated encryption
  94. NodeKey string `mapstructure:"node_key_file"`
  95. // A custom human readable name for this node
  96. Moniker string `mapstructure:"moniker"`
  97. // TCP or UNIX socket address for Tendermint to listen on for
  98. // connections from an external PrivValidator process
  99. PrivValidatorListenAddr string `mapstructure:"priv_validator_laddr"`
  100. // TCP or UNIX socket address of the ABCI application,
  101. // or the name of an ABCI application compiled in with the Tendermint binary
  102. ProxyApp string `mapstructure:"proxy_app"`
  103. // Mechanism to connect to the ABCI application: socket | grpc
  104. ABCI string `mapstructure:"abci"`
  105. // Output level for logging
  106. LogLevel string `mapstructure:"log_level"`
  107. // TCP or UNIX socket address for the profiling server to listen on
  108. ProfListenAddress string `mapstructure:"prof_laddr"`
  109. // If this node is many blocks behind the tip of the chain, FastSync
  110. // allows them to catchup quickly by downloading blocks in parallel
  111. // and verifying their commits
  112. FastSync bool `mapstructure:"fast_sync"`
  113. // If true, query the ABCI app on connecting to a new peer
  114. // so the app can decide if we should keep the connection or not
  115. FilterPeers bool `mapstructure:"filter_peers"` // false
  116. // Database backend: leveldb | memdb
  117. DBBackend string `mapstructure:"db_backend"`
  118. // Database directory
  119. DBPath string `mapstructure:"db_dir"`
  120. }
  121. // DefaultBaseConfig returns a default base configuration for a Tendermint node
  122. func DefaultBaseConfig() BaseConfig {
  123. return BaseConfig{
  124. Genesis: defaultGenesisJSONPath,
  125. PrivValidator: defaultPrivValPath,
  126. NodeKey: defaultNodeKeyPath,
  127. Moniker: defaultMoniker,
  128. ProxyApp: "tcp://127.0.0.1:26658",
  129. ABCI: "socket",
  130. LogLevel: DefaultPackageLogLevels(),
  131. ProfListenAddress: "",
  132. FastSync: true,
  133. FilterPeers: false,
  134. DBBackend: "leveldb",
  135. DBPath: "data",
  136. }
  137. }
  138. // TestBaseConfig returns a base configuration for testing a Tendermint node
  139. func TestBaseConfig() BaseConfig {
  140. cfg := DefaultBaseConfig()
  141. cfg.chainID = "tendermint_test"
  142. cfg.ProxyApp = "kvstore"
  143. cfg.FastSync = false
  144. cfg.DBBackend = "memdb"
  145. return cfg
  146. }
  147. func (cfg BaseConfig) ChainID() string {
  148. return cfg.chainID
  149. }
  150. // GenesisFile returns the full path to the genesis.json file
  151. func (cfg BaseConfig) GenesisFile() string {
  152. return rootify(cfg.Genesis, cfg.RootDir)
  153. }
  154. // PrivValidatorFile returns the full path to the priv_validator.json file
  155. func (cfg BaseConfig) PrivValidatorFile() string {
  156. return rootify(cfg.PrivValidator, cfg.RootDir)
  157. }
  158. // NodeKeyFile returns the full path to the node_key.json file
  159. func (cfg BaseConfig) NodeKeyFile() string {
  160. return rootify(cfg.NodeKey, cfg.RootDir)
  161. }
  162. // DBDir returns the full path to the database directory
  163. func (cfg BaseConfig) DBDir() string {
  164. return rootify(cfg.DBPath, cfg.RootDir)
  165. }
  166. // DefaultLogLevel returns a default log level of "error"
  167. func DefaultLogLevel() string {
  168. return "error"
  169. }
  170. // DefaultPackageLogLevels returns a default log level setting so all packages
  171. // log at "error", while the `state` and `main` packages log at "info"
  172. func DefaultPackageLogLevels() string {
  173. return fmt.Sprintf("main:info,state:info,*:%s", DefaultLogLevel())
  174. }
  175. //-----------------------------------------------------------------------------
  176. // RPCConfig
  177. // RPCConfig defines the configuration options for the Tendermint RPC server
  178. type RPCConfig struct {
  179. RootDir string `mapstructure:"home"`
  180. // TCP or UNIX socket address for the RPC server to listen on
  181. ListenAddress string `mapstructure:"laddr"`
  182. // TCP or UNIX socket address for the gRPC server to listen on
  183. // NOTE: This server only supports /broadcast_tx_commit
  184. GRPCListenAddress string `mapstructure:"grpc_laddr"`
  185. // Maximum number of simultaneous connections.
  186. // Does not include RPC (HTTP&WebSocket) connections. See max_open_connections
  187. // If you want to accept more significant number than the default, make sure
  188. // you increase your OS limits.
  189. // 0 - unlimited.
  190. GRPCMaxOpenConnections int `mapstructure:"grpc_max_open_connections"`
  191. // Activate unsafe RPC commands like /dial_persistent_peers and /unsafe_flush_mempool
  192. Unsafe bool `mapstructure:"unsafe"`
  193. // Maximum number of simultaneous connections (including WebSocket).
  194. // Does not include gRPC connections. See grpc_max_open_connections
  195. // If you want to accept more significant number than the default, make sure
  196. // you increase your OS limits.
  197. // 0 - unlimited.
  198. MaxOpenConnections int `mapstructure:"max_open_connections"`
  199. }
  200. // DefaultRPCConfig returns a default configuration for the RPC server
  201. func DefaultRPCConfig() *RPCConfig {
  202. return &RPCConfig{
  203. ListenAddress: "tcp://0.0.0.0:26657",
  204. GRPCListenAddress: "",
  205. GRPCMaxOpenConnections: 900, // no ipv4
  206. Unsafe: false,
  207. // should be < {ulimit -Sn} - {MaxNumPeers} - {N of wal, db and other open files}
  208. // 1024 - 50 - 50 = 924 = ~900
  209. MaxOpenConnections: 900,
  210. }
  211. }
  212. // TestRPCConfig returns a configuration for testing the RPC server
  213. func TestRPCConfig() *RPCConfig {
  214. cfg := DefaultRPCConfig()
  215. cfg.ListenAddress = "tcp://0.0.0.0:36657"
  216. cfg.GRPCListenAddress = "tcp://0.0.0.0:36658"
  217. cfg.Unsafe = true
  218. return cfg
  219. }
  220. //-----------------------------------------------------------------------------
  221. // P2PConfig
  222. // P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer
  223. type P2PConfig struct {
  224. RootDir string `mapstructure:"home"`
  225. // Address to listen for incoming connections
  226. ListenAddress string `mapstructure:"laddr"`
  227. // Address to advertise to peers for them to dial
  228. ExternalAddress string `mapstructure:"external_address"`
  229. // Comma separated list of seed nodes to connect to
  230. // We only use these if we can’t connect to peers in the addrbook
  231. Seeds string `mapstructure:"seeds"`
  232. // Comma separated list of nodes to keep persistent connections to
  233. PersistentPeers string `mapstructure:"persistent_peers"`
  234. // UPNP port forwarding
  235. UPNP bool `mapstructure:"upnp"`
  236. // Path to address book
  237. AddrBook string `mapstructure:"addr_book_file"`
  238. // Set true for strict address routability rules
  239. AddrBookStrict bool `mapstructure:"addr_book_strict"`
  240. // Maximum number of peers to connect to
  241. MaxNumPeers int `mapstructure:"max_num_peers"`
  242. // Time to wait before flushing messages out on the connection, in ms
  243. FlushThrottleTimeout int `mapstructure:"flush_throttle_timeout"`
  244. // Maximum size of a message packet payload, in bytes
  245. MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`
  246. // Rate at which packets can be sent, in bytes/second
  247. SendRate int64 `mapstructure:"send_rate"`
  248. // Rate at which packets can be received, in bytes/second
  249. RecvRate int64 `mapstructure:"recv_rate"`
  250. // Set true to enable the peer-exchange reactor
  251. PexReactor bool `mapstructure:"pex"`
  252. // Seed mode, in which node constantly crawls the network and looks for
  253. // peers. If another node asks it for addresses, it responds and disconnects.
  254. //
  255. // Does not work if the peer-exchange reactor is disabled.
  256. SeedMode bool `mapstructure:"seed_mode"`
  257. // Comma separated list of peer IDs to keep private (will not be gossiped to
  258. // other peers)
  259. PrivatePeerIDs string `mapstructure:"private_peer_ids"`
  260. // Toggle to disable guard against peers connecting from the same ip.
  261. AllowDuplicateIP bool `mapstructure:"allow_duplicate_ip"`
  262. // Peer connection configuration.
  263. HandshakeTimeout time.Duration `mapstructure:"handshake_timeout"`
  264. DialTimeout time.Duration `mapstructure:"dial_timeout"`
  265. // Testing params.
  266. // Force dial to fail
  267. TestDialFail bool `mapstructure:"test_dial_fail"`
  268. // FUzz connection
  269. TestFuzz bool `mapstructure:"test_fuzz"`
  270. TestFuzzConfig *FuzzConnConfig `mapstructure:"test_fuzz_config"`
  271. }
  272. // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
  273. func DefaultP2PConfig() *P2PConfig {
  274. return &P2PConfig{
  275. ListenAddress: "tcp://0.0.0.0:26656",
  276. ExternalAddress: "",
  277. UPNP: false,
  278. AddrBook: defaultAddrBookPath,
  279. AddrBookStrict: true,
  280. MaxNumPeers: 50,
  281. FlushThrottleTimeout: 100,
  282. MaxPacketMsgPayloadSize: 1024, // 1 kB
  283. SendRate: 5120000, // 5 mB/s
  284. RecvRate: 5120000, // 5 mB/s
  285. PexReactor: true,
  286. SeedMode: false,
  287. AllowDuplicateIP: true, // so non-breaking yet
  288. HandshakeTimeout: 20 * time.Second,
  289. DialTimeout: 3 * time.Second,
  290. TestDialFail: false,
  291. TestFuzz: false,
  292. TestFuzzConfig: DefaultFuzzConnConfig(),
  293. }
  294. }
  295. // TestP2PConfig returns a configuration for testing the peer-to-peer layer
  296. func TestP2PConfig() *P2PConfig {
  297. cfg := DefaultP2PConfig()
  298. cfg.ListenAddress = "tcp://0.0.0.0:36656"
  299. cfg.FlushThrottleTimeout = 10
  300. cfg.AllowDuplicateIP = true
  301. return cfg
  302. }
  303. // AddrBookFile returns the full path to the address book
  304. func (cfg *P2PConfig) AddrBookFile() string {
  305. return rootify(cfg.AddrBook, cfg.RootDir)
  306. }
  307. // FuzzConnConfig is a FuzzedConnection configuration.
  308. type FuzzConnConfig struct {
  309. Mode int
  310. MaxDelay time.Duration
  311. ProbDropRW float64
  312. ProbDropConn float64
  313. ProbSleep float64
  314. }
  315. // DefaultFuzzConnConfig returns the default config.
  316. func DefaultFuzzConnConfig() *FuzzConnConfig {
  317. return &FuzzConnConfig{
  318. Mode: FuzzModeDrop,
  319. MaxDelay: 3 * time.Second,
  320. ProbDropRW: 0.2,
  321. ProbDropConn: 0.00,
  322. ProbSleep: 0.00,
  323. }
  324. }
  325. //-----------------------------------------------------------------------------
  326. // MempoolConfig
  327. // MempoolConfig defines the configuration options for the Tendermint mempool
  328. type MempoolConfig struct {
  329. RootDir string `mapstructure:"home"`
  330. Recheck bool `mapstructure:"recheck"`
  331. RecheckEmpty bool `mapstructure:"recheck_empty"`
  332. Broadcast bool `mapstructure:"broadcast"`
  333. WalPath string `mapstructure:"wal_dir"`
  334. Size int `mapstructure:"size"`
  335. CacheSize int `mapstructure:"cache_size"`
  336. }
  337. // DefaultMempoolConfig returns a default configuration for the Tendermint mempool
  338. func DefaultMempoolConfig() *MempoolConfig {
  339. return &MempoolConfig{
  340. Recheck: true,
  341. RecheckEmpty: true,
  342. Broadcast: true,
  343. WalPath: filepath.Join(defaultDataDir, "mempool.wal"),
  344. Size: 100000,
  345. CacheSize: 100000,
  346. }
  347. }
  348. // TestMempoolConfig returns a configuration for testing the Tendermint mempool
  349. func TestMempoolConfig() *MempoolConfig {
  350. cfg := DefaultMempoolConfig()
  351. cfg.CacheSize = 1000
  352. return cfg
  353. }
  354. // WalDir returns the full path to the mempool's write-ahead log
  355. func (cfg *MempoolConfig) WalDir() string {
  356. return rootify(cfg.WalPath, cfg.RootDir)
  357. }
  358. //-----------------------------------------------------------------------------
  359. // ConsensusConfig
  360. // ConsensusConfig defines the configuration for the Tendermint consensus service,
  361. // including timeouts and details about the WAL and the block structure.
  362. type ConsensusConfig struct {
  363. RootDir string `mapstructure:"home"`
  364. WalPath string `mapstructure:"wal_file"`
  365. walFile string // overrides WalPath if set
  366. // All timeouts are in milliseconds
  367. TimeoutPropose int `mapstructure:"timeout_propose"`
  368. TimeoutProposeDelta int `mapstructure:"timeout_propose_delta"`
  369. TimeoutPrevote int `mapstructure:"timeout_prevote"`
  370. TimeoutPrevoteDelta int `mapstructure:"timeout_prevote_delta"`
  371. TimeoutPrecommit int `mapstructure:"timeout_precommit"`
  372. TimeoutPrecommitDelta int `mapstructure:"timeout_precommit_delta"`
  373. TimeoutCommit int `mapstructure:"timeout_commit"`
  374. // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  375. SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
  376. // EmptyBlocks mode and possible interval between empty blocks in seconds
  377. CreateEmptyBlocks bool `mapstructure:"create_empty_blocks"`
  378. CreateEmptyBlocksInterval int `mapstructure:"create_empty_blocks_interval"`
  379. // Reactor sleep duration parameters are in milliseconds
  380. PeerGossipSleepDuration int `mapstructure:"peer_gossip_sleep_duration"`
  381. PeerQueryMaj23SleepDuration int `mapstructure:"peer_query_maj23_sleep_duration"`
  382. }
  383. // DefaultConsensusConfig returns a default configuration for the consensus service
  384. func DefaultConsensusConfig() *ConsensusConfig {
  385. return &ConsensusConfig{
  386. WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
  387. TimeoutPropose: 3000,
  388. TimeoutProposeDelta: 500,
  389. TimeoutPrevote: 1000,
  390. TimeoutPrevoteDelta: 500,
  391. TimeoutPrecommit: 1000,
  392. TimeoutPrecommitDelta: 500,
  393. TimeoutCommit: 1000,
  394. SkipTimeoutCommit: false,
  395. CreateEmptyBlocks: true,
  396. CreateEmptyBlocksInterval: 0,
  397. PeerGossipSleepDuration: 100,
  398. PeerQueryMaj23SleepDuration: 2000,
  399. }
  400. }
  401. // TestConsensusConfig returns a configuration for testing the consensus service
  402. func TestConsensusConfig() *ConsensusConfig {
  403. cfg := DefaultConsensusConfig()
  404. cfg.TimeoutPropose = 100
  405. cfg.TimeoutProposeDelta = 1
  406. cfg.TimeoutPrevote = 10
  407. cfg.TimeoutPrevoteDelta = 1
  408. cfg.TimeoutPrecommit = 10
  409. cfg.TimeoutPrecommitDelta = 1
  410. cfg.TimeoutCommit = 10
  411. cfg.SkipTimeoutCommit = true
  412. cfg.PeerGossipSleepDuration = 5
  413. cfg.PeerQueryMaj23SleepDuration = 250
  414. return cfg
  415. }
  416. // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step
  417. func (cfg *ConsensusConfig) WaitForTxs() bool {
  418. return !cfg.CreateEmptyBlocks || cfg.CreateEmptyBlocksInterval > 0
  419. }
  420. // EmptyBlocks returns the amount of time to wait before proposing an empty block or starting the propose timer if there are no txs available
  421. func (cfg *ConsensusConfig) EmptyBlocksInterval() time.Duration {
  422. return time.Duration(cfg.CreateEmptyBlocksInterval) * time.Second
  423. }
  424. // Propose returns the amount of time to wait for a proposal
  425. func (cfg *ConsensusConfig) Propose(round int) time.Duration {
  426. return time.Duration(cfg.TimeoutPropose+cfg.TimeoutProposeDelta*round) * time.Millisecond
  427. }
  428. // Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
  429. func (cfg *ConsensusConfig) Prevote(round int) time.Duration {
  430. return time.Duration(cfg.TimeoutPrevote+cfg.TimeoutPrevoteDelta*round) * time.Millisecond
  431. }
  432. // Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
  433. func (cfg *ConsensusConfig) Precommit(round int) time.Duration {
  434. return time.Duration(cfg.TimeoutPrecommit+cfg.TimeoutPrecommitDelta*round) * time.Millisecond
  435. }
  436. // Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits for a single block (ie. a commit).
  437. func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
  438. return t.Add(time.Duration(cfg.TimeoutCommit) * time.Millisecond)
  439. }
  440. // PeerGossipSleep returns the amount of time to sleep if there is nothing to send from the ConsensusReactor
  441. func (cfg *ConsensusConfig) PeerGossipSleep() time.Duration {
  442. return time.Duration(cfg.PeerGossipSleepDuration) * time.Millisecond
  443. }
  444. // PeerQueryMaj23Sleep returns the amount of time to sleep after each VoteSetMaj23Message is sent in the ConsensusReactor
  445. func (cfg *ConsensusConfig) PeerQueryMaj23Sleep() time.Duration {
  446. return time.Duration(cfg.PeerQueryMaj23SleepDuration) * time.Millisecond
  447. }
  448. // WalFile returns the full path to the write-ahead log file
  449. func (cfg *ConsensusConfig) WalFile() string {
  450. if cfg.walFile != "" {
  451. return cfg.walFile
  452. }
  453. return rootify(cfg.WalPath, cfg.RootDir)
  454. }
  455. // SetWalFile sets the path to the write-ahead log file
  456. func (cfg *ConsensusConfig) SetWalFile(walFile string) {
  457. cfg.walFile = walFile
  458. }
  459. //-----------------------------------------------------------------------------
  460. // TxIndexConfig
  461. // TxIndexConfig defines the configuration for the transaction
  462. // indexer, including tags to index.
  463. type TxIndexConfig struct {
  464. // What indexer to use for transactions
  465. //
  466. // Options:
  467. // 1) "null"
  468. // 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  469. Indexer string `mapstructure:"indexer"`
  470. // Comma-separated list of tags to index (by default the only tag is tx hash)
  471. //
  472. // It's recommended to index only a subset of tags due to possible memory
  473. // bloat. This is, of course, depends on the indexer's DB and the volume of
  474. // transactions.
  475. IndexTags string `mapstructure:"index_tags"`
  476. // When set to true, tells indexer to index all tags. Note this may be not
  477. // desirable (see the comment above). IndexTags has a precedence over
  478. // IndexAllTags (i.e. when given both, IndexTags will be indexed).
  479. IndexAllTags bool `mapstructure:"index_all_tags"`
  480. }
  481. // DefaultTxIndexConfig returns a default configuration for the transaction indexer.
  482. func DefaultTxIndexConfig() *TxIndexConfig {
  483. return &TxIndexConfig{
  484. Indexer: "kv",
  485. IndexTags: "",
  486. IndexAllTags: false,
  487. }
  488. }
  489. // TestTxIndexConfig returns a default configuration for the transaction indexer.
  490. func TestTxIndexConfig() *TxIndexConfig {
  491. return DefaultTxIndexConfig()
  492. }
  493. //-----------------------------------------------------------------------------
  494. // InstrumentationConfig
  495. // InstrumentationConfig defines the configuration for metrics reporting.
  496. type InstrumentationConfig struct {
  497. // When true, Prometheus metrics are served under /metrics on
  498. // PrometheusListenAddr.
  499. // Check out the documentation for the list of available metrics.
  500. Prometheus bool `mapstructure:"prometheus"`
  501. // Address to listen for Prometheus collector(s) connections.
  502. PrometheusListenAddr string `mapstructure:"prometheus_listen_addr"`
  503. // Maximum number of simultaneous connections.
  504. // If you want to accept more significant number than the default, make sure
  505. // you increase your OS limits.
  506. // 0 - unlimited.
  507. MaxOpenConnections int `mapstructure:"max_open_connections"`
  508. }
  509. // DefaultInstrumentationConfig returns a default configuration for metrics
  510. // reporting.
  511. func DefaultInstrumentationConfig() *InstrumentationConfig {
  512. return &InstrumentationConfig{
  513. Prometheus: false,
  514. PrometheusListenAddr: ":26660",
  515. MaxOpenConnections: 3,
  516. }
  517. }
  518. // TestInstrumentationConfig returns a default configuration for metrics
  519. // reporting.
  520. func TestInstrumentationConfig() *InstrumentationConfig {
  521. return DefaultInstrumentationConfig()
  522. }
  523. //-----------------------------------------------------------------------------
  524. // Utils
  525. // helper function to make config creation independent of root dir
  526. func rootify(path, root string) string {
  527. if filepath.IsAbs(path) {
  528. return path
  529. }
  530. return filepath.Join(root, path)
  531. }
  532. //-----------------------------------------------------------------------------
  533. // Moniker
  534. var defaultMoniker = getDefaultMoniker()
  535. // getDefaultMoniker returns a default moniker, which is the host name. If runtime
  536. // fails to get the host name, "anonymous" will be returned.
  537. func getDefaultMoniker() string {
  538. moniker, err := os.Hostname()
  539. if err != nil {
  540. moniker = "anonymous"
  541. }
  542. return moniker
  543. }