Commit Graph

161 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
a2545d85dc
peer: ensure goroutine launched during initial handshake exits
This commit fixes a bug which was covered by the recent server
refactoring wherein the grouting would be stuck on the send over the
message channel in the case that the handshake failed. This blockage
would create a deadlock now that the ConnectToPeer method is full
synchronous.

We fix this issue by ensuring the goroutine properly exits.
2017-08-10 18:07:54 -07:00
Conner Fromknecht
efd9cf12b8 peer: adds tracking of go routines to sync disconnect
In addition to improved synchronization between the client
  and server, this commit also moves the channel snapshotting
  procedure such that it is handled without submitting a query
  to the primary select statement. This is primarily done as a
  precaution to ensure that no deadlocks occur, has channel
  snapshotting has the potential to block restarts.
2017-08-10 16:14:01 -07:00
Olaoluwa Osuntokun
43b736225b
multi: add new method to generate fresh node announcments 2017-08-04 18:32:33 -07:00
Olaoluwa Osuntokun
c183e8984c
peer: properly clean up chanMsgStreams map on readHandler exit
This commit ensures that all references within the chanMsgStreams are
all removed and deleted when the readHandler exits. This ensures that
all objects don’t have extra references, and will properly be garbage
collected.
2017-08-03 13:52:12 -07:00
Olaoluwa Osuntokun
36f4e2046d
peer: ensure mutex is freed up when the msgConsumer exits 2017-08-03 13:50:34 -07:00
Olaoluwa Osuntokun
79e68a2fdf
peer: properly initialize ChannelLink with new block+height info 2017-08-02 21:15:57 -07:00
Olaoluwa Osuntokun
0377a4f99d
peer: ensure the chanMsgStream for a channel exists on peer d/c 2017-07-31 21:31:24 -07:00
Olaoluwa Osuntokun
c47408119e
peer: abandon the prior activeChanStreams scheme in favor of chanMsgStream
This commit fixes a bug that existed in the prior scheme we used to
synchronize between the funding manager and the peer’s readHandler.
Previously, it was possible for messages to be re-ordered before the
reached the target ChannelLink. This would result in commitment
failures as the state machine assumes a strict in-order message
delivery. This would be manifested due to the goroutine that was
launched in the case of a pending channel funding.

The new approach using the chanMsgStream is much simpler, and easier to
read. It should also be a bit snappier, as we’ll no longer at times
create a goroutine for each message.
2017-07-31 21:25:54 -07:00
Olaoluwa Osuntokun
5e4b368348
peer: introduce chanMsgStream to provide a concurrent safe, in-order stream of msgs 2017-07-31 21:20:42 -07:00
Olaoluwa Osuntokun
f963859524
funding+peer: rename processFundingResponse to processFundingAccept 2017-07-31 21:04:58 -07:00
Olaoluwa Osuntokun
cd7b3290a8
peer: modify channel closing negotiation to create new delivery scripts
This commit modifies the channel close negotiation workflow to instead
take not of the fat that with the new funding workflow, the delivery
scripts are no longer pre-committed to at the start of the funding
workflow. Instead, both sides present their delivery addresses at the
start of the shutdown process, then use those to create the final
cooperative closure transaction.

To accommodate for this new change, we now have an intermediate staging
area where we store the delivery scripts for both sides.
2017-07-30 17:51:37 -07:00
Olaoluwa Osuntokun
01fe9adff0
peer: update logWireMessage to account for new lnwire messages 2017-07-30 17:51:34 -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
Johan T. Halseth
adbbd1e80f peer: handle received update_fee message. 2017-07-14 16:39:15 -07:00
Olaoluwa Osuntokun
e15604f7b5
peer: ensure latest version of htlcswitch.Peer interface is implemented 2017-06-17 00:11:10 +02:00
Olaoluwa Osuntokun
d202b730eb
peer: fix peer API usage due to incomplete cherry-pick 2017-06-05 19:41:18 -07:00
Olaoluwa Osuntokun
25dc294cf0
server: all references to primary interfaces are now through chainControl 2017-06-05 18:53:37 -07:00
Andrey Samokhvalov
c4955258f1 htlcswicth: start use htlcswitch and channel link inside lnd
In current commit big shift have been made in direction of unit testable
payments scenarios. Previosly two additional structures have been added
which had been spreaded in the lnd package before, and now we apply
them in the lnd itself:

1. ChannelLink - is an interface which represents the subsystem for
managing the incoming htlc requests, applying the changes to the
channel, and also propagating/forwarding it to htlc switch.

2. Switch - is a central messaging bus for all incoming/outgoing htlc's.
The goal of the switch is forward the incoming/outgoing htlc messages
from one channel to another, and also propagate the settle/fail htlc
messages back to original requester.

With this abtractions the folowing schema becomes nearly complete:

abstraction
    ^
    |
    | - - - - - - - - - - - - Lightning - - - - - - - - - - - - -
    |
    | (Switch)		        (Switch)		  (Switch)
    |  Alice <-- channel link --> Bob <-- channel link --> Carol
    |
    | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - -
    |
    |  (Peer) 		        (Peer)	                  (Peer)
    |  Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
2017-05-31 11:06:08 -07:00
Olaoluwa Osuntokun
311495e6d0
peer: add additional comments around new channel close workflow, minor fixes
This commit adds a set of additional comments around the new channel
closure workflow and also includes two minor fixes:
  * The error when parsing a signature previously wasn’t checked and is
    now.
  * As a result, we should only track the new signature iff it parses
    correctly and we agree to the details as specified w.r.t to the fee
    for the final closing transaction.

Additionally, as set of TODO’s has been added detailing the additional
work that needs to be done before the closing workflow is fully
compliant with the specification.
2017-05-23 15:26:50 -07:00
Olaoluwa Osuntokun
e635b958a5
peer: consolidate sendClosingSigned into shutdown resp flow 2017-05-23 15:23:06 -07:00
Olaoluwa Osuntokun
588a606a56
peer: ensure when closing the channel actually exists 2017-05-23 15:22:06 -07:00
bryanvu
408be356fb lnwallet: update channel close to use fee estimation interface
This commit switches the channel close workflow to use the lnwallet fee
estimation interface rather than the hardcoded proposedFee.
2017-05-23 14:31:20 -07:00
bryanvu
514760f529 peer: handling for channel shutdown messages
This commit changes the cooperative channel close workflow to comply
with the latest spec. This adds steps to handle and send shutdown
messages as well as moving responsibility for sending the channel close
message from the initiator to the responder.
2017-05-23 14:31:20 -07:00
bryanvu
d7bb600c23 lnwire: adjusted coop close messages to comply with spec
Removed close_request and close_complete and replaced with shutdown and
closing_signed.
2017-05-23 14:31:20 -07:00
Olaoluwa Osuntokun
e7420edd44 peer: fix last-mile settle stalling in concurrent multi-hop setting
This commit fixes an issue that would at times cause the htlcManager
which manages the link that’s the final hop to settle in an HTLC flow.
Previously, a case would arise wherein a set of HTLC’s were settled to,
but not properly committed to in the commitment transaction of the
remote node. This wasn’t an issue with HTLC’s which were added but
uncleared, as that batch was tracked independently.

In order to fix this issue, we now track pending HTLC settles
independently. This is a temporary fix, as has been noted in a TODO
within this commit.
2017-05-18 20:19:03 -07:00
Olaoluwa Osuntokun
041f3f1e98 peer: eliminate possibility of concurrent map writes in htlcManager
This commit fixed an issue in the htlcManager goroutine which manages
channel state updates. Due to lack of a mutex protecting the two maps
written in the goroutine launched to forward HTLC’s to the switch.

This issue was detected by golang’s runtime which is able to detect
invalid concurrent map writes.
2017-05-18 20:13:33 -07:00
bryanvu
abe2e502d5 lnwallet: add FeeEstimator interface, StaticFeeEstimator implementation
This commit adds the FeeEstimator interface, which can be used for
future fee calculation implementations. Currently, there is only the
StaticFeeEstimator implementation, which returns the same fee rate for
any transaction.
2017-05-15 20:26:11 -07:00
Olaoluwa Osuntokun
3b61675344
peer: revert 178f26b8d5ef14b437b9d8d1755bd238212b4dec
This commit reverts a prior commit
178f26b8d5ef14b437b9d8d1755bd238212b4dec that introduced a scenario
that could cause a state desynchronization and/or a few extraneous
commitment updates. To avoid such cases, the commitment tick timer is
now only started after _receiving_ a commitment update.
2017-05-15 18:20:56 -07:00
Olaoluwa Osuntokun
620695542c
peer: fix panic bug in watiForChanToClose
This commit fixes a panic bug in the watiForChanToClose method caused
by a logic error leading to the return value of the function at times
being a nil pointer in the case that an error occurred. We now avoid
such an error by _always_ returning from the function if there’s an
error, but conditionally (in a diff if-clause) sending an error over
the error channel.
2017-05-15 18:20:52 -07:00
Olaoluwa Osuntokun
34959e4648
peer+lnwallet: update API usage to recent channeldb changes 2017-05-14 19:23:57 -07:00
Olaoluwa Osuntokun
7df1d75267
peer: stop a channel's goroutines within wipeChannel 2017-05-14 19:21:23 -07:00
Olaoluwa Osuntokun
e05ec619ca
peer: ensure no messages are sent/processed _before_ all channels loaded
This commit fixes a bug which could at times cause channels to be
unusable upon connection. The bug would manifest like the following:
two peers would connect, one loads their channels faster than the
other, this would result in the winning peer attempting to extend their
revocation window. However, if the other peer hadn’t yet loaded the
channel, then this would appear to them to be an unknown channel.

We properly fix this issue by ensure all channels are loaded _before_
any of the goroutines needed for the operation of the peer are
launched.
2017-05-11 15:21:00 -07:00
Olaoluwa Osuntokun
d47f004fbd
peer+rpcserver+breacharbiter: usel latest ChainNotifier API 2017-05-11 15:20:55 -07:00
Olaoluwa Osuntokun
071aa3ad75
peer: log which channel point when revocation window exhausted 2017-05-04 17:39:42 -07:00
Olaoluwa Osuntokun
62d6ac6a8f
peer: properly manage channel close lifecycle within the database
Within this commit the peer will now properly manage the channel close
life cycle within the database. This entails marking the channel as
pending closed either once the closing transaction has been broadcast
or the close request message has been sent to the other side.

Once the closing transaction has been confirmed, the transaction will
be marked as fully closed within the database. A helper function has
been added to factor out “waiting for a transaction to confirm” when
handling moth local and remote cooperative closure flows.

Finally, we no longer delete the channel state within wipeChannel as
this will now be managed distinctly by callers.
2017-05-04 17:39:40 -07:00
Olaoluwa Osuntokun
4cb76071a2
server+peer: re-write persistent connection handling
The prior methods we employed to handle persistent connections could
result in the following situation: both peers come up, and
_concurrently_ establish connection to each other. With the prior
logic, at this point, both connections would be terminated as each peer
would go to kill the connection of the other peer. In order to resolve
this issue in this commit, we’ve re-written the way we handle
persistent connections.

The eliminate the issue described above, in the case of concurrent peer
connection, we now use a deterministic method to decide _which_
connection should be closed. The following rule governs which
connection should be closed: the connection of the peer with the
“smaller” public key should be closed. With this rule we now avoid the
issue described above.

Additionally, each peer now gains a peerTerminationWatcher which waits
until a peer has been disconnected, and then cleans up all resources
allocated to the peer, notifies relevant sub-systems of its demise, and
finally handles re-connecting to the peer if it's persistent. This
replaces the goroutine that was spawned in the old version of
peer.Disconnect().
2017-04-23 19:58:03 -07:00
Olaoluwa Osuntokun
00a7f140ff
peer: add WaitForDisconnect method
This commit adds a new method to the peer struct: WaitForDisconnect().
This method is put in place to be used by wallers to synchronize the
ending of a peer’s lifetime. A follow up commit will utilize this new
method to re-write the way we handle persistent peer connections.
2017-04-23 19:29:44 -07:00
Olaoluwa Osuntokun
0ef36dca9b
peer: remove the Stop() method in favor of only Disconnect() 2017-04-23 19:25:22 -07:00
Olaoluwa Osuntokun
52ffb026af
peer: return more detailed errors from the Start() method 2017-04-23 19:24:33 -07:00
Olaoluwa Osuntokun
adce64e21c
peer: we now load active channel during startup, not creation 2017-04-23 19:23:22 -07:00
Olaoluwa Osuntokun
010373fe0f
peer: modify readMessage/writeMessage to be message oriented
This commit modifies both readMessage and writeMessage to be further
message oriented. This means that message will be read and written _as
a whole_ rather than piece wise. This also fixes two bugs: the
readHandler could be blocked due to an sync read, and the writeHandler
would unnecessarily chunk up wire messages into distinct crypto
messages rather than writing it in one swoop.

Also with these series of changes, we’re now able to properly parse
messages that have been padded out with additional data as is allowed
by the current specification draft.
2017-04-20 15:45:59 -07:00
Olaoluwa Osuntokun
f867252139
peer: switch to new WriteMessage/ReadMessage after wire msg changes 2017-04-19 16:23:22 -07:00
Olaoluwa Osuntokun
feec611531
lnwire+peer: implement new ping/pong messages and behavior
This commit implements the new ping/pong messages along with their new
behavior. The new set of ping/pong messages allow clients to generate
fake cover traffic as the ping messages tells the pong message how many
bytes to included and can also be padded itself.
2017-04-16 18:11:45 -07:00
Olaoluwa Osuntokun
193936374a
peer: fix deadlock bug, block readHandler when waiting for chan open
This commit fixes a deadlock bug within the readHandler of the peer.
Previously, once a channel was pending opening, _no_ other message
would be processed by the readHandler as it would be blocked waiting
for the channel to open. On testnet this would be manifsted as a node
locking up, until the channel was detected as being open.

We fix this bug by tracking which channel streams are active. If a
channel stream is active, then we can send the update directly to it.
Otherwise, we launch a goroutine that’ll block until the channel is
open, then in a synchronized manner, update the channel stream as being
active and send the update to the channel.
2017-04-16 15:45:24 -07:00
Olaoluwa Osuntokun
60c0cebfd5
lnd: switch over internal indexes to use the new Channel ID's 2017-04-16 15:41:19 -07:00
Olaoluwa Osuntokun
609cba95d7
funding+peer: switch to using new channel ID's
This commit modifies the way the fundingManager tracks pending funding
workflows internally. Rather than using the old auto-incrementing
64-bit pending channel ID’s, we now use a 32-byte pending channel ID
which is generated using a CSPRG. Additionally, once the final funding
message has been sent, we now de-multiplex the FundingLocked message
according to the new Channel ID’s which replace the old ChannelPoint’s
and are exactly 32-bytes long.
2017-04-16 15:34:29 -07:00
Olaoluwa Osuntokun
d146411712
peer: lower logCommitTimer check to 100ms 2017-04-14 11:25:03 -07:00
Olaoluwa Osuntokun
b51a0eb094
peer: increase initial handshake timeout to 15 seconds 2017-04-13 14:48:43 -07:00
Olaoluwa Osuntokun
54c63f4aa1
peer: remove unused lastNMessages map
This map was added very early on as a possible path to implement proper
retransmission. However, we now have a proper persistent retransmission
sub-system being proposed as a PR, therefore we no longer have any use
for this.
2017-04-13 14:32:00 -07:00