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.

556 lines
21 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. "strings"
  8. "text/template"
  9. tmos "github.com/tendermint/tendermint/libs/os"
  10. )
  11. // DefaultDirPerm is the default permissions used when creating directories.
  12. const DefaultDirPerm = 0700
  13. var configTemplate *template.Template
  14. func init() {
  15. var err error
  16. tmpl := template.New("configFileTemplate").Funcs(template.FuncMap{
  17. "StringsJoin": strings.Join,
  18. })
  19. if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
  20. panic(err)
  21. }
  22. }
  23. /****** these are for production settings ***********/
  24. // EnsureRoot creates the root, config, and data directories if they don't exist,
  25. // and panics if it fails.
  26. func EnsureRoot(rootDir string) {
  27. if err := tmos.EnsureDir(rootDir, DefaultDirPerm); err != nil {
  28. panic(err.Error())
  29. }
  30. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  31. panic(err.Error())
  32. }
  33. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  34. panic(err.Error())
  35. }
  36. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  37. // Write default config file if missing.
  38. if !tmos.FileExists(configFilePath) {
  39. writeDefaultConfigFile(configFilePath)
  40. }
  41. }
  42. // XXX: this func should probably be called by cmd/tendermint/commands/init.go
  43. // alongside the writing of the genesis.json and priv_validator.json
  44. func writeDefaultConfigFile(configFilePath string) {
  45. WriteConfigFile(configFilePath, DefaultConfig())
  46. }
  47. // WriteConfigFile renders config using the template and writes it to configFilePath.
  48. func WriteConfigFile(configFilePath string, config *Config) {
  49. var buffer bytes.Buffer
  50. if err := configTemplate.Execute(&buffer, config); err != nil {
  51. panic(err)
  52. }
  53. tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
  54. }
  55. // Note: any changes to the comments/variables/mapstructure
  56. // must be reflected in the appropriate struct in config/config.go
  57. const defaultConfigTemplate = `# This is a TOML config file.
  58. # For more information, see https://github.com/toml-lang/toml
  59. # NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
  60. # relative to the home directory (e.g. "data"). The home directory is
  61. # "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
  62. # or --home cmd flag.
  63. #######################################################################
  64. ### Main Base Config Options ###
  65. #######################################################################
  66. # TCP or UNIX socket address of the ABCI application,
  67. # or the name of an ABCI application compiled in with the Tendermint binary
  68. proxy_app = "{{ .BaseConfig.ProxyApp }}"
  69. # A custom human readable name for this node
  70. moniker = "{{ .BaseConfig.Moniker }}"
  71. # If this node is many blocks behind the tip of the chain, FastSync
  72. # allows them to catchup quickly by downloading blocks in parallel
  73. # and verifying their commits
  74. fast_sync = {{ .BaseConfig.FastSyncMode }}
  75. # Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb
  76. # * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
  77. # - pure go
  78. # - stable
  79. # * cleveldb (uses levigo wrapper)
  80. # - fast
  81. # - requires gcc
  82. # - use cleveldb build tag (go build -tags cleveldb)
  83. # * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
  84. # - EXPERIMENTAL
  85. # - may be faster is some use-cases (random reads - indexer)
  86. # - use boltdb build tag (go build -tags boltdb)
  87. # * rocksdb (uses github.com/tecbot/gorocksdb)
  88. # - EXPERIMENTAL
  89. # - requires gcc
  90. # - use rocksdb build tag (go build -tags rocksdb)
  91. # * badgerdb (uses github.com/dgraph-io/badger)
  92. # - EXPERIMENTAL
  93. # - use badgerdb build tag (go build -tags badgerdb)
  94. db_backend = "{{ .BaseConfig.DBBackend }}"
  95. # Database directory
  96. db_dir = "{{ js .BaseConfig.DBPath }}"
  97. # Output level for logging, including package level options
  98. log_level = "{{ .BaseConfig.LogLevel }}"
  99. # Output format: 'plain' (colored text) or 'json'
  100. log_format = "{{ .BaseConfig.LogFormat }}"
  101. ##### additional base config options #####
  102. # Path to the JSON file containing the initial validator set and other meta data
  103. genesis_file = "{{ js .BaseConfig.Genesis }}"
  104. # Path to the JSON file containing the private key to use as a validator in the consensus protocol
  105. priv_validator_key_file = "{{ js .BaseConfig.PrivValidatorKey }}"
  106. # Path to the JSON file containing the last sign state of a validator
  107. priv_validator_state_file = "{{ js .BaseConfig.PrivValidatorState }}"
  108. # TCP or UNIX socket address for Tendermint to listen on for
  109. # connections from an external PrivValidator process
  110. priv_validator_laddr = "{{ .BaseConfig.PrivValidatorListenAddr }}"
  111. # Path to the JSON file containing the private key to use for node authentication in the p2p protocol
  112. node_key_file = "{{ js .BaseConfig.NodeKey }}"
  113. # Mechanism to connect to the ABCI application: socket | grpc
  114. abci = "{{ .BaseConfig.ABCI }}"
  115. # If true, query the ABCI app on connecting to a new peer
  116. # so the app can decide if we should keep the connection or not
  117. filter_peers = {{ .BaseConfig.FilterPeers }}
  118. #######################################################################
  119. ### Advanced Configuration Options ###
  120. #######################################################################
  121. #######################################################
  122. ### RPC Server Configuration Options ###
  123. #######################################################
  124. [rpc]
  125. # TCP or UNIX socket address for the RPC server to listen on
  126. laddr = "{{ .RPC.ListenAddress }}"
  127. # A list of origins a cross-domain request can be executed from
  128. # Default value '[]' disables cors support
  129. # Use '["*"]' to allow any origin
  130. cors_allowed_origins = [{{ range .RPC.CORSAllowedOrigins }}{{ printf "%q, " . }}{{end}}]
  131. # A list of methods the client is allowed to use with cross-domain requests
  132. cors_allowed_methods = [{{ range .RPC.CORSAllowedMethods }}{{ printf "%q, " . }}{{end}}]
  133. # A list of non simple headers the client is allowed to use with cross-domain requests
  134. cors_allowed_headers = [{{ range .RPC.CORSAllowedHeaders }}{{ printf "%q, " . }}{{end}}]
  135. # TCP or UNIX socket address for the gRPC server to listen on
  136. # NOTE: This server only supports /broadcast_tx_commit
  137. grpc_laddr = "{{ .RPC.GRPCListenAddress }}"
  138. # Maximum number of simultaneous connections.
  139. # Does not include RPC (HTTP&WebSocket) connections. See max_open_connections
  140. # If you want to accept a larger number than the default, make sure
  141. # you increase your OS limits.
  142. # 0 - unlimited.
  143. # Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  144. # 1024 - 40 - 10 - 50 = 924 = ~900
  145. grpc_max_open_connections = {{ .RPC.GRPCMaxOpenConnections }}
  146. # Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
  147. unsafe = {{ .RPC.Unsafe }}
  148. # Maximum number of simultaneous connections (including WebSocket).
  149. # Does not include gRPC connections. See grpc_max_open_connections
  150. # If you want to accept a larger number than the default, make sure
  151. # you increase your OS limits.
  152. # 0 - unlimited.
  153. # Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
  154. # 1024 - 40 - 10 - 50 = 924 = ~900
  155. max_open_connections = {{ .RPC.MaxOpenConnections }}
  156. # Maximum number of unique clientIDs that can /subscribe
  157. # If you're using /broadcast_tx_commit, set to the estimated maximum number
  158. # of broadcast_tx_commit calls per block.
  159. max_subscription_clients = {{ .RPC.MaxSubscriptionClients }}
  160. # Maximum number of unique queries a given client can /subscribe to
  161. # If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to
  162. # the estimated # maximum number of broadcast_tx_commit calls per block.
  163. max_subscriptions_per_client = {{ .RPC.MaxSubscriptionsPerClient }}
  164. # How long to wait for a tx to be committed during /broadcast_tx_commit.
  165. # WARNING: Using a value larger than 10s will result in increasing the
  166. # global HTTP write timeout, which applies to all connections and endpoints.
  167. # See https://github.com/tendermint/tendermint/issues/3435
  168. timeout_broadcast_tx_commit = "{{ .RPC.TimeoutBroadcastTxCommit }}"
  169. # Maximum size of request body, in bytes
  170. max_body_bytes = {{ .RPC.MaxBodyBytes }}
  171. # Maximum size of request header, in bytes
  172. max_header_bytes = {{ .RPC.MaxHeaderBytes }}
  173. # The path to a file containing certificate that is used to create the HTTPS server.
  174. # Migth be either absolute path or path related to tendermint's config directory.
  175. # If the certificate is signed by a certificate authority,
  176. # the certFile should be the concatenation of the server's certificate, any intermediates,
  177. # and the CA's certificate.
  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_cert_file = "{{ .RPC.TLSCertFile }}"
  181. # The path to a file containing matching private key that is used to create the HTTPS server.
  182. # Migth be either absolute path or path related to tendermint's config directory.
  183. # NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server.
  184. # Otherwise, HTTP server is run.
  185. tls_key_file = "{{ .RPC.TLSKeyFile }}"
  186. # pprof listen address (https://golang.org/pkg/net/http/pprof)
  187. pprof_laddr = "{{ .RPC.PprofListenAddress }}"
  188. #######################################################
  189. ### P2P Configuration Options ###
  190. #######################################################
  191. [p2p]
  192. # Address to listen for incoming connections
  193. laddr = "{{ .P2P.ListenAddress }}"
  194. # Address to advertise to peers for them to dial
  195. # If empty, will use the same port as the laddr,
  196. # and will introspect on the listener or use UPnP
  197. # to figure out the address.
  198. external_address = "{{ .P2P.ExternalAddress }}"
  199. # Comma separated list of seed nodes to connect to
  200. seeds = "{{ .P2P.Seeds }}"
  201. # Comma separated list of nodes to keep persistent connections to
  202. persistent_peers = "{{ .P2P.PersistentPeers }}"
  203. # UPNP port forwarding
  204. upnp = {{ .P2P.UPNP }}
  205. # Path to address book
  206. addr_book_file = "{{ js .P2P.AddrBook }}"
  207. # Set true for strict address routability rules
  208. # Set false for private or local networks
  209. addr_book_strict = {{ .P2P.AddrBookStrict }}
  210. # Maximum number of inbound peers
  211. max_num_inbound_peers = {{ .P2P.MaxNumInboundPeers }}
  212. # Maximum number of outbound peers to connect to, excluding persistent peers
  213. max_num_outbound_peers = {{ .P2P.MaxNumOutboundPeers }}
  214. # List of node IDs, to which a connection will be (re)established ignoring any existing limits
  215. unconditional_peer_ids = "{{ .P2P.UnconditionalPeerIDs }}"
  216. # Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
  217. persistent_peers_max_dial_period = "{{ .P2P.PersistentPeersMaxDialPeriod }}"
  218. # Time to wait before flushing messages out on the connection
  219. flush_throttle_timeout = "{{ .P2P.FlushThrottleTimeout }}"
  220. # Maximum size of a message packet payload, in bytes
  221. max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }}
  222. # Rate at which packets can be sent, in bytes/second
  223. send_rate = {{ .P2P.SendRate }}
  224. # Rate at which packets can be received, in bytes/second
  225. recv_rate = {{ .P2P.RecvRate }}
  226. # Set true to enable the peer-exchange reactor
  227. pex = {{ .P2P.PexReactor }}
  228. # Seed mode, in which node constantly crawls the network and looks for
  229. # peers. If another node asks it for addresses, it responds and disconnects.
  230. #
  231. # Does not work if the peer-exchange reactor is disabled.
  232. seed_mode = {{ .P2P.SeedMode }}
  233. # Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
  234. private_peer_ids = "{{ .P2P.PrivatePeerIDs }}"
  235. # Toggle to disable guard against peers connecting from the same ip.
  236. allow_duplicate_ip = {{ .P2P.AllowDuplicateIP }}
  237. # Peer connection configuration.
  238. handshake_timeout = "{{ .P2P.HandshakeTimeout }}"
  239. dial_timeout = "{{ .P2P.DialTimeout }}"
  240. #######################################################
  241. ### Mempool Configurattion Option ###
  242. #######################################################
  243. [mempool]
  244. recheck = {{ .Mempool.Recheck }}
  245. broadcast = {{ .Mempool.Broadcast }}
  246. wal_dir = "{{ js .Mempool.WalPath }}"
  247. # Maximum number of transactions in the mempool
  248. size = {{ .Mempool.Size }}
  249. # Limit the total size of all txs in the mempool.
  250. # This only accounts for raw transactions (e.g. given 1MB transactions and
  251. # max_txs_bytes=5MB, mempool will only accept 5 transactions).
  252. max_txs_bytes = {{ .Mempool.MaxTxsBytes }}
  253. # Size of the cache (used to filter transactions we saw earlier) in transactions
  254. cache_size = {{ .Mempool.CacheSize }}
  255. # Maximum size of a single transaction.
  256. # NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}.
  257. max_tx_bytes = {{ .Mempool.MaxTxBytes }}
  258. # Maximum size of a batch of transactions to send to a peer
  259. # Including space needed by encoding (one varint per transaction).
  260. max_batch_bytes = {{ .Mempool.MaxBatchBytes }}
  261. #######################################################
  262. ### State Sync Configuration Options ###
  263. #######################################################
  264. [statesync]
  265. # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
  266. # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
  267. # the network to take and serve state machine snapshots. State sync is not attempted if the node
  268. # has any local state (LastBlockHeight > 0). The node will have a truncated block history,
  269. # starting from the height of the snapshot.
  270. enable = {{ .StateSync.Enable }}
  271. # RPC servers (comma-separated) for light client verification of the synced state machine and
  272. # retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding
  273. # header hash obtained from a trusted source, and a period during which validators can be trusted.
  274. #
  275. # For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2
  276. # weeks) during which they can be financially punished (slashed) for misbehavior.
  277. rpc_servers = "{{ StringsJoin .StateSync.RPCServers "," }}"
  278. trust_height = {{ .StateSync.TrustHeight }}
  279. trust_hash = "{{ .StateSync.TrustHash }}"
  280. trust_period = "{{ .StateSync.TrustPeriod }}"
  281. # Time to spend discovering snapshots before initiating a restore.
  282. discovery_time = "{{ .StateSync.DiscoveryTime }}"
  283. # Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp).
  284. # Will create a new, randomly named directory within, and remove it when done.
  285. temp_dir = "{{ .StateSync.TempDir }}"
  286. #######################################################
  287. ### Fast Sync Configuration Connections ###
  288. #######################################################
  289. [fastsync]
  290. # Fast Sync version to use:
  291. # 1) "v0" (default) - the legacy fast sync implementation
  292. # 2) "v1" - refactor of v0 version for better testability
  293. # 2) "v2" - complete redesign of v0, optimized for testability & readability
  294. version = "{{ .FastSync.Version }}"
  295. #######################################################
  296. ### Consensus Configuration Options ###
  297. #######################################################
  298. [consensus]
  299. wal_file = "{{ js .Consensus.WalPath }}"
  300. # How long we wait for a proposal block before prevoting nil
  301. timeout_propose = "{{ .Consensus.TimeoutPropose }}"
  302. # How much timeout_propose increases with each round
  303. timeout_propose_delta = "{{ .Consensus.TimeoutProposeDelta }}"
  304. # How long we wait after receiving +2/3 prevotes for anything (ie. not a single block or nil)
  305. timeout_prevote = "{{ .Consensus.TimeoutPrevote }}"
  306. # How much the timeout_prevote increases with each round
  307. timeout_prevote_delta = "{{ .Consensus.TimeoutPrevoteDelta }}"
  308. # How long we wait after receiving +2/3 precommits for anything (ie. not a single block or nil)
  309. timeout_precommit = "{{ .Consensus.TimeoutPrecommit }}"
  310. # How much the timeout_precommit increases with each round
  311. timeout_precommit_delta = "{{ .Consensus.TimeoutPrecommitDelta }}"
  312. # How long we wait after committing a block, before starting on the new
  313. # height (this gives us a chance to receive some more precommits, even
  314. # though we already have +2/3).
  315. timeout_commit = "{{ .Consensus.TimeoutCommit }}"
  316. # How many blocks to look back to check existence of the node's consensus votes before joining consensus
  317. # When non-zero, the node will panic upon restart
  318. # if the same consensus key was used to sign {double_sign_check_height} last blocks.
  319. # So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
  320. double_sign_check_height = {{ .Consensus.DoubleSignCheckHeight }}
  321. # Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
  322. skip_timeout_commit = {{ .Consensus.SkipTimeoutCommit }}
  323. # EmptyBlocks mode and possible interval between empty blocks
  324. create_empty_blocks = {{ .Consensus.CreateEmptyBlocks }}
  325. create_empty_blocks_interval = "{{ .Consensus.CreateEmptyBlocksInterval }}"
  326. # Reactor sleep duration parameters
  327. peer_gossip_sleep_duration = "{{ .Consensus.PeerGossipSleepDuration }}"
  328. peer_query_maj23_sleep_duration = "{{ .Consensus.PeerQueryMaj23SleepDuration }}"
  329. #######################################################
  330. ### Transaction Indexer Configuration Options ###
  331. #######################################################
  332. [tx_index]
  333. # What indexer to use for transactions
  334. #
  335. # The application will set which txs to index. In some cases a node operator will be able
  336. # to decide which txs to index based on configuration set in the application.
  337. #
  338. # Options:
  339. # 1) "null"
  340. # 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
  341. # - When "kv" is chosen "tx.height" and "tx.hash" will always be indexed.
  342. indexer = "{{ .TxIndex.Indexer }}"
  343. #######################################################
  344. ### Instrumentation Configuration Options ###
  345. #######################################################
  346. [instrumentation]
  347. # When true, Prometheus metrics are served under /metrics on
  348. # PrometheusListenAddr.
  349. # Check out the documentation for the list of available metrics.
  350. prometheus = {{ .Instrumentation.Prometheus }}
  351. # Address to listen for Prometheus collector(s) connections
  352. prometheus_listen_addr = "{{ .Instrumentation.PrometheusListenAddr }}"
  353. # Maximum number of simultaneous connections.
  354. # If you want to accept a larger number than the default, make sure
  355. # you increase your OS limits.
  356. # 0 - unlimited.
  357. max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
  358. # Instrumentation namespace
  359. namespace = "{{ .Instrumentation.Namespace }}"
  360. `
  361. /****** these are for test settings ***********/
  362. func ResetTestRoot(testName string) *Config {
  363. return ResetTestRootWithChainID(testName, "")
  364. }
  365. func ResetTestRootWithChainID(testName string, chainID string) *Config {
  366. // create a unique, concurrency-safe test directory under os.TempDir()
  367. rootDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s_", chainID, testName))
  368. if err != nil {
  369. panic(err)
  370. }
  371. // ensure config and data subdirs are created
  372. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil {
  373. panic(err)
  374. }
  375. if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil {
  376. panic(err)
  377. }
  378. baseConfig := DefaultBaseConfig()
  379. configFilePath := filepath.Join(rootDir, defaultConfigFilePath)
  380. genesisFilePath := filepath.Join(rootDir, baseConfig.Genesis)
  381. privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey)
  382. privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState)
  383. // Write default config file if missing.
  384. if !tmos.FileExists(configFilePath) {
  385. writeDefaultConfigFile(configFilePath)
  386. }
  387. if !tmos.FileExists(genesisFilePath) {
  388. if chainID == "" {
  389. chainID = "tendermint_test"
  390. }
  391. testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
  392. tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
  393. }
  394. // we always overwrite the priv val
  395. tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
  396. tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
  397. config := TestConfig().SetRoot(rootDir)
  398. return config
  399. }
  400. var testGenesisFmt = `{
  401. "genesis_time": "2018-10-10T08:20:13.695936996Z",
  402. "chain_id": "%s",
  403. "initial_height": "1",
  404. "consensus_params": {
  405. "block": {
  406. "max_bytes": "22020096",
  407. "max_gas": "-1",
  408. "time_iota_ms": "10"
  409. },
  410. "evidence": {
  411. "max_age_num_blocks": "100000",
  412. "max_age_duration": "172800000000000",
  413. "max_num": 50
  414. },
  415. "validator": {
  416. "pub_key_types": [
  417. "ed25519"
  418. ]
  419. },
  420. "version": {}
  421. },
  422. "validators": [
  423. {
  424. "pub_key": {
  425. "type": "tendermint/PubKeyEd25519",
  426. "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  427. },
  428. "power": "10",
  429. "name": ""
  430. }
  431. ],
  432. "app_hash": ""
  433. }`
  434. var testPrivValidatorKey = `{
  435. "address": "A3258DCBF45DCA0DF052981870F2D1441A36D145",
  436. "pub_key": {
  437. "type": "tendermint/PubKeyEd25519",
  438. "value": "AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="
  439. },
  440. "priv_key": {
  441. "type": "tendermint/PrivKeyEd25519",
  442. "value": "EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="
  443. }
  444. }`
  445. var testPrivValidatorState = `{
  446. "height": "0",
  447. "round": 0,
  448. "step": 0
  449. }`