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.

393 lines
15 KiB

6 years ago
6 years ago
cli: debug sub-command (#4227) ## Issue Implement a new subcommand: tendermint debug. This subcommand itself has two subcommands: $ tendermint debug kill <pid> </path/to/out.zip> --home=</path/to/app.d> Writes debug info into a compressed archive. The archive will contain the following: ├── config.toml ├── consensus_state.json ├── net_info.json ├── stacktrace.out ├── status.json └── wal The Tendermint process will be killed. $ tendermint debug dump </path/to/out> --home=</path/to/app.d> This command will perform similar to kill except it only polls the node and dumps debugging data every frequency seconds to a compressed archive under a given destination directory. Each archive will contain: ├── consensus_state.json ├── goroutine.out ├── heap.out ├── net_info.json ├── status.json └── wal Note: goroutine.out and heap.out will only be written if a profile address is provided and is operational. This command is blocking and will log any error. replaces: #3327 closes: #3249 ## Commits: * Implement debug tool command stubs * Implement net getters and zip logic * Update zip dir API and add home flag * Add simple godocs for kill aux functions * Move IO util to new file and implement copy WAL func * Implement copy config function * Implement killProc * Remove debug fmt * Validate output file input * Direct STDERR to file * Godoc updates * Sleep prior to killing tail proc * Minor cleanup of godocs * Move debug command and add make target * Rename command handler function * Add example to command long descr * Move current implementation to cmd/tendermint/commands/debug * Update kill cmd long description * Implement dump command * Add pending log entry * Add gosec nolint * Add error check for Mkdir * Add os.IsNotExist(err) * Add to debugging section in running-in-prod doc
5 years ago
cli: debug sub-command (#4227) ## Issue Implement a new subcommand: tendermint debug. This subcommand itself has two subcommands: $ tendermint debug kill <pid> </path/to/out.zip> --home=</path/to/app.d> Writes debug info into a compressed archive. The archive will contain the following: ├── config.toml ├── consensus_state.json ├── net_info.json ├── stacktrace.out ├── status.json └── wal The Tendermint process will be killed. $ tendermint debug dump </path/to/out> --home=</path/to/app.d> This command will perform similar to kill except it only polls the node and dumps debugging data every frequency seconds to a compressed archive under a given destination directory. Each archive will contain: ├── consensus_state.json ├── goroutine.out ├── heap.out ├── net_info.json ├── status.json └── wal Note: goroutine.out and heap.out will only be written if a profile address is provided and is operational. This command is blocking and will log any error. replaces: #3327 closes: #3249 ## Commits: * Implement debug tool command stubs * Implement net getters and zip logic * Update zip dir API and add home flag * Add simple godocs for kill aux functions * Move IO util to new file and implement copy WAL func * Implement copy config function * Implement killProc * Remove debug fmt * Validate output file input * Direct STDERR to file * Godoc updates * Sleep prior to killing tail proc * Minor cleanup of godocs * Move debug command and add make target * Rename command handler function * Add example to command long descr * Move current implementation to cmd/tendermint/commands/debug * Update kill cmd long description * Implement dump command * Add pending log entry * Add gosec nolint * Add error check for Mkdir * Add os.IsNotExist(err) * Add to debugging section in running-in-prod doc
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. ---
  2. order: 4
  3. ---
  4. # Running in production
  5. ## Database
  6. By default, Tendermint uses the `syndtr/goleveldb` package for its in-process
  7. key-value database. Unfortunately, this implementation of LevelDB seems to suffer under heavy load (see
  8. [#226](https://github.com/syndtr/goleveldb/issues/226)). It may be best to
  9. install the real C-implementation of LevelDB and compile Tendermint to use
  10. that using `make build TENDERMINT_BUILD_OPTIONS=cleveldb`. See the [install instructions](../introduction/install.md) for details.
  11. Tendermint keeps multiple distinct databases in the `$TMROOT/data`:
  12. - `blockstore.db`: Keeps the entire blockchain - stores blocks,
  13. block commits, and block meta data, each indexed by height. Used to sync new
  14. peers.
  15. - `evidence.db`: Stores all verified evidence of misbehaviour.
  16. - `state.db`: Stores the current blockchain state (ie. height, validators,
  17. consensus params). Only grows if consensus params or validators change. Also
  18. used to temporarily store intermediate results during block processing.
  19. - `tx_index.db`: Indexes txs (and their results) by tx hash and by DeliverTx result events.
  20. By default, Tendermint will only index txs by their hash and height, not by their DeliverTx
  21. result events. See [indexing transactions](../app-dev/indexing-transactions.md) for
  22. details.
  23. Applications can expose block pruning strategies to the node operator. Please read the documentation of your application
  24. to find out more details.
  25. Applications can use State Sync <!--- TODO: add link to state sync doc when created ---> to help nodes bootstrap quickly.
  26. ## Logging
  27. Default logging level (`log_level = "main:info,state:info,statesync:info,*:error"`) should suffice for
  28. normal operation mode. Read [this
  29. post](https://blog.cosmos.network/one-of-the-exciting-new-features-in-0-10-0-release-is-smart-log-level-flag-e2506b4ab756)
  30. for details on how to configure `log_level` config variable. Some of the
  31. modules can be found [here](./how-to-read-logs.md#list-of-modules). If
  32. you're trying to debug Tendermint or asked to provide logs with debug
  33. logging level, you can do so by running Tendermint with
  34. `--log_level="*:debug"`.
  35. ## Write Ahead Logs (WAL)
  36. Tendermint uses write ahead logs for the consensus (`cs.wal`) and the mempool
  37. (`mempool.wal`). Both WALs have a max size of 1GB and are automatically rotated.
  38. ### Consensus WAL
  39. The `consensus.wal` is used to ensure we can recover from a crash at any point
  40. in the consensus state machine.
  41. It writes all consensus messages (timeouts, proposals, block part, or vote)
  42. to a single file, flushing to disk before processing messages from its own
  43. validator. Since Tendermint validators are expected to never sign a conflicting vote, the
  44. WAL ensures we can always recover deterministically to the latest state of the consensus without
  45. using the network or re-signing any consensus messages.
  46. If your `consensus.wal` is corrupted, see [below](#wal-corruption).
  47. ### Mempool WAL
  48. The `mempool.wal` logs all incoming txs before running CheckTx, but is
  49. otherwise not used in any programmatic way. It's just a kind of manual
  50. safe guard. Note the mempool provides no durability guarantees - a tx sent to one or many nodes
  51. may never make it into the blockchain if those nodes crash before being able to
  52. propose it. Clients must monitor their txs by subscribing over websockets,
  53. polling for them, or using `/broadcast_tx_commit`. In the worst case, txs can be
  54. resent from the mempool WAL manually.
  55. For the above reasons, the `mempool.wal` is disabled by default. To enable, set
  56. `mempool.wal_dir` to where you want the WAL to be located (e.g.
  57. `data/mempool.wal`).
  58. ## DOS Exposure and Mitigation
  59. Validators are supposed to setup [Sentry Node
  60. Architecture](./validators.md)
  61. to prevent Denial-of-service attacks.
  62. ### P2P
  63. The core of the Tendermint peer-to-peer system is `MConnection`. Each
  64. connection has `MaxPacketMsgPayloadSize`, which is the maximum packet
  65. size and bounded send & receive queues. One can impose restrictions on
  66. send & receive rate per connection (`SendRate`, `RecvRate`).
  67. The number of open P2P connections can become quite large, and hit the operating system's open
  68. file limit (since TCP connections are considered files on UNIX-based systems). Nodes should be
  69. given a sizable open file limit, e.g. 8192, via `ulimit -n 8192` or other deployment-specific
  70. mechanisms.
  71. ### RPC
  72. Endpoints returning multiple entries are limited by default to return 30
  73. elements (100 max). See the [RPC Documentation](https://docs.tendermint.com/master/rpc/)
  74. for more information.
  75. Rate-limiting and authentication are another key aspects to help protect
  76. against DOS attacks. Validators are supposed to use external tools like
  77. [NGINX](https://www.nginx.com/blog/rate-limiting-nginx/) or
  78. [traefik](https://docs.traefik.io/middlewares/ratelimit/)
  79. to achieve the same things.
  80. ## Debugging Tendermint
  81. If you ever have to debug Tendermint, the first thing you should probably do is
  82. check out the logs. See [How to read logs](./how-to-read-logs.md), where we
  83. explain what certain log statements mean.
  84. If, after skimming through the logs, things are not clear still, the next thing
  85. to try is querying the `/status` RPC endpoint. It provides the necessary info:
  86. whenever the node is syncing or not, what height it is on, etc.
  87. ```bash
  88. curl http(s)://{ip}:{rpcPort}/status
  89. ```
  90. `/dump_consensus_state` will give you a detailed overview of the consensus
  91. state (proposer, latest validators, peers states). From it, you should be able
  92. to figure out why, for example, the network had halted.
  93. ```bash
  94. curl http(s)://{ip}:{rpcPort}/dump_consensus_state
  95. ```
  96. There is a reduced version of this endpoint - `/consensus_state`, which returns
  97. just the votes seen at the current height.
  98. If, after consulting with the logs and above endpoints, you still have no idea
  99. what's happening, consider using `tendermint debug kill` sub-command. This
  100. command will scrap all the available info and kill the process. See
  101. [Debugging](../tools/debugging.md) for the exact format.
  102. You can inspect the resulting archive yourself or create an issue on
  103. [Github](https://github.com/tendermint/tendermint). Before opening an issue
  104. however, be sure to check if there's [no existing
  105. issue](https://github.com/tendermint/tendermint/issues) already.
  106. ## Monitoring Tendermint
  107. Each Tendermint instance has a standard `/health` RPC endpoint, which responds
  108. with 200 (OK) if everything is fine and 500 (or no response) - if something is
  109. wrong.
  110. Other useful endpoints include mentioned earlier `/status`, `/net_info` and
  111. `/validators`.
  112. Tendermint also can report and serve Prometheus metrics. See
  113. [Metrics](./metrics.md).
  114. `tendermint debug dump` sub-command can be used to periodically dump useful
  115. information into an archive. See [Debugging](../tools/debugging.md) for more
  116. information.
  117. ## What happens when my app dies
  118. You are supposed to run Tendermint under a [process
  119. supervisor](https://en.wikipedia.org/wiki/Process_supervision) (like
  120. systemd or runit). It will ensure Tendermint is always running (despite
  121. possible errors).
  122. Getting back to the original question, if your application dies,
  123. Tendermint will panic. After a process supervisor restarts your
  124. application, Tendermint should be able to reconnect successfully. The
  125. order of restart does not matter for it.
  126. ## Signal handling
  127. We catch SIGINT and SIGTERM and try to clean up nicely. For other
  128. signals we use the default behavior in Go: [Default behavior of signals
  129. in Go
  130. programs](https://golang.org/pkg/os/signal/#hdr-Default_behavior_of_signals_in_Go_programs).
  131. ## Corruption
  132. **NOTE:** Make sure you have a backup of the Tendermint data directory.
  133. ### Possible causes
  134. Remember that most corruption is caused by hardware issues:
  135. - RAID controllers with faulty / worn out battery backup, and an unexpected power loss
  136. - Hard disk drives with write-back cache enabled, and an unexpected power loss
  137. - Cheap SSDs with insufficient power-loss protection, and an unexpected power-loss
  138. - Defective RAM
  139. - Defective or overheating CPU(s)
  140. Other causes can be:
  141. - Database systems configured with fsync=off and an OS crash or power loss
  142. - Filesystems configured to use write barriers plus a storage layer that ignores write barriers. LVM is a particular culprit.
  143. - Tendermint bugs
  144. - Operating system bugs
  145. - Admin error (e.g., directly modifying Tendermint data-directory contents)
  146. (Source: <https://wiki.postgresql.org/wiki/Corruption>)
  147. ### WAL Corruption
  148. If consensus WAL is corrupted at the latest height and you are trying to start
  149. Tendermint, replay will fail with panic.
  150. Recovering from data corruption can be hard and time-consuming. Here are two approaches you can take:
  151. 1. Delete the WAL file and restart Tendermint. It will attempt to sync with other peers.
  152. 2. Try to repair the WAL file manually:
  153. 1) Create a backup of the corrupted WAL file:
  154. ```sh
  155. cp "$TMHOME/data/cs.wal/wal" > /tmp/corrupted_wal_backup
  156. ```
  157. 2) Use `./scripts/wal2json` to create a human-readable version:
  158. ```sh
  159. ./scripts/wal2json/wal2json "$TMHOME/data/cs.wal/wal" > /tmp/corrupted_wal
  160. ```
  161. 3) Search for a "CORRUPTED MESSAGE" line.
  162. 4) By looking at the previous message and the message after the corrupted one
  163. and looking at the logs, try to rebuild the message. If the consequent
  164. messages are marked as corrupted too (this may happen if length header
  165. got corrupted or some writes did not make it to the WAL ~ truncation),
  166. then remove all the lines starting from the corrupted one and restart
  167. Tendermint.
  168. ```sh
  169. $EDITOR /tmp/corrupted_wal
  170. ```
  171. 5) After editing, convert this file back into binary form by running:
  172. ```sh
  173. ./scripts/json2wal/json2wal /tmp/corrupted_wal $TMHOME/data/cs.wal/wal
  174. ```
  175. ## Hardware
  176. ### Processor and Memory
  177. While actual specs vary depending on the load and validators count, minimal
  178. requirements are:
  179. - 1GB RAM
  180. - 25GB of disk space
  181. - 1.4 GHz CPU
  182. SSD disks are preferable for applications with high transaction throughput.
  183. Recommended:
  184. - 2GB RAM
  185. - 100GB SSD
  186. - x64 2.0 GHz 2v CPU
  187. While for now, Tendermint stores all the history and it may require significant
  188. disk space over time, we are planning to implement state syncing (See [this
  189. issue](https://github.com/tendermint/tendermint/issues/828)). So, storing all
  190. the past blocks will not be necessary.
  191. ### Validator signing on 32 bit architectures (or ARM)
  192. Both our `ed25519` and `secp256k1` implementations require constant time
  193. `uint64` multiplication. Non-constant time crypto can (and has) leaked
  194. private keys on both `ed25519` and `secp256k1`. This doesn't exist in hardware
  195. on 32 bit x86 platforms ([source](https://bearssl.org/ctmul.html)), and it
  196. depends on the compiler to enforce that it is constant time. It's unclear at
  197. this point whenever the Golang compiler does this correctly for all
  198. implementations.
  199. **We do not support nor recommend running a validator on 32 bit architectures OR
  200. the "VIA Nano 2000 Series", and the architectures in the ARM section rated
  201. "S-".**
  202. ### Operating Systems
  203. Tendermint can be compiled for a wide range of operating systems thanks to Go
  204. language (the list of \$OS/\$ARCH pairs can be found
  205. [here](https://golang.org/doc/install/source#environment)).
  206. While we do not favor any operation system, more secure and stable Linux server
  207. distributions (like Centos) should be preferred over desktop operation systems
  208. (like Mac OS).
  209. ### Miscellaneous
  210. NOTE: if you are going to use Tendermint in a public domain, make sure
  211. you read [hardware recommendations](https://cosmos.network/validators) for a validator in the
  212. Cosmos network.
  213. ## Configuration parameters
  214. - `p2p.flush_throttle_timeout`
  215. - `p2p.max_packet_msg_payload_size`
  216. - `p2p.send_rate`
  217. - `p2p.recv_rate`
  218. If you are going to use Tendermint in a private domain and you have a
  219. private high-speed network among your peers, it makes sense to lower
  220. flush throttle timeout and increase other params.
  221. ```toml
  222. [p2p]
  223. send_rate=20000000 # 2MB/s
  224. recv_rate=20000000 # 2MB/s
  225. flush_throttle_timeout=10
  226. max_packet_msg_payload_size=10240 # 10KB
  227. ```
  228. - `mempool.recheck`
  229. After every block, Tendermint rechecks every transaction left in the
  230. mempool to see if transactions committed in that block affected the
  231. application state, so some of the transactions left may become invalid.
  232. If that does not apply to your application, you can disable it by
  233. setting `mempool.recheck=false`.
  234. - `mempool.broadcast`
  235. Setting this to false will stop the mempool from relaying transactions
  236. to other peers until they are included in a block. It means only the
  237. peer you send the tx to will see it until it is included in a block.
  238. - `consensus.skip_timeout_commit`
  239. We want `skip_timeout_commit=false` when there is economics on the line
  240. because proposers should wait to hear for more votes. But if you don't
  241. care about that and want the fastest consensus, you can skip it. It will
  242. be kept false by default for public deployments (e.g. [Cosmos
  243. Hub](https://cosmos.network/intro/hub)) while for enterprise
  244. applications, setting it to true is not a problem.
  245. - `consensus.peer_gossip_sleep_duration`
  246. You can try to reduce the time your node sleeps before checking if
  247. theres something to send its peers.
  248. - `consensus.timeout_commit`
  249. You can also try lowering `timeout_commit` (time we sleep before
  250. proposing the next block).
  251. - `p2p.addr_book_strict`
  252. By default, Tendermint checks whenever a peer's address is routable before
  253. saving it to the address book. The address is considered as routable if the IP
  254. is [valid and within allowed
  255. ranges](https://github.com/tendermint/tendermint/blob/27bd1deabe4ba6a2d9b463b8f3e3f1e31b993e61/p2p/netaddress.go#L209).
  256. This may not be the case for private or local networks, where your IP range is usually
  257. strictly limited and private. If that case, you need to set `addr_book_strict`
  258. to `false` (turn it off).
  259. - `rpc.max_open_connections`
  260. By default, the number of simultaneous connections is limited because most OS
  261. give you limited number of file descriptors.
  262. If you want to accept greater number of connections, you will need to increase
  263. these limits.
  264. [Sysctls to tune the system to be able to open more connections](https://github.com/satori-com/tcpkali/blob/master/doc/tcpkali.man.md#sysctls-to-tune-the-system-to-be-able-to-open-more-connections)
  265. The process file limits must also be increased, e.g. via `ulimit -n 8192`.
  266. ...for N connections, such as 50k:
  267. ```md
  268. kern.maxfiles=10000+2*N # BSD
  269. kern.maxfilesperproc=100+2*N # BSD
  270. kern.ipc.maxsockets=10000+2*N # BSD
  271. fs.file-max=10000+2*N # Linux
  272. net.ipv4.tcp_max_orphans=N # Linux
  273. # For load-generating clients.
  274. net.ipv4.ip_local_port_range="10000 65535" # Linux.
  275. net.inet.ip.portrange.first=10000 # BSD/Mac.
  276. net.inet.ip.portrange.last=65535 # (Enough for N < 55535)
  277. net.ipv4.tcp_tw_reuse=1 # Linux
  278. net.inet.tcp.maxtcptw=2*N # BSD
  279. # If using netfilter on Linux:
  280. net.netfilter.nf_conntrack_max=N
  281. echo $((N/8)) > /sys/module/nf_conntrack/parameters/hashsize
  282. ```
  283. The similar option exists for limiting the number of gRPC connections -
  284. `rpc.grpc_max_open_connections`.