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.

292 lines
10 KiB

  1. Specification
  2. =============
  3. Message Types
  4. ~~~~~~~~~~~~~
  5. ABCI requests/responses are defined as simple Protobuf messages in `this
  6. schema
  7. file <https://github.com/tendermint/abci/blob/master/types/types.proto>`__.
  8. TendermintCore sends the requests, and the ABCI application sends the
  9. responses. Here, we provide an overview of the messages types and how they
  10. are used by Tendermint. Then we describe each request-response pair as a
  11. function with arguments and return values, and add some notes on usage.
  12. Some messages (``Echo, Info, InitChain, BeginBlock, EndBlock, Commit``), don't
  13. return errors because an error would indicate a critical failure in the
  14. application and there's nothing Tendermint can do. The problem should be
  15. addressed and both Tendermint and the application restarted. All other
  16. messages (``SetOption, Query, CheckTx, DeliverTx``) return an
  17. application-specific response ``Code uint32``, where only ``0`` is reserved for
  18. ``OK``.
  19. Some messages (``SetOption, Query, CheckTx, DeliverTx``) return
  20. non-deterministic data in the form of ``Info`` and ``Log``. The ``Log`` is
  21. intended for the literal output from the application's logger, while the
  22. ``Info`` is any additional info that should be returned.
  23. The first time a new blockchain is started, Tendermint calls ``InitChain``.
  24. From then on, the Block Execution Sequence that causes the committed state to
  25. be updated is as follows:
  26. ``BeginBlock, [DeliverTx], EndBlock, Commit``
  27. where one ``DeliverTx`` is called for each transaction in the block.
  28. Cryptographic commitments to the results of DeliverTx, EndBlock, and
  29. Commit are included in the header of the next block.
  30. Tendermint opens three connections to the application to handle the different message
  31. types:
  32. - ``Consensus Connection - InitChain, BeginBlock, DeliverTx, EndBlock, Commit``
  33. - ``Mempool Connection - CheckTx``
  34. - ``Info Connection - Info, SetOption, Query``
  35. The ``Flush`` message is used on every connection, and the ``Echo`` message
  36. is only used for debugging.
  37. Note that messages may be sent concurrently across all connections -
  38. a typical application will thus maintain a distinct state for each
  39. connection. They may be referred to as the ``DeliverTx state``, the
  40. ``CheckTx state``, and the ``Commit state`` respectively.
  41. See below for more details on the message types and how they are used.
  42. Echo
  43. ^^^^
  44. - **Arguments**:
  45. - ``Message (string)``: A string to echo back
  46. - **Returns**:
  47. - ``Message (string)``: The input string
  48. - **Usage**:
  49. - Echo a string to test an abci client/server implementation
  50. Flush
  51. ^^^^^
  52. - **Usage**:
  53. - Signals that messages queued on the client should be flushed to
  54. the server. It is called periodically by the client implementation
  55. to ensure asynchronous requests are actually sent, and is called
  56. immediately to make a synchronous request, which returns when the
  57. Flush response comes back.
  58. Info
  59. ^^^^
  60. - **Arguments**:
  61. - ``Version (string)``: The Tendermint version
  62. - **Returns**:
  63. - ``Data (string)``: Some arbitrary information
  64. - ``Version (Version)``: Version information
  65. - ``LastBlockHeight (int64)``: Latest block for which the app has
  66. called Commit
  67. - ``LastBlockAppHash ([]byte)``: Latest result of Commit
  68. - **Usage**:
  69. - Return information about the application state.
  70. - Used to sync Tendermint with the application during a handshake that
  71. happens on startup.
  72. - Tendermint expects ``LastBlockAppHash`` and ``LastBlockHeight`` to be
  73. updated during ``Commit``, ensuring that ``Commit`` is never called twice
  74. for the same block height.
  75. SetOption
  76. ^^^^^^^^^
  77. - **Arguments**:
  78. - ``Key (string)``: Key to set
  79. - ``Value (string)``: Value to set for key
  80. - **Returns**:
  81. - ``Code (uint32)``: Response code
  82. - ``Log (string)``: The output of the application's logger. May be non-deterministic.
  83. - ``Info (string)``: Additional information. May be non-deterministic.
  84. - **Usage**:
  85. - Set non-consensus critical application specific options.
  86. - e.g. Key="min-fee", Value="100fermion" could set the minimum fee required for CheckTx
  87. (but not DeliverTx - that would be consensus critical).
  88. InitChain
  89. ^^^^^^^^^
  90. - **Arguments**:
  91. - ``Validators ([]Validator)``: Initial genesis validators
  92. - ``AppStateBytes ([]byte)``: Serialized initial application state
  93. - **Usage**:
  94. - Called once upon genesis.
  95. Query
  96. ^^^^^
  97. - **Arguments**:
  98. - ``Data ([]byte)``: Raw query bytes. Can be used with or in lieu of
  99. Path.
  100. - ``Path (string)``: Path of request, like an HTTP GET path. Can be
  101. used with or in liue of Data.
  102. - Apps MUST interpret '/store' as a query by key on the underlying
  103. store. The key SHOULD be specified in the Data field.
  104. - Apps SHOULD allow queries over specific types like '/accounts/...'
  105. or '/votes/...'
  106. - ``Height (int64)``: The block height for which you want the query
  107. (default=0 returns data for the latest committed block). Note that
  108. this is the height of the block containing the application's
  109. Merkle root hash, which represents the state as it was after
  110. committing the block at Height-1
  111. - ``Prove (bool)``: Return Merkle proof with response if possible
  112. - **Returns**:
  113. - ``Code (uint32)``: Response code.
  114. - ``Log (string)``: The output of the application's logger. May be non-deterministic.
  115. - ``Info (string)``: Additional information. May be non-deterministic.
  116. - ``Index (int64)``: The index of the key in the tree.
  117. - ``Key ([]byte)``: The key of the matching data.
  118. - ``Value ([]byte)``: The value of the matching data.
  119. - ``Proof ([]byte)``: Proof for the data, if requested.
  120. - ``Height (int64)``: The block height from which data was derived.
  121. Note that this is the height of the block containing the
  122. application's Merkle root hash, which represents the state as it
  123. was after committing the block at Height-1
  124. - **Usage**:
  125. - Query for data from the application at current or past height.
  126. - Optionally return Merkle proof.
  127. BeginBlock
  128. ^^^^^^^^^^
  129. - **Arguments**:
  130. - ``Hash ([]byte)``: The block's hash. This can be derived from the
  131. block header.
  132. - ``Header (struct{})``: The block header
  133. - ``AbsentValidators ([]int32)``: List of indices of validators not
  134. included in the LastCommit
  135. - ``ByzantineValidators ([]Evidence)``: List of evidence of
  136. validators that acted maliciously
  137. - **Usage**:
  138. - Signals the beginning of a new block. Called prior to any DeliverTxs.
  139. - The header is expected to at least contain the Height.
  140. - The ``AbsentValidators`` and ``ByzantineValidators`` can be used to
  141. determine rewards and punishments for the validators.
  142. CheckTx
  143. ^^^^^^^
  144. - **Arguments**:
  145. - ``Tx ([]byte)``: The request transaction bytes
  146. - **Returns**:
  147. - ``Code (uint32)``: Response code
  148. - ``Data ([]byte)``: Result bytes, if any.
  149. - ``Log (string)``: The output of the application's logger. May be non-deterministic.
  150. - ``Info (string)``: Additional information. May be non-deterministic.
  151. - ``GasWanted (int64)``: Amount of gas request for transaction.
  152. - ``GasUsed (int64)``: Amount of gas consumed by transaction.
  153. - ``Tags ([]cmn.KVPair)``: Key-Value tags for filtering and indexing transactions (eg. by account).
  154. - ``Fee (cmn.KI64Pair)``: Fee paid for the transaction.
  155. - **Usage**: Validate a mempool transaction, prior to broadcasting or
  156. proposing. CheckTx should perform stateful but light-weight checks
  157. of the validity of the transaction (like checking signatures and account balances),
  158. but need not execute in full (like running a smart contract).
  159. Tendermint runs CheckTx and DeliverTx concurrently with eachother,
  160. though on distinct ABCI connections - the mempool connection and the consensus
  161. connection, respectively.
  162. The application should maintain a separate state to support CheckTx.
  163. This state can be reset to the latest committed state during ``Commit``,
  164. where Tendermint ensures the mempool is locked and not sending new ``CheckTx``.
  165. After ``Commit``, the mempool will rerun CheckTx on all remaining
  166. transactions, throwing out any that are no longer valid.
  167. Keys and values in Tags must be UTF-8 encoded strings (e.g. "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02")
  168. DeliverTx
  169. ^^^^^^^^^
  170. - **Arguments**:
  171. - ``Tx ([]byte)``: The request transaction bytes.
  172. - **Returns**:
  173. - ``Code (uint32)``: Response code.
  174. - ``Data ([]byte)``: Result bytes, if any.
  175. - ``Log (string)``: The output of the application's logger. May be non-deterministic.
  176. - ``Info (string)``: Additional information. May be non-deterministic.
  177. - ``GasWanted (int64)``: Amount of gas requested for transaction.
  178. - ``GasUsed (int64)``: Amount of gas consumed by transaction.
  179. - ``Tags ([]cmn.KVPair)``: Key-Value tags for filtering and indexing transactions (eg. by account).
  180. - ``Fee (cmn.KI64Pair)``: Fee paid for the transaction.
  181. - **Usage**:
  182. - Deliver a transaction to be executed in full by the application. If the transaction is valid,
  183. returns CodeType.OK.
  184. - Keys and values in Tags must be UTF-8 encoded strings (e.g. "account.owner": "Bob", "balance": "100.0", "time": "2018-01-02T12:30:00Z")
  185. EndBlock
  186. ^^^^^^^^
  187. - **Arguments**:
  188. - ``Height (int64)``: Height of the block just executed.
  189. - **Returns**:
  190. - ``ValidatorUpdates ([]Validator)``: Changes to validator set (set
  191. voting power to 0 to remove).
  192. - ``ConsensusParamUpdates (ConsensusParams)``: Changes to
  193. consensus-critical time, size, and other parameters.
  194. - **Usage**:
  195. - Signals the end of a block.
  196. - Called prior to each Commit, after all transactions.
  197. - Validator set and consensus params are updated with the result.
  198. - Validator pubkeys are expected to be go-wire encoded.
  199. Commit
  200. ^^^^^^
  201. - **Returns**:
  202. - ``Data ([]byte)``: The Merkle root hash
  203. - **Usage**:
  204. - Persist the application state.
  205. - Return a Merkle root hash of the application state.
  206. - It's critical that all application instances return the same hash. If not,
  207. they will not be able to agree on the next block, because the hash is
  208. included in the next block!