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.

358 lines
14 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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. - `Time (google.protobuf.Timestamp)`: Genesis time.
  89. - `ChainID (string)`: ID of the blockchain.
  90. - `ConsensusParams (ConsensusParams)`: Initial consensus-critical parameters.
  91. - `Validators ([]ValidatorUpdate)`: Initial genesis validators.
  92. - `AppStateBytes ([]byte)`: Serialized initial application state. Amino-encoded JSON bytes.
  93. - **Response**:
  94. - `ConsensusParams (ConsensusParams)`: Initial
  95. consensus-critical parameters.
  96. - `Validators ([]ValidatorUpdate)`: Initial validator set (if non empty).
  97. - **Usage**:
  98. - Called once upon genesis.
  99. - If ResponseInitChain.Validators is empty, the initial validator set will be the RequestInitChain.Validators
  100. - If ResponseInitChain.Validators is not empty, the initial validator set will be the
  101. ResponseInitChain.Validators (regardless of what is in RequestInitChain.Validators).
  102. - This allows the app to decide if it wants to accept the initial validator
  103. set proposed by tendermint (ie. in the genesis file), or if it wants to use
  104. a different one (perhaps computed based on some application specific
  105. information in the genesis file).
  106. ### Query
  107. - **Request**:
  108. - `Data ([]byte)`: Raw query bytes. Can be used with or in lieu
  109. of Path.
  110. - `Path (string)`: Path of request, like an HTTP GET path. Can be
  111. used with or in liue of Data.
  112. - Apps MUST interpret '/store' as a query by key on the
  113. underlying store. The key SHOULD be specified in the Data field.
  114. - Apps SHOULD allow queries over specific types like
  115. '/accounts/...' or '/votes/...'
  116. - `Height (int64)`: The block height for which you want the query
  117. (default=0 returns data for the latest committed block). Note
  118. 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. - `Prove (bool)`: Return Merkle proof with response if possible
  122. - **Response**:
  123. - `Code (uint32)`: Response code.
  124. - `Log (string)`: The output of the application's logger. May
  125. be non-deterministic.
  126. - `Info (string)`: Additional information. May
  127. be non-deterministic.
  128. - `Index (int64)`: The index of the key in the tree.
  129. - `Key ([]byte)`: The key of the matching data.
  130. - `Value ([]byte)`: The value of the matching data.
  131. - `Proof ([]byte)`: Proof for the data, if requested.
  132. - `Height (int64)`: The block height from which data was derived.
  133. Note that this is the height of the block containing the
  134. application's Merkle root hash, which represents the state as it
  135. was after committing the block at Height-1
  136. - **Usage**:
  137. - Query for data from the application at current or past height.
  138. - Optionally return Merkle proof.
  139. ### BeginBlock
  140. - **Request**:
  141. - `Hash ([]byte)`: The block's hash. This can be derived from the
  142. block header.
  143. - `Header (struct{})`: The block header.
  144. - `LastCommitInfo (LastCommitInfo)`: Info about the last commit, including the
  145. round, and the list of validators and which ones signed the last block.
  146. - `ByzantineValidators ([]Evidence)`: List of evidence of
  147. validators that acted maliciously.
  148. - **Response**:
  149. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  150. - **Usage**:
  151. - Signals the beginning of a new block. Called prior to
  152. any DeliverTxs.
  153. - The header is expected to at least contain the Height.
  154. - The `LastCommitInfo` and `ByzantineValidators` can be used to determine
  155. rewards and punishments for the validators. NOTE validators here do not
  156. include pubkeys.
  157. ### CheckTx
  158. - **Request**:
  159. - `Tx ([]byte)`: The request transaction bytes
  160. - **Response**:
  161. - `Code (uint32)`: Response code
  162. - `Data ([]byte)`: Result bytes, if any.
  163. - `Log (string)`: The output of the application's logger. May
  164. be non-deterministic.
  165. - `Info (string)`: Additional information. May
  166. be non-deterministic.
  167. - `GasWanted (int64)`: Amount of gas request for transaction.
  168. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  169. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  170. transactions (eg. by account).
  171. - **Usage**: Validate a mempool transaction, prior to broadcasting
  172. or proposing. CheckTx should perform stateful but light-weight
  173. checks of the validity of the transaction (like checking signatures
  174. and account balances), but need not execute in full (like running a
  175. smart contract).
  176. Tendermint runs CheckTx and DeliverTx concurrently with eachother,
  177. though on distinct ABCI connections - the mempool connection and the
  178. consensus connection, respectively.
  179. The application should maintain a separate state to support CheckTx.
  180. This state can be reset to the latest committed state during
  181. `Commit`. Before calling Commit, Tendermint will lock and flush the mempool,
  182. ensuring that all existing CheckTx are responded to and no new ones can
  183. begin. After `Commit`, the mempool will rerun
  184. CheckTx for all remaining transactions, throwing out any that are no longer valid.
  185. Then the mempool will unlock and start sending CheckTx again.
  186. Keys and values in Tags must be UTF-8 encoded strings (e.g.
  187. "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02")
  188. ### DeliverTx
  189. - **Request**:
  190. - `Tx ([]byte)`: The request transaction bytes.
  191. - **Response**:
  192. - `Code (uint32)`: Response code.
  193. - `Data ([]byte)`: Result bytes, if any.
  194. - `Log (string)`: The output of the application's logger. May
  195. be non-deterministic.
  196. - `Info (string)`: Additional information. May
  197. be non-deterministic.
  198. - `GasWanted (int64)`: Amount of gas requested for transaction.
  199. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  200. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  201. transactions (eg. by account).
  202. - **Usage**:
  203. - Deliver a transaction to be executed in full by the application.
  204. If the transaction is valid, returns CodeType.OK.
  205. - Keys and values in Tags must be UTF-8 encoded strings (e.g.
  206. "account.owner": "Bob", "balance": "100.0",
  207. "time": "2018-01-02T12:30:00Z")
  208. ### EndBlock
  209. - **Request**:
  210. - `Height (int64)`: Height of the block just executed.
  211. - **Response**:
  212. - `ValidatorUpdates ([]ValidatorUpdate)`: Changes to validator set (set
  213. voting power to 0 to remove).
  214. - `ConsensusParamUpdates (ConsensusParams)`: Changes to
  215. consensus-critical time, size, and other parameters.
  216. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  217. - **Usage**:
  218. - Signals the end of a block.
  219. - Called prior to each Commit, after all transactions.
  220. - Validator set and consensus params are updated with the result.
  221. ### Commit
  222. - **Response**:
  223. - `Data ([]byte)`: The Merkle root hash
  224. - **Usage**:
  225. - Persist the application state.
  226. - Return a Merkle root hash of the application state.
  227. - It's critical that all application instances return the
  228. same hash. If not, they will not be able to agree on the next
  229. block, because the hash is included in the next block!
  230. ## Data Messages
  231. ### Header
  232. - **Fields**:
  233. - `ChainID (string)`: ID of the blockchain
  234. - `Height (int64)`: Height of the block in the chain
  235. - `Time (google.protobuf.Timestamp)`: Time of the block. It is the proposer's
  236. local time when block was created.
  237. - `NumTxs (int32)`: Number of transactions in the block
  238. - `TotalTxs (int64)`: Total number of transactions in the blockchain until
  239. now
  240. - `LastBlockID (BlockID)`: Hash of the previous (parent) block
  241. - `LastCommitHash ([]byte)`: Hash of the previous block's commit
  242. - `ValidatorsHash ([]byte)`: Hash of the validator set for this block
  243. - `NextValidatorsHash ([]byte)`: Hash of the validator set for the next block
  244. - `ConsensusHash ([]byte)`: Hash of the consensus parameters for this block
  245. - `AppHash ([]byte)`: Data returned by the last call to `Commit` - typically the
  246. Merkle root of the application state after executing the previous block's
  247. transactions
  248. - `LastResultsHash ([]byte)`: Hash of the ABCI results returned by the last block
  249. - `EvidenceHash ([]byte)`: Hash of the evidence included in this block
  250. - `ProposerAddress ([]byte)`: Original proposer for the block
  251. - **Usage**:
  252. - Provided in RequestBeginBlock
  253. - Provides important context about the current state of the blockchain -
  254. especially height and time.
  255. - Provides the proposer of the current block, for use in proposer-based
  256. reward mechanisms.
  257. ### Validator
  258. - **Fields**:
  259. - `Address ([]byte)`: Address of the validator (hash of the public key)
  260. - `Power (int64)`: Voting power of the validator
  261. - **Usage**:
  262. - Validator identified by address
  263. - Used in RequestBeginBlock as part of VoteInfo
  264. - Does not include PubKey to avoid sending potentially large quantum pubkeys
  265. over the ABCI
  266. ### ValidatorUpdate
  267. - **Fields**:
  268. - `PubKey (PubKey)`: Public key of the validator
  269. - `Power (int64)`: Voting power of the validator
  270. - **Usage**:
  271. - Validator identified by PubKey
  272. - Used to tell Tendermint to update the validator set
  273. ### VoteInfo
  274. - **Fields**:
  275. - `Validator (Validator)`: A validator
  276. - `SignedLastBlock (bool)`: Indicates whether or not the validator signed
  277. the last block
  278. - **Usage**:
  279. - Indicates whether a validator signed the last block, allowing for rewards
  280. based on validator availability
  281. ### PubKey
  282. - **Fields**:
  283. - `Type (string)`: Type of the public key. A simple string like `"ed25519"`.
  284. In the future, may indicate a serialization algorithm to parse the `Data`,
  285. for instance `"amino"`.
  286. - `Data ([]byte)`: Public key data. For a simple public key, it's just the
  287. raw bytes. If the `Type` indicates an encoding algorithm, this is the
  288. encoded public key.
  289. - **Usage**:
  290. - A generic and extensible typed public key
  291. ### Evidence
  292. - **Fields**:
  293. - `Type (string)`: Type of the evidence. A hierarchical path like
  294. "duplicate/vote".
  295. - `Validator (Validator`: The offending validator
  296. - `Height (int64)`: Height when the offense was committed
  297. - `Time (google.protobuf.Timestamp)`: Time of the block at height `Height`.
  298. It is the proposer's local time when block was created.
  299. - `TotalVotingPower (int64)`: Total voting power of the validator set at
  300. height `Height`
  301. ### LastCommitInfo
  302. - **Fields**:
  303. - `Round (int32)`: Commit round.
  304. - `Votes ([]VoteInfo)`: List of validators addresses in the last validator set
  305. with their voting power and whether or not they signed a vote.