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.

489 lines
19 KiB

6 years ago
  1. # Methods and Types
  2. ## Overview
  3. The ABCI message types are defined in a [protobuf
  4. file](https://github.com/tendermint/tendermint/blob/develop/abci/types/types.proto).
  5. ABCI methods are split across 3 separate ABCI *connections*:
  6. - `Consensus Connection`: `InitChain, BeginBlock, DeliverTx, EndBlock, Commit`
  7. - `Mempool Connection`: `CheckTx`
  8. - `Info Connection`: `Info, SetOption, Query`
  9. The `Consensus Connection` is driven by a consensus protocol and is responsible
  10. for block execution.
  11. The `Mempool Connection` is for validating new transactions, before they're
  12. shared or included in a block.
  13. The `Info Connection` is for initialization and for queries from the user.
  14. Additionally, there is a `Flush` method that is called on every connection,
  15. and an `Echo` method that is just for debugging.
  16. More details on managing state across connections can be found in the section on
  17. [ABCI Applications](apps.md).
  18. ## Errors
  19. Some methods (`Echo, Info, InitChain, BeginBlock, EndBlock, Commit`),
  20. don't return errors because an error would indicate a critical failure
  21. in the application and there's nothing Tendermint can do. The problem
  22. should be addressed and both Tendermint and the application restarted.
  23. All other methods (`SetOption, Query, CheckTx, DeliverTx`) return an
  24. application-specific response `Code uint32`, where only `0` is reserved
  25. for `OK`.
  26. Finally, `Query`, `CheckTx`, and `DeliverTx` include a `Codespace string`, whose
  27. intended use is to disambiguate `Code` values returned by different domains of the
  28. application. The `Codespace` is a namespace for the `Code`.
  29. ## Tags
  30. Some methods (`CheckTx, BeginBlock, DeliverTx, EndBlock`)
  31. include a `Tags` field in their `Response*`. Each tag is key-value pair denoting
  32. something about what happened during the methods execution.
  33. Tags can be used to index transactions and blocks according to what happened
  34. during their execution. Note that the set of tags returned for a block from
  35. `BeginBlock` and `EndBlock` are merged. In case both methods return the same
  36. tag, only the value defined in `EndBlock` is used.
  37. Keys and values in tags must be UTF-8 encoded strings (e.g.
  38. "account.owner": "Bob", "balance": "100.0",
  39. "time": "2018-01-02T12:30:00Z")
  40. ## Determinism
  41. ABCI applications must implement deterministic finite-state machines to be
  42. securely replicated by the Tendermint consensus. This means block execution
  43. over the Consensus Connection must be strictly deterministic: given the same
  44. ordered set of requests, all nodes will compute identical responses, for all
  45. BeginBlock, DeliverTx, EndBlock, and Commit. This is critical, because the
  46. responses are included in the header of the next block, either via a Merkle root
  47. or directly, so all nodes must agree on exactly what they are.
  48. For this reason, it is recommended that applications not be exposed to any
  49. external user or process except via the ABCI connections to a consensus engine
  50. like Tendermint Core. The application must only change its state based on input
  51. from block execution (BeginBlock, DeliverTx, EndBlock, Commit), and not through
  52. any other kind of request. This is the only way to ensure all nodes see the same
  53. transactions and compute the same results.
  54. If there is some non-determinism in the state machine, consensus will eventually
  55. fail as nodes disagree over the correct values for the block header. The
  56. non-determinism must be fixed and the nodes restarted.
  57. Sources of non-determinism in applications may include:
  58. - Hardware failures
  59. - Cosmic rays, overheating, etc.
  60. - Node-dependent state
  61. - Random numbers
  62. - Time
  63. - Underspecification
  64. - Library version changes
  65. - Race conditions
  66. - Floating point numbers
  67. - JSON serialization
  68. - Iterating through hash-tables/maps/dictionaries
  69. - External Sources
  70. - Filesystem
  71. - Network calls (eg. some external REST API service)
  72. See [#56](https://github.com/tendermint/abci/issues/56) for original discussion.
  73. Note that some methods (`SetOption, Query, CheckTx, DeliverTx`) return
  74. explicitly non-deterministic data in the form of `Info` and `Log` fields. The `Log` is
  75. intended for the literal output from the application's logger, while the
  76. `Info` is any additional info that should be returned. These are the only fields
  77. that are not included in block header computations, so we don't need agreement
  78. on them. All other fields in the `Response*` must be strictly deterministic.
  79. ## Block Execution
  80. The first time a new blockchain is started, Tendermint calls
  81. `InitChain`. From then on, the follow sequence of methods is executed for each
  82. block:
  83. `BeginBlock, [DeliverTx], EndBlock, Commit`
  84. where one `DeliverTx` is called for each transaction in the block.
  85. The result is an updated application state.
  86. Cryptographic commitments to the results of DeliverTx, EndBlock, and
  87. Commit are included in the header of the next block.
  88. ## Messages
  89. ### Echo
  90. - **Request**:
  91. - `Message (string)`: A string to echo back
  92. - **Response**:
  93. - `Message (string)`: The input string
  94. - **Usage**:
  95. - Echo a string to test an abci client/server implementation
  96. ### Flush
  97. - **Usage**:
  98. - Signals that messages queued on the client should be flushed to
  99. the server. It is called periodically by the client
  100. implementation to ensure asynchronous requests are actually
  101. sent, and is called immediately to make a synchronous request,
  102. which returns when the Flush response comes back.
  103. ### Info
  104. - **Request**:
  105. - `Version (string)`: The Tendermint software semantic version
  106. - `BlockVersion (uint64)`: The Tendermint Block Protocol version
  107. - `P2PVersion (uint64)`: The Tendermint P2P Protocol version
  108. - **Response**:
  109. - `Data (string)`: Some arbitrary information
  110. - `Version (string)`: The application software semantic version
  111. - `AppVersion (uint64)`: The application protocol version
  112. - `LastBlockHeight (int64)`: Latest block for which the app has
  113. called Commit
  114. - `LastBlockAppHash ([]byte)`: Latest result of Commit
  115. - **Usage**:
  116. - Return information about the application state.
  117. - Used to sync Tendermint with the application during a handshake
  118. that happens on startup.
  119. - The returned `AppVersion` will be included in the Header of every block.
  120. - Tendermint expects `LastBlockAppHash` and `LastBlockHeight` to
  121. be updated during `Commit`, ensuring that `Commit` is never
  122. called twice for the same block height.
  123. ### SetOption
  124. - **Request**:
  125. - `Key (string)`: Key to set
  126. - `Value (string)`: Value to set for key
  127. - **Response**:
  128. - `Code (uint32)`: Response code
  129. - `Log (string)`: The output of the application's logger. May
  130. be non-deterministic.
  131. - `Info (string)`: Additional information. May
  132. be non-deterministic.
  133. - **Usage**:
  134. - Set non-consensus critical application specific options.
  135. - e.g. Key="min-fee", Value="100fermion" could set the minimum fee
  136. required for CheckTx (but not DeliverTx - that would be
  137. consensus critical).
  138. ### InitChain
  139. - **Request**:
  140. - `Time (google.protobuf.Timestamp)`: Genesis time.
  141. - `ChainID (string)`: ID of the blockchain.
  142. - `ConsensusParams (ConsensusParams)`: Initial consensus-critical parameters.
  143. - `Validators ([]ValidatorUpdate)`: Initial genesis validators.
  144. - `AppStateBytes ([]byte)`: Serialized initial application state. Amino-encoded JSON bytes.
  145. - **Response**:
  146. - `ConsensusParams (ConsensusParams)`: Initial
  147. consensus-critical parameters.
  148. - `Validators ([]ValidatorUpdate)`: Initial validator set (if non empty).
  149. - **Usage**:
  150. - Called once upon genesis.
  151. - If ResponseInitChain.Validators is empty, the initial validator set will be the RequestInitChain.Validators
  152. - If ResponseInitChain.Validators is not empty, the initial validator set will be the
  153. ResponseInitChain.Validators (regardless of what is in RequestInitChain.Validators).
  154. - This allows the app to decide if it wants to accept the initial validator
  155. set proposed by tendermint (ie. in the genesis file), or if it wants to use
  156. a different one (perhaps computed based on some application specific
  157. information in the genesis file).
  158. ### Query
  159. - **Request**:
  160. - `Data ([]byte)`: Raw query bytes. Can be used with or in lieu
  161. of Path.
  162. - `Path (string)`: Path of request, like an HTTP GET path. Can be
  163. used with or in liue of Data.
  164. - Apps MUST interpret '/store' as a query by key on the
  165. underlying store. The key SHOULD be specified in the Data field.
  166. - Apps SHOULD allow queries over specific types like
  167. '/accounts/...' or '/votes/...'
  168. - `Height (int64)`: The block height for which you want the query
  169. (default=0 returns data for the latest committed block). Note
  170. that this is the height of the block containing the
  171. application's Merkle root hash, which represents the state as it
  172. was after committing the block at Height-1
  173. - `Prove (bool)`: Return Merkle proof with response if possible
  174. - **Response**:
  175. - `Code (uint32)`: Response code.
  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. - `Index (int64)`: The index of the key in the tree.
  181. - `Key ([]byte)`: The key of the matching data.
  182. - `Value ([]byte)`: The value of the matching data.
  183. - `Proof (Proof)`: Serialized proof for the value data, if requested, to be
  184. verified against the `AppHash` for the given Height.
  185. - `Height (int64)`: The block height from which data was derived.
  186. Note that this is the height of the block containing the
  187. application's Merkle root hash, which represents the state as it
  188. was after committing the block at Height-1
  189. - `Codespace (string)`: Namespace for the `Code`.
  190. - **Usage**:
  191. - Query for data from the application at current or past height.
  192. - Optionally return Merkle proof.
  193. - Merkle proof includes self-describing `type` field to support many types
  194. of Merkle trees and encoding formats.
  195. ### BeginBlock
  196. - **Request**:
  197. - `Hash ([]byte)`: The block's hash. This can be derived from the
  198. block header.
  199. - `Header (struct{})`: The block header.
  200. - `LastCommitInfo (LastCommitInfo)`: Info about the last commit, including the
  201. round, and the list of validators and which ones signed the last block.
  202. - `ByzantineValidators ([]Evidence)`: List of evidence of
  203. validators that acted maliciously.
  204. - **Response**:
  205. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  206. - **Usage**:
  207. - Signals the beginning of a new block. Called prior to
  208. any DeliverTxs.
  209. - The header contains the height, timestamp, and more - it exactly matches the
  210. Tendermint block header. We may seek to generalize this in the future.
  211. - The `LastCommitInfo` and `ByzantineValidators` can be used to determine
  212. rewards and punishments for the validators. NOTE validators here do not
  213. include pubkeys.
  214. ### CheckTx
  215. - **Request**:
  216. - `Tx ([]byte)`: The request transaction bytes
  217. - **Response**:
  218. - `Code (uint32)`: Response code
  219. - `Data ([]byte)`: Result bytes, if any.
  220. - `Log (string)`: The output of the application's logger. May
  221. be non-deterministic.
  222. - `Info (string)`: Additional information. May
  223. be non-deterministic.
  224. - `GasWanted (int64)`: Amount of gas requested for transaction.
  225. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  226. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  227. transactions (eg. by account).
  228. - `Codespace (string)`: Namespace for the `Code`.
  229. - **Usage**:
  230. - Technically optional - not involved in processing blocks.
  231. - Guardian of the mempool: every node runs CheckTx before letting a
  232. transaction into its local mempool.
  233. - The transaction may come from an external user or another node
  234. - CheckTx need not execute the transaction in full, but rather a light-weight
  235. yet stateful validation, like checking signatures and account balances, but
  236. not running code in a virtual machine.
  237. - Transactions where `ResponseCheckTx.Code != 0` will be rejected - they will not be broadcast to
  238. other nodes or included in a proposal block.
  239. - Tendermint attributes no other value to the response code
  240. ### DeliverTx
  241. - **Request**:
  242. - `Tx ([]byte)`: The request transaction bytes.
  243. - **Response**:
  244. - `Code (uint32)`: Response code.
  245. - `Data ([]byte)`: Result bytes, if any.
  246. - `Log (string)`: The output of the application's logger. May
  247. be non-deterministic.
  248. - `Info (string)`: Additional information. May
  249. be non-deterministic.
  250. - `GasWanted (int64)`: Amount of gas requested for transaction.
  251. - `GasUsed (int64)`: Amount of gas consumed by transaction.
  252. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  253. transactions (eg. by account).
  254. - `Codespace (string)`: Namespace for the `Code`.
  255. - **Usage**:
  256. - The workhorse of the application - non-optional.
  257. - Execute the transaction in full.
  258. - `ResponseDeliverTx.Code == 0` only if the transaction is fully valid.
  259. ### EndBlock
  260. - **Request**:
  261. - `Height (int64)`: Height of the block just executed.
  262. - **Response**:
  263. - `ValidatorUpdates ([]ValidatorUpdate)`: Changes to validator set (set
  264. voting power to 0 to remove).
  265. - `ConsensusParamUpdates (ConsensusParams)`: Changes to
  266. consensus-critical time, size, and other parameters.
  267. - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing
  268. - **Usage**:
  269. - Signals the end of a block.
  270. - Called after all transactions, prior to each Commit.
  271. - Validator updates returned by block `H` impact blocks `H+1`, `H+2`, and
  272. `H+3`, but only effects changes on the validator set of `H+2`:
  273. - `H+1`: NextValidatorsHash
  274. - `H+2`: ValidatorsHash (and thus the validator set)
  275. - `H+3`: LastCommitInfo (ie. the last validator set)
  276. - Consensus params returned for block `H` apply for block `H+1`
  277. ### Commit
  278. - **Response**:
  279. - `Data ([]byte)`: The Merkle root hash of the application state
  280. - **Usage**:
  281. - Persist the application state.
  282. - Return an (optional) Merkle root hash of the application state
  283. - `ResponseCommit.Data` is included as the `Header.AppHash` in the next block
  284. - it may be empty
  285. - Later calls to `Query` can return proofs about the application state anchored
  286. in this Merkle root hash
  287. - Note developers can return whatever they want here (could be nothing, or a
  288. constant string, etc.), so long as it is deterministic - it must not be a
  289. function of anything that did not come from the
  290. BeginBlock/DeliverTx/EndBlock methods.
  291. ## Data Types
  292. ### Header
  293. - **Fields**:
  294. - `Version (Version)`: Version of the blockchain and the application
  295. - `ChainID (string)`: ID of the blockchain
  296. - `Height (int64)`: Height of the block in the chain
  297. - `Time (google.protobuf.Timestamp)`: Time of the block. It is the proposer's
  298. local time when block was created.
  299. - `NumTxs (int32)`: Number of transactions in the block
  300. - `TotalTxs (int64)`: Total number of transactions in the blockchain until
  301. now
  302. - `LastBlockID (BlockID)`: Hash of the previous (parent) block
  303. - `LastCommitHash ([]byte)`: Hash of the previous block's commit
  304. - `ValidatorsHash ([]byte)`: Hash of the validator set for this block
  305. - `NextValidatorsHash ([]byte)`: Hash of the validator set for the next block
  306. - `ConsensusHash ([]byte)`: Hash of the consensus parameters for this block
  307. - `AppHash ([]byte)`: Data returned by the last call to `Commit` - typically the
  308. Merkle root of the application state after executing the previous block's
  309. transactions
  310. - `LastResultsHash ([]byte)`: Hash of the ABCI results returned by the last block
  311. - `EvidenceHash ([]byte)`: Hash of the evidence included in this block
  312. - `ProposerAddress ([]byte)`: Original proposer for the block
  313. - **Usage**:
  314. - Provided in RequestBeginBlock
  315. - Provides important context about the current state of the blockchain -
  316. especially height and time.
  317. - Provides the proposer of the current block, for use in proposer-based
  318. reward mechanisms.
  319. ### Version
  320. - **Fields**:
  321. - `Block (uint64)`: Protocol version of the blockchain data structures.
  322. - `App (uint64)`: Protocol version of the application.
  323. - **Usage**:
  324. - Block version should be static in the life of a blockchain.
  325. - App version may be updated over time by the application.
  326. ### Validator
  327. - **Fields**:
  328. - `Address ([]byte)`: Address of the validator (hash of the public key)
  329. - `Power (int64)`: Voting power of the validator
  330. - **Usage**:
  331. - Validator identified by address
  332. - Used in RequestBeginBlock as part of VoteInfo
  333. - Does not include PubKey to avoid sending potentially large quantum pubkeys
  334. over the ABCI
  335. ### ValidatorUpdate
  336. - **Fields**:
  337. - `PubKey (PubKey)`: Public key of the validator
  338. - `Power (int64)`: Voting power of the validator
  339. - **Usage**:
  340. - Validator identified by PubKey
  341. - Used to tell Tendermint to update the validator set
  342. ### VoteInfo
  343. - **Fields**:
  344. - `Validator (Validator)`: A validator
  345. - `SignedLastBlock (bool)`: Indicates whether or not the validator signed
  346. the last block
  347. - **Usage**:
  348. - Indicates whether a validator signed the last block, allowing for rewards
  349. based on validator availability
  350. ### PubKey
  351. - **Fields**:
  352. - `Type (string)`: Type of the public key. A simple string like `"ed25519"`.
  353. In the future, may indicate a serialization algorithm to parse the `Data`,
  354. for instance `"amino"`.
  355. - `Data ([]byte)`: Public key data. For a simple public key, it's just the
  356. raw bytes. If the `Type` indicates an encoding algorithm, this is the
  357. encoded public key.
  358. - **Usage**:
  359. - A generic and extensible typed public key
  360. ### Evidence
  361. - **Fields**:
  362. - `Type (string)`: Type of the evidence. A hierarchical path like
  363. "duplicate/vote".
  364. - `Validator (Validator`: The offending validator
  365. - `Height (int64)`: Height when the offense was committed
  366. - `Time (google.protobuf.Timestamp)`: Time of the block at height `Height`.
  367. It is the proposer's local time when block was created.
  368. - `TotalVotingPower (int64)`: Total voting power of the validator set at
  369. height `Height`
  370. ### LastCommitInfo
  371. - **Fields**:
  372. - `Round (int32)`: Commit round.
  373. - `Votes ([]VoteInfo)`: List of validators addresses in the last validator set
  374. with their voting power and whether or not they signed a vote.
  375. ### ConsensusParams
  376. - **Fields**:
  377. - `BlockSize (BlockSizeParams)`: Parameters limiting the size of a block.
  378. - `Evidence (EvidenceParams)`: Parameters limiting the validity of
  379. evidence of byzantine behaviour.
  380. - `Validator (ValidatorParams)`: Parameters limitng the types of pubkeys validators can use.
  381. ### BlockSizeParams
  382. - **Fields**:
  383. - `MaxBytes (int64)`: Max size of a block, in bytes.
  384. - `MaxGas (int64)`: Max sum of `GasWanted` in a proposed block.
  385. - NOTE: blocks that violate this may be committed if there are Byzantine proposers.
  386. It's the application's responsibility to handle this when processing a
  387. block!
  388. ### EvidenceParams
  389. - **Fields**:
  390. - `MaxAge (int64)`: Max age of evidence, in blocks. Evidence older than this
  391. is considered stale and ignored.
  392. - This should correspond with an app's "unbonding period" or other
  393. similar mechanism for handling Nothing-At-Stake attacks.
  394. - NOTE: this should change to time (instead of blocks)!
  395. ### ValidatorParams
  396. - **Fields**:
  397. - `PubKeyTypes ([]string)`: List of accepted pubkey types. Uses same
  398. naming as `PubKey.Type`.
  399. ### Proof
  400. - **Fields**:
  401. - `Ops ([]ProofOp)`: List of chained Merkle proofs, of possibly different types
  402. - The Merkle root of one op is the value being proven in the next op.
  403. - The Merkle root of the final op should equal the ultimate root hash being
  404. verified against.
  405. ### ProofOp
  406. - **Fields**:
  407. - `Type (string)`: Type of Merkle proof and how it's encoded.
  408. - `Key ([]byte)`: Key in the Merkle tree that this proof is for.
  409. - `Data ([]byte)`: Encoded Merkle proof for the key.