@@ -2399,8 +2399,10 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
23992399 ann * lnwire.ChannelAnnouncement ,
24002400 ops []batch.SchedulerOption ) ([]networkMsg , bool ) {
24012401
2402+ scid := ann .ShortChannelID
2403+
24022404 log .Debugf ("Processing ChannelAnnouncement: peer=%v, short_chan_id=%v" ,
2403- nMsg .peer , ann . ShortChannelID .ToUint64 ())
2405+ nMsg .peer , scid .ToUint64 ())
24042406
24052407 // We'll ignore any channel announcements that target any chain other
24062408 // than the set of chains we know of.
@@ -2411,7 +2413,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24112413 log .Errorf (err .Error ())
24122414
24132415 key := newRejectCacheKey (
2414- ann . ShortChannelID .ToUint64 (),
2416+ scid .ToUint64 (),
24152417 sourceToPub (nMsg .source ),
24162418 )
24172419 _ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -2423,13 +2425,12 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24232425 // If this is a remote ChannelAnnouncement with an alias SCID, we'll
24242426 // reject the announcement. Since the router accepts alias SCIDs,
24252427 // not erroring out would be a DoS vector.
2426- if nMsg .isRemote && d .cfg .IsAlias (ann .ShortChannelID ) {
2427- err := fmt .Errorf ("ignoring remote alias channel=%v" ,
2428- ann .ShortChannelID )
2428+ if nMsg .isRemote && d .cfg .IsAlias (scid ) {
2429+ err := fmt .Errorf ("ignoring remote alias channel=%v" , scid )
24292430 log .Errorf (err .Error ())
24302431
24312432 key := newRejectCacheKey (
2432- ann . ShortChannelID .ToUint64 (),
2433+ scid .ToUint64 (),
24332434 sourceToPub (nMsg .source ),
24342435 )
24352436 _ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -2441,11 +2442,10 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24412442 // If the advertised inclusionary block is beyond our knowledge of the
24422443 // chain tip, then we'll ignore it for now.
24432444 d .Lock ()
2444- if nMsg .isRemote && d .isPremature (ann . ShortChannelID , 0 , nMsg ) {
2445+ if nMsg .isRemote && d .isPremature (scid , 0 , nMsg ) {
24452446 log .Warnf ("Announcement for chan_id=(%v), is premature: " +
24462447 "advertises height %v, only height %v is known" ,
2447- ann .ShortChannelID .ToUint64 (),
2448- ann .ShortChannelID .BlockHeight , d .bestHeight )
2448+ scid .ToUint64 (), scid .BlockHeight , d .bestHeight )
24492449 d .Unlock ()
24502450 nMsg .err <- nil
24512451 return nil , false
@@ -2454,7 +2454,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24542454
24552455 // At this point, we'll now ask the router if this is a zombie/known
24562456 // edge. If so we can skip all the processing below.
2457- if d .cfg .Graph .IsKnownEdge (ann . ShortChannelID ) {
2457+ if d .cfg .Graph .IsKnownEdge (scid ) {
24582458 nMsg .err <- nil
24592459 return nil , true
24602460 }
@@ -2468,7 +2468,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24682468 "%v" , err )
24692469
24702470 key := newRejectCacheKey (
2471- ann . ShortChannelID .ToUint64 (),
2471+ scid .ToUint64 (),
24722472 sourceToPub (nMsg .source ),
24732473 )
24742474 _ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -2499,7 +2499,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
24992499 }
25002500
25012501 edge := & models.ChannelEdgeInfo {
2502- ChannelID : ann . ShortChannelID .ToUint64 (),
2502+ ChannelID : scid .ToUint64 (),
25032503 ChainHash : ann .ChainHash ,
25042504 NodeKey1Bytes : ann .NodeID1 ,
25052505 NodeKey2Bytes : ann .NodeID2 ,
@@ -2522,8 +2522,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25222522 }
25232523 }
25242524
2525- log .Debugf ("Adding edge for short_chan_id: %v" ,
2526- ann .ShortChannelID .ToUint64 ())
2525+ log .Debugf ("Adding edge for short_chan_id: %v" , scid .ToUint64 ())
25272526
25282527 // We will add the edge to the channel router. If the nodes present in
25292528 // this channel are not present in the database, a partial node will be
@@ -2533,13 +2532,13 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25332532 // channel ID. We do this to ensure no other goroutine has read the
25342533 // database and is now making decisions based on this DB state, before
25352534 // it writes to the DB.
2536- d .channelMtx .Lock (ann . ShortChannelID .ToUint64 ())
2535+ d .channelMtx .Lock (scid .ToUint64 ())
25372536 err := d .cfg .Graph .AddEdge (edge , ops ... )
25382537 if err != nil {
25392538 log .Debugf ("Graph rejected edge for short_chan_id(%v): %v" ,
2540- ann . ShortChannelID .ToUint64 (), err )
2539+ scid .ToUint64 (), err )
25412540
2542- defer d .channelMtx .Unlock (ann . ShortChannelID .ToUint64 ())
2541+ defer d .channelMtx .Unlock (scid .ToUint64 ())
25432542
25442543 // If the edge was rejected due to already being known, then it
25452544 // may be the case that this new message has a fresh channel
@@ -2550,7 +2549,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25502549 anns , rErr := d .processRejectedEdge (ann , proof )
25512550 if rErr != nil {
25522551 key := newRejectCacheKey (
2553- ann . ShortChannelID .ToUint64 (),
2552+ scid .ToUint64 (),
25542553 sourceToPub (nMsg .source ),
25552554 )
25562555 cr := & cachedReject {}
@@ -2575,7 +2574,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25752574 } else {
25762575 // Otherwise, this is just a regular rejected edge.
25772576 key := newRejectCacheKey (
2578- ann . ShortChannelID .ToUint64 (),
2577+ scid .ToUint64 (),
25792578 sourceToPub (nMsg .source ),
25802579 )
25812580 _ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -2586,17 +2585,15 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25862585 }
25872586
25882587 // If err is nil, release the lock immediately.
2589- d .channelMtx .Unlock (ann . ShortChannelID .ToUint64 ())
2588+ d .channelMtx .Unlock (scid .ToUint64 ())
25902589
2591- log .Debugf ("Finish adding edge for short_chan_id: %v" ,
2592- ann .ShortChannelID .ToUint64 ())
2590+ log .Debugf ("Finish adding edge for short_chan_id: %v" , scid .ToUint64 ())
25932591
25942592 // If we earlier received any ChannelUpdates for this channel, we can
25952593 // now process them, as the channel is added to the graph.
2596- shortChanID := ann .ShortChannelID .ToUint64 ()
25972594 var channelUpdates []* processedNetworkMsg
25982595
2599- earlyChanUpdates , err := d .prematureChannelUpdates .Get (shortChanID )
2596+ earlyChanUpdates , err := d .prematureChannelUpdates .Get (scid . ToUint64 () )
26002597 if err == nil {
26012598 // There was actually an entry in the map, so we'll accumulate
26022599 // it. We don't worry about deletion, since it'll eventually
@@ -2629,8 +2626,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
26292626 // shuts down.
26302627 case * lnwire.ChannelUpdate :
26312628 log .Debugf ("Reprocessing ChannelUpdate for " +
2632- "shortChanID=%v" ,
2633- msg .ShortChannelID .ToUint64 ())
2629+ "shortChanID=%v" , scid .ToUint64 ())
26342630
26352631 select {
26362632 case d .networkMsgs <- updMsg :
@@ -2664,7 +2660,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
26642660 nMsg .err <- nil
26652661
26662662 log .Debugf ("Processed ChannelAnnouncement: peer=%v, short_chan_id=%v" ,
2667- nMsg .peer , ann . ShortChannelID .ToUint64 ())
2663+ nMsg .peer , scid .ToUint64 ())
26682664
26692665 return announcements , true
26702666}
0 commit comments