@@ -126,55 +126,67 @@ func (s *Service) validateVoteMessage(from peer.ID, m *VoteMessage) (*Vote, erro
126
126
// check for message signature
127
127
pk , err := ed25519 .NewPublicKey (m .Message .AuthorityID [:])
128
128
if err != nil {
129
+ // TODO: affect peer reputation
129
130
return nil , err
130
131
}
131
132
132
133
err = validateMessageSignature (pk , m )
133
134
if err != nil {
135
+ // TODO: affect peer reputation
134
136
return nil , err
135
137
}
136
138
137
139
if m .SetID != s .state .setID {
138
140
return nil , ErrSetIDMismatch
139
141
}
140
142
141
- // check that vote is for current round
142
- if m .Round != s .state .round {
143
- if m .Round < s .state .round {
144
- // peer doesn't know round was finalised, send out another commit message
145
- header , err := s .blockState .GetFinalisedHeader (m .Round , m .SetID )
146
- if err != nil {
147
- return nil , err
148
- }
143
+ const maxRoundsLag = 1
144
+ minRoundAccepted := s .state .round - maxRoundsLag
145
+ if minRoundAccepted > s .state .round {
146
+ // we overflowed below 0 so set the minimum to 0.
147
+ minRoundAccepted = 0
148
+ }
149
149
150
- cm , err := s .newCommitMessage (header , m .Round )
151
- if err != nil {
152
- return nil , err
153
- }
150
+ const maxRoundsAhead = 1
151
+ maxRoundAccepted := s .state .round + maxRoundsAhead
154
152
155
- // send finalised block from previous round to network
156
- msg , err := cm . ToConsensusMessage ()
157
- if err != nil {
158
- return nil , err
159
- }
153
+ if m . Round < minRoundAccepted || m . Round > maxRoundAccepted {
154
+ // Discard message
155
+ // TODO: affect peer reputation, this is shameful impolite behaviour
156
+ return nil , nil //nolint:nilnil
157
+ }
160
158
161
- if err = s .network .SendMessage (from , msg ); err != nil {
162
- logger .Warnf ("failed to send CommitMessage: %s" , err )
163
- }
164
- } else {
165
- // Message round is higher than the round of our state,
166
- // we may be lagging behind, so store the message in the tracker
167
- // for processing later.
168
- const maxFutureRoundsDiff = 5
169
- if m .Round < s .state .round + maxFutureRoundsDiff {
170
- // We ensure the message round is not too far away
171
- // from our state round, to avoid abuses of the tracker storage.
172
- s .tracker .addVote (from , m )
173
- }
159
+ if m .Round < s .state .round {
160
+ // message round is lagging by 1
161
+ // peer doesn't know round was finalised, send out another commit message
162
+ header , err := s .blockState .GetFinalisedHeader (m .Round , m .SetID )
163
+ if err != nil {
164
+ return nil , err
165
+ }
166
+
167
+ cm , err := s .newCommitMessage (header , m .Round )
168
+ if err != nil {
169
+ return nil , err
170
+ }
171
+
172
+ // send finalised block from previous round to network
173
+ msg , err := cm .ToConsensusMessage ()
174
+ if err != nil {
175
+ return nil , err
176
+ }
177
+
178
+ if err = s .network .SendMessage (from , msg ); err != nil {
179
+ logger .Warnf ("failed to send CommitMessage: %s" , err )
174
180
}
175
181
176
182
// TODO: get justification if your round is lower, or just do catch-up? (#1815)
177
183
return nil , errRoundMismatch (m .Round , s .state .round )
184
+ } else if m .Round > s .state .round {
185
+ // Message round is higher by 1 than the round of our state,
186
+ // we may be lagging behind, so store the message in the tracker
187
+ // for processing later in the coming few milliseconds.
188
+ s .tracker .addVote (from , m )
189
+ return nil , errRoundMismatch (m .Round , s .state .round )
178
190
}
179
191
180
192
// check for equivocation ie. multiple votes within one subround
0 commit comments