github.com/adoriasoft/tendermint@v0.34.0-dev1.0.20200722151356-96d84601a75a/docs/tendermint-core/running-in-production.md (about)

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