From a202860ce1986d131dd8fae27f49a0c5ceec99d2 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 13 Dec 2018 15:27:14 +0100 Subject: [PATCH] autopilot: make n uint32 in chooseN To avoid negative values being input, as it doesn't really make sense. --- autopilot/agent.go | 2 +- autopilot/choice.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autopilot/agent.go b/autopilot/agent.go index 8475bb7c..56038c01 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -551,7 +551,7 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32, // Now use the score to make a weighted choice which // nodes to attempt to open channels to. - chanCandidates, err := chooseN(int(numChans), scores) + chanCandidates, err := chooseN(numChans, scores) if err != nil { return fmt.Errorf("Unable to make weighted choice: %v", err) diff --git a/autopilot/choice.go b/autopilot/choice.go index 6e4ec9c0..c51062d2 100644 --- a/autopilot/choice.go +++ b/autopilot/choice.go @@ -52,7 +52,7 @@ func weightedChoice(s map[NodeID]*AttachmentDirective) (NodeID, error) { // chooseN picks at random min[n, len(s)] nodes if from the // AttachmentDirectives map, with a probability weighted by their score. -func chooseN(n int, s map[NodeID]*AttachmentDirective) ( +func chooseN(n uint32, s map[NodeID]*AttachmentDirective) ( map[NodeID]*AttachmentDirective, error) { // Keep a map of nodes not yet choosen. @@ -64,7 +64,7 @@ func chooseN(n int, s map[NodeID]*AttachmentDirective) ( // Pick a weighted choice from the remaining nodes as long as there are // nodes left, and we haven't already picked n. chosen := make(map[NodeID]*AttachmentDirective) - for len(chosen) < n && len(rem) > 0 { + for len(chosen) < int(n) && len(rem) > 0 { choice, err := weightedChoice(rem) if err == ErrNoPositive { return chosen, nil