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.

679 lines
23 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. // TCP or UNIX socket address of the ABCI application,
  90. // or the name of an ABCI application compiled in with the Tendermint binary
  91. ProxyApp string `mapstructure:"proxy_app"`
  92. // A custom human readable name for this node
  93. Moniker string `mapstructure:"moniker"`
  94. // If this node is many blocks behind the tip of the chain, FastSync
  95. // allows them to catchup quickly by downloading blocks in parallel
  96. // and verifying their commits
  97. FastSync bool `mapstructure:"fast_sync"`
  98. // Database backend: leveldb | memdb
  99. DBBackend string `mapstructure:"db_backend"`
  100. // Database directory
  101. DBPath string `mapstructure:"db_dir"`
  102. // Output level for logging
  103. LogLevel string `mapstructure:"log_level"`
  104. // Path to the JSON file containing the initial validator set and other meta data
  105. Genesis string `mapstructure:"genesis_file"`
  106. // Path to the JSON file containing the private key to use as a validator in the consensus protocol
  107. PrivValidator string `mapstructure:"priv_validator_file"`
  108. // TCP or UNIX socket address for Tendermint to listen on for
  109. // connections from an external PrivValidator process
  110. PrivValidatorListenAddr string `mapstructure:"priv_validator_laddr"`
  111. // A JSON file containing the private key to use for p2p authenticated encryption
  112. NodeKey string `mapstructure:"node_key_file"`
  113. // Mechanism to connect to the ABCI application: socket | grpc
  114. ABCI string `mapstructure:"abci"`
  115. // TCP or UNIX socket address for the profiling server to listen on
  116. ProfListenAddress string `mapstructure:"prof_laddr"`
  117. // If true, query the ABCI app on connecting to a new peer
  118. // so the app can decide if we should keep the connection or not
  119. FilterPeers bool `mapstructure:"filter_peers"` // false
  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. // Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  199. // 1024 - 40 - 10 - 50 = 924 = ~900
  200. MaxOpenConnections int `mapstructure:"max_open_connections"`
  201. }
  202. // DefaultRPCConfig returns a default configuration for the RPC server
  203. func DefaultRPCConfig() *RPCConfig {
  204. return &RPCConfig{
  205. ListenAddress: "tcp://0.0.0.0:26657",
  206. GRPCListenAddress: "",
  207. GRPCMaxOpenConnections: 900,
  208. Unsafe: false,
  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. // Set false for private or local networks
  240. AddrBookStrict bool `mapstructure:"addr_book_strict"`
  241. // Maximum number of inbound peers
  242. MaxNumInboundPeers int `mapstructure:"max_num_inbound_peers"`
  243. // Maximum number of outbound peers to connect to, excluding persistent peers
  244. MaxNumOutboundPeers int `mapstructure:"max_num_outbound_peers"`
  245. // Time to wait before flushing messages out on the connection, in ms
  246. FlushThrottleTimeout int `mapstructure:"flush_throttle_timeout"`
  247. // Maximum size of a message packet payload, in bytes
  248. MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`
  249. // Rate at which packets can be sent, in bytes/second
  250. SendRate int64 `mapstructure:"send_rate"`
  251. // Rate at which packets can be received, in bytes/second
  252. RecvRate int64 `mapstructure:"recv_rate"`
  253. // Set true to enable the peer-exchange reactor
  254. PexReactor bool `mapstructure:"pex"`
  255. // Seed mode, in which node constantly crawls the network and looks for
  256. // peers. If another node asks it for addresses, it responds and disconnects.
  257. //
  258. // Does not work if the peer-exchange reactor is disabled.
  259. SeedMode bool `mapstructure:"seed_mode"`
  260. // Comma separated list of peer IDs to keep private (will not be gossiped to
  261. // other peers)
  262. PrivatePeerIDs string `mapstructure:"private_peer_ids"`
  263. // Toggle to disable guard against peers connecting from the same ip.
  264. AllowDuplicateIP bool `mapstructure:"allow_duplicate_ip"`
  265. // Peer connection configuration.
  266. HandshakeTimeout time.Duration `mapstructure:"handshake_timeout"`
  267. DialTimeout time.Duration `mapstructure:"dial_timeout"`
  268. // Testing params.
  269. // Force dial to fail
  270. TestDialFail bool `mapstructure:"test_dial_fail"`
  271. // FUzz connection
  272. TestFuzz bool `mapstructure:"test_fuzz"`
  273. TestFuzzConfig *FuzzConnConfig `mapstructure:"test_fuzz_config"`
  274. }
  275. // DefaultP2PConfig returns a default configuration for the peer-to-peer layer
  276. func DefaultP2PConfig() *P2PConfig {
  277. return &P2PConfig{
  278. ListenAddress: "tcp://0.0.0.0:26656",
  279. ExternalAddress: "",
  280. UPNP: false,
  281. AddrBook: defaultAddrBookPath,
  282. AddrBookStrict: true,
  283. MaxNumInboundPeers: 40,
  284. MaxNumOutboundPeers: 10,
  285. FlushThrottleTimeout: 100,
  286. MaxPacketMsgPayloadSize: 1024, // 1 kB
  287. SendRate: 5120000, // 5 mB/s
  288. RecvRate: 5120000, // 5 mB/s
  289. PexReactor: true,
  290. SeedMode: false,
  291. AllowDuplicateIP: true, // so non-breaking yet
  292. HandshakeTimeout: 20 * time.Second,
  293. DialTimeout: 3 * time.Second,
  294. TestDialFail: false,
  295. TestFuzz: false,
  296. TestFuzzConfig: DefaultFuzzConnConfig(),
  297. }
  298. }
  299. // TestP2PConfig returns a configuration for testing the peer-to-peer layer
  300. func TestP2PConfig() *P2PConfig {
  301. cfg := DefaultP2PConfig()
  302. cfg.ListenAddress = "tcp://0.0.0.0:36656"
  303. cfg.FlushThrottleTimeout = 10
  304. cfg.AllowDuplicateIP = true
  305. return cfg
  306. }
  307. // AddrBookFile returns the full path to the address book
  308. func (cfg *P2PConfig) AddrBookFile() string {
  309. return rootify(cfg.AddrBook, cfg.RootDir)
  310. }
  311. // FuzzConnConfig is a FuzzedConnection configuration.
  312. type FuzzConnConfig struct {
  313. Mode int
  314. MaxDelay time.Duration
  315. ProbDropRW float64
  316. ProbDropConn float64
  317. ProbSleep float64
  318. }
  319. // DefaultFuzzConnConfig returns the default config.
  320. func DefaultFuzzConnConfig() *FuzzConnConfig {
  321. return &FuzzConnConfig{
  322. Mode: FuzzModeDrop,
  323. MaxDelay: 3 * time.Second,
  324. ProbDropRW: 0.2,
  325. ProbDropConn: 0.00,
  326. ProbSleep: 0.00,
  327. }
  328. }
  329. //-----------------------------------------------------------------------------
  330. // MempoolConfig
  331. // MempoolConfig defines the configuration options for the Tendermint mempool
  332. type MempoolConfig struct {
  333. RootDir string `mapstructure:"home"`
  334. Recheck bool `mapstructure:"recheck"`
  335. RecheckEmpty bool `mapstructure:"recheck_empty"`
  336. Broadcast bool `mapstructure:"broadcast"`
  337. WalPath string `mapstructure:"wal_dir"`
  338. Size int `mapstructure:"size"`
  339. CacheSize int `mapstructure:"cache_size"`
  340. }
  341. // DefaultMempoolConfig returns a default configuration for the Tendermint mempool
  342. func DefaultMempoolConfig() *MempoolConfig {
  343. return &MempoolConfig{
  344. Recheck: true,
  345. RecheckEmpty: true,
  346. Broadcast: true,
  347. WalPath: filepath.Join(defaultDataDir, "mempool.wal"),
  348. // Each signature verification takes .5ms, size reduced until we implement
  349. // ABCI Recheck
  350. Size: 5000,
  351. CacheSize: 10000,
  352. }
  353. }
  354. // TestMempoolConfig returns a configuration for testing the Tendermint mempool
  355. func TestMempoolConfig() *MempoolConfig {
  356. cfg := DefaultMempoolConfig()
  357. cfg.CacheSize = 1000
  358. return cfg
  359. }
  360. // WalDir returns the full path to the mempool's write-ahead log
  361. func (cfg *MempoolConfig) WalDir() string {
  362. return rootify(cfg.WalPath, cfg.RootDir)
  363. }
  364. //-----------------------------------------------------------------------------
  365. // ConsensusConfig
  366. // ConsensusConfig defines the configuration for the Tendermint consensus service,
  367. // including timeouts and details about the WAL and the block structure.
  368. type ConsensusConfig struct {
  369. RootDir string `mapstructure:"home"`
  370. WalPath string `mapstructure:"wal_file"`
  371. walFile string // overrides WalPath if set
  372. // All timeouts are in milliseconds
  373. TimeoutPropose int `mapstructure:"timeout_propose"`
  374. TimeoutProposeDelta int `mapstructure:"timeout_propose_delta"`
  375. TimeoutPrevote int `mapstructure:"timeout_prevote"`
  376. TimeoutPrevoteDelta int `mapstructure:"timeout_prevote_delta"`
  377. TimeoutPrecommit int `mapstructure:"timeout_precommit"`
  378. TimeoutPrecommitDelta int `mapstructure:"timeout_precommit_delta"`
  379. TimeoutCommit int `mapstructure:"timeout_commit"`
  380. // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  381. SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
  382. // EmptyBlocks mode and possible interval between empty blocks in seconds
  383. CreateEmptyBlocks bool `mapstructure:"create_empty_blocks"`
  384. CreateEmptyBlocksInterval int `mapstructure:"create_empty_blocks_interval"`
  385. // Reactor sleep duration parameters are in milliseconds
  386. PeerGossipSleepDuration int `mapstructure:"peer_gossip_sleep_duration"`
  387. PeerQueryMaj23SleepDuration int `mapstructure:"peer_query_maj23_sleep_duration"`
  388. // Block time parameters in milliseconds. Corresponds to the minimum time increment between consecutive blocks.
  389. BlockTimeIota int `mapstructure:"blocktime_iota"`
  390. }
  391. // DefaultConsensusConfig returns a default configuration for the consensus service
  392. func DefaultConsensusConfig() *ConsensusConfig {
  393. return &ConsensusConfig{
  394. WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
  395. TimeoutPropose: 3000,
  396. TimeoutProposeDelta: 500,
  397. TimeoutPrevote: 1000,
  398. TimeoutPrevoteDelta: 500,
  399. TimeoutPrecommit: 1000,
  400. TimeoutPrecommitDelta: 500,
  401. TimeoutCommit: 1000,
  402. SkipTimeoutCommit: false,
  403. CreateEmptyBlocks: true,
  404. CreateEmptyBlocksInterval: 0,
  405. PeerGossipSleepDuration: 100,
  406. PeerQueryMaj23SleepDuration: 2000,
  407. BlockTimeIota: 1000,
  408. }
  409. }
  410. // TestConsensusConfig returns a configuration for testing the consensus service
  411. func TestConsensusConfig() *ConsensusConfig {
  412. cfg := DefaultConsensusConfig()
  413. cfg.TimeoutPropose = 100
  414. cfg.TimeoutProposeDelta = 1
  415. cfg.TimeoutPrevote = 10
  416. cfg.TimeoutPrevoteDelta = 1
  417. cfg.TimeoutPrecommit = 10
  418. cfg.TimeoutPrecommitDelta = 1
  419. cfg.TimeoutCommit = 10
  420. cfg.SkipTimeoutCommit = true
  421. cfg.PeerGossipSleepDuration = 5
  422. cfg.PeerQueryMaj23SleepDuration = 250
  423. cfg.BlockTimeIota = 10
  424. return cfg
  425. }
  426. // MinValidVoteTime returns the minimum acceptable block time.
  427. // See the [BFT time spec](https://godoc.org/github.com/tendermint/tendermint/docs/spec/consensus/bft-time.md).
  428. func (cfg *ConsensusConfig) MinValidVoteTime(lastBlockTime time.Time) time.Time {
  429. return lastBlockTime.
  430. Add(time.Duration(cfg.BlockTimeIota) * time.Millisecond)
  431. }
  432. // WaitForTxs returns true if the consensus should wait for transactions before entering the propose step
  433. func (cfg *ConsensusConfig) WaitForTxs() bool {
  434. return !cfg.CreateEmptyBlocks || cfg.CreateEmptyBlocksInterval > 0
  435. }
  436. // EmptyBlocks returns the amount of time to wait before proposing an empty block or starting the propose timer if there are no txs available
  437. func (cfg *ConsensusConfig) EmptyBlocksInterval() time.Duration {
  438. return time.Duration(cfg.CreateEmptyBlocksInterval) * time.Second
  439. }
  440. // Propose returns the amount of time to wait for a proposal
  441. func (cfg *ConsensusConfig) Propose(round int) time.Duration {
  442. return time.Duration(cfg.TimeoutPropose+cfg.TimeoutProposeDelta*round) * time.Millisecond
  443. }
  444. // Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
  445. func (cfg *ConsensusConfig) Prevote(round int) time.Duration {
  446. return time.Duration(cfg.TimeoutPrevote+cfg.TimeoutPrevoteDelta*round) * time.Millisecond
  447. }
  448. // Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
  449. func (cfg *ConsensusConfig) Precommit(round int) time.Duration {
  450. return time.Duration(cfg.TimeoutPrecommit+cfg.TimeoutPrecommitDelta*round) * time.Millisecond
  451. }
  452. // Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits for a single block (ie. a commit).
  453. func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
  454. return t.Add(time.Duration(cfg.TimeoutCommit) * time.Millisecond)
  455. }
  456. // PeerGossipSleep returns the amount of time to sleep if there is nothing to send from the ConsensusReactor
  457. func (cfg *ConsensusConfig) PeerGossipSleep() time.Duration {
  458. return time.Duration(cfg.PeerGossipSleepDuration) * time.Millisecond
  459. }
  460. // PeerQueryMaj23Sleep returns the amount of time to sleep after each VoteSetMaj23Message is sent in the ConsensusReactor
  461. func (cfg *ConsensusConfig) PeerQueryMaj23Sleep() time.Duration {
  462. return time.Duration(cfg.PeerQueryMaj23SleepDuration) * time.Millisecond
  463. }
  464. // WalFile returns the full path to the write-ahead log file
  465. func (cfg *ConsensusConfig) WalFile() string {
  466. if cfg.walFile != "" {
  467. return cfg.walFile
  468. }
  469. return rootify(cfg.WalPath, cfg.RootDir)
  470. }
  471. // SetWalFile sets the path to the write-ahead log file
  472. func (cfg *ConsensusConfig) SetWalFile(walFile string) {
  473. cfg.walFile = walFile
  474. }
  475. //-----------------------------------------------------------------------------
  476. // TxIndexConfig
  477. // TxIndexConfig defines the configuration for the transaction indexer,
  478. // including tags to index.
  479. type TxIndexConfig struct {
  480. // What indexer to use for transactions
  481. //
  482. // Options:
  483. // 1) "null"
  484. // 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  485. Indexer string `mapstructure:"indexer"`
  486. // Comma-separated list of tags to index (by default the only tag is "tx.hash")
  487. //
  488. // You can also index transactions by height by adding "tx.height" tag here.
  489. //
  490. // It's recommended to index only a subset of tags due to possible memory
  491. // bloat. This is, of course, depends on the indexer's DB and the volume of
  492. // transactions.
  493. IndexTags string `mapstructure:"index_tags"`
  494. // When set to true, tells indexer to index all tags (predefined tags:
  495. // "tx.hash", "tx.height" and all tags from DeliverTx responses).
  496. //
  497. // Note this may be not desirable (see the comment above). IndexTags has a
  498. // precedence over IndexAllTags (i.e. when given both, IndexTags will be
  499. // indexed).
  500. IndexAllTags bool `mapstructure:"index_all_tags"`
  501. }
  502. // DefaultTxIndexConfig returns a default configuration for the transaction indexer.
  503. func DefaultTxIndexConfig() *TxIndexConfig {
  504. return &TxIndexConfig{
  505. Indexer: "kv",
  506. IndexTags: "",
  507. IndexAllTags: false,
  508. }
  509. }
  510. // TestTxIndexConfig returns a default configuration for the transaction indexer.
  511. func TestTxIndexConfig() *TxIndexConfig {
  512. return DefaultTxIndexConfig()
  513. }
  514. //-----------------------------------------------------------------------------
  515. // InstrumentationConfig
  516. // InstrumentationConfig defines the configuration for metrics reporting.
  517. type InstrumentationConfig struct {
  518. // When true, Prometheus metrics are served under /metrics on
  519. // PrometheusListenAddr.
  520. // Check out the documentation for the list of available metrics.
  521. Prometheus bool `mapstructure:"prometheus"`
  522. // Address to listen for Prometheus collector(s) connections.
  523. PrometheusListenAddr string `mapstructure:"prometheus_listen_addr"`
  524. // Maximum number of simultaneous connections.
  525. // If you want to accept more significant number than the default, make sure
  526. // you increase your OS limits.
  527. // 0 - unlimited.
  528. MaxOpenConnections int `mapstructure:"max_open_connections"`
  529. }
  530. // DefaultInstrumentationConfig returns a default configuration for metrics
  531. // reporting.
  532. func DefaultInstrumentationConfig() *InstrumentationConfig {
  533. return &InstrumentationConfig{
  534. Prometheus: false,
  535. PrometheusListenAddr: ":26660",
  536. MaxOpenConnections: 3,
  537. }
  538. }
  539. // TestInstrumentationConfig returns a default configuration for metrics
  540. // reporting.
  541. func TestInstrumentationConfig() *InstrumentationConfig {
  542. return DefaultInstrumentationConfig()
  543. }
  544. //-----------------------------------------------------------------------------
  545. // Utils
  546. // helper function to make config creation independent of root dir
  547. func rootify(path, root string) string {
  548. if filepath.IsAbs(path) {
  549. return path
  550. }
  551. return filepath.Join(root, path)
  552. }
  553. //-----------------------------------------------------------------------------
  554. // Moniker
  555. var defaultMoniker = getDefaultMoniker()
  556. // getDefaultMoniker returns a default moniker, which is the host name. If runtime
  557. // fails to get the host name, "anonymous" will be returned.
  558. func getDefaultMoniker() string {
  559. moniker, err := os.Hostname()
  560. if err != nil {
  561. moniker = "anonymous"
  562. }
  563. return moniker
  564. }