@@ -123,6 +123,11 @@ type Builder struct {
123123 // of our currently known best chain are sent over.
124124 staleBlocks <- chan * chainview.FilteredBlock
125125
126+ // networkUpdates is a channel that carries new topology updates
127+ // messages from outside the Builder to be processed by the
128+ // networkHandler.
129+ networkUpdates chan * routingMsg
130+
126131 // topologyClients maps a client's unique notification ID to a
127132 // topologyClient client that contains its notification dispatch
128133 // channel.
@@ -159,6 +164,7 @@ var _ ChannelGraphSource = (*Builder)(nil)
159164func NewBuilder (cfg * Config ) (* Builder , error ) {
160165 return & Builder {
161166 cfg : cfg ,
167+ networkUpdates : make (chan * routingMsg ),
162168 topologyClients : & lnutils.SyncMap [uint64 , * topologyClient ]{},
163169 ntfnClientUpdates : make (chan * topologyClientUpdate ),
164170 channelEdgeMtx : multimutex .NewMutex [uint64 ](),
@@ -707,8 +713,8 @@ func (b *Builder) handleNetworkUpdate(update *routingMsg) {
707713
708714// networkHandler is the primary goroutine for the Builder. The roles of
709715// this goroutine include answering queries related to the state of the
710- // network, pruning the graph on new block notification and registering new
711- // topology clients.
716+ // network, pruning the graph on new block notification, applying network
717+ // updates, and registering new topology clients.
712718//
713719// NOTE: This MUST be run as a goroutine.
714720func (b * Builder ) networkHandler () {
@@ -728,6 +734,17 @@ func (b *Builder) networkHandler() {
728734 }
729735
730736 select {
737+ // A new fully validated network update has just arrived. As a
738+ // result we'll modify the channel graph accordingly depending
739+ // on the exact type of the message.
740+ case update := <- b .networkUpdates :
741+ b .wg .Add (1 )
742+ go b .handleNetworkUpdate (update )
743+
744+ // TODO(roasbeef): remove all unconnected vertexes
745+ // after N blocks pass with no corresponding
746+ // announcements.
747+
731748 case chainUpdate , ok := <- b .staleBlocks :
732749 // If the channel has been closed, then this indicates
733750 // the daemon is shutting down, so we exit ourselves.
@@ -1091,12 +1108,14 @@ func (b *Builder) AddNode(node *models.LightningNode,
10911108 err : make (chan error , 1 ),
10921109 }
10931110
1094- b .wg .Add (1 )
1095- go b .handleNetworkUpdate (rMsg )
1096-
10971111 select {
1098- case err := <- rMsg .err :
1099- return err
1112+ case b .networkUpdates <- rMsg :
1113+ select {
1114+ case err := <- rMsg .err :
1115+ return err
1116+ case <- b .quit :
1117+ return ErrGraphBuilderShuttingDown
1118+ }
11001119 case <- b .quit :
11011120 return ErrGraphBuilderShuttingDown
11021121 }
@@ -1142,12 +1161,14 @@ func (b *Builder) AddEdge(edge *models.ChannelEdgeInfo,
11421161 err : make (chan error , 1 ),
11431162 }
11441163
1145- b .wg .Add (1 )
1146- go b .handleNetworkUpdate (rMsg )
1147-
11481164 select {
1149- case err := <- rMsg .err :
1150- return err
1165+ case b .networkUpdates <- rMsg :
1166+ select {
1167+ case err := <- rMsg .err :
1168+ return err
1169+ case <- b .quit :
1170+ return ErrGraphBuilderShuttingDown
1171+ }
11511172 case <- b .quit :
11521173 return ErrGraphBuilderShuttingDown
11531174 }
@@ -1250,12 +1271,14 @@ func (b *Builder) UpdateEdge(update *models.ChannelEdgePolicy,
12501271 err : make (chan error , 1 ),
12511272 }
12521273
1253- b .wg .Add (1 )
1254- go b .handleNetworkUpdate (rMsg )
1255-
12561274 select {
1257- case err := <- rMsg .err :
1258- return err
1275+ case b .networkUpdates <- rMsg :
1276+ select {
1277+ case err := <- rMsg .err :
1278+ return err
1279+ case <- b .quit :
1280+ return ErrGraphBuilderShuttingDown
1281+ }
12591282 case <- b .quit :
12601283 return ErrGraphBuilderShuttingDown
12611284 }
0 commit comments