Commit Graph

38 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
083b574fd8
autopilot: fix race condition in new test 2019-11-01 19:30:21 -07:00
Johan T. Halseth
5a8ecfcc49
autopilot/agent_test: add TestAgentHeuristicUpdateSignal
TestAgentHeuristicUpdateSignal tests that upon notification about a
heuristic update, the agent reconsults the heuristic.
2019-10-31 10:19:50 +01:00
Johan T. Halseth
7838e6e1fa
autopilot/agent_test: add more agent channel allocation testcases
Add tests for allocation when well within and well above channel budget.
2019-07-18 00:58:12 +02:00
Johan T. Halseth
68f7642564
autopilot/agent_test: wait for expected num chans and balance
Previously we waited only for the number of channels to become what we
expected, but this wasn't enough. Sometimes the agent had't yet updated
its internal balance, causing the test to fail with an unexpected
balance.
2019-07-18 00:58:12 +02:00
Johan T. Halseth
fb5b6ff425
autopilot/agent_test: add TestAgentChannelSizeAllocation
TestAgentChannelSizeAllocation tests that the autopilot agent opens
channel of size that stays within the channel budget and size
restrictions.
2019-03-14 08:49:28 +01:00
Johan T. Halseth
b71f4632a6
autopilot/agent_test: define testCtx, setup, other helpers
This commit defines a set of helper methods that are used by many of the existing tests.
2019-03-14 08:49:28 +01:00
Johan T. Halseth
49a85b2eb3
autopilot/agent_test: add TestAgentQuitWhenPendingConns
TestAgentQuitWhenPendingConns tests that we are able to stop the autopilot
agent even though there are pending connections to nodes.
2019-02-05 10:45:53 +01:00
Johan T. Halseth
c0fed861d2
autopilot/interface: add Name() to AttachmentHeuristic interface 2019-01-23 09:05:42 +01:00
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
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
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
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
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
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
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
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
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
Wilmer Paulino
e1a376d9f8
autopilot: use updateBalance rather than tracking balance explicitly
In this commit, we modify the balanceUpdate autopilot signal to update
the balance according to what's returned to the WalletBalance callback
rather than explicitly tracking the balance. This gives the agent a
better sense of what the wallet's balance actually is.
2018-08-29 02:06:02 -07:00
Conner Fromknecht
1898e57807
autopilot/agent_test: test that agent recovers from initial empty graph 2018-08-23 18:58:12 -07:00
Wilmer Paulino
aa7c2e6d47
autopilot: add OnChannelPendingOpen state update 2018-08-16 20:22:40 -07:00
Wilmer Paulino
956acdfa14
autopilot/agent_test: pass in agent's quit chan to heuristic
In this commit, we alter our mock heuristic to also take in a quit chan.
It's possible that at the end of a test the agent is blocked on a
NeedMoreChans/Select call as their mock implementations use channels. To
prevent this, we use the agent's quit chan so that the heuristic can
safely exit once the agent does.
2018-08-16 20:19:33 -07:00
Wilmer Paulino
454b549c7e
autopilot+pilot: refactor connection logic out of OpenChannel
In this commit, we refactor the existing connection logic outside of the
ChanController's OpenChannel method. We do this as previously it was
possible for peers to stall us while attempting to connect to them. In
order to remedy this, we now attempt to connect the peer before tracking
them in our set of pending opens.
2018-08-16 20:17:03 -07:00
Wilmer Paulino
89325a13b7
autopilot+config: support opening private channels with autopilot agent 2018-08-10 20:45:59 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Olaoluwa Osuntokun
ce2d5a2156
autopilot: limit the number of outstanding channel open goroutines
In this commit, we fix an existing bug that would at times cause us to
spiral out of control and potentially created thousands of outbound
connections. Our fix is simple: limit the total number of outstanding
channel establishment attempts. Without this limit, we have no way to
bound the number of active goroutines.

Fixes #772.
2018-03-10 16:53:02 -08:00
Olaoluwa Osuntokun
9f52372cd2
autopilot: modify interfaces to specify *exactly* how many chans to open
In this commit, we fix a regression introduced by a recent change which
would allow the agent to detect a channel as failed, and blacklist the
node, promising faster convergence with the ideal state of the
heuristic.

The source of this bug is that we would use the set of blacklisted
nodes in order to compute how many additional channels we should open.
If 10 failures happened, then we would think that we had opened up 10
channels, and stop much earlier than we actually should.

To fix this, while ensuring we don’t retry to failed peers, the
NeedMoreChans method will now return *how* anymore channels to open,
and the Select method will take in how many channels it should try to
open *exactly*.
2018-02-08 20:08:18 -08:00
Olaoluwa Osuntokun
cb48a5827a
autopilot: update API usage to account for recent channeldb changes 2018-02-06 20:14:32 -08:00
Simon Horlick
a43d7d3532 autopilot: Make autopilot aware of channel open failures 2018-01-27 18:35:31 -08:00
Olaoluwa Osuntokun
711b695a2f
autopilot: add tracking of pending channel state
This commit adds tracking of the pending channels state within the
autopilot.Agent. This fixes a class of bugs which was discovered during
the latest test net block storm wherein the Agent would attempt to
repeatedly attach to the same node due to rapid closure of other
channels.

In this commit we fix this issue by ensuring that we always factor in
the pending channel state when querying the heuristic w.r.t if we need
more channels, and if so to which nodes should be attached to.
2017-08-15 18:23:58 -07:00
Olaoluwa Osuntokun
306c4aef8e
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.

The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.

With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.

This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-10 21:14:55 -07:00