Commit Graph

251 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
ccd1dad71e
peer: set HtlcPoint to nil within logWireMessage
This new field was added as a recent modification to the spec, but the
curve parameter within the attribute wasn’t set to nil. As a result
this would result in a large degree of spam within the logs when set to
trace mode. This commit fixes this issue by setting it to nil along
with all the other pub keys within messages.
2017-12-01 19:31:56 -08:00
Olaoluwa Osuntokun
c3ec32e67b
peer: display lnwire.Error body as ascii string in messageSummary
It dictates in the spec, that the error message should be an ASCII
string to allow other implementations to easily discern the type of
error. The other implementations do this, but we don’t yet, but we’ll
go ahead and display it anyway as it’s helpful when debugging.
2017-11-30 22:19:18 -08:00
Olaoluwa Osuntokun
58ab3f5f83
peer: show conf depth in message summary for AcceptChannel 2017-11-27 16:50:10 -08:00
Olaoluwa Osuntokun
56632235fd
peer: set FeeEstimator in ChannelLinkConfig when creating link 2017-11-23 23:10:21 -06:00
Olaoluwa Osuntokun
39295dc5aa
lnwallet+peer: add new ResetState method to channel state machine
In this commit, we add a new ResetState method to the channel state
machine which will reset the state of the channel to `channelOpen`. We
add this as before this commit, it was possible for a channel to shift
into the closing state, the closing negotiation be cancelled for
whatever reason, resulting the the channel held by the breachArbiter
unable to act to potential on-chain events.
2017-11-23 23:10:16 -06:00
Olaoluwa Osuntokun
259a01b29d
peer: integrate new channelCloser state machine for co-cop channel closes
In this commit, we refactor the existing channel closure logic for
co-op closes to use the new channelCloser state machine. This results
in a large degree of deleted code as all the logic is now centralized
to a single state machine.
2017-11-23 23:10:11 -06:00
Olaoluwa Osuntokun
1cf1d250b3
peer: update WipeChannel method to match recent htlcswitch API change 2017-11-23 23:10:11 -06:00
Johan T. Halseth
555cead5ad peer: avoid blocked writeHandler<->queueHandler interaction
This commit addresses an issue that could occur if a
message was attempted added to the sendQueue by the
queueHandler before the writeHandler had started.

If a message was sent to the queueHandler before the
writeHandler was ready to accept messages on the
sendQueue, the message would be added to the
pendingMsg queue, but would not be attempted sent
on the sendQueue again before a new incoming message
triggered a new attempt.
2017-11-15 18:54:06 -08:00
Olaoluwa Osuntokun
150ab00842
peer: add message summary for lnwire.ChannelReestablish 2017-11-10 19:51:11 -08:00
Olaoluwa Osuntokun
e337a329cd
peer+rpc: properly set ChainHash in ChannelCloseSummary instances 2017-11-10 19:51:09 -08:00
Andrey Samokhvalov
d70ffe93e4 htlcswitch+channel: add channel states synchronization
In this commit BOLT№2 retranmission logic for the channel link have
been added. Now if channel link have been initialised with the
'SyncState' field than it will send the lnwire.ChannelReestablish
message and will be waiting for receiving the same message from remote
side. Exchange of this message allow both sides understand which
updates they should exchange with each other in order sync their
states.
2017-11-09 16:38:57 -08:00
Conner Fromknecht
04a56e7286
peer: add async queue for gossiper msgs
This commit refactors the core logic of the
  chanMsgStream to support an additional stream
  that is used to asynchronously queue for in-order
  delivery to the authenticated gossiper. The channel
  streams are slightly adapted to use the more flexible
  primitive. We may look to refactor this using more
  isolated interfaces, but for now this provides a
  minimal change to resolving known flakes.
2017-11-02 15:57:12 -07:00
Olaoluwa Osuntokun
bb1fd98b67
peer: print hex encoded failure reason for lnwire.UpdateFailHTLC in msg summaries 2017-10-22 18:36:40 -07:00
Olaoluwa Osuntokun
8de0a4cb24
peer: when logging message summaries use the correct preposition 2017-10-19 19:45:34 -07:00
Olaoluwa Osuntokun
4cf4fd377f
peer: in chanMsgStream release lock for condition var after msg q pop
In this commit we fix an existing bug within the msgConsumer grouting
of the chanMsgStream that could result in a partial deadlock, as the
readHandler would no longer be able to add messages to the message
queue. The primary cause of this issue would be if we got an update for
a channel that “we don’t know of”. The main loop would continue,
leaving the mutex unlocked. We would then try to re-lock at the top of
the loop, leading to a deadlock.

We avoid this situation by properly unlocking the condition variable as
soon as we’re done modifying the condition itself.
2017-10-19 19:45:08 -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
Olaoluwa Osuntokun
f6f983a13b
peer: rename theirLocalFeatures+theirGlobal features to remote prefix 2017-10-18 15:14:27 -07:00
Jim Posen
af49752d4d peer: Update peer handling of received feature vectors.
This updates peer to be compatible with the new feature vector API.
2017-10-17 22:47:20 -07:00
Olaoluwa Osuntokun
f953f94f71
peer: display reversed bytes of chain hash in message summaries 2017-10-17 19:44:15 -07:00
Olaoluwa Osuntokun
dc124baca1
peer: if cooperative closing transaction is rejected, return err to caller 2017-10-17 19:44:14 -07:00
Olaoluwa Osuntokun
b7e193354a
peer: add message summaries of sent/recv'd message for debug log level
This commit fills in an existing logging gap by adding a new set of
message summaries that is shown for the debug logging level.

Before this commit, if a user wanted to get a close up feel for what
lnd was doing under the covers, they had to use the trace logging
level. Trace can be very verbose, so we now provide a debug logging
level with message “summaries”. The summaries may not contain all the
data in the message, hut have been crafted in order to provide
sufficient detail at a glance.
2017-10-17 19:44:12 -07:00
Olaoluwa Osuntokun
0692d2d408
peer: log type of received unknown message 2017-10-16 18:43:19 -07:00
Olaoluwa Osuntokun
f4e7c36c80
peer: eliminate excessive queueHandler spinning w/ blocked writeHandler
This commit fixes an existing bug within the iteration between the
queueHandler and the writeHandler. Under certain scenarios, if the
writeHandler was blocked for a non negligible period of time, then the
queueHandler would enter a very tight spinning loop. This was due to
the fact that the break statement in the inner select loop of the
queueHandler wouldn’t actually break the inner for loop, instead it
would cause the execution logic to re-enter that same select loop,
causing a very tight spin.

In this commit, we fix the issue by adding to things: we now label the
inner select loop so we can break out of it if we detect that the
writeHandler has blocked. Secondly, we introduce a new channel between
the queueHandler and the writeHandler to signal the queueHandler that
the writeHandler has finished processing the last message.
2017-10-15 15:19:57 -07:00
Olaoluwa Osuntokun
cbdf139696
peer: add an idle timer to the readHandler
In this commit, we add an idle timer to the readHandler itself. This
will serve to slowly prune away inactive TCP connections as a result of
remote peer being blocked either upon reading or writing to the socket.
Our ping timer interval is 1 minute, so an idle timer interval of 5
minutes seem reasonable.
2017-10-15 15:14:35 -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
171c997fe0
peer: within loadActiveChannels, skip channel if FundingLocked not processed
This commit fixes a bug to wrap up the recently merged PR to properly
handle duplicate FundingLocked retransmissions and also ensure that we
reliably re-send the FundingLocked message if we’re unable to the first
time around.

In this commit, we skip processing a channel that does not yet have a
set remote revocation as otherwise, if we attempt to trigger a state
update, then we’ll be attempting to manipulate a nil commitment point.
Therefore, we’ll rely on the fundingManager to properly send the
channel all relevant subsystems.
2017-10-02 16:30:28 -07:00
Johan T. Halseth
ee2eec6188
peer: ignore new channel requests for already active channels. 2017-10-02 13:29:54 +02:00
Olaoluwa Osuntokun
c5876e5d21
peer: avoid exit deadlock by ensuring WaitGroups are decremented before disconnect 2017-09-27 20:22:52 -07:00
Olaoluwa Osuntokun
ab25b636f5
peer: add conditional sends on quit within readHandler message dispatch 2017-09-27 20:18:29 -07:00
Olaoluwa Osuntokun
37d03d1e56
peer: avoid possible GC leak by setting popped queue element to nil 2017-09-24 20:08:34 -07:00
Conner Fromknecht
74322a99be config+htlclink+peer: htlc hodl mode!
This commit adds a new debug mode for lnd
  called hodlhtlc. This mode instructs a node
  to refrain from settling incoming HTLCs for
  which it is the exit node. We plan to use
  this in testing to more precisely control
  the states a node can take during
  execution.
2017-09-19 11:31:52 -07:00
Olaoluwa Osuntokun
a43e9c6883
peer: check for ErrEdgeNotFound when loading chan edge for fwrding policy
This commit adds a precautionary check for the error returned if the
channel hasn’t yet been announced when attempting to read the our
current routing policy to initialize the channelLink for a channel.
Previously, if the channel wasn’t they announced, the function would
return early instead of using the default policy.

We also include another bug fix, that avoids a possible nil pointer
panic in the case that the ChannelEdgeInfo reread form the graph is
nil.
2017-08-30 15:34:27 -07:00
Olaoluwa Osuntokun
d4d5198e85
peer: if we don't have an advertised routing policy, fall back to default
This commit fixes a bug that could arise if either we had not, or the
remote party had not advertised a routing policy for either outgoing
channel edge. In this commit, we now detect if a policy wasn’t
advertised, falling back to the default routing policy if so.

Fixes #259.
2017-08-23 11:34:53 -07:00
Olaoluwa Osuntokun
b069406d1e
peer: fix bug, use the existing timestamp for the ChannelUpdate msg
This commit fixes a lingering bug within the logic for the
peer/htlcswitch/channellink. When the link needs to fetch the latest
update to send to a sending party due to a violation of the set routing
policy, previously it would modify the timestamp on the message read
from disk. This was incorrect as it would invalidate the signature
within the message itself. We fix this by instead
2017-08-22 00:53:31 -07:00
Olaoluwa Osuntokun
3086a9d06a
peer: ensure a peer can exit mid cooperative closure
This commit adds another conditional send select statement to ensure
that when sending the finalized contract to the breach arbiter, the
peer doesn’t possible cause the daemon to hang on shutdown.
2017-08-22 00:53:28 -07:00
Olaoluwa Osuntokun
c09713ebd1
peer+server: rename discoverSrv to authGossiper 2017-08-22 00:53:25 -07:00
Olaoluwa Osuntokun
dd1d69b140
peer: fetch forwarding policy from disk rather than using default
This commit modifies the logic when we are loading alll the channels
that we have with a particular peer to grab the current committed
forwarding policy from disk rather then using the default forwarding
policy. We do this as it’s now possible for active channels to have
distinct forwarding policies.
2017-08-22 00:53:23 -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
65dede2584
peer: ensure chan sends to breachArbiter can't block indefinitely
This commit fixes a possible deadlock bug that may arise during
shutdown due to an unconditional send on a channel to the breach
arbiter. We do this on two occasions within the peer: when loading a
new contract to give it the live version, and also when closing a
channel to ensure that it no longer watches over it.

Previously it was possible for these sends to block indefinitely in the
scenario that the server was shutting down (which means the breach
arbiter) is. As a result, the channel would never be drained, meaning
the server couldn’t complete shutdown as the peer hadn’t exited yet.
2017-08-18 12:16:29 -07:00
Johan T. Halseth
e8e87322dd
peer: add channel close fee negotiation
This commit adds the fee negotiation procedure performed
on channel shutdown. The current algorithm picks an ideal
a fee based on the FeeEstimator and commit weigth, then
accepts the remote's fee if it is at most 50%-200% away
from the ideal. The fee negotiation procedure is similar
both as sender and receiver of the initial shutdown
message, and this commit also make both sides use the
same code path for handling these messages.
2017-08-11 12:10:32 +02:00
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
Olaoluwa Osuntokun
178f26b8d5
peer: restore the htlcManager's logCommitTimer to a persistent ticker
This commit patches a whole in our optimistic channel synchronization
logic by making the logCommitTimer a persistent ticker rather than one
that is activated after receiving a commitment, and disabled once we
send a new commitment ourself. In the setting of batched full-duplex
channel updates, the prior approach could at times result in a benign
state desync caused by one side being one commitment ahead of the other
because one of the nodes failed to, or was unable to provide the other
with a state update during the workflow.
2017-04-11 22:02:44 -07:00
Olaoluwa Osuntokun
3393f3a8db
peer: simplify channel state update handling by using
This commit simplifies the channel state update handling by doing away
with the commitmentState.pendingUpdate method all together. The newly
added LightningChannel.FullySynced method replace the prior state and
also replaced all other uses of PendingUpdates.

By moving to using channel.FullySynced() we also eliminate class of
desynchronization error caused by a node failing to provide the other
side with the latest commitment state.
2017-04-11 22:02:36 -07:00
Andrey Samokhvalov
d4055d7830 discovery+funding: add validation of the announcement messages
Add validation functions and include validation checks in the
annoncement process function.
2017-03-29 19:49:05 -07:00
Andrey Samokhvalov
fbf766e3c6 discovery+funding: add 'AnnounceSignature' proof exchange
Add the interaction between nodes of announce signature messages, which
will allow us to exhcnage the half channel announcemen proofs later.
2017-03-29 19:49:05 -07:00
Andrey Samokhvalov
c3b2854428 lnwire: converge discovery part of messages with specification
Change the name of fields of messages which are belong to the discovery
subsystem in a such way so they were the same with the names that are
defined in the specification.
2017-03-29 19:49:05 -07:00
Andrey Samokhvalov
4c52b6e6a4 lnd: replace 'routing' with 'discovery' package
Add usage of the 'discovery' package in the lnd, now discovery service
will be handle all lnwire announcement messages and send them to the
remote party.
2017-03-29 19:49:05 -07:00
Olaoluwa Osuntokun
0e96d273d9
peer: enforce strict timeout on opening handshake
This commit modifies the logic around the opening p2p handshake to
enforce a strict timeout around the receipt of the responding init
message. Before this commit, it was possible for the daemon and certain
RPC calls to deadlock as if a peer connected, but didn’t respond with
an init msg, then we’d be sitting there waiting for them to respond.
With this commit, we’ll now time out, kill the connection and then
possible attempt to re-connect if the connection was persistent.
2017-03-29 19:00:40 -07:00
Olaoluwa Osuntokun
505421db2c
htlcswitch: add HTLC overflow flow-control via bounded channels
This commit fixes a prior bug which would cause the set of HTLC’s on a
node’s commitment to potentially overflow if an HTLC was accepted or
attempted to be forwarded that but the commitment transaction over the
maximum allowed HTLC’s on a commitment transaction. This would cause
the HTLC to silently be rejected or cause a connection disconnect. In
either case, this would cause the two states to be desynchronized any
pending HTLC’s to be ignored.

We fix this issue by introducing the concept of a bounded channel,
which is a channel in which the number of items send and recevied over
the channel must be balanced in order to allow a new send to succeed
w/o blocking. We achieve this by using a chan struct{} as a semaphore
and decrement it each time a packet it sent, increasing the semaphore
one a packet is received. This creates a channel that we can use to
ensure the switch never sends more than N HTLC’s to a link before any
of the HTLC’s have been settled.

With this bug fix, it’s now once again possible to trigger sustained
bursts of payments through lnd nodes.
2017-03-24 16:40:02 -07:00
Olaoluwa Osuntokun
ac83b8ae06
peer: fix bug in handshake wherein RevokeAndAck would be sent first
This commit fixes a bug in the opening handshake between to peers. The
bug would arise when on or many channels were active between a node
establishing a new connection. The htlcManager goroutines will
immediately attempt to extend the revocation window once they’re
active. However, at this time, the init message may not yet have been
sent as the two executions are in distinct goroutines.

We fix this bug by manually writing the init message directly to the
socket, rather than traveling through the queueHandler goroutine. With
this, we ensure that the init message is _always_ sent first.
2017-03-16 19:45:16 -07:00
Olaoluwa Osuntokun
f217093c00
multi: replace usage of fastsha256 with crypto/sha256
This commit removes all instances of the fastsha256 library and
replaces it with the sha256 library in the standard library. This
change should see a number of performance improvements as the standard
library has highly optimized assembly instructions with use vectorized
instructions as the platform supports.
2017-03-15 18:56:41 -07:00