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.

526 lines
20 KiB

blockchain: Reorg reactor (#3561) * go routines in blockchain reactor * Added reference to the go routine diagram * Initial commit * cleanup * Undo testing_logger change, committed by mistake * Fix the test loggers * pulled some fsm code into pool.go * added pool tests * changes to the design added block requests under peer moved the request trigger in the reactor poolRoutine, triggered now by a ticker in general moved everything required for making block requests smarter in the poolRoutine added a simple map of heights to keep track of what will need to be requested next added a few more tests * send errors to FSM in a different channel than blocks send errors (RemovePeer) from switch on a different channel than the one receiving blocks renamed channels added more pool tests * more pool tests * lint errors * more tests * more tests * switch fast sync to new implementation * fixed data race in tests * cleanup * finished fsm tests * address golangci comments :) * address golangci comments :) * Added timeout on next block needed to advance * updating docs and cleanup * fix issue in test from previous cleanup * cleanup * Added termination scenarios, tests and more cleanup * small fixes to adr, comments and cleanup * Fix bug in sendRequest() If we tried to send a request to a peer not present in the switch, a missing continue statement caused the request to be blackholed in a peer that was removed and never retried. While this bug was manifesting, the reactor kept asking for other blocks that would be stored and never consumed. Added the number of unconsumed blocks in the math for requesting blocks ahead of current processing height so eventually there will be no more blocks requested until the already received ones are consumed. * remove bpPeer's didTimeout field * Use distinct err codes for peer timeout and FSM timeouts * Don't allow peers to update with lower height * review comments from Ethan and Zarko * some cleanup, renaming, comments * Move block execution in separate goroutine * Remove pool's numPending * review comments * fix lint, remove old blockchain reactor and duplicates in fsm tests * small reorg around peer after review comments * add the reactor spec * verify block only once * review comments * change to int for max number of pending requests * cleanup and godoc * Add configuration flag fast sync version * golangci fixes * fix config template * move both reactor versions under blockchain * cleanup, golint, renaming stuff * updated documentation, fixed more golint warnings * integrate with behavior package * sync with master * gofmt * add changelog_pending entry * move to improvments * suggestion to changelog entry
5 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
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
blockchain: Reorg reactor (#3561) * go routines in blockchain reactor * Added reference to the go routine diagram * Initial commit * cleanup * Undo testing_logger change, committed by mistake * Fix the test loggers * pulled some fsm code into pool.go * added pool tests * changes to the design added block requests under peer moved the request trigger in the reactor poolRoutine, triggered now by a ticker in general moved everything required for making block requests smarter in the poolRoutine added a simple map of heights to keep track of what will need to be requested next added a few more tests * send errors to FSM in a different channel than blocks send errors (RemovePeer) from switch on a different channel than the one receiving blocks renamed channels added more pool tests * more pool tests * lint errors * more tests * more tests * switch fast sync to new implementation * fixed data race in tests * cleanup * finished fsm tests * address golangci comments :) * address golangci comments :) * Added timeout on next block needed to advance * updating docs and cleanup * fix issue in test from previous cleanup * cleanup * Added termination scenarios, tests and more cleanup * small fixes to adr, comments and cleanup * Fix bug in sendRequest() If we tried to send a request to a peer not present in the switch, a missing continue statement caused the request to be blackholed in a peer that was removed and never retried. While this bug was manifesting, the reactor kept asking for other blocks that would be stored and never consumed. Added the number of unconsumed blocks in the math for requesting blocks ahead of current processing height so eventually there will be no more blocks requested until the already received ones are consumed. * remove bpPeer's didTimeout field * Use distinct err codes for peer timeout and FSM timeouts * Don't allow peers to update with lower height * review comments from Ethan and Zarko * some cleanup, renaming, comments * Move block execution in separate goroutine * Remove pool's numPending * review comments * fix lint, remove old blockchain reactor and duplicates in fsm tests * small reorg around peer after review comments * add the reactor spec * verify block only once * review comments * change to int for max number of pending requests * cleanup and godoc * Add configuration flag fast sync version * golangci fixes * fix config template * move both reactor versions under blockchain * cleanup, golint, renaming stuff * updated documentation, fixed more golint warnings * integrate with behavior package * sync with master * gofmt * add changelog_pending entry * move to improvments * suggestion to changelog entry
5 years ago
blockchain: Reorg reactor (#3561) * go routines in blockchain reactor * Added reference to the go routine diagram * Initial commit * cleanup * Undo testing_logger change, committed by mistake * Fix the test loggers * pulled some fsm code into pool.go * added pool tests * changes to the design added block requests under peer moved the request trigger in the reactor poolRoutine, triggered now by a ticker in general moved everything required for making block requests smarter in the poolRoutine added a simple map of heights to keep track of what will need to be requested next added a few more tests * send errors to FSM in a different channel than blocks send errors (RemovePeer) from switch on a different channel than the one receiving blocks renamed channels added more pool tests * more pool tests * lint errors * more tests * more tests * switch fast sync to new implementation * fixed data race in tests * cleanup * finished fsm tests * address golangci comments :) * address golangci comments :) * Added timeout on next block needed to advance * updating docs and cleanup * fix issue in test from previous cleanup * cleanup * Added termination scenarios, tests and more cleanup * small fixes to adr, comments and cleanup * Fix bug in sendRequest() If we tried to send a request to a peer not present in the switch, a missing continue statement caused the request to be blackholed in a peer that was removed and never retried. While this bug was manifesting, the reactor kept asking for other blocks that would be stored and never consumed. Added the number of unconsumed blocks in the math for requesting blocks ahead of current processing height so eventually there will be no more blocks requested until the already received ones are consumed. * remove bpPeer's didTimeout field * Use distinct err codes for peer timeout and FSM timeouts * Don't allow peers to update with lower height * review comments from Ethan and Zarko * some cleanup, renaming, comments * Move block execution in separate goroutine * Remove pool's numPending * review comments * fix lint, remove old blockchain reactor and duplicates in fsm tests * small reorg around peer after review comments * add the reactor spec * verify block only once * review comments * change to int for max number of pending requests * cleanup and godoc * Add configuration flag fast sync version * golangci fixes * fix config template * move both reactor versions under blockchain * cleanup, golint, renaming stuff * updated documentation, fixed more golint warnings * integrate with behavior package * sync with master * gofmt * add changelog_pending entry * move to improvments * suggestion to changelog entry
5 years ago
  1. package config
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "path/filepath"
  7. "text/template"
  8. tmos "github.com/tendermint/tendermint/libs/os"
  9. )
  10. // DefaultDirPerm is the default permissions used when creating directories.
  11. const DefaultDirPerm = 0700
  12. var configTemplate *template.Template
  13. func init() {
  14. var err error
  15. if configTemplate, err = template.New("configFileTemplate").Parse(defaultConfigTemplate); err != nil {
  16. panic(err)
  17. }
  18. }
  19. /****** these are for production settings ***********/
  20. // EnsureRoot creates the root, config, and data directories if they don't exist,
  21. // and panics if it fails.
  22. func EnsureRoot(rootDir string) {
  23. if err := tmos.EnsureDir(rootDir, DefaultDirPerm); err != nil {
  24. panic(err.Error())
  25. }
  26. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  27. panic(err.Error())
  28. }
  29. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  30. panic(err.Error())
  31. }
  32. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  33. // Write default config file if missing.
  34. if !tmos.FileExists(configFilePath) {
  35. writeDefaultConfigFile(configFilePath)
  36. }
  37. }
  38. // XXX: this func should probably be called by cmd/tendermint/commands/init.go
  39. // alongside the writing of the genesis.json and priv_validator.json
  40. func writeDefaultConfigFile(configFilePath string) {
  41. WriteConfigFile(configFilePath, DefaultConfig())
  42. }
  43. // WriteConfigFile renders config using the template and writes it to configFilePath.
  44. func WriteConfigFile(configFilePath string, config *Config) {
  45. var buffer bytes.Buffer
  46. if err := configTemplate.Execute(&buffer, config); err != nil {
  47. panic(err)
  48. }
  49. tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
  50. }
  51. // Note: any changes to the comments/variables/mapstructure
  52. // must be reflected in the appropriate struct in config/config.go
  53. const defaultConfigTemplate = `# This is a TOML config file.
  54. # For more information, see https://github.com/toml-lang/toml
  55. # NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
  56. # relative to the home directory (e.g. "data"). The home directory is
  57. # "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
  58. # or --home cmd flag.
  59. #######################################################################
  60. ### Main Base Config Options ###
  61. #######################################################################
  62. # TCP or UNIX socket address of the ABCI application,
  63. # or the name of an ABCI application compiled in with the Tendermint binary
  64. proxy_app = "{{ .BaseConfig.ProxyApp }}"
  65. # A custom human readable name for this node
  66. moniker = "{{ .BaseConfig.Moniker }}"
  67. # If this node is many blocks behind the tip of the chain, FastSync
  68. # allows them to catchup quickly by downloading blocks in parallel
  69. # and verifying their commits
  70. fast_sync = {{ .BaseConfig.FastSyncMode }}
  71. # Database backend: goleveldb | cleveldb | boltdb | rocksdb
  72. # * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
  73. # - pure go
  74. # - stable
  75. # * cleveldb (uses levigo wrapper)
  76. # - fast
  77. # - requires gcc
  78. # - use cleveldb build tag (go build -tags cleveldb)
  79. # * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
  80. # - EXPERIMENTAL
  81. # - may be faster is some use-cases (random reads - indexer)
  82. # - use boltdb build tag (go build -tags boltdb)
  83. # * rocksdb (uses github.com/tecbot/gorocksdb)
  84. # - EXPERIMENTAL
  85. # - requires gcc
  86. # - use rocksdb build tag (go build -tags rocksdb)
  87. db_backend = "{{ .BaseConfig.DBBackend }}"
  88. # Database directory
  89. db_dir = "{{ js .BaseConfig.DBPath }}"
  90. # Output level for logging, including package level options
  91. log_level = "{{ .BaseConfig.LogLevel }}"
  92. # Output format: 'plain' (colored text) or 'json'
  93. log_format = "{{ .BaseConfig.LogFormat }}"
  94. ##### additional base config options #####
  95. # Path to the JSON file containing the initial validator set and other meta data
  96. genesis_file = "{{ js .BaseConfig.Genesis }}"
  97. # Path to the JSON file containing the private key to use as a validator in the consensus protocol
  98. priv_validator_key_file = "{{ js .BaseConfig.PrivValidatorKey }}"
  99. # Path to the JSON file containing the last sign state of a validator
  100. priv_validator_state_file = "{{ js .BaseConfig.PrivValidatorState }}"
  101. # TCP or UNIX socket address for Tendermint to listen on for
  102. # connections from an external PrivValidator process
  103. priv_validator_laddr = "{{ .BaseConfig.PrivValidatorListenAddr }}"
  104. # Path to the JSON file containing the private key to use for node authentication in the p2p protocol
  105. node_key_file = "{{ js .BaseConfig.NodeKey }}"
  106. # Mechanism to connect to the ABCI application: socket | grpc
  107. abci = "{{ .BaseConfig.ABCI }}"
  108. # TCP or UNIX socket address for the profiling server to listen on
  109. prof_laddr = "{{ .BaseConfig.ProfListenAddress }}"
  110. # If true, query the ABCI app on connecting to a new peer
  111. # so the app can decide if we should keep the connection or not
  112. filter_peers = {{ .BaseConfig.FilterPeers }}
  113. #######################################################################
  114. ### Advanced Configuration Options ###
  115. #######################################################################
  116. #######################################################
  117. ### RPC Server Configuration Options ###
  118. #######################################################
  119. [rpc]
  120. # TCP or UNIX socket address for the RPC server to listen on
  121. laddr = "{{ .RPC.ListenAddress }}"
  122. # A list of origins a cross-domain request can be executed from
  123. # Default value '[]' disables cors support
  124. # Use '["*"]' to allow any origin
  125. cors_allowed_origins = [{{ range .RPC.CORSAllowedOrigins }}{{ printf "%q, " . }}{{end}}]
  126. # A list of methods the client is allowed to use with cross-domain requests
  127. cors_allowed_methods = [{{ range .RPC.CORSAllowedMethods }}{{ printf "%q, " . }}{{end}}]
  128. # A list of non simple headers the client is allowed to use with cross-domain requests
  129. cors_allowed_headers = [{{ range .RPC.CORSAllowedHeaders }}{{ printf "%q, " . }}{{end}}]
  130. # TCP or UNIX socket address for the gRPC server to listen on
  131. # NOTE: This server only supports /broadcast_tx_commit
  132. grpc_laddr = "{{ .RPC.GRPCListenAddress }}"
  133. # Maximum number of simultaneous connections.
  134. # Does not include RPC (HTTP&WebSocket) connections. See max_open_connections
  135. # If you want to accept a larger number than the default, make sure
  136. # you increase your OS limits.
  137. # 0 - unlimited.
  138. # Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  139. # 1024 - 40 - 10 - 50 = 924 = ~900
  140. grpc_max_open_connections = {{ .RPC.GRPCMaxOpenConnections }}
  141. # Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
  142. unsafe = {{ .RPC.Unsafe }}
  143. # Maximum number of simultaneous connections (including WebSocket).
  144. # Does not include gRPC connections. See grpc_max_open_connections
  145. # If you want to accept a larger number than the default, make sure
  146. # you increase your OS limits.
  147. # 0 - unlimited.
  148. # Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  149. # 1024 - 40 - 10 - 50 = 924 = ~900
  150. max_open_connections = {{ .RPC.MaxOpenConnections }}
  151. # Maximum number of unique clientIDs that can /subscribe
  152. # If you're using /broadcast_tx_commit, set to the estimated maximum number
  153. # of broadcast_tx_commit calls per block.
  154. max_subscription_clients = {{ .RPC.MaxSubscriptionClients }}
  155. # Maximum number of unique queries a given client can /subscribe to
  156. # If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to
  157. # the estimated # maximum number of broadcast_tx_commit calls per block.
  158. max_subscriptions_per_client = {{ .RPC.MaxSubscriptionsPerClient }}
  159. # How long to wait for a tx to be committed during /broadcast_tx_commit.
  160. # WARNING: Using a value larger than 10s will result in increasing the
  161. # global HTTP write timeout, which applies to all connections and endpoints.
  162. # See https://github.com/tendermint/tendermint/issues/3435
  163. timeout_broadcast_tx_commit = "{{ .RPC.TimeoutBroadcastTxCommit }}"
  164. # Maximum size of request body, in bytes
  165. max_body_bytes = {{ .RPC.MaxBodyBytes }}
  166. # Maximum size of request header, in bytes
  167. max_header_bytes = {{ .RPC.MaxHeaderBytes }}
  168. # The path to a file containing certificate that is used to create the HTTPS server.
  169. # Migth be either absolute path or path related to tendermint's config directory.
  170. # If the certificate is signed by a certificate authority,
  171. # the certFile should be the concatenation of the server's certificate, any intermediates,
  172. # and the CA's certificate.
  173. # NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server.
  174. # Otherwise, HTTP server is run.
  175. tls_cert_file = "{{ .RPC.TLSCertFile }}"
  176. # The path to a file containing matching private key that is used to create the HTTPS server.
  177. # Migth be either absolute path or path related to tendermint's config directory.
  178. # NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server.
  179. # Otherwise, HTTP server is run.
  180. tls_key_file = "{{ .RPC.TLSKeyFile }}"
  181. #######################################################
  182. ### P2P Configuration Options ###
  183. #######################################################
  184. [p2p]
  185. # Address to listen for incoming connections
  186. laddr = "{{ .P2P.ListenAddress }}"
  187. # Address to advertise to peers for them to dial
  188. # If empty, will use the same port as the laddr,
  189. # and will introspect on the listener or use UPnP
  190. # to figure out the address.
  191. external_address = "{{ .P2P.ExternalAddress }}"
  192. # Comma separated list of seed nodes to connect to
  193. seeds = "{{ .P2P.Seeds }}"
  194. # Comma separated list of nodes to keep persistent connections to
  195. persistent_peers = "{{ .P2P.PersistentPeers }}"
  196. # UPNP port forwarding
  197. upnp = {{ .P2P.UPNP }}
  198. # Path to address book
  199. addr_book_file = "{{ js .P2P.AddrBook }}"
  200. # Set true for strict address routability rules
  201. # Set false for private or local networks
  202. addr_book_strict = {{ .P2P.AddrBookStrict }}
  203. # Maximum number of inbound peers
  204. max_num_inbound_peers = {{ .P2P.MaxNumInboundPeers }}
  205. # Maximum number of outbound peers to connect to, excluding persistent peers
  206. max_num_outbound_peers = {{ .P2P.MaxNumOutboundPeers }}
  207. # List of node IDs, to which a connection will be (re)established ignoring any existing limits
  208. unconditional_peer_ids = "{{ .P2P.UnconditionalPeerIDs }}"
  209. # Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
  210. persistent_peers_max_dial_period = "{{ .P2P.PersistentPeersMaxDialPeriod }}"
  211. # Time to wait before flushing messages out on the connection
  212. flush_throttle_timeout = "{{ .P2P.FlushThrottleTimeout }}"
  213. # Maximum size of a message packet payload, in bytes
  214. max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }}
  215. # Rate at which packets can be sent, in bytes/second
  216. send_rate = {{ .P2P.SendRate }}
  217. # Rate at which packets can be received, in bytes/second
  218. recv_rate = {{ .P2P.RecvRate }}
  219. # Set true to enable the peer-exchange reactor
  220. pex = {{ .P2P.PexReactor }}
  221. # Seed mode, in which node constantly crawls the network and looks for
  222. # peers. If another node asks it for addresses, it responds and disconnects.
  223. #
  224. # Does not work if the peer-exchange reactor is disabled.
  225. seed_mode = {{ .P2P.SeedMode }}
  226. # Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
  227. private_peer_ids = "{{ .P2P.PrivatePeerIDs }}"
  228. # Toggle to disable guard against peers connecting from the same ip.
  229. allow_duplicate_ip = {{ .P2P.AllowDuplicateIP }}
  230. # Peer connection configuration.
  231. handshake_timeout = "{{ .P2P.HandshakeTimeout }}"
  232. dial_timeout = "{{ .P2P.DialTimeout }}"
  233. #######################################################
  234. ### Mempool Configurattion Option ###
  235. #######################################################
  236. [mempool]
  237. recheck = {{ .Mempool.Recheck }}
  238. broadcast = {{ .Mempool.Broadcast }}
  239. wal_dir = "{{ js .Mempool.WalPath }}"
  240. # Maximum number of transactions in the mempool
  241. size = {{ .Mempool.Size }}
  242. # Limit the total size of all txs in the mempool.
  243. # This only accounts for raw transactions (e.g. given 1MB transactions and
  244. # max_txs_bytes=5MB, mempool will only accept 5 transactions).
  245. max_txs_bytes = {{ .Mempool.MaxTxsBytes }}
  246. # Size of the cache (used to filter transactions we saw earlier) in transactions
  247. cache_size = {{ .Mempool.CacheSize }}
  248. # Maximum size of a single transaction.
  249. # NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}.
  250. max_tx_bytes = {{ .Mempool.MaxTxBytes }}
  251. #######################################################
  252. ### State Sync Configuration Options ###
  253. #######################################################
  254. [statesync]
  255. # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
  256. # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
  257. # the network to take and serve state machine snapshots. State sync is not attempted if the node
  258. # has any local state (LastBlockHeight > 0). The node will have a truncated block history,
  259. # starting from the height of the snapshot.
  260. enable = {{ .StateSync.Enable }}
  261. # RPC servers (comma-separated) for light client verification of the synced state machine and
  262. # retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding
  263. # header hash obtained from a trusted source, and a period during which validators can be trusted.
  264. #
  265. # For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2
  266. # weeks) during which they can be financially punished (slashed) for misbehavior.
  267. rpc_servers = ""
  268. trust_height = {{ .StateSync.TrustHeight }}
  269. trust_hash = "{{ .StateSync.TrustHash }}"
  270. trust_period = "{{ .StateSync.TrustPeriod }}"
  271. # Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp).
  272. # Will create a new, randomly named directory within, and remove it when done.
  273. temp_dir = "{{ .StateSync.TempDir }}"
  274. #######################################################
  275. ### Fast Sync Configuration Connections ###
  276. #######################################################
  277. [fastsync]
  278. # Fast Sync version to use:
  279. # 1) "v0" (default) - the legacy fast sync implementation
  280. # 2) "v1" - refactor of v0 version for better testability
  281. # 2) "v2" - complete redesign of v0, optimized for testability & readability
  282. version = "{{ .FastSync.Version }}"
  283. #######################################################
  284. ### Consensus Configuration Options ###
  285. #######################################################
  286. [consensus]
  287. wal_file = "{{ js .Consensus.WalPath }}"
  288. timeout_propose = "{{ .Consensus.TimeoutPropose }}"
  289. timeout_propose_delta = "{{ .Consensus.TimeoutProposeDelta }}"
  290. timeout_prevote = "{{ .Consensus.TimeoutPrevote }}"
  291. timeout_prevote_delta = "{{ .Consensus.TimeoutPrevoteDelta }}"
  292. timeout_precommit = "{{ .Consensus.TimeoutPrecommit }}"
  293. timeout_precommit_delta = "{{ .Consensus.TimeoutPrecommitDelta }}"
  294. timeout_commit = "{{ .Consensus.TimeoutCommit }}"
  295. # Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  296. skip_timeout_commit = {{ .Consensus.SkipTimeoutCommit }}
  297. # EmptyBlocks mode and possible interval between empty blocks
  298. create_empty_blocks = {{ .Consensus.CreateEmptyBlocks }}
  299. create_empty_blocks_interval = "{{ .Consensus.CreateEmptyBlocksInterval }}"
  300. # Reactor sleep duration parameters
  301. peer_gossip_sleep_duration = "{{ .Consensus.PeerGossipSleepDuration }}"
  302. peer_query_maj23_sleep_duration = "{{ .Consensus.PeerQueryMaj23SleepDuration }}"
  303. #######################################################
  304. ### Transaction Indexer Configuration Options ###
  305. #######################################################
  306. [tx_index]
  307. # What indexer to use for transactions
  308. #
  309. # Options:
  310. # 1) "null"
  311. # 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  312. indexer = "{{ .TxIndex.Indexer }}"
  313. # Comma-separated list of compositeKeys to index (by default the only key is "tx.hash")
  314. # Remember that Event has the following structure: type.key
  315. # type: [
  316. # key: value,
  317. # ...
  318. # ]
  319. #
  320. # You can also index transactions by height by adding "tx.height" key here.
  321. #
  322. # It's recommended to index only a subset of keys due to possible memory
  323. # bloat. This is, of course, depends on the indexer's DB and the volume of
  324. # transactions.
  325. index_keys = "{{ .TxIndex.IndexKeys }}"
  326. # When set to true, tells indexer to index all compositeKeys (predefined keys:
  327. # "tx.hash", "tx.height" and all keys from DeliverTx responses).
  328. #
  329. # Note this may be not desirable (see the comment above). IndexKeys has a
  330. # precedence over IndexAllKeys (i.e. when given both, IndexKeys will be
  331. # indexed).
  332. index_all_keys = {{ .TxIndex.IndexAllKeys }}
  333. #######################################################
  334. ### Instrumentation Configuration Options ###
  335. #######################################################
  336. [instrumentation]
  337. # When true, Prometheus metrics are served under /metrics on
  338. # PrometheusListenAddr.
  339. # Check out the documentation for the list of available metrics.
  340. prometheus = {{ .Instrumentation.Prometheus }}
  341. # Address to listen for Prometheus collector(s) connections
  342. prometheus_listen_addr = "{{ .Instrumentation.PrometheusListenAddr }}"
  343. # Maximum number of simultaneous connections.
  344. # If you want to accept a larger number than the default, make sure
  345. # you increase your OS limits.
  346. # 0 - unlimited.
  347. max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
  348. # Instrumentation namespace
  349. namespace = "{{ .Instrumentation.Namespace }}"
  350. `
  351. /****** these are for test settings ***********/
  352. func ResetTestRoot(testName string) *Config {
  353. return ResetTestRootWithChainID(testName, "")
  354. }
  355. func ResetTestRootWithChainID(testName string, chainID string) *Config {
  356. // create a unique, concurrency-safe test directory under os.TempDir()
  357. rootDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s_", chainID, testName))
  358. if err != nil {
  359. panic(err)
  360. }
  361. // ensure config and data subdirs are created
  362. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  363. panic(err)
  364. }
  365. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  366. panic(err)
  367. }
  368. baseConfig := DefaultBaseConfig()
  369. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  370. genesisFilePath := filepath.Join(rootDir, baseConfig.Genesis)
  371. privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey)
  372. privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState)
  373. // Write default config file if missing.
  374. if !tmos.FileExists(configFilePath) {
  375. writeDefaultConfigFile(configFilePath)
  376. }
  377. if !tmos.FileExists(genesisFilePath) {
  378. if chainID == "" {
  379. chainID = "tendermint_test"
  380. }
  381. testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
  382. tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
  383. }
  384. // we always overwrite the priv val
  385. tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
  386. tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
  387. config := TestConfig().SetRoot(rootDir)
  388. return config
  389. }
  390. var testGenesisFmt = `{
  391. "genesis_time": "2018-10-10T08:20:13.695936996Z",
  392. "chain_id": "%s",
  393. "validators": [
  394. {
  395. "pub_key": {
  396. "type": "tendermint/PubKeyEd25519",
  397. "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  398. },
  399. "power": "10",
  400. "name": ""
  401. }
  402. ],
  403. "app_hash": ""
  404. }`
  405. var testPrivValidatorKey = `{
  406. "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145",
  407. "pub_key": {
  408. "type": "tendermint/PubKeyEd25519",
  409. "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  410. },
  411. "priv_key": {
  412. "type": "tendermint/PrivKeyEd25519",
  413. "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="
  414. }
  415. }`
  416. var testPrivValidatorState = `{
  417. "height": "0",
  418. "round": 0,
  419. "step": 0
  420. }`