-
Notifications
You must be signed in to change notification settings - Fork 175
/
synchronization.go
79 lines (70 loc) · 2.67 KB
/
synchronization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package messages
import (
"github.com/onflow/flow-go/model/cluster"
"github.com/onflow/flow-go/model/flow"
)
// SyncRequest is part of the synchronization protocol and represents a node on
// the network sharing the height of its latest finalized block and requesting
// the same information from the recipient.
// All SyncRequest messages are validated before being processed. If validation fails, then a misbehavior report is created.
// See synchronization.validateSyncRequestForALSP for more details.
type SyncRequest struct {
Nonce uint64
Height uint64
}
// SyncResponse is part of the synchronization protocol and represents the reply
// to a synchronization request that contains the latest finalized block height
// of the responding node.
type SyncResponse struct {
Nonce uint64
Height uint64
}
// RangeRequest is part of the synchronization protocol and represents an active
// (pulling) attempt to synchronize with the consensus state of the network. It
// requests finalized blocks by a range of block heights, including from and to
// heights.
// All RangeRequest messages are validated before being processed. If validation fails, then a misbehavior report is created.
// See synchronization.validateRangeRequestForALSP for more details.
type RangeRequest struct {
Nonce uint64
FromHeight uint64
ToHeight uint64
}
// BatchRequest is part of the synchronization protocol and represents an active
// (pulling) attempt to synchronize with the consensus state of the network. It
// requests finalized or unfinalized blocks by a list of block IDs.
// All BatchRequest messages are validated before being processed. If validation fails, then a misbehavior report is created.
// See synchronization.validateBatchRequestForALSP for more details.
type BatchRequest struct {
Nonce uint64
BlockIDs []flow.Identifier
}
// BlockResponse is part of the synchronization protocol and represents the
// reply to any active synchronization attempts. It contains a list of blocks
// that should correspond to the request.
type BlockResponse struct {
Nonce uint64
Blocks []UntrustedBlock
}
func (br *BlockResponse) BlocksInternal() []*flow.Block {
internal := make([]*flow.Block, len(br.Blocks))
for i, block := range br.Blocks {
block := block
internal[i] = block.ToInternal()
}
return internal
}
// ClusterBlockResponse is the same thing as BlockResponse, but for cluster
// consensus.
type ClusterBlockResponse struct {
Nonce uint64
Blocks []UntrustedClusterBlock
}
func (br *ClusterBlockResponse) BlocksInternal() []*cluster.Block {
internal := make([]*cluster.Block, len(br.Blocks))
for i, block := range br.Blocks {
block := block
internal[i] = block.ToInternal()
}
return internal
}