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.

314 lines
11 KiB

  1. # Using Tendermint
  2. This is a guide to using the `tendermint` program from the command line.
  3. It assumes only that you [have tendermint installed](/download) and have some rudimentary idea
  4. of what Tendermint and ABCI are.
  5. You can see the help menu with `tendermint --help`, and the version number with `tendermint version`.
  6. ## Directory Root
  7. The default directory for blockchain data is `~/.tendermint`. Override this by setting the `TMROOT` environment variable.
  8. ## Initialize
  9. Initialize the root directory by running:
  10. ```
  11. tendermint init
  12. ```
  13. This will create a new private key (`priv_validator.json`), and a genesis file (`genesis.json`) containing the associated public key.
  14. This is all that's necessary to run a local testnet with one validator.
  15. For more elaborate initialization, see our quick and dirty deployment tool, [mintnet](https://github.com/tendermint/mintnet).
  16. ## Run
  17. To run a tendermint node, use
  18. ```
  19. tendermint node
  20. ```
  21. By default, Tendermint will try to connect to a abci appliction on [127.0.0.1:46658](127.0.0.1:46658).
  22. If you have the `dummy` ABCI app installed, run it in another window.
  23. If you don't, kill tendermint and run an in-process version with
  24. ```
  25. tendermint node --proxy_app=dummy
  26. ```
  27. After a few seconds you should see blocks start streaming in.
  28. Note that blocks are produced regularly, even if there are no transactions.
  29. Hopefully we will change this.
  30. Tendermint supports in-process versions of the dummy, counter, and nil apps that ship as examples in the [ABCI repository](https://github.com/tendermint/abci).
  31. It's easy to compile your own app in-process with tendermint if it's written in Go.
  32. If your app is not written in Go, simply run it in another process,
  33. and use the `--proxy_app` flag to specify the address of the socket it is listening on, for instance
  34. ```
  35. tendermint node --proxy_app=/var/run/abci.sock
  36. ```
  37. ## Transactions
  38. To send a transaction, use `curl` to make requests to the Tendermint RPC server:
  39. ```
  40. curl http://localhost:46657/broadcast_tx_commit?tx=\"abcd\"
  41. ```
  42. For handling responses, we recommend you [install the `jsonpp` tool](http://jmhodges.github.io/jsonpp/) to pretty print the JSON
  43. We can see the chain's status at the `/status` end-point:
  44. ```
  45. curl http://localhost:46657/status | jsonpp
  46. ```
  47. and the `latest_app_hash` in particular:
  48. ```
  49. curl http://localhost:46657/status | jsonpp | grep app_hash
  50. ```
  51. Visit [http://localhost:46657](http://localhost:46657) in your browser to see the list of other endpoints.
  52. Some take no arguments (like `/status`), while others specify the argument name and use `_` as a placeholder.
  53. ## Reset
  54. WARNING: UNSAFE. Only do this in development and only if you can afford to lose all blockchain data!
  55. To reset a blockchain, stop the node, remove the `~/.tendermint/data` directory and run
  56. ```
  57. tendermint unsafe_reset_priv_validator
  58. ```
  59. This final step is necessary to reset the `priv_validator.json`,
  60. which otherwise prevents you from making conflicting votes in the consensus
  61. (something that could get you in trouble if you do it on a real blockchain).
  62. If you don't reset the priv_validator, your fresh new blockchain will not make any blocks.
  63. ## Configuration
  64. Tendermint uses a `config.toml` for configutation. For details, see [the documentation](/docs/specs/configuration).
  65. Notable options include the socket address of the application (`proxy_app`),
  66. the listenting address of the tendermint peer (`p2p.laddr`),
  67. and the listening address of the rpc server (`rpc.laddr`).
  68. Some fields from the config file can be overwritten with flags.
  69. ## Broadcast API
  70. Earlier, we used the `broadcast_tx_commit` endpoint to send a transaction.
  71. When a transaction is sent to a tendermint node,
  72. it will run via `CheckTx` against the application.
  73. If it passes `CheckTx`, it will be included in the mempool,
  74. broadcast to other peers, and eventually included in a block.
  75. Since there are multiple phases to processing a transaction, we offer multiple endpoints to broadcast a transaction:
  76. ```
  77. /broadcast_tx_async
  78. /broadcast_tx_sync
  79. /broadcast_tx_commit
  80. ```
  81. These correspond to no-processing, processing through the mempool, and processing through a block, respectively.
  82. That is, `broadcast_tx_async`, will return right away without waiting to hear if the transaction is even valid,
  83. while `broadcast_tx_sync` will return with the result of running the transaction through `CheckTx`.
  84. Using `broadcast_tx_commit` will wait until the transaction is committed in a block or until some timeout is reached,
  85. but will return right away if the transaction does not pass `CheckTx`.
  86. The return value for `broadcast_tx_commit` includes two fields, `check_tx` and `deliver_tx`, pertaining to the result of running
  87. the transaction through those ABCI messages.
  88. The benefit of using `broadcast_tx_commit` is that the request returns after the transaction is committed (ie. included in a block),
  89. but that can take on the order of a second.
  90. For a quick result, use `broadcast_tx_sync`,
  91. but the transaction will not be committed until later, and by that point its effect on the state may change.
  92. We are working to improve the API and add more ways to track the status of a transaction and get its results.
  93. ## Tendermint Networks
  94. When `tendermint init` is run, both a `genesis.json` and `priv_validator.json` are created in `~/.tendermint`.
  95. The `genesis.json` might look like:
  96. ```
  97. {
  98. "app_hash": "",
  99. "chain_id": "test-chain-HZw6TB",
  100. "genesis_time": "0001-01-01T00:00:00.000Z",
  101. "validators": [
  102. {
  103. "amount": 10,
  104. "name": "",
  105. "pub_key": [
  106. 1,
  107. "5770B4DD55B3E08B7F5711C48B516347D8C33F47C30C226315D21AA64E0DFF2E"
  108. ]
  109. }
  110. ]
  111. }
  112. ```
  113. And the `priv_validator.json`:
  114. ```
  115. {
  116. "address": "4F4D895F882A18E1D1FC608D102601DA8D3570E5",
  117. "last_height": 0,
  118. "last_round": 0,
  119. "last_signature": null,
  120. "last_signbytes": "",
  121. "last_step": 0,
  122. "priv_key": [
  123. 1,
  124. "F9FA3CD435BDAE54D0BCA8F1BC289D718C23D855C6DB21E8543F5E4F457E62805770B4DD55B3E08B7F5711C48B516347D8C33F47C30C226315D21AA64E0DFF2E"
  125. ],
  126. "pub_key": [
  127. 1,
  128. "5770B4DD55B3E08B7F5711C48B516347D8C33F47C30C226315D21AA64E0DFF2E"
  129. ]
  130. }
  131. ```
  132. The `priv_validator.json` actually contains a private key, and should be kept absolutely secret,
  133. but for now we work with the plain text.
  134. Note the `last_` fields, which prevent us from signing conflicting messages.
  135. Note also that the `pub_key` (the public key) in the `priv_validator.json` is also present in the `genesis.json`.
  136. The genesis file contains the list of public keys which may participate in the consensus,
  137. and their corresponding voting power.
  138. More than 2/3 of the voting power must be active (ie. the corresponding private keys must be producing signatures)
  139. for the consensus to make progress.
  140. In our case, the genesis file contains the public key of our `priv_validator.json`,
  141. so a tendermint node started with the default root directory will be able to make new blocks,
  142. as we've already seen.
  143. If we want to add more nodes to the network, we have two choices:
  144. we can add a new validator node, who will also participate in the consensus
  145. by proposing blocks and voting on them,
  146. or we can add a new non-validator node, who will not participate directly,
  147. but will verify and keep up with the consensus protocol.
  148. ### Peers
  149. To connect to peers on start-up, specify them in the `config.toml` or on the command line.
  150. For instance,
  151. ```
  152. tendermint node --p2p.seeds "1.2.3.4:46656,5.6.7.8:46656"
  153. ```
  154. Alternatively, you can use the `/dial_seeds` endpoint of the RPC to specify peers for a running node to connect to:
  155. ```
  156. curl --data-urlencode "seeds=[\"1.2.3.4:46656\",\"5.6.7.8:46656\"]" localhost:46657/dial_seeds
  157. ```
  158. Additionally, the peer-exchange protocol can be enabled using the `--pex` flag,
  159. though this feature is still under development (beware of dragons!).
  160. If `--pex` is enabled, peers will gossip about known peers and form a more resilient network.
  161. ### Adding a Non-Validator
  162. Adding a non-validator is simple. Just copy the original `genesis.json` to `~/.tendermint` on the new machine
  163. and start the node, specifying seeds as necessary.
  164. If no seeds are specified, the node won't make any blocks, because it's not a validator,
  165. and it won't hear about any blocks, because it's not connected to the other peer.
  166. ### Adding a Validator
  167. The easiest way to add new validators is to do it in the `genesis.json`, before starting the network.
  168. For instance, we could make a new `priv_validator.json`, and copy it's `pub_key` into the above genesis.
  169. We can generate a new `priv_validator.json` with the command:
  170. ```
  171. tendermint gen_validator
  172. ```
  173. Now we can update our genesis file. For instance, if the new `priv_validator.json` looks like:
  174. ```
  175. {
  176. "address": "AC379688105901436A34A65F185C115B8BB277A1",
  177. "last_height": 0,
  178. "last_round": 0,
  179. "last_signature": null,
  180. "last_signbytes": "",
  181. "last_step": 0,
  182. "priv_key": [
  183. 1,
  184. "0D2ED337D748ADF79BE28559B9E59EBE1ABBA0BAFE6D65FCB9797985329B950C8F2B5AACAACC9FCE41881349743B0CFDE190DF0177744568D4E82A18F0B7DF94"
  185. ],
  186. "pub_key": [
  187. 1,
  188. "8F2B5AACAACC9FCE41881349743B0CFDE190DF0177744568D4E82A18F0B7DF94"
  189. ]
  190. }
  191. ```
  192. then the new `genesis.json` will be:
  193. ```
  194. {
  195. "app_hash": "",
  196. "chain_id": "test-chain-HZw6TB",
  197. "genesis_time": "0001-01-01T00:00:00.000Z",
  198. "validators": [
  199. {
  200. "amount": 10,
  201. "name": "",
  202. "pub_key": [
  203. 1,
  204. "5770B4DD55B3E08B7F5711C48B516347D8C33F47C30C226315D21AA64E0DFF2E"
  205. ]
  206. },
  207. {
  208. "amount": 10,
  209. "name": "",
  210. "pub_key": [
  211. 1,
  212. "8F2B5AACAACC9FCE41881349743B0CFDE190DF0177744568D4E82A18F0B7DF94"
  213. ]
  214. }
  215. ]
  216. }
  217. ```
  218. Update the `genesis.json` in `~/.tendermint`. Copy the genesis file and the new `priv_validator.json`
  219. to the `~/.tendermint` on a new machine.
  220. Now run `tendermint node` on both machines, and use either `--p2p.seeds` or the `/dial_seeds` to get them to peer up.
  221. They should start making blocks, and will only continue to do so so long as both of them are online.
  222. To make a Tendermint network that can tolerate one of the validators failing, you need at least four validator nodes.
  223. Updating validators in a live network is supported as of v0.8, but it must be explicitly programmed by the application developer.
  224. See the [application developers guide](/docs/guides/app-development#Handshake) for more details.
  225. ### Local Network
  226. To run a network locally, say on a single machine, you must change the `_laddr` fields in the `config.toml` (or using the flags)
  227. so that the listening addresses of the various sockets don't conflict.
  228. Additionally, you must set `addrbook_strict=false` in the `config.toml`,
  229. otherwise Tendermint's p2p library will deny making connections to peers with the same IP address.
  230. ## More
  231. Got a couple nodes talking to each other using the dummy app?
  232. Try a more sophisticated app like [Ethermint](https://github.com/tendermint/ethermint),
  233. or learn more about building your own in the [Application Developer's Guide](/docs/guides/app-development).