Skip to content

Commit 4b30b09

Browse files
committed
discovery: add new method handleSyncingChans
This is a pure refactor to add a dedicated handler when the gossiper is in state syncingChans.
1 parent eb2b0c7 commit 4b30b09

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

discovery/syncer.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,28 @@ func (g *GossipSyncer) Stop() {
475475
})
476476
}
477477

478+
// handleSyncingChans handles the state syncingChans for the GossipSyncer. When
479+
// in this state, we will send a QueryChannelRange msg to our peer and advance
480+
// the syncer's state to waitingQueryRangeReply.
481+
func (g *GossipSyncer) handleSyncingChans() {
482+
// Prepare the query msg.
483+
queryRangeMsg, err := g.genChanRangeQuery(g.genHistoricalChanRangeQuery)
484+
if err != nil {
485+
log.Errorf("Unable to gen chan range query: %v", err)
486+
return
487+
}
488+
489+
err = g.cfg.sendToPeer(queryRangeMsg)
490+
if err != nil {
491+
log.Errorf("Unable to send chan range query: %v", err)
492+
return
493+
}
494+
495+
// With the message sent successfully, we'll transition into the next
496+
// state where we wait for their reply.
497+
g.setSyncState(waitingQueryRangeReply)
498+
}
499+
478500
// channelGraphSyncer is the main goroutine responsible for ensuring that we
479501
// properly channel graph state with the remote peer, and also that we only
480502
// send them messages which actually pass their defined update horizon.
@@ -495,27 +517,7 @@ func (g *GossipSyncer) channelGraphSyncer() {
495517
// understand, as we'll as responding to any other queries by
496518
// them.
497519
case syncingChans:
498-
// If we're in this state, then we'll send the remote
499-
// peer our opening QueryChannelRange message.
500-
queryRangeMsg, err := g.genChanRangeQuery(
501-
g.genHistoricalChanRangeQuery,
502-
)
503-
if err != nil {
504-
log.Errorf("Unable to gen chan range "+
505-
"query: %v", err)
506-
return
507-
}
508-
509-
err = g.cfg.sendToPeer(queryRangeMsg)
510-
if err != nil {
511-
log.Errorf("Unable to send chan range "+
512-
"query: %v", err)
513-
return
514-
}
515-
516-
// With the message sent successfully, we'll transition
517-
// into the next state where we wait for their reply.
518-
g.setSyncState(waitingQueryRangeReply)
520+
g.handleSyncingChans()
519521

520522
// In this state, we've sent out our initial channel range
521523
// query and are waiting for the final response from the remote

0 commit comments

Comments
 (0)