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.

724 lines
46 KiB

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