autopilot/interface+agent: return NodeScore from NodeScores

Since NodeScores no longer returns fully populated AttachmentDirectives,
we make this explicit by defining a new type NodeScore that includes a
subset of what the AttachmentDirective does.
This commit is contained in:
Johan T. Halseth
2018-12-19 15:24:17 +01:00
parent 25de66d27b
commit 5b1e72a019
5 changed files with 129 additions and 173 deletions

View File

@@ -62,7 +62,7 @@ func NewNodeID(pub *btcec.PublicKey) NodeID {
// NOTE: This is a part of the AttachmentHeuristic interface.
func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel,
chanSize btcutil.Amount, nodes map[NodeID]struct{}) (
map[NodeID]*AttachmentDirective, error) {
map[NodeID]*NodeScore, error) {
// Count the number of channels in the graph. We'll also count the
// number of channels as we go for the nodes we are interested in.
@@ -108,7 +108,7 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel,
// For each node in the set of nodes, count their fraction of channels
// in the graph, and use that as the score.
candidates := make(map[NodeID]*AttachmentDirective)
candidates := make(map[NodeID]*NodeScore)
for nID, nodeChans := range nodeChanNum {
_, ok := existingPeers[nID]
@@ -129,10 +129,9 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel,
// Otherwise we score the node according to its fraction of
// channels in the graph.
score := float64(nodeChans) / float64(graphChans)
candidates[nID] = &AttachmentDirective{
NodeID: nID,
ChanAmt: chanSize,
Score: score,
candidates[nID] = &NodeScore{
NodeID: nID,
Score: score,
}
}