autopilot/prefattach: trace log score process

This commit is contained in:
Johan T. Halseth 2019-08-27 09:55:08 +02:00
parent 2dbc4fe973
commit bad9f4b685
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

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