Commit Graph

99 Commits

Author SHA1 Message Date
Johan T. Halseth
5b1e72a019
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.
2019-01-08 10:23:50 +01:00
Johan T. Halseth
25de66d27b
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.
2019-01-08 10:23:48 +01:00
Johan T. Halseth
3739c19ef8
autopilot/pref_attachment: rename ConstrainedPrefAttachment->PrefAttachment
Since the ConstrainedPrefAttachment no longers require the heuristic to
be aware of the autopilot constraints, we rename it PrefAttachment.
2019-01-08 10:10:59 +01:00
Johan T. Halseth
ccf4b7feab
autopilot: move address lookup from heuristic to agent
To avoid having the heuristics deal with (possibly conflicting) address
lookups, we let the agent handle them.
2019-01-08 10:10:59 +01:00
Johan T. Halseth
cfd237bf1f
autopilot: move determining chanSize from heuristic to agent
Since we want to combine scores from multiple heuristics, things get
complicated if the heuristics report their own individual channel sizes.
Therefore we change the NodeScores interface slightly, letting the agent
specify the wanted channel size, and let the heuristic score the nodes
accordingly.
2019-01-08 10:10:59 +01:00
Johan T. Halseth
d5f3714f86
autopilot/agent: return early if no funds available
If there are less funds available than the minumum channel size, there's
no reason to score candidates, so we continue early.
2019-01-08 10:10:59 +01:00
Johan T. Halseth
d0c4e253c6
autopilot/interface: remove NeedMoreChans from AttachmentHeuristic
Since the agent is now querying the constraints directly, NeedMoreChans
is no longer needed on the heuristic.
2019-01-08 10:10:59 +01:00
Johan T. Halseth
fbfc9a53af
autopilot: TestConstrainedPrefAttachmentNeedMoreChan->TestConstraintsChannelBudget
Since the constraints are no longer something the heuristic needs to be
aware of, we move the test.
2019-01-08 10:10:58 +01:00
Johan T. Halseth
0e1713956b
autopilot/agent: call ChannelBudget on constrainsts
We let the agent call ChannelBudget on its constraints directly, and
not go through the heuristic. This is needed since when we want to have
multiple active heuristics concurrently, it won't make sense anymore to
ask each of the heuristics.

The mockConstraints are also updated to act as the mockHeuristic did
before, by making it possible to control the responses it gives by
sending them on the contained channels.
2019-01-08 10:10:58 +01:00
Johan T. Halseth
1d82e12fcf
autopilot: define AgentConstraints
To decouple the autopilot heuristic from the constraints, we start by
abstracting them behind an interface to make them easier to mock. We
also rename them HeuristicConstraints->AgentConstraints to make it clear
that they are now constraints the agent must adhere to.
2019-01-08 10:10:58 +01:00
Olaoluwa Osuntokun
21460c9e67
Merge pull request #2293 from halseth/unit-tests-weighted-choice
[autopilot] weighted choice unit tests and optimizations
2019-01-07 19:42:29 -08:00
Johan T. Halseth
dbf7b380a9
autopilot/manager: only set m.pilot if started successfully
This commit fixes a subtle bug within the autopilot manager, that would
cause the active pilot to not be reset in case it wasn't started
successfully.

We also make sure the associated goroutines close over the started
pilot, and not the active pilot.
2018-12-19 19:48:44 +01:00
Johan T. Halseth
902d6edad2
autopilot/choice: add weightedChoice tests 2018-12-19 08:27:35 +01:00
Johan T. Halseth
4ac3c171ec
autopilot/choice: avoid costly map allocations
This commit makes the weightedChoice algorithm take a slice of weights
instead of a map of node scores. This let us avoid costly map allocation
and iteration.

In addition we make the chooseN algorithm keep track of the remaining
nodes by keeping a slice of weights through its entire run, similarly
avoiding costly map allocation and iteration.

In total this brings the runtime of the TestChooseNSample testcase down
from ~73s to ~3.6s.
2018-12-19 08:27:34 +01:00
Johan T. Halseth
3d2a39a18c
autopilot/choice_test: add chooseN tests 2018-12-19 08:27:34 +01:00
Johan T. Halseth
a202860ce1
autopilot: make n uint32 in chooseN
To avoid negative values being input, as it doesn't really make sense.
2018-12-19 08:27:34 +01:00
Johan T. Halseth
6310ed0f1c
autopilot: add autopilot.Manager
This commit adds a new type Manager responsible for managing an
autopilot agent, making it possible to start and stop it at runtime.
2018-12-13 12:26:29 +01:00
Olaoluwa Osuntokun
d24a6d2a3d
Merge pull request #2304 from halseth/weigthed-choice-errnopositive
[autopilot] Don't fail on no more positive nodes
2018-12-12 12:21:06 -08:00
Johan T. Halseth
8e57ed7025
autopilot/agent_test: let agent self-trigger retry
This ensures that it is done updating its pending connections map before
re-querying the heuristic.
2018-12-11 10:21:40 +01:00
Johan T. Halseth
dda7355ad6
autopilot/agent_test: ensure mochHeuristics exits cleanly 2018-12-11 10:20:38 +01:00
Johan T. Halseth
0255db5120
autopilot/prefattach_test: ensure non-connected nodes get 0-score
This addition to the unit tests makes sure nodes that have no channels
in the graph are left out od the scored nodes, implicitly giving them a
score of 0.
2018-12-10 15:05:24 +01:00
Johan T. Halseth
b9c33da3f8
autopilot/prefattach: skip nodes having no channels 2018-12-10 15:01:43 +01:00
Johan T. Halseth
aeeff4714d
autopilot/graph: define addRandNode 2018-12-10 15:01:43 +01:00
Johan T. Halseth
5224c94aaf
autopilot/prefattach_test: assert scored nodes having addresses
This addtion to the test makes sure the scored nodes have their
addresses populated. This would fail without the previous commit.
2018-12-10 15:01:05 +01:00
Johan T. Halseth
d9eef4625e
autopilot/prefattach: populate Addrs field 2018-12-10 15:00:41 +01:00
Johan T. Halseth
55ba5fe654
autopilot/graph: add addresses to memNode 2018-12-10 14:56:54 +01:00
Johan T. Halseth
40db2dd5a5
autopilot/choice: return ErrNoPositive in case no choice can be made 2018-12-10 13:53:36 +01:00
Johan T. Halseth
f1e8c8d5b5
autopilot/agent: move choice algorithms to new file choice.go 2018-12-10 13:53:31 +01:00
Johan T. Halseth
6130189d95
autopilot/interface+agent: remove Select 2018-12-06 14:26:28 +01:00
Johan T. Halseth
b3d315298c
autopilot/agent: use NodeScores to select channel candidates
This commit makes the autopilot agent use the new NodeScores heuristic
API to select channel candiates, instead of the Select API. The result
will be similar, but instead of selecting a set of nodes to open
channels to, we get a score based results which can later be used
together with other heuristics to choose nodes to open channels to.

This commit also makes the existing autopilot agent tests compatible
with the new NodeScores API.
2018-12-06 14:26:26 +01:00
Johan T. Halseth
e84bd29836
autopilot/agent: add weightedChoice and chooseN algorithm
The algorithms will be used to select nodes at random from the weighted
distribution set by the node's scores given by the heuristic.
2018-12-06 14:26:05 +01:00
Johan T. Halseth
be45697c6d
autopilot/prefattach_test: use NodeScores API for prefAttach tests
This commit converts the existing unit tests of Select into tests of
NodeScores.
2018-12-06 14:26:05 +01:00
Johan T. Halseth
5e8e54083f
autopilot/prefattach+interface: add API NodeScores
This commit adds a new method NodeScores to the AttachementHeuristic
interface. Its intended use is to score a set of nodes according to
their preference as channel counterparties.

The PrefAttach heuristic gets a NodeScores method that will score the
ndoes according to their number of already existing channels, similar to
what is done already in Select.
2018-12-06 14:26:05 +01:00
Johan T. Halseth
5ecc209c41
autopilot/interface+agent: remove NodeKey from AttachmentDirective
Instead parse the pubkey bytes only when needed.
2018-12-06 14:26:05 +01:00
Johan T. Halseth
89c3c5319f
autopilot/agent: split opening logic into own method
This commit takes the logic after the autopilot agent has decided that it
needs to open more channels, and moves it into a new method openChan.
2018-12-06 14:26:03 +01:00
Johan T. Halseth
26810fe928
autopilot/agent: split attachement directive attempts into method 2018-12-06 14:25:22 +01:00
Johan T. Halseth
fb10175ea5
autopilot/agent: add maps to agent struct
This commit moves the maps used by the controller loop to the Agent
struct, in preparation for breaking it up into smaller parts.
2018-12-06 14:24:18 +01:00
Johan T. Halseth
86e6d230f2
autopilot/agent: add attachment directive goroutine to wait group 2018-12-06 14:24:15 +01:00
Johan T. Halseth
35f4ec84d1
autopilot/prefattach: use HeuristicConstraints
This commit makes the pref attach heuristic and the agent use the
HeuristicConstraints internally.
2018-12-06 11:25:30 +01:00
Johan T. Halseth
e98d859882
autopilot: define HeuristicConstraints
This commit defines a new struct HeuristicConstraints that will be used
to keep track of the initial constraints the autopilot agent needs to
adhere to. This is currently done in the ConstrainedPrefAttachement
heuristic itself, but this lets us share these constraints and common
method netween several heuristics.
2018-12-06 11:20:09 +01:00
Olaoluwa Osuntokun
1fd3aac925
multi: switch from bolt packge to bbolt package for all imports 2018-11-29 20:33:49 -08:00
ErikEk
c5f61b3c06 Typo fix autopilot 2018-10-09 18:28:34 +02:00
Olaoluwa Osuntokun
3fda1029c0
Merge pull request #1786 from Roasbeef/golang-1.1
build+docs: bump to golang 1.11
2018-10-08 13:26:07 +09:00
Olaoluwa Osuntokun
d8e6085c17
multi: update to go 1.11 gofmt 2018-10-07 14:37:38 +09:00
Conner Fromknecht
59b459674d
multi: init subsystem loggers via build pkg 2018-10-05 13:04:45 +09:00
Conner Fromknecht
d5f97f7bdc
autopilot/multi: replace PubKey -> NodeKey on directive 2018-09-05 20:10:37 -07:00
Conner Fromknecht
e702a6a266
autopilot/agent_test: remove Fatalf calls from goroutines 2018-09-05 20:10:36 -07:00
Conner Fromknecht
2b578e06fc
autopilot/agent_test: ensure directives use unique keys
This commit ensures that the mock attachment
directives use unique keys, ensuring that they
aren't skipped due to already having pending
connection requests. The tests fail when
they're all the same since they collide
in the pendingConns map.
2018-09-05 20:10:35 -07:00
Conner Fromknecht
7d9483c20d
autopilot/agent_test: adds TestAgentSkipPendingConns
Adds a test asserting that the agent prevents
itself from making duplicate outstanding
connection requests to the same peer.
2018-09-05 20:10:35 -07:00
Conner Fromknecht
c214bea9db
autopilot/prefattach: set NodeID for selection candidates 2018-09-05 20:10:34 -07:00