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.

777 lines
50 KiB

  1. ---
  2. order: 1
  3. title: Method and Types
  4. ---
  5. # Methods and Types
  6. ## Connections
  7. ABCI applications can run either within the _same_ process as the Tendermint
  8. state-machine replication engine, or as a _separate_ process from the state-machine
  9. replication engine. When run within the same process, Tendermint will call the ABCI
  10. application methods directly as Go method calls.
  11. When Tendermint and the ABCI application are run as separate processes, Tendermint
  12. opens four connections to the application for ABCI methods. The connections each
  13. handle a subset of the ABCI method calls. These subsets are defined as follows:
  14. #### **Consensus** connection
  15. * Driven by a consensus protocol and is responsible for block execution.
  16. * Handles the `InitChain`, `BeginBlock`, `DeliverTx`, `EndBlock`, and `Commit` method
  17. calls.
  18. #### **Mempool** connection
  19. * For validating new transactions, before they're shared or included in a block.
  20. * Handles the `CheckTx` calls.
  21. #### **Info** connection
  22. * For initialization and for queries from the user.
  23. * Handles the `Info` and `Query` calls.
  24. #### **Snapshot** connection
  25. * For serving and restoring [state sync snapshots](apps.md#state-sync).
  26. * Handles the `ListSnapshots`, `LoadSnapshotChunk`, `OfferSnapshot`, and `ApplySnapshotChunk` calls.
  27. Additionally, there is a `Flush` method that is called on every connection,
  28. and an `Echo` method that is just for debugging.
  29. More details on managing state across connections can be found in the section on
  30. [ABCI Applications](apps.md).
  31. ## Errors
  32. The `Query`, `CheckTx` and `DeliverTx` methods include a `Code` field in their `Response*`.
  33. This field is meant to contain an application-specific response code.
  34. A response code of `0` indicates no error. Any other response code
  35. indicates to Tendermint that an error occurred.
  36. These methods also return a `Codespace` string to Tendermint. This field is
  37. used to disambiguate `Code` values returned by different domains of the
  38. application. The `Codespace` is a namespace for the `Code`.
  39. The `Echo`, `Info`, `InitChain`, `BeginBlock`, `EndBlock`, `Commit` methods
  40. do not return errors. An error in any of these methods represents a critical
  41. issue that Tendermint has no reasonable way to handle. If there is an error in one
  42. of these methods, the application must crash to ensure that the error is safely
  43. handled by an operator.
  44. The handling of non-zero response codes by Tendermint is described below
  45. ### CheckTx
  46. The `CheckTx` ABCI method controls what transactions are considered for inclusion in a block.
  47. When Tendermint receives a `ResponseCheckTx` with a non-zero `Code`, the associated
  48. transaction will be not be added to Tendermint's mempool or it will be removed if
  49. it is already included.
  50. ### DeliverTx
  51. The `DeliverTx` ABCI method delivers transactions from Tendermint to the application.
  52. When Tendermint recieves a `ResponseDeliverTx` with a non-zero `Code`, the response code is logged.
  53. The transaction was already included in a block, so the `Code` does not influence
  54. Tendermint consensus.
  55. ### Query
  56. The `Query` ABCI method query queries the application for information about application state.
  57. When Tendermint receives a `ResponseQuery` with a non-zero `Code`, this code is
  58. returned directly to the client that initiated the query.
  59. ## Events
  60. The `CheckTx`, `BeginBlock`, `DeliverTx`, `EndBlock` methods include an `Events`
  61. field in their `Response*`. Applications may respond to these ABCI methods with a set of events.
  62. Events allow applications to associate metadata about ABCI method execution with the
  63. transactions and blocks this metadata relates to.
  64. Events returned via these ABCI methods do not impact Tendermint consensus in any way
  65. and instead exist to power subscriptions and queries of Tendermint state.
  66. An `Event` contains a `type` and a list of `EventAttributes`, which are key-value
  67. string pairs denoting metadata about what happened during the method's execution.
  68. `Event` values can be used to index transactions and blocks according to what happened
  69. during their execution. Note that the set of events returned for a block from
  70. `BeginBlock` and `EndBlock` are merged. In case both methods return the same
  71. key, only the value defined in `EndBlock` is used.
  72. Each event has a `type` which is meant to categorize the event for a particular
  73. `Response*` or `Tx`. A `Response*` or `Tx` may contain multiple events with duplicate
  74. `type` values, where each distinct entry is meant to categorize attributes for a
  75. particular event. Every key and value in an event's attributes must be UTF-8
  76. encoded strings along with the event type itself.
  77. ```protobuf
  78. message Event {
  79. string type = 1;
  80. repeated EventAttribute attributes = 2;
  81. }
  82. ```
  83. The attributes of an `Event` consist of a `key`, a `value`, and an `index` flag. The
  84. index flag notifies the Tendermint indexer to index the attribute. The value of
  85. the `index` flag is non-deterministic and may vary across different nodes in the network.
  86. ```protobuf
  87. message EventAttribute {
  88. bytes key = 1;
  89. bytes value = 2;
  90. bool index = 3; // nondeterministic
  91. }
  92. ```
  93. Example:
  94. ```go
  95. abci.ResponseDeliverTx{
  96. // ...
  97. Events: []abci.Event{
  98. {
  99. Type: "validator.provisions",
  100. Attributes: []abci.EventAttribute{
  101. abci.EventAttribute{Key: []byte("address"), Value: []byte("..."), Index: true},
  102. abci.EventAttribute{Key: []byte("amount"), Value: []byte("..."), Index: true},
  103. abci.EventAttribute{Key: []byte("balance"), Value: []byte("..."), Index: true},
  104. },
  105. },
  106. {
  107. Type: "validator.provisions",
  108. Attributes: []abci.EventAttribute{
  109. abci.EventAttribute{Key: []byte("address"), Value: []byte("..."), Index: true},
  110. abci.EventAttribute{Key: []byte("amount"), Value: []byte("..."), Index: false},
  111. abci.EventAttribute{Key: []byte("balance"), Value: []byte("..."), Index: false},
  112. },
  113. },
  114. {
  115. Type: "validator.slashed",
  116. Attributes: []abci.EventAttribute{
  117. abci.EventAttribute{Key: []byte("address"), Value: []byte("..."), Index: false},
  118. abci.EventAttribute{Key: []byte("amount"), Value: []byte("..."), Index: true},
  119. abci.EventAttribute{Key: []byte("reason"), Value: []byte("..."), Index: true},
  120. },
  121. },
  122. // ...
  123. },
  124. }
  125. ```
  126. ## EvidenceType
  127. Tendermint's security model relies on the use of "evidence". Evidence is proof of
  128. malicious behaviour by a network participant. It is the responsibility of Tendermint
  129. to detect such malicious behaviour. When malicious behavior is detected, Tendermint
  130. will gossip evidence of the behavior to other nodes and commit the evidence to
  131. the chain once it is verified by all validators. This evidence will then be
  132. passed it on to the application through the ABCI. It is the responsibility of the
  133. application to handle the evidence and exercise punishment.
  134. EvidenceType has the following protobuf format:
  135. ```proto
  136. enum EvidenceType {
  137. UNKNOWN = 0;
  138. DUPLICATE_VOTE = 1;
  139. LIGHT_CLIENT_ATTACK = 2;
  140. }
  141. ```
  142. There are two forms of evidence: Duplicate Vote and Light Client Attack. More
  143. information can be found in either [data structures](../core/data_structures.md)
  144. or [accountability](../light-client/accountability/README.md)
  145. ## Determinism
  146. ABCI applications must implement deterministic finite-state machines to be
  147. securely replicated by the Tendermint consensus engine. This means block execution
  148. over the Consensus Connection must be strictly deterministic: given the same
  149. ordered set of requests, all nodes will compute identical responses, for all
  150. BeginBlock, DeliverTx, EndBlock, and Commit. This is critical, because the
  151. responses are included in the header of the next block, either via a Merkle root
  152. or directly, so all nodes must agree on exactly what they are.
  153. For this reason, it is recommended that applications not be exposed to any
  154. external user or process except via the ABCI connections to a consensus engine
  155. like Tendermint Core. The application must only change its state based on input
  156. from block execution (BeginBlock, DeliverTx, EndBlock, Commit), and not through
  157. any other kind of request. This is the only way to ensure all nodes see the same
  158. transactions and compute the same results.
  159. If there is some non-determinism in the state machine, consensus will eventually
  160. fail as nodes disagree over the correct values for the block header. The
  161. non-determinism must be fixed and the nodes restarted.
  162. Sources of non-determinism in applications may include:
  163. * Hardware failures
  164. * Cosmic rays, overheating, etc.
  165. * Node-dependent state
  166. * Random numbers
  167. * Time
  168. * Underspecification
  169. * Library version changes
  170. * Race conditions
  171. * Floating point numbers
  172. * JSON serialization
  173. * Iterating through hash-tables/maps/dictionaries
  174. * External Sources
  175. * Filesystem
  176. * Network calls (eg. some external REST API service)
  177. See [#56](https://github.com/tendermint/abci/issues/56) for original discussion.
  178. Note that some methods (`Query, CheckTx, DeliverTx`) return
  179. explicitly non-deterministic data in the form of `Info` and `Log` fields. The `Log` is
  180. intended for the literal output from the application's logger, while the
  181. `Info` is any additional info that should be returned. These are the only fields
  182. that are not included in block header computations, so we don't need agreement
  183. on them. All other fields in the `Response*` must be strictly deterministic.
  184. ## Block Execution
  185. The first time a new blockchain is started, Tendermint calls
  186. `InitChain`. From then on, the following sequence of methods is executed for each
  187. block:
  188. `BeginBlock, [DeliverTx], EndBlock, Commit`
  189. where one `DeliverTx` is called for each transaction in the block.
  190. The result is an updated application state.
  191. Cryptographic commitments to the results of DeliverTx, EndBlock, and
  192. Commit are included in the header of the next block.
  193. ## State Sync
  194. State sync allows new nodes to rapidly bootstrap by discovering, fetching, and applying
  195. state machine snapshots instead of replaying historical blocks. For more details, see the
  196. [state sync section](../p2p/messages/state-sync.md).
  197. New nodes will discover and request snapshots from other nodes in the P2P network.
  198. A Tendermint node that receives a request for snapshots from a peer will call
  199. `ListSnapshots` on its application to retrieve any local state snapshots. After receiving
  200. snapshots from peers, the new node will offer each snapshot received from a peer
  201. to its local application via the `OfferSnapshot` method.
  202. Snapshots may be quite large and are thus broken into smaller "chunks" that can be
  203. assembled into the whole snapshot. Once the application accepts a snapshot and
  204. begins restoring it, Tendermint will fetch snapshot "chunks" from existing nodes.
  205. The node providing "chunks" will fetch them from its local application using
  206. the `LoadSnapshotChunk` method.
  207. As the new node receives "chunks" it will apply them sequentially to the local
  208. application with `ApplySnapshotChunk`. When all chunks have been applied, the application
  209. `AppHash` is retrieved via an `Info` query. The `AppHash` is then compared to
  210. the blockchain's `AppHash` which is verified via [light client verification](../light-client/verification/README.md).
  211. ## Messages
  212. ### Echo
  213. * **Request**:
  214. * `Message (string)`: A string to echo back
  215. * **Response**:
  216. * `Message (string)`: The input string
  217. * **Usage**:
  218. * Echo a string to test an abci client/server implementation
  219. ### Flush
  220. * **Usage**:
  221. * Signals that messages queued on the client should be flushed to
  222. the server. It is called periodically by the client
  223. implementation to ensure asynchronous requests are actually
  224. sent, and is called immediately to make a synchronous request,
  225. which returns when the Flush response comes back.
  226. ### Info
  227. * **Request**:
  228. | Name | Type | Description | Field Number |
  229. |---------------|--------|------------------------------------------|--------------|
  230. | version | string | The Tendermint software semantic version | 1 |
  231. | block_version | uint64 | The Tendermint Block Protocol version | 2 |
  232. | p2p_version | uint64 | The Tendermint P2P Protocol version | 3 |
  233. | abci_version | string | The Tendermint ABCI semantic version | 4 |
  234. * **Response**:
  235. | Name | Type | Description | Field Number |
  236. |---------------------|--------|--------------------------------------------------|--------------|
  237. | data | string | Some arbitrary information | 1 |
  238. | version | string | The application software semantic version | 2 |
  239. | app_version | uint64 | The application protocol version | 3 |
  240. | last_block_height | int64 | Latest block for which the app has called Commit | 4 |
  241. | last_block_app_hash | bytes | Latest result of Commit | 5 |
  242. * **Usage**:
  243. * Return information about the application state.
  244. * Used to sync Tendermint with the application during a handshake
  245. that happens on startup.
  246. * The returned `app_version` will be included in the Header of every block.
  247. * Tendermint expects `last_block_app_hash` and `last_block_height` to
  248. be updated during `Commit`, ensuring that `Commit` is never
  249. called twice for the same block height.
  250. > Note: Semantic version is a reference to [semantic versioning](https://semver.org/). Semantic versions in info will be displayed as X.X.x.
  251. ### InitChain
  252. * **Request**:
  253. | Name | Type | Description | Field Number |
  254. |------------------|--------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|--------------|
  255. | time | [google.protobuf.Timestamp](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp) | Genesis time | 1 |
  256. | chain_id | string | ID of the blockchain. | 2 |
  257. | consensus_params | [ConsensusParams](#consensusparams) | Initial consensus-critical parameters. | 3 |
  258. | validators | repeated [ValidatorUpdate](#validatorupdate) | Initial genesis validators, sorted by voting power. | 4 |
  259. | app_state_bytes | bytes | Serialized initial application state. JSON bytes. | 5 |
  260. | initial_height | int64 | Height of the initial block (typically `1`). | 6 |
  261. * **Response**:
  262. | Name | Type | Description | Field Number |
  263. |------------------|----------------------------------------------|-------------------------------------------------|--------------|
  264. | consensus_params | [ConsensusParams](#consensusparams) | Initial consensus-critical parameters (optional | 1 |
  265. | validators | repeated [ValidatorUpdate](#validatorupdate) | Initial validator set (optional). | 2 |
  266. | app_hash | bytes | Initial application hash. | 3 |
  267. * **Usage**:
  268. * Called once upon genesis.
  269. * If ResponseInitChain.Validators is empty, the initial validator set will be the RequestInitChain.Validators
  270. * If ResponseInitChain.Validators is not empty, it will be the initial
  271. validator set (regardless of what is in RequestInitChain.Validators).
  272. * This allows the app to decide if it wants to accept the initial validator
  273. set proposed by tendermint (ie. in the genesis file), or if it wants to use
  274. a different one (perhaps computed based on some application specific
  275. information in the genesis file).
  276. ### Query
  277. * **Request**:
  278. | Name | Type | Description | Field Number |
  279. |--------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  280. | data | bytes | Raw query bytes. Can be used with or in lieu of Path. | 1 |
  281. | path | string | Path field of the request URI. Can be used with or in lieu of `data`. Apps MUST interpret `/store` as a query by key on the underlying store. The key SHOULD be specified in the `data` field. Apps SHOULD allow queries over specific types like `/accounts/...` or `/votes/...` | 2 |
  282. | height | int64 | The block height for which you want the query (default=0 returns data for the latest committed block). Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1 | 3 |
  283. | prove | bool | Return Merkle proof with response if possible | 4 |
  284. * **Response**:
  285. | Name | Type | Description | Field Number |
  286. |-----------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  287. | code | uint32 | Response code. | 1 |
  288. | log | string | The output of the application's logger. **May be non-deterministic.** | 3 |
  289. | info | string | Additional information. **May be non-deterministic.** | 4 |
  290. | index | int64 | The index of the key in the tree. | 5 |
  291. | key | bytes | The key of the matching data. | 6 |
  292. | value | bytes | The value of the matching data. | 7 |
  293. | proof_ops | [ProofOps](#proofops) | Serialized proof for the value data, if requested, to be verified against the `app_hash` for the given Height. | 8 |
  294. | height | int64 | The block height from which data was derived. Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1 | 9 |
  295. | codespace | string | Namespace for the `code`. | 10 |
  296. * **Usage**:
  297. * Query for data from the application at current or past height.
  298. * Optionally return Merkle proof.
  299. * Merkle proof includes self-describing `type` field to support many types
  300. of Merkle trees and encoding formats.
  301. ### BeginBlock
  302. * **Request**:
  303. | Name | Type | Description | Field Number |
  304. |----------------------|---------------------------------------------|-------------------------------------------------------------------------------------------------------------------|--------------|
  305. | hash | bytes | The block's hash. This can be derived from the block header. | 1 |
  306. | header | [Header](../core/data_structures.md#header) | The block header. | 2 |
  307. | last_commit_info | [LastCommitInfo](#lastcommitinfo) | Info about the last commit, including the round, and the list of validators and which ones signed the last block. | 3 |
  308. | byzantine_validators | repeated [Evidence](#evidence) | List of evidence of validators that acted maliciously. | 4 |
  309. * **Response**:
  310. | Name | Type | Description | Field Number |
  311. |--------|---------------------------|-------------------------------------|--------------|
  312. | events | repeated [Event](#events) | type & Key-Value events for indexing | 1 |
  313. * **Usage**:
  314. * Signals the beginning of a new block.
  315. * Called prior to any `DeliverTx` method calls.
  316. * The header contains the height, timestamp, and more - it exactly matches the
  317. Tendermint block header. We may seek to generalize this in the future.
  318. * The `LastCommitInfo` and `ByzantineValidators` can be used to determine
  319. rewards and punishments for the validators.
  320. ### CheckTx
  321. * **Request**:
  322. | Name | Type | Description | Field Number |
  323. |------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  324. | tx | bytes | The request transaction bytes | 1 |
  325. | type | CheckTxType | One of `CheckTx_New` or `CheckTx_Recheck`. `CheckTx_New` is the default and means that a full check of the tranasaction is required. `CheckTx_Recheck` types are used when the mempool is initiating a normal recheck of a transaction. | 2 |
  326. * **Response**:
  327. | Name | Type | Description | Field Number |
  328. |------------|---------------------------|-----------------------------------------------------------------------|--------------|
  329. | code | uint32 | Response code. | 1 |
  330. | data | bytes | Result bytes, if any. | 2 |
  331. | log | string | The output of the application's logger. **May be non-deterministic.** | 3 |
  332. | info | string | Additional information. **May be non-deterministic.** | 4 |
  333. | gas_wanted | int64 | Amount of gas requested for transaction. | 5 |
  334. | gas_used | int64 | Amount of gas consumed by transaction. | 6 |
  335. | events | repeated [Event](#events) | Type & Key-Value events for indexing transactions (eg. by account). | 7 |
  336. | codespace | string | Namespace for the `code`. | 8 |
  337. | sender | string | The transaction's sender (e.g. the signer) | 9 |
  338. | priority | int64 | The transaction's priority (for mempool ordering) | 10 |
  339. * **Usage**:
  340. * Technically optional - not involved in processing blocks.
  341. * Guardian of the mempool: every node runs `CheckTx` before letting a
  342. transaction into its local mempool.
  343. * The transaction may come from an external user or another node
  344. * `CheckTx` validates the transaction against the current state of the application,
  345. for example, checking signatures and account balances, but does not apply any
  346. of the state changes described in the transaction.
  347. not running code in a virtual machine.
  348. * Transactions where `ResponseCheckTx.Code != 0` will be rejected - they will not be broadcast to
  349. other nodes or included in a proposal block.
  350. * Tendermint attributes no other value to the response code
  351. ### DeliverTx
  352. * **Request**:
  353. | Name | Type | Description | Field Number |
  354. |------|-------|--------------------------------|--------------|
  355. | tx | bytes | The request transaction bytes. | 1 |
  356. * **Response**:
  357. | Name | Type | Description | Field Number |
  358. |------------|---------------------------|-----------------------------------------------------------------------|--------------|
  359. | code | uint32 | Response code. | 1 |
  360. | data | bytes | Result bytes, if any. | 2 |
  361. | log | string | The output of the application's logger. **May be non-deterministic.** | 3 |
  362. | info | string | Additional information. **May be non-deterministic.** | 4 |
  363. | gas_wanted | int64 | Amount of gas requested for transaction. | 5 |
  364. | gas_used | int64 | Amount of gas consumed by transaction. | 6 |
  365. | events | repeated [Event](#events) | Type & Key-Value events for indexing transactions (eg. by account). | 7 |
  366. | codespace | string | Namespace for the `code`. | 8 |
  367. * **Usage**:
  368. * [**Required**] The core method of the application.
  369. * When `DeliverTx` is called, the application must execute the transaction in full before returning control to Tendermint.
  370. * `ResponseDeliverTx.Code == 0` only if the transaction is fully valid.
  371. ### EndBlock
  372. * **Request**:
  373. | Name | Type | Description | Field Number |
  374. |--------|-------|------------------------------------|--------------|
  375. | height | int64 | Height of the block just executed. | 1 |
  376. * **Response**:
  377. | Name | Type | Description | Field Number |
  378. |-------------------------|----------------------------------------------|-----------------------------------------------------------------|--------------|
  379. | validator_updates | repeated [ValidatorUpdate](#validatorupdate) | Changes to validator set (set voting power to 0 to remove). | 1 |
  380. | consensus_param_updates | [ConsensusParams](#consensusparams) | Changes to consensus-critical time, size, and other parameters. | 2 |
  381. | events | repeated [Event](#events) | Type & Key-Value events for indexing | 3 |
  382. * **Usage**:
  383. * Signals the end of a block.
  384. * Called after all the transactions for the current block have been delivered, prior to the block's `Commit` message.
  385. * Optional `validator_updates` triggered by block `H`. These updates affect validation
  386. for blocks `H+1`, `H+2`, and `H+3`.
  387. * Heights following a validator update are affected in the following way:
  388. * `H+1`: `NextValidatorsHash` includes the new `validator_updates` value.
  389. * `H+2`: The validator set change takes effect and `ValidatorsHash` is updated.
  390. * `H+3`: `LastCommitInfo` is changed to include the altered validator set.
  391. * `consensus_param_updates` returned for block `H` apply to the consensus
  392. params for block `H+1`. For more information on the consensus parameters,
  393. see the [application spec entry on consensus parameters](./apps.md#consensus-parameters).
  394. ### Commit
  395. * **Request**:
  396. | Name | Type | Description | Field Number |
  397. |--------|-------|------------------------------------|--------------|
  398. Commit signals the application to persist application state. It takes no parameters.
  399. * **Response**:
  400. | Name | Type | Description | Field Number |
  401. |---------------|-------|------------------------------------------------------------------------|--------------|
  402. | data | bytes | The Merkle root hash of the application state. | 2 |
  403. | retain_height | int64 | Blocks below this height may be removed. Defaults to `0` (retain all). | 3 |
  404. * **Usage**:
  405. * Signal the application to persist the application state.
  406. * Return an (optional) Merkle root hash of the application state
  407. * `ResponseCommit.Data` is included as the `Header.AppHash` in the next block
  408. * it may be empty
  409. * Later calls to `Query` can return proofs about the application state anchored
  410. in this Merkle root hash
  411. * Note developers can return whatever they want here (could be nothing, or a
  412. constant string, etc.), so long as it is deterministic - it must not be a
  413. function of anything that did not come from the
  414. BeginBlock/DeliverTx/EndBlock methods.
  415. * Use `RetainHeight` with caution! If all nodes in the network remove historical
  416. blocks then this data is permanently lost, and no new nodes will be able to
  417. join the network and bootstrap. Historical blocks may also be required for
  418. other purposes, e.g. auditing, replay of non-persisted heights, light client
  419. verification, and so on.
  420. ### ListSnapshots
  421. * **Request**:
  422. | Name | Type | Description | Field Number |
  423. |--------|-------|------------------------------------|--------------|
  424. Empty request asking the application for a list of snapshots.
  425. * **Response**:
  426. | Name | Type | Description | Field Number |
  427. |-----------|--------------------------------|--------------------------------|--------------|
  428. | snapshots | repeated [Snapshot](#snapshot) | List of local state snapshots. | 1 |
  429. * **Usage**:
  430. * Used during state sync to discover available snapshots on peers.
  431. * See `Snapshot` data type for details.
  432. ### LoadSnapshotChunk
  433. * **Request**:
  434. | Name | Type | Description | Field Number |
  435. |--------|--------|-----------------------------------------------------------------------|--------------|
  436. | height | uint64 | The height of the snapshot the chunks belongs to. | 1 |
  437. | format | uint32 | The application-specific format of the snapshot the chunk belongs to. | 2 |
  438. | chunk | uint32 | The chunk index, starting from `0` for the initial chunk. | 3 |
  439. * **Response**:
  440. | Name | Type | Description | Field Number |
  441. |-------|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  442. | chunk | bytes | The binary chunk contents, in an arbitray format. Chunk messages cannot be larger than 16 MB _including metadata_, so 10 MB is a good starting point. | 1 |
  443. * **Usage**:
  444. * Used during state sync to retrieve snapshot chunks from peers.
  445. ### OfferSnapshot
  446. * **Request**:
  447. | Name | Type | Description | Field Number |
  448. |----------|-----------------------|--------------------------------------------------------------------------|--------------|
  449. | snapshot | [Snapshot](#snapshot) | The snapshot offered for restoration. | 1 |
  450. | app_hash | bytes | The light client-verified app hash for this height, from the blockchain. | 2 |
  451. * **Response**:
  452. | Name | Type | Description | Field Number |
  453. |--------|-------------------|-----------------------------------|--------------|
  454. | result | [Result](#result) | The result of the snapshot offer. | 1 |
  455. #### Result
  456. ```proto
  457. enum Result {
  458. UNKNOWN = 0; // Unknown result, abort all snapshot restoration
  459. ACCEPT = 1; // Snapshot is accepted, start applying chunks.
  460. ABORT = 2; // Abort snapshot restoration, and don't try any other snapshots.
  461. REJECT = 3; // Reject this specific snapshot, try others.
  462. REJECT_FORMAT = 4; // Reject all snapshots with this `format`, try others.
  463. REJECT_SENDER = 5; // Reject all snapshots from all senders of this snapshot, try others.
  464. }
  465. ```
  466. * **Usage**:
  467. * `OfferSnapshot` is called when bootstrapping a node using state sync. The application may
  468. accept or reject snapshots as appropriate. Upon accepting, Tendermint will retrieve and
  469. apply snapshot chunks via `ApplySnapshotChunk`. The application may also choose to reject a
  470. snapshot in the chunk response, in which case it should be prepared to accept further
  471. `OfferSnapshot` calls.
  472. * Only `AppHash` can be trusted, as it has been verified by the light client. Any other data
  473. can be spoofed by adversaries, so applications should employ additional verification schemes
  474. to avoid denial-of-service attacks. The verified `AppHash` is automatically checked against
  475. the restored application at the end of snapshot restoration.
  476. * For more information, see the `Snapshot` data type or the [state sync section](../p2p/messages/state-sync.md).
  477. ### ApplySnapshotChunk
  478. * **Request**:
  479. | Name | Type | Description | Field Number |
  480. |--------|--------|-----------------------------------------------------------------------------|--------------|
  481. | index | uint32 | The chunk index, starting from `0`. Tendermint applies chunks sequentially. | 1 |
  482. | chunk | bytes | The binary chunk contents, as returned by `LoadSnapshotChunk`. | 2 |
  483. | sender | string | The P2P ID of the node who sent this chunk. | 3 |
  484. * **Response**:
  485. | Name | Type | Description | Field Number |
  486. |----------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  487. | result | Result (see below) | The result of applying this chunk. | 1 |
  488. | refetch_chunks | repeated uint32 | Refetch and reapply the given chunks, regardless of `result`. Only the listed chunks will be refetched, and reapplied in sequential order. | 2 |
  489. | reject_senders | repeated string | Reject the given P2P senders, regardless of `Result`. Any chunks already applied will not be refetched unless explicitly requested, but queued chunks from these senders will be discarded, and new chunks or other snapshots rejected. | 3 |
  490. ```proto
  491. enum Result {
  492. UNKNOWN = 0; // Unknown result, abort all snapshot restoration
  493. ACCEPT = 1; // The chunk was accepted.
  494. ABORT = 2; // Abort snapshot restoration, and don't try any other snapshots.
  495. RETRY = 3; // Reapply this chunk, combine with `RefetchChunks` and `RejectSenders` as appropriate.
  496. RETRY_SNAPSHOT = 4; // Restart this snapshot from `OfferSnapshot`, reusing chunks unless instructed otherwise.
  497. REJECT_SNAPSHOT = 5; // Reject this snapshot, try a different one.
  498. }
  499. ```
  500. * **Usage**:
  501. * The application can choose to refetch chunks and/or ban P2P peers as appropriate. Tendermint
  502. will not do this unless instructed by the application.
  503. * The application may want to verify each chunk, e.g. by attaching chunk hashes in
  504. `Snapshot.Metadata` and/or incrementally verifying contents against `AppHash`.
  505. * When all chunks have been accepted, Tendermint will make an ABCI `Info` call to verify that
  506. `LastBlockAppHash` and `LastBlockHeight` matches the expected values, and record the
  507. `AppVersion` in the node state. It then switches to fast sync or consensus and joins the
  508. network.
  509. * If Tendermint is unable to retrieve the next chunk after some time (e.g. because no suitable
  510. peers are available), it will reject the snapshot and try a different one via `OfferSnapshot`.
  511. The application should be prepared to reset and accept it or abort as appropriate.
  512. ## Data Types
  513. Most of the data structures used in ABCI are shared [common data structures](../core/data_structures.md). In certain cases, ABCI uses different data structures which are documented here:
  514. ### Validator
  515. * **Fields**:
  516. | Name | Type | Description | Field Number |
  517. |---------|-------|---------------------------------------------------------------------|--------------|
  518. | address | bytes | [Address](../core/data_structures.md#address) of validator | 1 |
  519. | power | int64 | Voting power of the validator | 3 |
  520. * **Usage**:
  521. * Validator identified by address
  522. * Used in RequestBeginBlock as part of VoteInfo
  523. * Does not include PubKey to avoid sending potentially large quantum pubkeys
  524. over the ABCI
  525. ### ValidatorUpdate
  526. * **Fields**:
  527. | Name | Type | Description | Field Number |
  528. |---------|--------------------------------------------------|-------------------------------|--------------|
  529. | pub_key | [Public Key](../core/data_structures.md#pub_key) | Public key of the validator | 1 |
  530. | power | int64 | Voting power of the validator | 2 |
  531. * **Usage**:
  532. * Validator identified by PubKey
  533. * Used to tell Tendermint to update the validator set
  534. ### VoteInfo
  535. * **Fields**:
  536. | Name | Type | Description | Field Number |
  537. |-------------------|-------------------------|--------------------------------------------------------------|--------------|
  538. | validator | [Validator](#validator) | A validator | 1 |
  539. | signed_last_block | bool | Indicates whether or not the validator signed the last block | 2 |
  540. * **Usage**:
  541. * Indicates whether a validator signed the last block, allowing for rewards
  542. based on validator availability
  543. ### Evidence
  544. * **Fields**:
  545. | Name | Type | Description | Field Number |
  546. |--------------------|--------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|--------------|
  547. | type | [EvidenceType](#evidencetype) | Type of the evidence. An enum of possible evidence's. | 1 |
  548. | validator | [Validator](#validator) | The offending validator | 2 |
  549. | height | int64 | Height when the offense occurred | 3 |
  550. | time | [google.protobuf.Timestamp](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp) | Time of the block that was committed at the height that the offense occurred | 4 |
  551. | total_voting_power | int64 | Total voting power of the validator set at height `Height` | 5 |
  552. #### EvidenceType
  553. * **Fields**
  554. EvidenceType is an enum with the listed fields:
  555. | Name | Field Number |
  556. |---------------------|--------------|
  557. | UNKNOWN | 0 |
  558. | DUPLICATE_VOTE | 1 |
  559. | LIGHT_CLIENT_ATTACK | 2 |
  560. ### LastCommitInfo
  561. * **Fields**:
  562. | Name | Type | Description | Field Number |
  563. |-------|--------------------------------|-----------------------------------------------------------------------------------------------------------------------|--------------|
  564. | round | int32 | Commit round. Reflects the total amount of rounds it took to come to consensus for the current block. | 1 |
  565. | votes | repeated [VoteInfo](#voteinfo) | List of validators addresses in the last validator set with their voting power and whether or not they signed a vote. | 2 |
  566. ### ConsensusParams
  567. * **Fields**:
  568. | Name | Type | Description | Field Number |
  569. |-----------|---------------------------------------------------------------|------------------------------------------------------------------------------|--------------|
  570. | block | [BlockParams](../core/data_structures.md#blockparams) | Parameters limiting the size of a block and time between consecutive blocks. | 1 |
  571. | evidence | [EvidenceParams](../core/data_structures.md#evidenceparams) | Parameters limiting the validity of evidence of byzantine behaviour. | 2 |
  572. | validator | [ValidatorParams](../core/data_structures.md#validatorparams) | Parameters limiting the types of public keys validators can use. | 3 |
  573. | version | [VersionsParams](../core/data_structures.md#versionparams) | The ABCI application version. | 4 |
  574. | synchrony | [SynchronyParams](../core/data_structures.md#synchronyparams) | Parameters that determine the bounds under which a proposed block's timestamp is considered valid. | 5 |
  575. | timeout | [TimeoutParams](../core/data_structures.md#timeoutparams) | Parameters that configure the timeouts for the steps of the Tendermint consensus algorithm. | 6 |
  576. ### ProofOps
  577. * **Fields**:
  578. | Name | Type | Description | Field Number |
  579. |------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  580. | ops | repeated [ProofOp](#proofop) | List of chained Merkle proofs, of possibly different types. The Merkle root of one op is the value being proven in the next op. The Merkle root of the final op should equal the ultimate root hash being verified against.. | 1 |
  581. ### ProofOp
  582. * **Fields**:
  583. | Name | Type | Description | Field Number |
  584. |------|--------|------------------------------------------------|--------------|
  585. | type | string | Type of Merkle proof and how it's encoded. | 1 |
  586. | key | bytes | Key in the Merkle tree that this proof is for. | 2 |
  587. | data | bytes | Encoded Merkle proof for the key. | 3 |
  588. ### Snapshot
  589. * **Fields**:
  590. | Name | Type | Description | Field Number |
  591. |----------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
  592. | height | uint64 | The height at which the snapshot was taken (after commit). | 1 |
  593. | format | uint32 | An application-specific snapshot format, allowing applications to version their snapshot data format and make backwards-incompatible changes. Tendermint does not interpret this. | 2 |
  594. | chunks | uint32 | The number of chunks in the snapshot. Must be at least 1 (even if empty). | 3 |
  595. | hash | bytes | TAn arbitrary snapshot hash. Must be equal only for identical snapshots across nodes. Tendermint does not interpret the hash, it only compares them. | 3 |
  596. | metadata | bytes | Arbitrary application metadata, for example chunk hashes or other verification data. | 3 |
  597. * **Usage**:
  598. * Used for state sync snapshots, see the [state sync section](../p2p/messages/state-sync.md) for details.
  599. * A snapshot is considered identical across nodes only if _all_ fields are equal (including
  600. `Metadata`). Chunks may be retrieved from all nodes that have the same snapshot.
  601. * When sent across the network, a snapshot message can be at most 4 MB.