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.

491 lines
20 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 previous block.
  298. For heights > 1, it's the weighted median of the timestamps of the valid
  299. votes in the block.LastCommit.
  300. For height == 1, it's genesis time.
  301. - `NumTxs (int32)`: Number of transactions in the block
  302. - `TotalTxs (int64)`: Total number of transactions in the blockchain until
  303. now
  304. - `LastBlockID (BlockID)`: Hash of the previous (parent) block
  305. - `LastCommitHash ([]byte)`: Hash of the previous block's commit
  306. - `ValidatorsHash ([]byte)`: Hash of the validator set for this block
  307. - `NextValidatorsHash ([]byte)`: Hash of the validator set for the next block
  308. - `ConsensusHash ([]byte)`: Hash of the consensus parameters for this block
  309. - `AppHash ([]byte)`: Data returned by the last call to `Commit` - typically the
  310. Merkle root of the application state after executing the previous block's
  311. transactions
  312. - `LastResultsHash ([]byte)`: Hash of the ABCI results returned by the last block
  313. - `EvidenceHash ([]byte)`: Hash of the evidence included in this block
  314. - `ProposerAddress ([]byte)`: Original proposer for the block
  315. - **Usage**:
  316. - Provided in RequestBeginBlock
  317. - Provides important context about the current state of the blockchain -
  318. especially height and time.
  319. - Provides the proposer of the current block, for use in proposer-based
  320. reward mechanisms.
  321. ### Version
  322. - **Fields**:
  323. - `Block (uint64)`: Protocol version of the blockchain data structures.
  324. - `App (uint64)`: Protocol version of the application.
  325. - **Usage**:
  326. - Block version should be static in the life of a blockchain.
  327. - App version may be updated over time by the application.
  328. ### Validator
  329. - **Fields**:
  330. - `Address ([]byte)`: Address of the validator (hash of the public key)
  331. - `Power (int64)`: Voting power of the validator
  332. - **Usage**:
  333. - Validator identified by address
  334. - Used in RequestBeginBlock as part of VoteInfo
  335. - Does not include PubKey to avoid sending potentially large quantum pubkeys
  336. over the ABCI
  337. ### ValidatorUpdate
  338. - **Fields**:
  339. - `PubKey (PubKey)`: Public key of the validator
  340. - `Power (int64)`: Voting power of the validator
  341. - **Usage**:
  342. - Validator identified by PubKey
  343. - Used to tell Tendermint to update the validator set
  344. ### VoteInfo
  345. - **Fields**:
  346. - `Validator (Validator)`: A validator
  347. - `SignedLastBlock (bool)`: Indicates whether or not the validator signed
  348. the last block
  349. - **Usage**:
  350. - Indicates whether a validator signed the last block, allowing for rewards
  351. based on validator availability
  352. ### PubKey
  353. - **Fields**:
  354. - `Type (string)`: Type of the public key. A simple string like `"ed25519"`.
  355. In the future, may indicate a serialization algorithm to parse the `Data`,
  356. for instance `"amino"`.
  357. - `Data ([]byte)`: Public key data. For a simple public key, it's just the
  358. raw bytes. If the `Type` indicates an encoding algorithm, this is the
  359. encoded public key.
  360. - **Usage**:
  361. - A generic and extensible typed public key
  362. ### Evidence
  363. - **Fields**:
  364. - `Type (string)`: Type of the evidence. A hierarchical path like
  365. "duplicate/vote".
  366. - `Validator (Validator`: The offending validator
  367. - `Height (int64)`: Height when the offense was committed
  368. - `Time (google.protobuf.Timestamp)`: Time of the block at height `Height`.
  369. It is the proposer's local time when block was created.
  370. - `TotalVotingPower (int64)`: Total voting power of the validator set at
  371. height `Height`
  372. ### LastCommitInfo
  373. - **Fields**:
  374. - `Round (int32)`: Commit round.
  375. - `Votes ([]VoteInfo)`: List of validators addresses in the last validator set
  376. with their voting power and whether or not they signed a vote.
  377. ### ConsensusParams
  378. - **Fields**:
  379. - `Block (BlockParams)`: Parameters limiting the size of a block and time between consecutive blocks.
  380. - `Evidence (EvidenceParams)`: Parameters limiting the validity of
  381. evidence of byzantine behaviour.
  382. - `Validator (ValidatorParams)`: Parameters limitng the types of pubkeys validators can use.
  383. ### BlockParams
  384. - **Fields**:
  385. - `MaxBytes (int64)`: Max size of a block, in bytes.
  386. - `MaxGas (int64)`: Max sum of `GasWanted` in a proposed block.
  387. - NOTE: blocks that violate this may be committed if there are Byzantine proposers.
  388. It's the application's responsibility to handle this when processing a
  389. block!
  390. ### EvidenceParams
  391. - **Fields**:
  392. - `MaxAge (int64)`: Max age of evidence, in blocks. Evidence older than this
  393. is considered stale and ignored.
  394. - This should correspond with an app's "unbonding period" or other
  395. similar mechanism for handling Nothing-At-Stake attacks.
  396. - NOTE: this should change to time (instead of blocks)!
  397. ### ValidatorParams
  398. - **Fields**:
  399. - `PubKeyTypes ([]string)`: List of accepted pubkey types. Uses same
  400. naming as `PubKey.Type`.
  401. ### Proof
  402. - **Fields**:
  403. - `Ops ([]ProofOp)`: List of chained Merkle proofs, of possibly different types
  404. - The Merkle root of one op is the value being proven in the next op.
  405. - The Merkle root of the final op should equal the ultimate root hash being
  406. verified against.
  407. ### ProofOp
  408. - **Fields**:
  409. - `Type (string)`: Type of Merkle proof and how it's encoded.
  410. - `Key ([]byte)`: Key in the Merkle tree that this proof is for.
  411. - `Data ([]byte)`: Encoded Merkle proof for the key.