@@ -123,10 +123,10 @@ type Builder struct {
123
123
// of our currently known best chain are sent over.
124
124
staleBlocks <- chan * chainview.FilteredBlock
125
125
126
- // networkUpdates is a channel that carries new topology updates
126
+ // topologyUpdates is a channel that carries new topology updates
127
127
// messages from outside the Builder to be processed by the
128
128
// networkHandler.
129
- networkUpdates chan * routingMsg
129
+ topologyUpdates chan any
130
130
131
131
// topologyClients maps a client's unique notification ID to a
132
132
// topologyClient client that contains its notification dispatch
@@ -164,7 +164,7 @@ var _ ChannelGraphSource = (*Builder)(nil)
164
164
func NewBuilder (cfg * Config ) (* Builder , error ) {
165
165
return & Builder {
166
166
cfg : cfg ,
167
- networkUpdates : make (chan * routingMsg ),
167
+ topologyUpdates : make (chan any ),
168
168
topologyClients : & lnutils.SyncMap [uint64 , * topologyClient ]{},
169
169
ntfnClientUpdates : make (chan * topologyClientUpdate ),
170
170
channelEdgeMtx : multimutex .NewMutex [uint64 ](),
@@ -656,59 +656,26 @@ func (b *Builder) pruneZombieChans() error {
656
656
return nil
657
657
}
658
658
659
- // handleNetworkUpdate is responsible for processing the update message and
660
- // notifies topology changes, if any .
659
+ // handleTopologyUpdate is responsible for sending any topology changes
660
+ // notifications to registered clients .
661
661
//
662
662
// NOTE: must be run inside goroutine.
663
- func (b * Builder ) handleNetworkUpdate (update * routingMsg ) {
663
+ func (b * Builder ) handleTopologyUpdate (update any ) {
664
664
defer b .wg .Done ()
665
665
666
- // Process the routing update to determine if this is either a new
667
- // update from our PoV or an update to a prior vertex/edge we
668
- // previously accepted.
669
- var err error
670
- switch msg := update .msg .(type ) {
671
- case * models.LightningNode :
672
- err = b .addNode (msg , update .op ... )
673
-
674
- case * models.ChannelEdgeInfo :
675
- err = b .addEdge (msg , update .op ... )
676
-
677
- case * models.ChannelEdgePolicy :
678
- err = b .updateEdge (msg , update .op ... )
679
-
680
- default :
681
- err = errors .Errorf ("wrong routing update message type" )
682
- }
683
- update .err <- err
684
-
685
- // If the error is not nil here, there's no need to send topology
686
- // change.
687
- if err != nil {
688
- // Log as a debug message if this is not an error we need to be
689
- // concerned about.
690
- if IsError (err , ErrIgnored , ErrOutdated ) {
691
- log .Debugf ("process network updates got: %v" , err )
692
- } else {
693
- log .Errorf ("process network updates got: %v" , err )
694
- }
695
-
696
- return
697
- }
698
-
699
- // Otherwise, we'll send off a new notification for the newly accepted
700
- // update, if any.
701
666
topChange := & TopologyChange {}
702
- err = addToTopologyChange (b .cfg .Graph , topChange , update . msg )
667
+ err : = addToTopologyChange (b .cfg .Graph , topChange , update )
703
668
if err != nil {
704
669
log .Errorf ("unable to update topology change notification: %v" ,
705
670
err )
706
671
return
707
672
}
708
673
709
- if ! topChange .isEmpty () {
710
- b . notifyTopologyChange ( topChange )
674
+ if topChange .isEmpty () {
675
+ return
711
676
}
677
+
678
+ b .notifyTopologyChange (topChange )
712
679
}
713
680
714
681
// networkHandler is the primary goroutine for the Builder. The roles of
@@ -734,12 +701,11 @@ func (b *Builder) networkHandler() {
734
701
}
735
702
736
703
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 :
704
+ // A new fully validated topology update has just arrived.
705
+ // We'll notify any registered clients.
706
+ case update := <- b .topologyUpdates :
741
707
b .wg .Add (1 )
742
- go b .handleNetworkUpdate (update )
708
+ go b .handleTopologyUpdate (update )
743
709
744
710
// TODO(roasbeef): remove all unconnected vertexes
745
711
// after N blocks pass with no corresponding
@@ -1033,14 +999,6 @@ func (b *Builder) MarkZombieEdge(chanID uint64) error {
1033
999
return nil
1034
1000
}
1035
1001
1036
- // routingMsg couples a routing related routing topology update to the
1037
- // error channel.
1038
- type routingMsg struct {
1039
- msg interface {}
1040
- op []batch.SchedulerOption
1041
- err chan error
1042
- }
1043
-
1044
1002
// ApplyChannelUpdate validates a channel update and if valid, applies it to the
1045
1003
// database. It returns a bool indicating whether the updates were successful.
1046
1004
func (b * Builder ) ApplyChannelUpdate (msg * lnwire.ChannelUpdate1 ) bool {
@@ -1102,23 +1060,20 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
1102
1060
func (b * Builder ) AddNode (node * models.LightningNode ,
1103
1061
op ... batch.SchedulerOption ) error {
1104
1062
1105
- rMsg := & routingMsg {
1106
- msg : node ,
1107
- op : op ,
1108
- err : make (chan error , 1 ),
1063
+ err := b .addNode (node , op ... )
1064
+ if err != nil {
1065
+ logNetworkMsgProcessError (err )
1066
+
1067
+ return err
1109
1068
}
1110
1069
1111
1070
select {
1112
- case b .networkUpdates <- rMsg :
1113
- select {
1114
- case err := <- rMsg .err :
1115
- return err
1116
- case <- b .quit :
1117
- return ErrGraphBuilderShuttingDown
1118
- }
1071
+ case b .topologyUpdates <- node :
1119
1072
case <- b .quit :
1120
1073
return ErrGraphBuilderShuttingDown
1121
1074
}
1075
+
1076
+ return nil
1122
1077
}
1123
1078
1124
1079
// addNode does some basic checks on the given LightningNode against what we
@@ -1155,23 +1110,20 @@ func (b *Builder) addNode(node *models.LightningNode,
1155
1110
func (b * Builder ) AddEdge (edge * models.ChannelEdgeInfo ,
1156
1111
op ... batch.SchedulerOption ) error {
1157
1112
1158
- rMsg := & routingMsg {
1159
- msg : edge ,
1160
- op : op ,
1161
- err : make (chan error , 1 ),
1113
+ err := b .addEdge (edge , op ... )
1114
+ if err != nil {
1115
+ logNetworkMsgProcessError (err )
1116
+
1117
+ return err
1162
1118
}
1163
1119
1164
1120
select {
1165
- case b .networkUpdates <- rMsg :
1166
- select {
1167
- case err := <- rMsg .err :
1168
- return err
1169
- case <- b .quit :
1170
- return ErrGraphBuilderShuttingDown
1171
- }
1121
+ case b .topologyUpdates <- edge :
1172
1122
case <- b .quit :
1173
1123
return ErrGraphBuilderShuttingDown
1174
1124
}
1125
+
1126
+ return nil
1175
1127
}
1176
1128
1177
1129
// addEdge does some validation on the new channel edge against what we
@@ -1265,23 +1217,20 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
1265
1217
func (b * Builder ) UpdateEdge (update * models.ChannelEdgePolicy ,
1266
1218
op ... batch.SchedulerOption ) error {
1267
1219
1268
- rMsg := & routingMsg {
1269
- msg : update ,
1270
- op : op ,
1271
- err : make (chan error , 1 ),
1220
+ err := b .updateEdge (update , op ... )
1221
+ if err != nil {
1222
+ logNetworkMsgProcessError (err )
1223
+
1224
+ return err
1272
1225
}
1273
1226
1274
1227
select {
1275
- case b .networkUpdates <- rMsg :
1276
- select {
1277
- case err := <- rMsg .err :
1278
- return err
1279
- case <- b .quit :
1280
- return ErrGraphBuilderShuttingDown
1281
- }
1228
+ case b .topologyUpdates <- update :
1282
1229
case <- b .quit :
1283
1230
return ErrGraphBuilderShuttingDown
1284
1231
}
1232
+
1233
+ return nil
1285
1234
}
1286
1235
1287
1236
// updateEdge validates the new edge policy against what we currently have
@@ -1375,6 +1324,18 @@ func (b *Builder) updateEdge(policy *models.ChannelEdgePolicy,
1375
1324
return nil
1376
1325
}
1377
1326
1327
+ // logNetworkMsgProcessError logs the error received from processing a network
1328
+ // message. It logs as a debug message if the error is not critical.
1329
+ func logNetworkMsgProcessError (err error ) {
1330
+ if IsError (err , ErrIgnored , ErrOutdated ) {
1331
+ log .Debugf ("process network updates got: %v" , err )
1332
+
1333
+ return
1334
+ }
1335
+
1336
+ log .Errorf ("process network updates got: %v" , err )
1337
+ }
1338
+
1378
1339
// CurrentBlockHeight returns the block height from POV of the router subsystem.
1379
1340
//
1380
1341
// NOTE: This method is part of the ChannelGraphSource interface.
0 commit comments