@@ -10,94 +10,32 @@ import (
1010 "github.com/ChainSafe/gossamer/lib/common"
1111)
1212
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
3314
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
3619
37- func (excessiveSecondedIncoming ) isRejectIncoming () {}
20+ // withPrejudice means accept the message; the peer hasn't exceeded limits but the originator has.
21+ withPrejudice
3822
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
4126
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
5829
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
6132
62- func (candidateUnknownOutgoing ) isRejectOutgoing () {}
33+ // duplicate means the statement is a duplicate.
34+ duplicate
6335
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+ )
10139
10240// knowledge about a candidate
10341type knowledge interface {
@@ -214,13 +152,13 @@ func (c *clusterTracker) canReceive(
214152 sender parachaintypes.ValidatorIndex ,
215153 originator parachaintypes.ValidatorIndex ,
216154 statement parachaintypes.CompactStatement ,
217- ) acceptOrRejectIncoming {
155+ ) acceptOrReject {
218156 if ! c .isInGroup (sender ) || ! c .isInGroup (originator ) {
219- return notInGroupIncoming {}
157+ return notInGroup
220158 }
221159
222160 if c .theySent (sender , specific {statement , originator }) {
223- return duplicateIncoming {}
161+ return duplicate
224162 }
225163
226164 switch statement .(type ) {
@@ -250,20 +188,20 @@ func (c *clusterTracker) canReceive(
250188 }
251189
252190 if otherSecondedForOrigFromRemote == c .secondingLimit {
253- return excessiveSecondedIncoming {}
191+ return excessiveSeconded
254192 }
255193
256194 // at this point, it doesn't seem like the remote has done anything wrong.
257195 if c .secondedAlreadyOrWithinLimit (originator , statement .CandidateHash ()) {
258- return ok {}
196+ return ok
259197 } else {
260- return withPrejudice {}
198+ return withPrejudice
261199 }
262200 case * parachaintypes.CompactValid :
263201 if ! c .knowsCandidate (sender , statement .CandidateHash ()) {
264- return candidateUnknownIncoming {}
202+ return candidateUnknown
265203 }
266- return ok {}
204+ return ok
267205 default :
268206 panic ("unreachable" )
269207 }
@@ -461,28 +399,28 @@ func (c *clusterTracker) canSend(
461399 target parachaintypes.ValidatorIndex ,
462400 originator parachaintypes.ValidatorIndex ,
463401 statement parachaintypes.CompactStatement ,
464- ) acceptOrRejectOutgoing {
402+ ) acceptOrReject {
465403 if ! c .isInGroup (target ) || ! c .isInGroup (originator ) {
466- return notInGroupOutgoing {}
404+ return notInGroup
467405 }
468406
469407 if c .theyKnowStatement (target , originator , statement ) {
470- return knownOutgoing {}
408+ return known
471409 }
472410
473411 switch statement .(type ) {
474412 case * parachaintypes.CompactSeconded :
475413 // we send the same `Seconded` statements to all our peers, and only the first `k`
476414 // from each originator.
477415 if ! c .secondedAlreadyOrWithinLimit (originator , statement .CandidateHash ()) {
478- return excessiveSecondedOutgoing {}
416+ return excessiveSeconded
479417 }
480- return ok {}
418+ return ok
481419 case * parachaintypes.CompactValid :
482420 if ! c .knowsCandidate (target , statement .CandidateHash ()) {
483- return candidateUnknownOutgoing {}
421+ return candidateUnknown
484422 }
485- return ok {}
423+ return ok
486424 default :
487425 panic ("unreachable" )
488426 }
0 commit comments