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.

325 lines
12 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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/tendermint/blob/master/abci/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`. Before calling Commit, Tendermint will lock and flush the mempool,
  172. ensuring that all existing CheckTx are responded to and no new ones can
  173. begin. After `Commit`, the mempool will rerun
  174. CheckTx for all remaining transactions, throwing out any that are no longer valid.
  175. Then the mempool will unlock and start sending CheckTx again.
  176. Keys and values in Tags must be UTF-8 encoded strings (e.g.
  177. "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02")
  178. ### DeliverTx
  179. - **Request**:
  180. - `Tx ([]byte)`: The request transaction bytes.
  181. - **Response**:
  182. - `Code (uint32)`: Response code.
  183. - `Data ([]byte)`: Result bytes, if any.
  184. - `Log (string)`: The output of the application's logger. May
  185. be non-deterministic.
  186. - `Info (string)`: Additional information. May
  187. be non-deterministic.
  188. - `GasWanted (int64)`: Amount of gas requested for transaction.
  189. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  190. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  191. transactions (eg. by account).
  192. - `Fee (cmn.KI64Pair)`: Fee paid for the transaction.
  193. - **Usage**:
  194. - Deliver a transaction to be executed in full by the application.
  195. If the transaction is valid, returns CodeType.OK.
  196. - Keys and values in Tags must be UTF-8 encoded strings (e.g.
  197. "account.owner": "Bob", "balance": "100.0",
  198. "time": "2018-01-02T12:30:00Z")
  199. ### EndBlock
  200. - **Request**:
  201. - `Height (int64)`: Height of the block just executed.
  202. - **Response**:
  203. - `ValidatorUpdates ([]Validator)`: Changes to validator set (set
  204. voting power to 0 to remove).
  205. - `ConsensusParamUpdates (ConsensusParams)`: Changes to
  206. consensus-critical time, size, and other parameters.
  207. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  208. - **Usage**:
  209. - Signals the end of a block.
  210. - Called prior to each Commit, after all transactions.
  211. - Validator set and consensus params are updated with the result.
  212. - Validator pubkeys are expected to be go-wire encoded.
  213. ### Commit
  214. - **Response**:
  215. - `Data ([]byte)`: The Merkle root hash
  216. - **Usage**:
  217. - Persist the application state.
  218. - Return a Merkle root hash of the application state.
  219. - It's critical that all application instances return the
  220. same hash. If not, they will not be able to agree on the next
  221. block, because the hash is included in the next block!
  222. ## Data Messages
  223. ### Header
  224. - **Fields**:
  225. - `ChainID (string)`: ID of the blockchain
  226. - `Height (int64)`: Height of the block in the chain
  227. - `Time (int64)`: Unix time of the block
  228. - `NumTxs (int32)`: Number of transactions in the block
  229. - `TotalTxs (int64)`: Total number of transactions in the blockchain until
  230. now
  231. - `LastBlockHash ([]byte)`: Hash of the previous (parent) block
  232. - `ValidatorsHash ([]byte)`: Hash of the validator set for this block
  233. - `AppHash ([]byte)`: Data returned by the last call to `Commit` - typically the
  234. Merkle root of the application state after executing the previous block's
  235. transactions
  236. - `Proposer (Validator)`: Original proposer for the block
  237. - **Usage**:
  238. - Provided in RequestBeginBlock
  239. - Provides important context about the current state of the blockchain -
  240. especially height and time.
  241. - Provides the proposer of the current block, for use in proposer-based
  242. reward mechanisms.
  243. ### Validator
  244. - **Fields**:
  245. - `Address ([]byte)`: Address of the validator (hash of the public key)
  246. - `PubKey (PubKey)`: Public key of the validator
  247. - `Power (int64)`: Voting power of the validator
  248. - **Usage**:
  249. - Provides all identifying information about the validator
  250. ### SigningValidator
  251. - **Fields**:
  252. - `Validator (Validator)`: A validator
  253. - `SignedLastBlock (bool)`: Indicated whether or not the validator signed
  254. the last block
  255. - **Usage**:
  256. - Indicates whether a validator signed the last block, allowing for rewards
  257. based on validator availability
  258. ### PubKey
  259. - **Fields**:
  260. - `Type (string)`: Type of the public key. A simple string like `"ed25519"`.
  261. In the future, may indicate a serialization algorithm to parse the `Data`,
  262. for instance `"amino"`.
  263. - `Data ([]byte)`: Public key data. For a simple public key, it's just the
  264. raw bytes. If the `Type` indicates an encoding algorithm, this is the
  265. encoded public key.
  266. - **Usage**:
  267. - A generic and extensible typed public key
  268. ### Evidence
  269. - **Fields**:
  270. - `Type (string)`: Type of the evidence. A hierarchical path like
  271. "duplicate/vote".
  272. - `Validator (Validator`: The offending validator
  273. - `Height (int64)`: Height when the offense was committed
  274. - `Time (int64)`: Unix time of the block at height `Height`
  275. - `TotalVotingPower (int64)`: Total voting power of the validator set at
  276. height `Height`