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.

249 lines
10 KiB

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