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.

294 lines
10 KiB

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