@@ -182,13 +182,9 @@ func (s *Service) getBlockAnnounceHandshake() (Handshake, error) {
182
182
}, nil
183
183
}
184
184
185
- func (s * Service ) validateBlockAnnounceHandshake (peer peer.ID , hs Handshake ) error {
186
- var (
187
- bhs * BlockAnnounceHandshake
188
- ok bool
189
- )
190
-
191
- if bhs , ok = hs .(* BlockAnnounceHandshake ); ! ok {
185
+ func (s * Service ) validateBlockAnnounceHandshake (from peer.ID , hs Handshake ) error {
186
+ bhs , ok := hs .(* BlockAnnounceHandshake )
187
+ if ! ok {
192
188
return errors .New ("invalid handshake type" )
193
189
}
194
190
@@ -204,12 +200,12 @@ func (s *Service) validateBlockAnnounceHandshake(peer peer.ID, hs Handshake) err
204
200
205
201
// don't need to lock here, since function is always called inside the func returned by
206
202
// `createNotificationsMessageHandler` which locks the map beforehand.
207
- data , ok := np .getInboundHandshakeData (peer )
203
+ data , ok := np .getInboundHandshakeData (from )
208
204
if ok {
209
205
data .handshake = hs
210
206
// TODO: since this is used only for rpc system_peers only,
211
207
// we can just set the inbound handshake and use that in Peers()
212
- np .inboundHandshakeData .Store (peer , data )
208
+ np .inboundHandshakeData .Store (from , data )
213
209
}
214
210
215
211
// if peer has higher best block than us, begin syncing
@@ -225,21 +221,20 @@ func (s *Service) validateBlockAnnounceHandshake(peer peer.ID, hs Handshake) err
225
221
return nil
226
222
}
227
223
228
- go s .syncQueue .handleBlockAnnounceHandshake (bhs .BestBlockNumber , peer )
229
-
230
- return nil
224
+ return s .syncer .HandleBlockAnnounceHandshake (from , bhs )
231
225
}
232
226
233
227
// handleBlockAnnounceMessage handles BlockAnnounce messages
234
228
// if some more blocks are required to sync the announced block, the node will open a sync stream
235
229
// with its peer and send a BlockRequest message
236
- func (s * Service ) handleBlockAnnounceMessage (peer peer.ID , msg NotificationsMessage ) (propagate bool , err error ) {
237
- if an , ok := msg .(* BlockAnnounceMessage ); ok {
238
- s .syncQueue .handleBlockAnnounce (an , peer )
239
- err = s .syncer .HandleBlockAnnounce (an )
240
- if err != nil {
241
- return false , err
242
- }
230
+ func (s * Service ) handleBlockAnnounceMessage (from peer.ID , msg NotificationsMessage ) (propagate bool , err error ) {
231
+ bam , ok := msg .(* BlockAnnounceMessage )
232
+ if ! ok {
233
+ return false , errors .New ("invalid message" )
234
+ }
235
+
236
+ if err = s .syncer .HandleBlockAnnounce (from , bam ); err != nil {
237
+ return false , err
243
238
}
244
239
245
240
return true , nil
0 commit comments