mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 14:40:51 +02:00
autopilot/interface+choice: add NodeScore type
We create a new type NodeScore which is a tuple (NodeID, score). The weightedChoice and chooseN algorithms are altered to expect this type. This is done in order to simplify the types we are using, since we were only using a subset of the fields in AttachmentDirective.
This commit is contained in:
@@ -46,10 +46,10 @@ func weightedChoice(w []float64) (int, error) {
|
||||
return 0, fmt.Errorf("unable to make choice")
|
||||
}
|
||||
|
||||
// chooseN picks at random min[n, len(s)] nodes if from the
|
||||
// AttachmentDirectives map, with a probability weighted by their score.
|
||||
func chooseN(n uint32, s map[NodeID]*AttachmentDirective) (
|
||||
map[NodeID]*AttachmentDirective, error) {
|
||||
// chooseN picks at random min[n, len(s)] nodes if from the NodeScore map, with
|
||||
// a probability weighted by their score.
|
||||
func chooseN(n uint32, s map[NodeID]*NodeScore) (
|
||||
map[NodeID]*NodeScore, error) {
|
||||
|
||||
// Keep track of the number of nodes not yet chosen, in addition to
|
||||
// their scores and NodeIDs.
|
||||
@@ -65,7 +65,7 @@ func chooseN(n uint32, 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)
|
||||
chosen := make(map[NodeID]*NodeScore)
|
||||
for len(chosen) < int(n) && rem > 0 {
|
||||
choice, err := weightedChoice(scores)
|
||||
if err == ErrNoPositive {
|
||||
|
Reference in New Issue
Block a user