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.

111 lines
6.0 KiB

  1. ---
  2. order: 5
  3. ---
  4. # State Sync
  5. ## Channels
  6. State sync has three distinct channels. The channel identifiers are listed below.
  7. | Name | Number |
  8. |-------------------|--------|
  9. | SnapshotChannel | 96 |
  10. | ChunkChannel | 97 |
  11. | LightBlockChannel | 98 |
  12. ## Message Types
  13. ### SnapshotRequest
  14. When a new node begin state syncing, it will ask all peers it encounters if it has any
  15. available snapshots:
  16. | Name | Type | Description | Field Number |
  17. |----------|--------|-------------|--------------|
  18. ### SnapShotResponse
  19. The receiver will query the local ABCI application via `ListSnapshots`, and send a message
  20. containing snapshot metadata (limited to 4 MB) for each of the 10 most recent snapshots: and stored at the application layer. When a peer is starting it will request snapshots.
  21. | Name | Type | Description | Field Number |
  22. |----------|--------|-----------------------------------------------------------|--------------|
  23. | height | uint64 | Height at which the snapshot was taken | 1 |
  24. | format | uint32 | Format of the snapshot. | 2 |
  25. | chunks | uint32 | How many chunks make up the snapshot | 3 |
  26. | hash | bytes | Arbitrary snapshot hash | 4 |
  27. | metadata | bytes | Arbitrary application data. **May be non-deterministic.** | 5 |
  28. ### ChunkRequest
  29. The node running state sync will offer these snapshots to the local ABCI application via
  30. `OfferSnapshot` ABCI calls, and keep track of which peers contain which snapshots. Once a snapshot
  31. is accepted, the state syncer will request snapshot chunks from appropriate peers:
  32. | Name | Type | Description | Field Number |
  33. |--------|--------|-------------------------------------------------------------|--------------|
  34. | height | uint64 | Height at which the chunk was created | 1 |
  35. | format | uint32 | Format chosen for the chunk. **May be non-deterministic.** | 2 |
  36. | index | uint32 | Index of the chunk within the snapshot. | 3 |
  37. ### ChunkResponse
  38. The receiver will load the requested chunk from its local application via `LoadSnapshotChunk`,
  39. and respond with it (limited to 16 MB):
  40. | Name | Type | Description | Field Number |
  41. |---------|--------|-------------------------------------------------------------|--------------|
  42. | height | uint64 | Height at which the chunk was created | 1 |
  43. | format | uint32 | Format chosen for the chunk. **May be non-deterministic.** | 2 |
  44. | index | uint32 | Index of the chunk within the snapshot. | 3 |
  45. | hash | bytes | Arbitrary snapshot hash | 4 |
  46. | missing | bool | Arbitrary application data. **May be non-deterministic.** | 5 |
  47. Here, `Missing` is used to signify that the chunk was not found on the peer, since an empty
  48. chunk is a valid (although unlikely) response.
  49. The returned chunk is given to the ABCI application via `ApplySnapshotChunk` until the snapshot
  50. is restored. If a chunk response is not returned within some time, it will be re-requested,
  51. possibly from a different peer.
  52. The ABCI application is able to request peer bans and chunk refetching as part of the ABCI protocol.
  53. ### LightBlockRequest
  54. To verify state and to provide state relevant information for consensus, the node will ask peers for
  55. light blocks at specified heights.
  56. | Name | Type | Description | Field Number |
  57. |----------|--------|----------------------------|--------------|
  58. | height | uint64 | Height of the light block | 1 |
  59. ### LightBlockResponse
  60. The sender will retrieve and construct the light block from both the block and state stores. The
  61. receiver will verify the data by comparing the hashes and store the header, commit and validator set
  62. if necessary. The light block at the height of the snapshot will be used to verify the `AppHash`.
  63. | Name | Type | Description | Field Number |
  64. |---------------|---------------------------------------------------------|--------------------------------------|--------------|
  65. | light_block | [LightBlock](../../core/data_structures.md#lightblock) | light block at the height requested | 1 |
  66. State sync will use [light client verification](../../light-client/verification.README.md) to verify
  67. the light blocks.
  68. If no state sync is in progress (i.e. during normal operation), any unsolicited response messages
  69. are discarded.
  70. ### Message
  71. Message is a [`oneof` protobuf type](https://developers.google.com/protocol-buffers/docs/proto#oneof). The `oneof` consists of six messages.
  72. | Name | Type | Description | Field Number |
  73. |----------------------|--------------------------------------------|----------------------------------------------|--------------|
  74. | snapshots_request | [SnapshotRequest](#snapshotrequest) | Request a recent snapshot from a peer | 1 |
  75. | snapshots_response | [SnapshotResponse](#snapshotresponse) | Respond with the most recent snapshot stored | 2 |
  76. | chunk_request | [ChunkRequest](#chunkrequest) | Request chunks of the snapshot. | 3 |
  77. | chunk_response | [ChunkRequest](#chunkresponse) | Response of chunks used to recreate state. | 4 |
  78. | light_block_request | [LightBlockRequest](#lightblockrequest) | Request a light block. | 5 |
  79. | light_block_response | [LightBlockResponse](#lightblockresponse) | Respond with a light block | 6 |