github.com/number571/tendermint@v0.34.11-gost/docs/nodes/running-in-production.md (about)

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