diff --git a/autopilot/prefattach.go b/autopilot/prefattach.go index 5d94e14d..4068fe10 100644 --- a/autopilot/prefattach.go +++ b/autopilot/prefattach.go @@ -107,6 +107,8 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel, } medianChanSize := Median(allChans) + log.Tracef("Found channel median %v for preferential score heuristic", + medianChanSize) // Count the number of large-ish channels for each particular node in // the graph. @@ -143,11 +145,14 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel, // early. nID := NodeID(n.PubKey()) if _, ok := nodes[nID]; !ok { + log.Tracef("Node %x not among nodes to score, "+ + "ignoring", nID[:]) return nil } // Otherwise we'll record the number of channels. nodeChanNum[nID] = nodeChans + log.Tracef("Counted %v channels for node %x", nodeChans, nID[:]) return nil }); err != nil { @@ -158,6 +163,7 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel, // preferences, so we return, indicating all candidates get a score of // zero. if maxChans == 0 { + log.Tracef("No channels in the graph") return nil, nil } @@ -171,18 +177,19 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel, candidates := make(map[NodeID]*NodeScore) for nID, nodeChans := range nodeChanNum { - _, ok := existingPeers[nID] - - switch { - // If the node is among or existing channel peers, we don't // need another channel. - case ok: + if _, ok := existingPeers[nID]; ok { + log.Tracef("Node %x among existing peers for pref "+ + "attach heuristic, giving zero score", nID[:]) continue + } // If the node had no large channels, we skip it, since it // would have gotten a zero score anyway. - case nodeChans <= 0: + if nodeChans <= 0 { + log.Tracef("Skipping node %x with channel count %v", + nID[:], nodeChans) continue } @@ -190,6 +197,9 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel, // channels in the graph, scaled such that the highest-degree // node will be given a score of 1.0. score := float64(nodeChans) / float64(maxChans) + log.Tracef("Giving node %x a pref attach score of %v", + nID[:], score) + candidates[nID] = &NodeScore{ NodeID: nID, Score: score,