-
Notifications
You must be signed in to change notification settings - Fork 662
/
sender.go
159 lines (137 loc) · 5.64 KB
/
sender.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
)
// Sender defines how a consensus engine sends messages and requests to other
// validators
type Sender interface {
snow.Acceptor
StateSummarySender
AcceptedStateSummarySender
FrontierSender
AcceptedSender
FetchSender
QuerySender
Gossiper
AppSender
}
// StateSummarySender defines how a consensus engine sends state sync messages to
// other nodes.
type StateSummarySender interface {
// SendGetStateSummaryFrontier requests that every node in [nodeIDs] sends a
// StateSummaryFrontier message.
SendGetStateSummaryFrontier(nodeIDs ids.NodeIDSet, requestID uint32)
// SendStateSummaryFrontier responds to a StateSummaryFrontier message with this
// engine's current state summary frontier.
SendStateSummaryFrontier(nodeID ids.NodeID, requestID uint32, summary []byte)
}
type AcceptedStateSummarySender interface {
// SendGetAcceptedStateSummary requests that every node in [nodeIDs] sends an
// AcceptedStateSummary message with all the state summary IDs referenced by [heights]
// that the node thinks are accepted.
SendGetAcceptedStateSummary(nodeIDs ids.NodeIDSet, requestID uint32, heights []uint64)
// SendAcceptedStateSummary responds to a AcceptedStateSummary message with a
// set of summary ids that are accepted.
SendAcceptedStateSummary(nodeID ids.NodeID, requestID uint32, summaryIDs []ids.ID)
}
// FrontierSender defines how a consensus engine sends frontier messages to
// other nodes.
type FrontierSender interface {
// SendGetAcceptedFrontier requests that every node in [nodeIDs] sends an
// AcceptedFrontier message.
SendGetAcceptedFrontier(nodeIDs ids.NodeIDSet, requestID uint32)
// SendAcceptedFrontier responds to a AcceptedFrontier message with this
// engine's current accepted frontier.
SendAcceptedFrontier(
nodeID ids.NodeID,
requestID uint32,
containerIDs []ids.ID,
)
}
// AcceptedSender defines how a consensus engine sends messages pertaining to
// accepted containers
type AcceptedSender interface {
// SendGetAccepted requests that every node in [nodeIDs] sends an Accepted
// message with all the IDs in [containerIDs] that the node thinks are
// accepted.
SendGetAccepted(
nodeIDs ids.NodeIDSet,
requestID uint32,
containerIDs []ids.ID,
)
// SendAccepted responds to a GetAccepted message with a set of IDs of
// containers that are accepted.
SendAccepted(nodeID ids.NodeID, requestID uint32, containerIDs []ids.ID)
}
// FetchSender defines how a consensus engine sends retrieval messages to other
// nodes.
type FetchSender interface {
// Request that the specified node send the specified container to this
// node.
SendGet(nodeID ids.NodeID, requestID uint32, containerID ids.ID)
// SendGetAncestors requests that node [nodeID] send container [containerID]
// and its ancestors.
SendGetAncestors(nodeID ids.NodeID, requestID uint32, containerID ids.ID)
// Tell the specified node that the container whose ID is [containerID] has
// body [container].
SendPut(
nodeID ids.NodeID,
requestID uint32,
containerID ids.ID,
container []byte,
)
// Give the specified node several containers at once. Should be in response
// to a GetAncestors message with request ID [requestID] from the node.
SendAncestors(nodeID ids.NodeID, requestID uint32, containers [][]byte)
}
// QuerySender defines how a consensus engine sends query messages to other
// nodes.
type QuerySender interface {
// Request from the specified nodes their preferred frontier, given the
// existence of the specified container.
// This is the same as PullQuery, except that this message includes not only
// the ID of the container but also its body.
SendPushQuery(
nodeIDs ids.NodeIDSet,
requestID uint32,
containerID ids.ID,
container []byte,
)
// Request from the specified nodes their preferred frontier, given the
// existence of the specified container.
SendPullQuery(nodeIDs ids.NodeIDSet, requestID uint32, containerID ids.ID)
// Send chits to the specified node
SendChits(nodeID ids.NodeID, requestID uint32, votes []ids.ID)
// Send chits v2 to the specified node
SendChitsV2(nodeID ids.NodeID, requestID uint32, votes []ids.ID, vote ids.ID)
}
// Gossiper defines how a consensus engine gossips a container on the accepted
// frontier to other nodes
type Gossiper interface {
// Gossip the provided container throughout the network
SendGossip(containerID ids.ID, container []byte)
}
// AppSender sends application (VM) level messages.
// See also common.AppHandler.
type AppSender interface {
// Send an application-level request.
// A nil return value guarantees that for each nodeID in [nodeIDs],
// the VM corresponding to this AppSender eventually receives either:
// * An AppResponse from nodeID with ID [requestID]
// * An AppRequestFailed from nodeID with ID [requestID]
// Exactly one of the above messages will eventually be received per nodeID.
// A non-nil error should be considered fatal.
SendAppRequest(nodeIDs ids.NodeIDSet, requestID uint32, appRequestBytes []byte) error
// Send an application-level response to a request.
// This response must be in response to an AppRequest that the VM corresponding
// to this AppSender received from [nodeID] with ID [requestID].
// A non-nil error should be considered fatal.
SendAppResponse(nodeID ids.NodeID, requestID uint32, appResponseBytes []byte) error
// Gossip an application-level message.
// A non-nil error should be considered fatal.
SendAppGossip(appGossipBytes []byte) error
SendAppGossipSpecific(nodeIDs ids.NodeIDSet, appGossipBytes []byte) error
}