@@ -10,94 +10,32 @@ import (
10
10
"github.com/ChainSafe/gossamer/lib/common"
11
11
)
12
12
13
- // accept signifies that an incoming statement was accepted.
14
- type accept interface { //nolint:unused
15
- isAccept ()
16
- }
17
-
18
- // ok means neither the peer nor the originator have apparently exceeded limits.
19
- // Candidate or statement may already be known.
20
- type ok struct {}
21
-
22
- func (ok ) isAccept () {}
23
-
24
- // / withPrejudice means accept the message; the peer hasn't exceeded limits but the originator has.
25
- type withPrejudice struct {}
26
-
27
- func (withPrejudice ) isAccept () {}
28
-
29
- // / rejectIncoming signifies that an incoming statement was rejected.
30
- type rejectIncoming interface { //nolint:unused
31
- isRejectIncoming ()
32
- }
13
+ type acceptOrReject byte
33
14
34
- // excessiveSecondedIncoming means peer sent excessive `Seconded` statements.
35
- type excessiveSecondedIncoming struct {}
15
+ const (
16
+ // ok means neither the peer nor the originator have apparently exceeded limits.
17
+ // Candidate or statement may already be known.
18
+ ok acceptOrReject = iota
36
19
37
- func (excessiveSecondedIncoming ) isRejectIncoming () {}
20
+ // withPrejudice means accept the message; the peer hasn't exceeded limits but the originator has.
21
+ withPrejudice
38
22
39
- // notInGroupIncoming means sender or originator is not in the group.
40
- type notInGroupIncoming struct {}
23
+ // excessiveSeconded means peer sent excessive `Seconded` statements or we attempted to send excessive `Seconded`
24
+ // statements. The latter indicates a bug on the local node's code.
25
+ excessiveSeconded
41
26
42
- func (notInGroupIncoming ) isRejectIcoming () {} //nolint:unused
43
-
44
- // candidateUnknownIncoming means the candidate is unknown to us. Only applies to `Valid` statements.
45
- type candidateUnknownIncoming struct {}
46
-
47
- func (candidateUnknownIncoming ) isRejectIncoming () {}
48
-
49
- // duplicateIncoming means the statement is a duplicate.
50
- type duplicateIncoming struct {}
51
-
52
- func (duplicateIncoming ) isRejectIncoming () {}
53
-
54
- // / rejectOutgoing signifies that an outgoing statement was rejected.
55
- type rejectOutgoing interface { //nolint:unused
56
- isRejectOutgoing ()
57
- }
27
+ // notInGroup means sender/target or originator is not in the group.
28
+ notInGroup
58
29
59
- // candidateUnknownOutgoing means the candidate was unknown. Only applies to `Valid` statements.
60
- type candidateUnknownOutgoing struct {}
30
+ // candidateUnknown means the candidate is unknown to us . Only applies to `Valid` statements.
31
+ candidateUnknown
61
32
62
- func (candidateUnknownOutgoing ) isRejectOutgoing () {}
33
+ // duplicate means the statement is a duplicate.
34
+ duplicate
63
35
64
- // excessiveSecondedOutgoing means we attempted to send excessive `Seconded` statements.
65
- // Indicates a bug on the local node's code.
66
- type excessiveSecondedOutgoing struct {}
67
-
68
- func (excessiveSecondedOutgoing ) isRejectOutgoing () {}
69
-
70
- // knownOutgoing means the statement was already known to the peer.
71
- type knownOutgoing struct {}
72
-
73
- func (knownOutgoing ) isRejectOutgoing () {}
74
-
75
- // notInGroupOutgoing means the target or originator are not in the group.
76
- type notInGroupOutgoing struct {}
77
-
78
- func (notInGroupOutgoing ) isRejectOutgoing () {}
79
-
80
- type acceptOrRejectIncoming interface {
81
- isAcceptOrRejectIncoming ()
82
- }
83
-
84
- func (ok ) isAcceptOrRejectIncoming () {}
85
- func (withPrejudice ) isAcceptOrRejectIncoming () {}
86
- func (excessiveSecondedIncoming ) isAcceptOrRejectIncoming () {}
87
- func (notInGroupIncoming ) isAcceptOrRejectIncoming () {}
88
- func (candidateUnknownIncoming ) isAcceptOrRejectIncoming () {}
89
- func (duplicateIncoming ) isAcceptOrRejectIncoming () {}
90
-
91
- type acceptOrRejectOutgoing interface {
92
- isAcceptOrRejectOutgoing ()
93
- }
94
-
95
- func (ok ) isAcceptOrRejectOutgoing () {}
96
- func (withPrejudice ) isAcceptOrRejectOutgoing () {}
97
- func (candidateUnknownOutgoing ) isAcceptOrRejectOutgoing () {}
98
- func (excessiveSecondedOutgoing ) isAcceptOrRejectOutgoing () {}
99
- func (knownOutgoing ) isAcceptOrRejectOutgoing () {}
100
- func (notInGroupOutgoing ) isAcceptOrRejectOutgoing () {}
36
+ // known means the statement was already known to the peer.
37
+ known
38
+ )
101
39
102
40
// knowledge about a candidate
103
41
type knowledge interface {
@@ -214,13 +152,13 @@ func (c *clusterTracker) canReceive(
214
152
sender parachaintypes.ValidatorIndex ,
215
153
originator parachaintypes.ValidatorIndex ,
216
154
statement parachaintypes.CompactStatement ,
217
- ) acceptOrRejectIncoming {
155
+ ) acceptOrReject {
218
156
if ! c .isInGroup (sender ) || ! c .isInGroup (originator ) {
219
- return notInGroupIncoming {}
157
+ return notInGroup
220
158
}
221
159
222
160
if c .theySent (sender , specific {statement , originator }) {
223
- return duplicateIncoming {}
161
+ return duplicate
224
162
}
225
163
226
164
switch statement .(type ) {
@@ -250,20 +188,20 @@ func (c *clusterTracker) canReceive(
250
188
}
251
189
252
190
if otherSecondedForOrigFromRemote == c .secondingLimit {
253
- return excessiveSecondedIncoming {}
191
+ return excessiveSeconded
254
192
}
255
193
256
194
// at this point, it doesn't seem like the remote has done anything wrong.
257
195
if c .secondedAlreadyOrWithinLimit (originator , statement .CandidateHash ()) {
258
- return ok {}
196
+ return ok
259
197
} else {
260
- return withPrejudice {}
198
+ return withPrejudice
261
199
}
262
200
case * parachaintypes.CompactValid :
263
201
if ! c .knowsCandidate (sender , statement .CandidateHash ()) {
264
- return candidateUnknownIncoming {}
202
+ return candidateUnknown
265
203
}
266
- return ok {}
204
+ return ok
267
205
default :
268
206
panic ("unreachable" )
269
207
}
@@ -461,28 +399,28 @@ func (c *clusterTracker) canSend(
461
399
target parachaintypes.ValidatorIndex ,
462
400
originator parachaintypes.ValidatorIndex ,
463
401
statement parachaintypes.CompactStatement ,
464
- ) acceptOrRejectOutgoing {
402
+ ) acceptOrReject {
465
403
if ! c .isInGroup (target ) || ! c .isInGroup (originator ) {
466
- return notInGroupOutgoing {}
404
+ return notInGroup
467
405
}
468
406
469
407
if c .theyKnowStatement (target , originator , statement ) {
470
- return knownOutgoing {}
408
+ return known
471
409
}
472
410
473
411
switch statement .(type ) {
474
412
case * parachaintypes.CompactSeconded :
475
413
// we send the same `Seconded` statements to all our peers, and only the first `k`
476
414
// from each originator.
477
415
if ! c .secondedAlreadyOrWithinLimit (originator , statement .CandidateHash ()) {
478
- return excessiveSecondedOutgoing {}
416
+ return excessiveSeconded
479
417
}
480
- return ok {}
418
+ return ok
481
419
case * parachaintypes.CompactValid :
482
420
if ! c .knowsCandidate (target , statement .CandidateHash ()) {
483
- return candidateUnknownOutgoing {}
421
+ return candidateUnknown
484
422
}
485
- return ok {}
423
+ return ok
486
424
default :
487
425
panic ("unreachable" )
488
426
}
0 commit comments