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.

85 lines
2.7 KiB

  1. ---
  2. order: 1
  3. parent:
  4. title: State Sync
  5. order: 4
  6. ---
  7. State sync allows new nodes to rapidly bootstrap and join the network by discovering, fetching,
  8. and restoring state machine snapshots. For more information, see the [state sync ABCI section](https://docs.tendermint.com/master/spec/abci/abci.html#state-sync)).
  9. The state sync reactor has two main responsibilities:
  10. * Serving state machine snapshots taken by the local ABCI application to new nodes joining the
  11. network.
  12. * Discovering existing snapshots and fetching snapshot chunks for an empty local application
  13. being bootstrapped.
  14. The state sync process for bootstrapping a new node is described in detail in the section linked
  15. above. While technically part of the reactor (see `statesync/syncer.go` and related components),
  16. this document will only cover the P2P reactor component.
  17. For details on the ABCI methods and data types, see the [ABCI documentation](https://docs.tendermint.com/master/spec/abci/).
  18. Information on how to configure state sync is located in the [nodes section](../../nodes/state-sync.md)
  19. ## State Sync P2P Protocol
  20. When a new node begin state syncing, it will ask all peers it encounters if it has any
  21. available snapshots:
  22. ```go
  23. type snapshotsRequestMessage struct{}
  24. ```
  25. The receiver will query the local ABCI application via `ListSnapshots`, and send a message
  26. containing snapshot metadata (limited to 4 MB) for each of the 10 most recent snapshots:
  27. ```go
  28. type snapshotsResponseMessage struct {
  29. Height uint64
  30. Format uint32
  31. Chunks uint32
  32. Hash []byte
  33. Metadata []byte
  34. }
  35. ```
  36. The node running state sync will offer these snapshots to the local ABCI application via
  37. `OfferSnapshot` ABCI calls, and keep track of which peers contain which snapshots. Once a snapshot
  38. is accepted, the state syncer will request snapshot chunks from appropriate peers:
  39. ```go
  40. type chunkRequestMessage struct {
  41. Height uint64
  42. Format uint32
  43. Index uint32
  44. }
  45. ```
  46. The receiver will load the requested chunk from its local application via `LoadSnapshotChunk`,
  47. and respond with it (limited to 16 MB):
  48. ```go
  49. type chunkResponseMessage struct {
  50. Height uint64
  51. Format uint32
  52. Index uint32
  53. Chunk []byte
  54. Missing bool
  55. }
  56. ```
  57. Here, `Missing` is used to signify that the chunk was not found on the peer, since an empty
  58. chunk is a valid (although unlikely) response.
  59. The returned chunk is given to the ABCI application via `ApplySnapshotChunk` until the snapshot
  60. is restored. If a chunk response is not returned within some time, it will be re-requested,
  61. possibly from a different peer.
  62. The ABCI application is able to request peer bans and chunk refetching as part of the ABCI protocol.
  63. If no state sync is in progress (i.e. during normal operation), any unsolicited response messages
  64. are discarded.