Commit Graph

219 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
d4e650c85d
peer: the chancloser no longer needs to notify the breach arb of settled transactions 2018-01-22 19:19:59 -08:00
Olaoluwa Osuntokun
5df6704a9c
contractcourt: make synchronous chain watcher notifications optional
In this commit, we modify the way that notifications are dispatched
within the chainWatcher. Before we would *always* wait for an ack back
before we started to clean up he database state. This would at times
lead to deadlocks. To remedy this, we now allow callers to decide if
they want notifications to be sync or not. The only current caller that
requires this is the breach arbiter.
2018-01-22 19:19:58 -08:00
Olaoluwa Osuntokun
3ec83cc82f
peer+contractcourt: delegate watching for co-op closes to the chainWatcher
In this commit, we modify the interaction between the chanCloser
sub-system and the chain notifier all together. This fixes a series of
bugs as before this commit, we wouldn’t be able to detect if the remote
party actually broadcasted *any* of the transactions that we signed off
upon. This would be rejected to the user by having a “zombie” channel
close that would never actually be resolved.

Rather than the chanCloser watching for on-chain closes, we’ll now open
up a co-op close context to the chainWatcher (via a layer of
indirection via the ChainArbitrator), and report to it all possible
closes that we’ve signed. The chainWatcher will then be able to launch
a goroutine to properly update the database state once any of the
possible closure transactions confirms.
2018-01-22 19:19:53 -08:00
Olaoluwa Osuntokun
69e6ec9954
peer+funding: remove unneeded channel handoff code with the breach arbiter
We no longer need to hand off new channels that come online as the
chainWatcher will be persistent, and always have an active signal for
the entire lifetime of the channel.
2018-01-22 19:19:50 -08:00
Olaoluwa Osuntokun
defa1bc3e3
peer: when creating new links, obtain an on-chain events subscription 2018-01-22 19:19:49 -08:00
Olaoluwa Osuntokun
24a16b4f49
lnd: properly initialize entities of new contractcourt package 2018-01-22 19:19:42 -08:00
Olaoluwa Osuntokun
b1fe0c12bf
peer: ensure that any active msgStreams properly exit upon peer D/C
In this commit, we modify the logic within the Stop() method for
msgStream to ensure that the main goroutine properly exits. It has been
observed on running nodes with tens of connections, that if a node is
very flappy, then the node can end up with hundreds of leaked
goroutines.

In order to fix this, we’ll continually signal the msgConsumer to wake
up after the quit channel has been closed. We do this until the
msgConsumer sets a bool indicating that it has exited atomically.
2018-01-08 19:50:22 -08:00
Conner Fromknecht
44805be8d9
peer: filter borked channels when loading active chans 2018-01-05 13:47:18 -08:00
Johan T. Halseth
25b77a0aee peer: add error chan to queueMsg 2017-12-19 13:01:59 -06:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Olaoluwa Osuntokun
ecf58d64f7
peer: properly route UpdateFailMalformedHTLC messages to the switch
This commit adds an overlooked case into the main type switch statement
within the peer’s readHandler. Before this commit, we would fail to
process any UpdateFailMalformedHTLC messages, possibly leading to a
commitment desynchronization. To avoid this case, we’ll no properly
process the UpdateFailMalformedHTLC message by sending the message to
an active link registered to the switch.
2017-12-12 11:22:50 -08:00
Olaoluwa Osuntokun
ce6dee6ee4
peer: check LocalUnrevokedCommitPoint for nil-ness as it's optional
In this commit, we modify the logWireMessage function to ensure that we
don't attempt to nil out the LocalUnrevokedCommitPoint.Curve field
unless it's actually set. We need to do this as the field as actually
optional, and we may be reading a message from a node that doesn't
support the option.

Fixes #461.
2017-12-07 13:11:23 -08:00
Olaoluwa Osuntokun
4444ec39ea
funding: properly display our 1-byte error code messages 2017-12-06 18:43:58 -08:00
Olaoluwa Osuntokun
7960b5240f
peer: when processing a msg, skip he funding barrier if it's a ChanSync message
This commit is a follow up to the prior commit: as it’s possible for
the channel_reestablish message to be sent *before* the channel has
been fully confirmed, we’ll now ensure that we process it to the link
even if the channel isn’t yet open.
2017-12-06 16:43:00 -08:00
Olaoluwa Osuntokun
084d477ec3
peer: always load active channels upon connection reestablishment with peer
In this commit, we modify the logic within loadActiveChannels to
*always* load a channel, even if it isn’t yet fully confirmed. With
this change, we ensure that we’ll always send a channel_reestablish
message upon reconnection.

Fixes #458.
2017-12-06 16:43:00 -08:00
Olaoluwa Osuntokun
7b10f54216
peer: in logWireMessage also unset curve field for lnwire.ChannelReestablish
This will allow users to run in trace mode again, without having an
excessive amount of spam in their logs.
2017-12-06 16:43:00 -08:00
Olaoluwa Osuntokun
3bc248e01c
peer: properly process retransmitted FundingLocked message we've never processed
In this commit, we modify the logic within the channelManager to be
able to process any retransmitted FundingLocked messages. Before this
commit, we would simply ignore any new channels sent to us, iff, we
already had an active channel with the same channel point. With the
recent change to the loadActiveChannels method in the peer, this is now
incorrect.

When a peer retransmits the FundingLocked message, it goes through to
the fundingManager. The fundingMgr will then (if we haven’t already
processed it), send the channel to the breach arbiter and also to the
peer’s channelManager. In order to handle this case properly, if we
already have the channel, we’ll check if our current channel *doesn’t*
already have the RemoteNextRevocation field set. If it doesn’t, then
this means that we haven’t yet processed the FundingLcoked message, so
we’ll process it for the first time.

This new logic will properly:
  * ensure that the breachArbiter still has the most up to date channel
  * allow us to update the state of the link has been added to the
switch at this point
      * this link will now be eligible for forwarding after this
sequence
2017-12-06 16:42:59 -08:00
Olaoluwa Osuntokun
ddc5a0fc85
peer: unconditionally add a channel to the switch if it's open
In this commit we revert a prior change which was added after
FundingLocked retransmission was implemented. This prior change didn’t
factor in the fact that the FundingLocked message will *only* be
re-sent after both sides receive the ChannelReestablishment message.
With the prior code, as we never added the channel to the link, we’d
never re-send the ChannelReestablishment, meaning the other side would
never send the FundingLocked message.

By unconditionally adding the channel to the switch, we ensure that
we’ll always properly retransmit the FundingLocked message.
2017-12-06 16:42:59 -08:00
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