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.

324 lines
13 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. ## Request/Response Messages
  41. ### Echo
  42. - **Request**:
  43. - `Message (string)`: A string to echo back
  44. - **Response**:
  45. - `Message (string)`: The input string
  46. - **Usage**:
  47. - Echo a string to test an abci client/server implementation
  48. ### Flush
  49. - **Usage**:
  50. - Signals that messages queued on the client should be flushed to
  51. the server. It is called periodically by the client
  52. implementation to ensure asynchronous requests are actually
  53. sent, and is called immediately to make a synchronous request,
  54. which returns when the Flush response comes back.
  55. ### Info
  56. - **Request**:
  57. - `Version (string)`: The Tendermint version
  58. - **Response**:
  59. - `Data (string)`: Some arbitrary information
  60. - `Version (Version)`: Version information
  61. - `LastBlockHeight (int64)`: Latest block for which the app has
  62. called Commit
  63. - `LastBlockAppHash ([]byte)`: Latest result of Commit
  64. - **Usage**:
  65. - Return information about the application state.
  66. - Used to sync Tendermint with the application during a handshake
  67. that happens on startup.
  68. - Tendermint expects `LastBlockAppHash` and `LastBlockHeight` to
  69. be updated during `Commit`, ensuring that `Commit` is never
  70. called twice for the same block height.
  71. ### SetOption
  72. - **Request**:
  73. - `Key (string)`: Key to set
  74. - `Value (string)`: Value to set for key
  75. - **Response**:
  76. - `Code (uint32)`: Response code
  77. - `Log (string)`: The output of the application's logger. May
  78. be non-deterministic.
  79. - `Info (string)`: Additional information. May
  80. be non-deterministic.
  81. - **Usage**:
  82. - Set non-consensus critical application specific options.
  83. - e.g. Key="min-fee", Value="100fermion" could set the minimum fee
  84. required for CheckTx (but not DeliverTx - that would be
  85. consensus critical).
  86. ### InitChain
  87. - **Request**:
  88. - `Validators ([]Validator)`: Initial genesis validators
  89. - `AppStateBytes ([]byte)`: Serialized initial application state
  90. - **Response**:
  91. - `ConsensusParams (ConsensusParams)`: Initial
  92. consensus-critical parameters.
  93. - `Validators ([]Validator)`: Initial validator set.
  94. - **Usage**:
  95. - Called once upon genesis.
  96. ### Query
  97. - **Request**:
  98. - `Data ([]byte)`: Raw query bytes. Can be used with or in lieu
  99. of 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
  103. underlying store. The key SHOULD be specified in the Data field.
  104. - Apps SHOULD allow queries over specific types like
  105. '/accounts/...' 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
  108. that this is the height of the block containing the
  109. application's Merkle root hash, which represents the state as it
  110. was after committing the block at Height-1
  111. - `Prove (bool)`: Return Merkle proof with response if possible
  112. - **Response**:
  113. - `Code (uint32)`: Response code.
  114. - `Log (string)`: The output of the application's logger. May
  115. be non-deterministic.
  116. - `Info (string)`: Additional information. May
  117. be non-deterministic.
  118. - `Index (int64)`: The index of the key in the tree.
  119. - `Key ([]byte)`: The key of the matching data.
  120. - `Value ([]byte)`: The value of the matching data.
  121. - `Proof ([]byte)`: Proof for the data, if requested.
  122. - `Height (int64)`: The block height from which data was derived.
  123. Note that this is the height of the block containing the
  124. application's Merkle root hash, which represents the state as it
  125. was after committing the block at Height-1
  126. - **Usage**:
  127. - Query for data from the application at current or past height.
  128. - Optionally return Merkle proof.
  129. ### BeginBlock
  130. - **Request**:
  131. - `Hash ([]byte)`: The block's hash. This can be derived from the
  132. block header.
  133. - `Header (struct{})`: The block header
  134. - `Validators ([]SigningValidator)`: List of validators in the current validator
  135. set and whether or not they signed a vote in the LastCommit
  136. - `ByzantineValidators ([]Evidence)`: List of evidence of
  137. validators that acted maliciously
  138. - **Response**:
  139. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  140. - **Usage**:
  141. - Signals the beginning of a new block. Called prior to
  142. any DeliverTxs.
  143. - The header is expected to at least contain the Height.
  144. - The `Validators` and `ByzantineValidators` can be used to
  145. determine rewards and punishments for the validators.
  146. ### CheckTx
  147. - **Request**:
  148. - `Tx ([]byte)`: The request transaction bytes
  149. - **Response**:
  150. - `Code (uint32)`: Response code
  151. - `Data ([]byte)`: Result bytes, if any.
  152. - `Log (string)`: The output of the application's logger. May
  153. be non-deterministic.
  154. - `Info (string)`: Additional information. May
  155. be non-deterministic.
  156. - `GasWanted (int64)`: Amount of gas request for transaction.
  157. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  158. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  159. transactions (eg. by account).
  160. - `Fee (cmn.KI64Pair)`: Fee paid for the transaction.
  161. - **Usage**: Validate a mempool transaction, prior to broadcasting
  162. or proposing. CheckTx should perform stateful but light-weight
  163. checks of the validity of the transaction (like checking signatures
  164. and account balances), but need not execute in full (like running a
  165. smart contract).
  166. Tendermint runs CheckTx and DeliverTx concurrently with eachother,
  167. though on distinct ABCI connections - the mempool connection and the
  168. consensus connection, respectively.
  169. The application should maintain a separate state to support CheckTx.
  170. This state can be reset to the latest committed state during
  171. `Commit`, where Tendermint ensures the mempool is locked and not
  172. sending new `CheckTx`. After `Commit`, the mempool will rerun
  173. CheckTx on all remaining transactions, throwing out any that are no
  174. longer valid.
  175. Keys and values in Tags must be UTF-8 encoded strings (e.g.
  176. "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02")
  177. ### DeliverTx
  178. - **Request**:
  179. - `Tx ([]byte)`: The request transaction bytes.
  180. - **Response**:
  181. - `Code (uint32)`: Response code.
  182. - `Data ([]byte)`: Result bytes, if any.
  183. - `Log (string)`: The output of the application's logger. May
  184. be non-deterministic.
  185. - `Info (string)`: Additional information. May
  186. be non-deterministic.
  187. - `GasWanted (int64)`: Amount of gas requested for transaction.
  188. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  189. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  190. transactions (eg. by account).
  191. - `Fee (cmn.KI64Pair)`: Fee paid for the transaction.
  192. - **Usage**:
  193. - Deliver a transaction to be executed in full by the application.
  194. If the transaction is valid, returns CodeType.OK.
  195. - Keys and values in Tags must be UTF-8 encoded strings (e.g.
  196. "account.owner": "Bob", "balance": "100.0",
  197. "time": "2018-01-02T12:30:00Z")
  198. ### EndBlock
  199. - **Request**:
  200. - `Height (int64)`: Height of the block just executed.
  201. - **Response**:
  202. - `ValidatorUpdates ([]Validator)`: Changes to validator set (set
  203. voting power to 0 to remove).
  204. - `ConsensusParamUpdates (ConsensusParams)`: Changes to
  205. consensus-critical time, size, and other parameters.
  206. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  207. - **Usage**:
  208. - Signals the end of a block.
  209. - Called prior to each Commit, after all transactions.
  210. - Validator set and consensus params are updated with the result.
  211. - Validator pubkeys are expected to be go-wire encoded.
  212. ### Commit
  213. - **Response**:
  214. - `Data ([]byte)`: The Merkle root hash
  215. - **Usage**:
  216. - Persist the application state.
  217. - Return a Merkle root hash of the application state.
  218. - It's critical that all application instances return the
  219. same hash. If not, they will not be able to agree on the next
  220. block, because the hash is included in the next block!
  221. ## Data Messages
  222. ### Header
  223. - **Fields**:
  224. - `ChainID (string)`: ID of the blockchain
  225. - `Height (int64)`: Height of the block in the chain
  226. - `Time (int64)`: Unix time of the block
  227. - `NumTxs (int32)`: Number of transactions in the block
  228. - `TotalTxs (int64)`: Total number of transactions in the blockchain until
  229. now
  230. - `LastBlockHash ([]byte)`: Hash of the previous (parent) block
  231. - `ValidatorsHash ([]byte)`: Hash of the validator set for this block
  232. - `AppHash ([]byte)`: Data returned by the last call to `Commit` - typically the
  233. Merkle root of the application state after executing the previous block's
  234. transactions
  235. - `Proposer (Validator)`: Original proposer for the block
  236. - **Usage**:
  237. - Provided in RequestBeginBlock
  238. - Provides important context about the current state of the blockchain -
  239. especially height and time.
  240. - Provides the proposer of the current block, for use in proposer-based
  241. reward mechanisms.
  242. ### Validator
  243. - **Fields**:
  244. - `Address ([]byte)`: Address of the validator (hash of the public key)
  245. - `PubKey (PubKey)`: Public key of the validator
  246. - `Power (int64)`: Voting power of the validator
  247. - **Usage**:
  248. - Provides all identifying information about the validator
  249. ### SigningValidator
  250. - **Fields**:
  251. - `Validator (Validator)`: A validator
  252. - `SignedLastBlock (bool)`: Indicated whether or not the validator signed
  253. the last block
  254. - **Usage**:
  255. - Indicates whether a validator signed the last block, allowing for rewards
  256. based on validator availability
  257. ### PubKey
  258. - **Fields**:
  259. - `Type (string)`: Type of the public key. A simple string like `"ed25519"`.
  260. In the future, may indicate a serialization algorithm to parse the `Data`,
  261. for instance `"amino"`.
  262. - `Data ([]byte)`: Public key data. For a simple public key, it's just the
  263. raw bytes. If the `Type` indicates an encoding algorithm, this is the
  264. encoded public key.
  265. - **Usage**:
  266. - A generic and extensible typed public key
  267. ### Evidence
  268. - **Fields**:
  269. - `Type (string)`: Type of the evidence. A hierarchical path like
  270. "duplicate/vote".
  271. - `Validator (Validator`: The offending validator
  272. - `Height (int64)`: Height when the offense was committed
  273. - `Time (int64)`: Unix time of the block at height `Height`
  274. - `TotalVotingPower (int64)`: Total voting power of the validator set at
  275. height `Height`