Commit Graph

300 Commits

Author SHA1 Message Date
Johan T. Halseth
e9066c2d34
peer: print warning if selfPolicy not found 2018-08-23 07:50:18 +02:00
Johan T. Halseth
19e3a194fa
peer+server: make fetchLastChanUpdate _always_ fetch our own update
This commit fixes a bug that would cause us to fetch our peer's
ChannelUpdate in some cases, where we really wanted to fetch our own.

The reason this happened was that we passed the peer's pubkey to
fetchLastChanUpdate, making us match on their policy. This would lead to
ChannelUpdates being sent during routing which would have no effect on
the attempted path.

We fix this by always use our own pubkey in fetchLastChanUpdate, and
also uses the common methods within the server to be able to extract the
update even when only one policy is known.
2018-08-23 07:50:18 +02:00
Johan T. Halseth
de5e9e139c
server: make extractChannelUpdate extract from set of potential policies 2018-08-23 07:50:17 +02:00
Johan T. Halseth
229fd88289
peer: use custom MinHTLC value at initial link add
This commit fixes a bug within the peer, where we would always use the
default forwarding policy when adding new links to the switch. Mostly
this wasn't a problem, as we most often are using default values for new
channels, but the min_htlc value is a value that is set by the remote,
not us.

If the remote specified a custom min_htlc during channel creation, we
would still use our DefaultMinHtlc value when first adding the link,
making us try to forward HTLCs that would be rejected by the remote.

We fix this by getting the required min_htlc value from the channel
state machine, and setting this for the link's forwarding policy.

Note that on restarts we will query the database for our latest
ChannelEdgePolicy, and use that to craft the forwardingPolicy. This
means that the value will be set correctly if the policy is found in the
database.
2018-08-23 07:50:17 +02:00
Johan T. Halseth
5deffd228c
peer: call disableChannel with disabled=false after loading channels
This to ensure now active channel is available in the router, for path
finding, as it might have been disabled if the peer has been offline a
while.
2018-08-17 23:24:13 +02:00
Johan T. Halseth
b5bfdd72b5
server+peer: rename disableChannel->announceChanStatus
Now takes a boolean whether to disable/activate, and keeps track of the
last update sent to avoid sending duplicates.
2018-08-17 23:24:12 +02:00
Conner Fromknecht
d4d90979ef
peer: increase peer write timeout to 50 seconds
Sometimes when performing an initial sync, the remote
node isn't able to pull messages off the wire because
of long running tasks and queues are saturated. With
a shorter write timeout, we will give up trying to send
messages and teardown the connection, even though the
peer is still active.
2018-08-13 21:55:32 -07:00
Conner Fromknecht
a1abb11dc5
peer: add ready chan arg to WaitForDisconnect
This commit adds additional synchronization logic to
WaitForDisconnect, such that it can be spawned before
Start has been executed by the server. Without
modification, the current version will return
immediately since no goroutines will have been
spawned.

To solve this, we modify WaitForDisconnect to block until:
 1) the peer is disconnected,
 2) the peer is successfully started,
before watching the waitgroup.

In the first case, the waitgroup will block until all
(if any) spawned goroutines have exited. Otherwise, if
the Start is successful, we can switch to watching the
waitgroup, knowing that waitgroup counter is positive.
2018-08-13 21:52:32 -07:00
Olaoluwa Osuntokun
7a113d469b
Merge pull request #1551 from cfromknecht/switch-revert-replace-link
[htlcswitch]: revert replace link, ensure removed links are stopped
2018-08-13 21:44:42 -07:00
Johan T. Halseth
64c2c6b118
peer: print ChanStatus return value, not address 2018-08-11 12:51:50 +02:00
Conner Fromknecht
5f90973f76
peer: always purge link before adding new one 2018-08-10 11:42:25 -07:00
Conner Fromknecht
1113684dc3
Revert "htlcswitch: in event of duplicate link add, prefer newer link"
This reverts commit e60d2b774a35e446081f9be2d4901925cac05379.
2018-08-10 11:42:20 -07:00
Olaoluwa Osuntokun
d3b1b9aa98
Merge pull request #1668 from cfromknecht/interface-tickers
Ticker Package
2018-08-09 20:55:25 -07:00
Wilmer Paulino
9d2eeb6304
multi: update to latest fee estimation interface 2018-08-09 17:29:52 -07:00
Conner Fromknecht
2762546eeb
peer: replace NewBatchTicker with ticker.New 2018-08-09 02:48:07 -07:00
Conner Fromknecht
60edca164c
peer: adds StartTime() used to compute backoff relaxation 2018-08-07 14:50:07 -07:00
Olaoluwa Osuntokun
07defe5f93
rpc+peer: use pkScripts for close ntfns 2018-07-31 21:28:52 -07:00
Olaoluwa Osuntokun
1e39cfc65f
Merge pull request #1364 from halseth/data-loss-protect
Data loss protection
2018-07-31 20:53:42 -07:00
Johan T. Halseth
ea6aca26a5
channeldb: make chanStatus unexported
Since the ChanStatus field can be changed from concurrent callers, we
make it unexported and add the method ChanStatus() for safe retrieval.
2018-07-31 15:07:30 +02:00
Conner Fromknecht
0efe5ca49d
peer: only pass duration to htlcswitch.NewBatchTicker 2018-07-30 22:33:37 -07:00
Olaoluwa Osuntokun
e0baa49690
Merge pull request #1387 from wpaulino/send-disable-chan-update
multi: send a channel update with disabled flag set on channel close
2018-07-23 17:46:37 -07:00
Olaoluwa Osuntokun
bca926d6af
Merge pull request #1371 from wpaulino/prune-link-nodes
server: prune link nodes without any open channels
2018-07-21 18:55:38 -07:00
Wilmer Paulino
9cedef9245
fundingmanager: send messages to peers directly
In this commit, we modify the existing message sending functionality
within the fundingmanager. Due to each mesage send requiring to hold the
server's lock to retrieve the peer, we might run into a case where the
lock is held for a larger than usual amount of time and would therefore
block on sending the message within the fundingmanager. We remedy this
by taking a similar approach to some recent changes within the gossiper.
We now keep track of each peer within the internal fundingmanager
messages and send messages directly to them.
2018-07-19 12:34:11 -07:00
Wilmer Paulino
6504a9cfa8
fundingmanager+peer: modify fundingErrorMsg to use peer key 2018-07-19 12:32:31 -07:00
Wilmer Paulino
3ab17063ff
multi: satisfy new lnpeer interface 2018-07-19 12:32:29 -07:00
Wilmer Paulino
38b52df51f
peer+server: remove persistent connections for peers with no open channels remaining 2018-07-17 17:35:30 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Wilmer Paulino
873cccc7a6
multi: send channel update with disabled active on force and coop chan closes 2018-07-11 17:07:03 -07:00
Yaacov Akiba Slama
17223c1215 peer: add write timeout within writeMessage
In this commit, we add a timeout within the writeMessage method when we go to write to the socket. We do this as otherwise, if the other peer is blocked for some reason, we'll never actually unblock ourselves, which may cause issues in other sub-systems waiting on this write call. For now, we use a value of 10 seconds, and will adjust in the future if we deem this time period too short.
2018-06-26 17:27:22 -07:00
Wilmer Paulino
b1ba83bf2b
peer: prevent processing close msg if channel is not found 2018-06-25 13:13:12 -07:00
Johan T. Halseth
55c8741e42
peer: don't stop nil channel 2018-06-19 12:48:11 +01:00
Wilmer Paulino
90a50bd893
peer: remove no longer needed block epoch 2018-06-13 19:23:44 -07:00
Wilmer Paulino
8198466972
multi: move block epochs dependency from links to switch
In this commit, we move the block height dependency from the links in
the switch to the switch itself. This is possible due to a recent change
on the links no longer depending on the block height to update their
commitment fees.

We'll now only have the switch be alerted of new blocks coming in and
links will retrieve the height from it atomically.
2018-06-13 17:41:21 -07:00
Wilmer Paulino
4cc60493d2
peer+htlcswitch: randomize link commitment fee updates
In this commit, we modify the behavior of links updating their
commitment fees. Rather than attempting to update the commitment fee for
each link every time a new block comes in, we'll use a timer with a
random interval between 10 and 60 minutes for each link to determine
when to update their corresponding commitment fee. This prevents us from
oscillating the fee rate for our various commitment transactions.
2018-06-13 17:41:01 -07:00
Olaoluwa Osuntokun
e60d2b774a
htlcswitch: in event of duplicate link add, prefer newer link 2018-06-12 00:44:30 -07:00
Olaoluwa Osuntokun
e1d8c37708
peer: only add an active link to the channelManager if addPeer succeeds
In this commit we fix an existing bug which could cause internal state
inconsistency between then switch, funding manager, and the peer. Before
this commit, we would _always_ add a new channel to the channelManager.
However, due to recent logic, it may be the case that this isn't the
channel that will ultimately reside in the link. As a result, we would
be unable to process incoming FundingLocked messages properly, as we
would mutate the incorrect channel in memory.

We remedy this by moving the inserting of the new channel into the
activeChannels map until the end of the loadActiveChannels method, where
we know that this will be the link that persists.
2018-06-12 00:44:26 -07:00
Conner Fromknecht
edf08458c1
peer: changes to satisfy lnpeer.Peer
This commit adds:
 - variadic SendMessage method (w/ sync bool reorder)
 - passes peer object directly to ProcessRemoteAnnouncment
 - adds IdentityKey() method for lnpeer.Peer
2018-06-08 13:47:57 -07:00
maurycy
3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -07:00
Olaoluwa Osuntokun
210e28a483
peer: add messages summaries for the new gossip query messages 2018-05-31 16:30:56 -07:00
Olaoluwa Osuntokun
40bb19eb6e
peer: dispath new gossip query messages to the gossiper 2018-05-31 16:30:55 -07:00
Olaoluwa Osuntokun
bfcdbe2204 peer: when failing link, depend on server wg, not peer
In this commit, we fix a recently introduced bug. The issue is that
while we're failing the link, the peer we're attempting to force close
on may disconnect. As a result, if the peerTerminationWatcher exits
before we can add to the wait group (it's waiting on that), then we'll
run into a panic as we're attempting to increment the wait group while
another goroutine is calling wait.

The fix is to first check that the server isn't shutting down, and then
use the server's wait group rather than the peer to synchronize
goroutines.

Fixes #1285.
2018-05-25 20:36:40 -07:00
Johan T. Halseth
3b2fd32523
peer: populate OnChannelFailure in link config
This commit makes the peer aware of the LinkFailureErrors that can
happen during link operation, and making it start a goroutine to
properly remove the link and force close the channel.
2018-05-25 06:58:23 +02:00
Johan T. Halseth
4836a25c98
peer: move link creation into new method 2018-05-25 06:54:05 +02:00
Johan T. Halseth
bb611e065d
peer: don't pass closeCtx to chanCloser 2018-05-22 12:06:33 +02:00
Olaoluwa Osuntokun
f0050e7ffb
Merge pull request #1201 from lightningnetwork/peer-async-disconnect
server: Peer Async Disconnect w/ Scheduled peerConnected
2018-05-10 17:05:16 -07:00
Olaoluwa Osuntokun
b271ed5ffb
Merge pull request #1199 from cfromknecht/queue-msg-err-chans
peer/server: Remove Broadcast err chans
2018-05-10 16:55:57 -07:00
Conner Fromknecht
a2f7170ff0
peer: make Disconnect async, block on WaitForDisconnect 2018-05-08 16:37:14 -07:00
Conner Fromknecht
0691b21a30
peer: improves disconnect handling
This commit attempts to resolve some potential deadlock
scenarios during a peer disconnect.

Currently, writeMessage returns a nil error when disconnecting.
This should have minimal impact on the writeHanlder, as the
subsequent loop selects on the quit chan, and will cause it to
exit. However, if this happens when sending the init message,
the Start() method will attempt to proceed even though the peer
has been disconnected.

In addition, this commit changes the behavior of synchronous
write errors, by using a non-blocking select. Though unlikely,
this prevents any cases where multiple errors are returned, and
the errors are not being pulled from the other side of the errChan.
This removes any naked sends on the errChan from stalling the peer's
shutdown.
2018-05-08 16:35:49 -07:00
Olaoluwa Osuntokun
72f48b6abe
htlcswitch+server: ensure we always send an update w/ a TempChannelFailure
In this commit, we ensure that any time we send a TempChannelFailure
that's destined for a multi-hop source sender, then we'll always package
the latest channel update along with it.
2018-05-08 13:00:28 -04:00
Olaoluwa Osuntokun
d72f28839d
Merge pull request #1104 from halseth/chainwatcher-handoff-race
Fix chainwatcher handoff race
2018-05-03 17:18:31 -07:00