通道
状态同步有四个不同的通道。通道标识符如下所示。| 名称 | 编号 |
|---|---|
| SnapshotChannel | 96 |
| ChunkChannel | 97 |
| LightBlockChannel | 98 |
| ParamsChannel | 99 |
消息类型
SnapshotRequest
当一个新节点开始进行状态同步时,它会询问遇到的所有对等节点是否有可用的快照:| 名称 | 类型 | 说明 | 字段编号 |
|---|
SnapShotResponse
接收方将通过ListSnapshots 查询本地 ABCI 应用,并为最近的 10 个快照分别发送一条包含快照元数据的消息(限制为 4 MB);这些快照存储在应用层。当一个对等节点启动时,它会请求快照。
| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 拍摄该快照时的高度 | 1 |
| format | uint32 | 快照的格式。 | 2 |
| chunks | uint32 | 构成该快照的分块数量 | 3 |
| hash | bytes | 任意快照哈希 | 4 |
| metadata | bytes | 任意应用数据。可能是非确定性的。 | 5 |
ChunkRequest
运行状态同步的节点会通过OfferSnapshot ABCI 调用将这些快照提供给本地 ABCI 应用,并跟踪哪些对等节点持有哪些快照。一旦某个快照被接受,状态同步器就会向合适的对等节点请求该快照的分块:
| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 创建该分块时的高度 | 1 |
| format | uint32 | 为该分块选择的格式。可能是非确定性的。 | 2 |
| index | uint32 | 该分块在快照中的索引。 | 3 |
ChunkResponse
接收方将通过LoadSnapshotChunk 从本地应用加载所请求的分块,并返回该分块(限制为 16 MB):
| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 创建该分块时的高度 | 1 |
| format | uint32 | 为该分块选择的格式。可能是非确定性的。 | 2 |
| index | uint32 | 该分块在快照中的索引。 | 3 |
| hash | bytes | 任意快照哈希 | 4 |
| missing | bool | 任意应用数据。可能是非确定性的。 | 5 |
Missing 用于表示该分块在对等节点上未找到,因为空分块也是一种有效的响应(尽管不太可能出现)。
返回的分块会通过 ApplySnapshotChunk 提交给 ABCI 应用,直到快照恢复完成。如果某个分块响应在一段时间内未返回,将会重新请求,且可能改由另一个对等节点提供。
ABCI 应用能够作为 ABCI 协议的一部分,请求封禁对等节点并重新抓取分块。
LightBlockRequest
为了验证状态并为共识提供与状态相关的信息,节点会向对等节点请求指定高度的轻区块。| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 轻区块的高度 | 1 |
LightBlockResponse
接收方会从区块存储和状态存储中检索并构造轻区块。接收方会通过比较哈希来验证数据,并在必要时存储区块头、提交信息和验证者集合。快照高度对应的轻区块将用于验证AppHash。
| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| light_block | LightBlock | 请求高度对应的轻区块 | 1 |
ParamsRequest
为了构建状态,状态提供方会请求快照高度处的参数,并使用区块头对其进行验证。| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 共识参数对应的高度 | 1 |
ParamsResponse
请求的接收方将使用状态存储获取该高度的共识参数,并将其返回给发送方。| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| height | uint64 | 共识参数对应的高度 | 1 |
| consensus_params | ConsensusParams | 请求高度对应的共识参数 | 2 |
Message
Message 是一种oneof protobuf type。该 oneof 由八种消息组成。
| 名称 | 类型 | 说明 | 字段编号 |
|---|---|---|---|
| snapshots_request | SnapshotRequest | 向对等节点请求最近的快照 | 1 |
| snapshots_response | SnapshotResponse | 返回最近存储的快照 | 2 |
| chunk_request | ChunkRequest | 请求快照的分块。 | 3 |
| chunk_response | ChunkRequest | 返回用于重建状态的分块。 | 4 |
| light_block_request | LightBlockRequest | 请求轻区块。 | 5 |
| light_block_response | LightBlockResponse | 返回轻区块 | 6 |
| params_request | ParamsRequest | 请求某一高度的共识参数。 | 7 |
| params_response | ParamsResponse | 返回共识参数 | 8 |
Channels
State sync has four distinct channels. The channel identifiers are listed below.| Name | Number |
|---|---|
| SnapshotChannel | 96 |
| ChunkChannel | 97 |
| LightBlockChannel | 98 |
| ParamsChannel | 99 |
Message Types
SnapshotRequest
When a new node begin state syncing, it will ask all peers it encounters if it has any available snapshots:| Name | Type | Description | Field Number |
|---|
SnapShotResponse
The receiver will query the local ABCI application viaListSnapshots, and send a message
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.
| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height at which the snapshot was taken | 1 |
| format | uint32 | Format of the snapshot. | 2 |
| chunks | uint32 | How many chunks make up the snapshot | 3 |
| hash | bytes | Arbitrary snapshot hash | 4 |
| metadata | bytes | Arbitrary application data. May be non-deterministic. | 5 |
ChunkRequest
The node running state sync will offer these snapshots to the local ABCI application viaOfferSnapshot ABCI calls, and keep track of which peers contain which snapshots. Once a snapshot
is accepted, the state syncer will request snapshot chunks from appropriate peers:
| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height at which the chunk was created | 1 |
| format | uint32 | Format chosen for the chunk. May be non-deterministic. | 2 |
| index | uint32 | Index of the chunk within the snapshot. | 3 |
ChunkResponse
The receiver will load the requested chunk from its local application viaLoadSnapshotChunk,
and respond with it (limited to 16 MB):
| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height at which the chunk was created | 1 |
| format | uint32 | Format chosen for the chunk. May be non-deterministic. | 2 |
| index | uint32 | Index of the chunk within the snapshot. | 3 |
| hash | bytes | Arbitrary snapshot hash | 4 |
| missing | bool | Arbitrary application data. May be non-deterministic. | 5 |
Missing is used to signify that the chunk was not found on the peer, since an empty
chunk is a valid (although unlikely) response.
The returned chunk is given to the ABCI application via ApplySnapshotChunk until the snapshot
is restored. If a chunk response is not returned within some time, it will be re-requested,
possibly from a different peer.
The ABCI application is able to request peer bans and chunk refetching as part of the ABCI protocol.
LightBlockRequest
To verify state and to provide state relevant information for consensus, the node will ask peers for light blocks at specified heights.| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height of the light block | 1 |
LightBlockResponse
The receiver will retrieve and construct the light block from both the block and state stores. The receiver will verify the data by comparing the hashes and store the header, commit and validator set if necessary. The light block at the height of the snapshot will be used to verify theAppHash.
| Name | Type | Description | Field Number |
|---|---|---|---|
| light_block | LightBlock | Light block at the height requested | 1 |
ParamsRequest
In order to build the state, the state provider will request the params at the height of the snapshot and use the header to verify it.| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height of the consensus params | 1 |
ParamsResponse
A reciever to the request will use the state store to fetch the consensus params at that height and return it to the sender.| Name | Type | Description | Field Number |
|---|---|---|---|
| height | uint64 | Height of the consensus params | 1 |
| consensus_params | ConsensusParams | Consensus params at the height requested | 2 |
Message
Message is aoneof protobuf type. The oneof consists of eight messages.
| Name | Type | Description | Field Number |
|---|---|---|---|
| snapshots_request | SnapshotRequest | Request a recent snapshot from a peer | 1 |
| snapshots_response | SnapshotResponse | Respond with the most recent snapshot stored | 2 |
| chunk_request | ChunkRequest | Request chunks of the snapshot. | 3 |
| chunk_response | ChunkRequest | Response of chunks used to recreate state. | 4 |
| light_block_request | LightBlockRequest | Request a light block. | 5 |
| light_block_response | LightBlockResponse | Respond with a light block | 6 |
| params_request | ParamsRequest | Request the consensus params at a height. | 7 |
| params_response | ParamsResponse | Respond with the consensus params | 8 |