Commit Graph

163 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
c986e52da7
funding+server: ensure we cancel all reservations when a peer disconnects
In this commit, we fix an existing issue that could at times cause an
inconsistent view between the set of total coins, and the set of segwit
coins in the wallet of the node. This could be caused by initiating a
funding flow, but then the funding negotiation breaking down somewhere
along the lines. In this case, us or the other peer will disconnect.
When we initiate funding flows, we lock coins exclusively, to ensure
that concurrent funding flows don’t end up double spending the same
coin. Before this commit, we wouldn’t ever unlock those coins. As a
result, our view of available coins would be skewed.

The walletbalance call would show all the coins, but when adding the
—witness_only flag, some coins would be missing, or gone all together.
This is because the former call actually scans the txstore and manually
tallies the amount of available coins, while the latter looks at the
sent of available outputs, which is filtered based on which coins are
locked.

To remedy this, we now ensure that when a peer disconnects, we wipe all
existing reservations which will return any locked outputs to the set
of available outputs for funding flows.
2017-11-26 14:08:53 -06:00
Olaoluwa Osuntokun
ad364ae9a1
chains+server: if not in simnet mode, use BtcdFeeEstimator 2017-11-23 23:10:12 -06:00
Olaoluwa Osuntokun
3c4a6f42fa
server: update OpenChannel to properly pass in custom funding fee 2017-11-23 23:10:09 -06:00
Conner Fromknecht
2b74a6549f
server: instantiate utxon with NurseryConfig 2017-11-16 16:16:04 -08:00
Laura Cressman
ed6ad22e85 config+server+networktest: make trickleDelay configurable
Add option to set trickleDelay for AuthenticatedGossiper in
command line, with default value of 300 milliseconds. Pass this
value to newServer, which uses it when creating a new instance of
AuthenticatedGossiper. Also set this value to 300 milliseconds when
creating nodes in integration tests.
2017-11-15 16:50:19 -08:00
Olaoluwa Osuntokun
d894917458
server: add new shouldRequestGraphSync method to gate third feature bit
In this commit, we add a new method shouldRequestGraphSync which the
server will use in order to determine if we should request a full
channel graph sync from a newly connected remote peer. Atm, we’ll only
request a full sync iff, we have less than two peers. This is only the
initial basic logic, as we’ll later extend this to be more
comprehensive.

With this change, we’ll no longer be blasted by full channel graph
dumps for _each_ new connection after we deem that we’ve been
sufficiently bootstrapped to the network.
2017-10-18 15:18:13 -07:00
Olaoluwa Osuntokun
56d4c15914
peer: add localFeatures as parameter to newPeer
In this commit we add the set of local features advertised as a
parameter to the newPeer function. With this change, the server will be
able to programmatically determine _which_ bits should be set on a
connection basis, rather than re-using the same global set of bits for
each peer.
2017-10-18 15:16:09 -07:00
Jim Posen
ee49cdd103 server: Respect the initial_routing_sync feature bit.
Only synchronize routing info with peer if they request it by setting
the appropriate local feature bit.
2017-10-17 22:47:20 -07:00
Jim Posen
9fd77a6e40 multi: Update lnd to use new feature vector API. 2017-10-17 22:47:20 -07:00
Olaoluwa Osuntokun
61be23dc31
htlcswitch+server: add new field SelfKey to htlcswitch.Config
This commit adds a new field to the switch’s Config, namely the public
key of the backing lightning node. This field will soon be used to
return more detailed errors messages back to the ChannelRouter itself.
2017-10-16 18:39:17 -07:00
Olaoluwa Osuntokun
9b0b945a3d
Revert "server: BroadcastMessage will no longer block until completion"
This reverts commit 6db90ef09ab974df0ff09aeaf75a3d80414d4f50.

The root cause was fixed by commit
f4e7c36c80e8e2be9edb78b3b317c69d28d6d78f. As a result, this commit is no
longer needed.
2017-10-16 14:54:30 -07:00
Olaoluwa Osuntokun
7300452225
Revert "server: make sendToPeer async"
This reverts commit b7704e2de3dc96a4aebc2f47908a8f9def1da7f6.

The root issue was fixed by commit
f4e7c36c80e8e2be9edb78b3b317c69d28d6d78f. As a result, this commit is no
longer needed.
2017-10-16 14:53:24 -07:00
Olaoluwa Osuntokun
b7704e2de3
server: make sendToPeer async
This commit removes another case of unnecessary blockage, by modifying
the sendToPeer method to be fully asynchronous. From the PoV of the
callers that utilize this method currently, there’s no reason to block
until the completion of this method. Additionally, as the graph grows
larger without more intelligent the number of messages sent during
initial dump will start to be prohibitive to waiting for full
completion before proceeding.
2017-10-14 17:07:08 -07:00
Olaoluwa Osuntokun
6db90ef09a
server: BroadcastMessage will no longer block until completion
In this commit, we make the BroadcastMessage method on the server more
asynchronous by abandoning the two wait groups that it used for
synchronization. It has been observed that a circular waiting loop
between the AuthenticatedGossiper and a peer’s readHandler can cause
the system to dead lock.

By removing this unnecessary synchronization, we avoid the deadlock
case and allow the gossiper itself to no longer block in this scenario.
2017-10-14 16:04:06 -07:00
Conner Fromknecht
7aa64d58da server: improves readibility of peer connection logic 2017-10-13 16:12:31 -07:00
Conner Fromknecht
96ff63d219 server: fixes race condition during unexpected peer disconnect 2017-10-13 16:12:31 -07:00
Olaoluwa Osuntokun
63838f5764
peer+server: use new sphinx package and htlcswitch package type names 2017-10-10 22:19:21 -07:00
Olaoluwa Osuntokun
e5c303375b
server: in peerBootstrapper check for enough conns before attempting backoff
In this commit we modify the main loop within the peerBootstrapper
slightly to check for a sufficient amount of connections, _before_
checking to see if we need to back off the main loop. With this, we
avoid unnecessarily backing off unless an actual error occurs.
2017-10-10 22:19:13 -07:00
Olaoluwa Osuntokun
3b7855e449
routing: implement 2-week zombie channel pruning
This commit implements 2-week zombie channel pruning. This means that
every GraphPruneInterval (currently set to one hour), we’ll scan the
channel graph, marking any channels which haven’t had *both* edges
updated in 2 weeks as a “zombie”. During the second pass, all “zombie”
channel are removed from the channel graph all together.

Adding this functionality means we’ll ensure that we maintain a
“healthy” network view, which will cut down on the number of failed
HTLC routing attempts, and also reflect an active portion of the graph.
2017-10-04 20:46:09 -07:00
Brandon
3907ae65c2 routing+discovery: implement 2-week network view pruning 2017-10-04 20:40:21 -07:00
Olaoluwa Osuntokun
32508344db
server: use Debugf instead of Debug for logging in peerBootstrapper 2017-10-04 16:58:57 -07:00
Olaoluwa Osuntokun
c8226b1393
server: fix logging statement in peerBootstrapper
This commit fixes an incorrect logging statement within the
peerBootstrapper goroutine. We we’re using a Debug method previously
when we should’ve been using Debugf in order to properly pass the
logging statement through.
2017-10-04 14:52:54 -07:00
John Griffith
54c4fc4559 htlcswitch+server: pass onion error to ChannelRouter 2017-10-02 22:12:50 -07:00
Johan T. Halseth
4b4c431d67
server: add NotifyWhenOnline method.
This commit adds a listener queue for each peer, that can be used
to queue listeners that will be notified when the targetted peer
eventually comes online.
2017-10-02 13:29:51 +02:00
Olaoluwa Osuntokun
bd63e048d8
server: remove stray logging debugging statement from peerBootstrapper 2017-09-25 11:06:47 -07:00
Conner Fromknecht
e32d3024ae
server: instantiate breacharbiter using BreachConfig 2017-09-19 19:18:20 -07:00
Olaoluwa Osuntokun
8a208ae3cd
server: disable bootstrapping for simnet mode by default 2017-09-12 22:13:52 +02:00
Olaoluwa Osuntokun
fe0a7b6a09
multi: fix linter errors 2017-09-03 17:05:11 -07:00
Olaoluwa Osuntokun
1196c2e254
server: introduce new peerBootstrapper goroutine to seed initial conns
This commit adds a new primary goroutine to the server struct:
peerBootstrapper. If peer boostrapping isn’t disabled in the config,
this new goroutine will be launched to attempt to establish a set of
initial connections for a new node. The logic is pretty straight
forward: first a set of initial connections is attempted, if after our
first epoch, we don’t have enough connections yet, then we’ll attempt
to query for an additional set. In each iteration, if we haven’t been
successful, then we increase our exponential backoff in order to not
spam any of our bootstrapping sources.
2017-09-03 16:58:21 -07:00
Olaoluwa Osuntokun
2eb718e177
server: populate gossiper with chainhash of active chain 2017-09-03 16:41:43 -07:00
Olaoluwa Osuntokun
c09713ebd1
peer+server: rename discoverSrv to authGossiper 2017-08-22 00:53:25 -07:00
Olaoluwa Osuntokun
01b0ddf1c5
lnd+rpc: update RPC responses to convert mSAT to SAT 2017-08-22 00:52:56 -07:00
Olaoluwa Osuntokun
c4e43dbaa2
server: avoid nil pointer deference within OutboundPeerConnected 2017-08-15 17:49:35 -07:00
Olaoluwa Osuntokun
472d9967e5
server: fix some minor style deviations in new server code 2017-08-10 21:20:54 -07:00
Olaoluwa Osuntokun
bee7ed7758
server: re-introduce the quit channel to the server
This commit re-introduces the quit channel to the server as an upcoming
addition needs to synchronize its shutdown with the lifetime of the
server.
2017-08-10 21:19:00 -07:00
Olaoluwa Osuntokun
947544753f
server: use %x (hex encoding) when logging peer's pub key 2017-08-10 21:17:07 -07:00
Conner Fromknecht
91d6b0492e server: refactors w/ single mutex and sync disconnect
This commit alters the synchronization patterns used in the server
  such that the internal state is protected by a single mutex.  Overall,
  this simplifies the ability to reason about the behavior and
  manipulation of the internal state, which has resolved a few of flakes
  related to race conditions that were observed before hand.

  Invoking DisconnectPeer is now fully synchronous, and waits until
  the provided peer's peerTerminationWatcher has exited before
  returning.  Currently this is done by tracking the watcher using the
  peer's WaitGroup, and locking until the peer has shutdown.

  The server's API has also been refactored such that all public methods
  are safe for concurrent use. Therefore, other subsystems should be
  sure to make use of these endpoints to avoid corrupting the internal
  state.
2017-08-10 16:14:01 -07:00
Johan T. Halseth
c497a63f14 server: return copy of current node announcement instead of ref 2017-08-08 12:29:27 -07:00
Olaoluwa Osuntokun
d38b4471c2
server: if a fresh announcement is requested, ensure seqno increases 2017-08-07 16:31:20 -07:00
Olaoluwa Osuntokun
43b736225b
multi: add new method to generate fresh node announcments 2017-08-04 18:32:33 -07:00
Olaoluwa Osuntokun
d39410cc01
rpc: wrap canceling a breach watch in a select case 2017-08-03 16:40:15 -07:00
Olaoluwa Osuntokun
c2aafe7e51
server: add a method to query if the server has started
This commit adds a new utility method to the server struct itself. This
method will allow callers to query the state of the server in order to
decide if the server has been started or not. This can be useful
elsewhere in the project as we start to decouple the lifetime of
certain sub-systems from others.
2017-08-02 20:56:34 -07:00
Johan T. Halseth
ebbe6d7a10 server: set HaveNodeAnnouncement=true for self LightningNode 2017-08-02 15:58:58 -07:00
Olaoluwa Osuntokun
07212588fc
funding: update funding workflow to adhere to BOLT-0002
This commit updates the main single-funder funding workflow within the
fundingManager (initiated via the rpcserver or by a message from a
connected peer) to fully adhere to the funding protocol outlined in
BOLT-0002.

The major changes are as follows:
  * All messages modified to use the new funding messages in BOLT-0002.
  * The initiator of a funding workflow no longer decides how many
confirmations must elapse before the channel can be considered open.
  * Rather than each side specifying their desired CSV delay, both
sides now specify the CSV delay for the _other_ party.
2017-07-30 17:51:57 -07:00
Olaoluwa Osuntokun
34bb0ec36f
server: within peerTerminationWatcher exit early if daemon is exiting 2017-07-30 17:51:41 -07:00
Olaoluwa Osuntokun
a04fa76a4c
lnwire+htlcswitch: minor grammatical, formatting fixes after error PR 2017-07-14 20:08:37 -07:00
Andrey Samokhvalov
79b8d26b1a htlcswitch+router+server: handle payment error topology updates
In previous commits we have intoduced the onion errors. Some of this
errors include lnwire.ChannelUpdate message. In order to change
topology accordingly to the received error, from nodes where failure
have occured, we have to propogate the update to the router subsystem.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
6bbb7cbfc3 lnd: hook up encrypted onion error scaffolding
In this commit daemon have been changed to set the proper hooks in the
channel link and switch subsystems so that they could send and receive
encrypted onion errors.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
ef73062c14 peer+server+htlcswitch: add reason to disconnnect function
In order to recognize exact reason of the disconnect the additional
field have been added in the disconnect function.
2017-07-14 19:08:04 -07:00
Olaoluwa Osuntokun
11f7a227ab
server: update to latest htlcswitch API changes 2017-06-17 00:10:22 +02:00