From bad9f4b685a5781992ff80197f14889b7c5f978d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 27 Aug 2019 09:55:08 +0200 Subject: [PATCH] autopilot/prefattach: trace log score process --- autopilot/prefattach.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) 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,