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.

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