Commit Graph

742 Commits

Author SHA1 Message Date
Conner Fromknecht
ec1b8d874d
htlcswitch/link: add pending commit ticker for stall detection
This commit adds a PendingCommitTicker to the link config, which allows
us to control how quickly we fail the link if the commitment dance
stalls. Now that the mailbox has the ability to cancel packets, when the
link fails it will reset the mailbox packets on exit, forcing a
reevaluation of the HTLCs against their mailbox expiries.
2020-04-14 10:51:30 -07:00
Conner Fromknecht
a8977651cc
htlcswitch/linkfailure: use whitelist for ShouldSendToPeer 2020-04-14 10:51:06 -07:00
Conner Fromknecht
6fca22be2b
htlcswitch/link: use return instead of break out
There is no clean up logic after the loop, done purely to improve
clarity.
2020-04-14 10:50:45 -07:00
Conner Fromknecht
16ad0274c9
htlcswitch/mailbox: fail on duplicate adds 2020-04-14 10:50:25 -07:00
Conner Fromknecht
e7ece11c29
htlcswitch/mailbox: fail htlcs when delayed for 1 minute
Now that packet failure is handled by the mailbox, we can now enforce
a delivery deadline and fail the packet if it the deadilne is exceeded.
This gives senders quicker feedback about tried routes, and allows them
to try alternative paths to the destination in the meantime.
2020-04-14 10:50:07 -07:00
Conner Fromknecht
1aa2dde4a4
htlcswithc/mailbox: prioritize settles/fails over adds
This commit splits the packet courier internally into two distinct
queues, one for adds and one for settles+fails. This allows us to
prioritize HTLCs that will clear the commitment transaction and make
space for adds. Previously this responsibility was handled by the
overflow queue.
2020-04-14 10:49:48 -07:00
Conner Fromknecht
37dca27a3d
htlcswitch: thread clock from switch to mailbox 2020-04-14 10:49:26 -07:00
Conner Fromknecht
63f3d0b012
htlcswitch/mailbox: advance packet head after delivery
This commit delays the advancement of the pktHead until after the
message has been delivered. This is a prepatory step, as in the future
we may fail to deliver the packet due to a deadline expiring.
2020-04-14 10:48:59 -07:00
Conner Fromknecht
564534c829
htlcswitch: move packet failure to mailbox
This commit moves the current logic for sending failures out of the link
and into the mailbox in preparation for our failing delayed htlcs. We do
so because the mailbox may need to fail packets while the link is
offline, and needs to be able to complete the task without member
methods on the link.
2020-04-14 10:48:40 -07:00
Conner Fromknecht
12bbf28e65
htlcswitch: make handleBatchFwdErrors a pure function 2020-04-14 10:48:23 -07:00
Conner Fromknecht
f3051efeb3
htlcswitch/mailbox: block until mailbox shutdown
Fixes a bug where Stop() wouldn't actually wait for the mailbox to exit.
2020-04-14 10:48:06 -07:00
Conner Fromknecht
5b38ed0b3e
htlcswitch/link: correct link log statement 2020-04-14 10:47:47 -07:00
Conner Fromknecht
0f94b8dc62
multi: return input.Signature from SignOutputRaw 2020-04-10 14:27:35 -07:00
Conner Fromknecht
f50649d21b
htlcswitch/link: remove overflow queue
This commit removes the overflowQueue from the link. We do so in order
to promote better UX for senders, so that HTLCs are failed faster when
the commitment is full. This gives the sender the opportunity to try
another, more open path, rather than perceive the HTLC as being stuck.

At the same time, we remove the total number of active goroutines in lnd
by a factor of N where N is the number of active channels.
2020-04-07 13:20:36 -07:00
Conner Fromknecht
68d1753dcb
htlcswitch/test_utils: send htlcs before waiting for result
This commit is preparation for the test added in the subsequent commit.
We modify makeHoldPayment to return any failures direectly when trying
to add an HTLC to the switch. This lets us know that the HTLC was indeed
sent without failure when the method returns.
2020-04-07 11:56:22 -07:00
Conner Fromknecht
5a057de5c4
htlcswitch/mailbox: remove errors from AckPacket, Start, Stop
A following commits will move/modify callsites of AckPacket, Start, and
Stop, none of which use the return value and ultimately cause the linter
to complain. However, none of these in-memory operations can fail so we
just remove the returned errors altogether.
2020-04-07 11:55:54 -07:00
Conner Fromknecht
e86ddf6ae7
htlcswitch/link: remove unused isReProcess argument 2020-04-07 11:55:25 -07:00
Conner Fromknecht
759d7a122f
htlcswitch/test_utils: add missing return
This commit corrects a bug in the testing harness that could cause
more than one error to be returned on the error channel.
2020-04-07 11:54:56 -07:00
Conner Fromknecht
77041c131a
htlcswitch/switch_test: add t.Helper() to assertion 2020-04-07 11:54:02 -07:00
Conner Fromknecht
028345daea
htlcswithc/link_test: rm unused arg from generateHtlc
Linter started complaining.
2020-04-07 11:53:36 -07:00
Conner Fromknecht
2c3641e915
htlcswitch/link_test: fix preimage assertion
This flakes locally for me on darwin.
2020-04-07 11:53:15 -07:00
Conner Fromknecht
425b2c712f
htlcswitch/switch_test: increase checkHtlcEvents timeout
This flakes locally for me on darwin.
2020-04-07 11:52:50 -07:00
Conner Fromknecht
ec784db511
multi: remove returned error from WipeChannel
The linter complains about not checking the return value from
WipeChannel in certain places. Instead of checking we simply remove the
returned error because the in-memory modifications cannot fail.
2020-04-02 17:39:29 -07:00
nsa
966cd2112c multi: link notifies subscribers of ActiveLinkEvent, rpc ignores 2020-03-27 08:49:46 -04:00
Olaoluwa Osuntokun
31de32686e
Merge pull request #4107 from Crypt-iQ/switch_err_0220
htlcswitch: log fixes
2020-03-26 16:45:58 -07:00
nsa
8c0c53eac3 htlcswitch: only error in closeCircuit if the htlc was failed
This commit changes the switch to only log an error if update_fail_htlc
comes in and closeCircuit returns ErrUnknownCircuit. Rationale
being that only settles should hit this code path, anything else
is a result of a link flap and should be treated as an error.
2020-03-25 11:53:46 -04:00
nsa
4fe174ba4e htlcswitch: switch ackDownStreamPackets order with contract update call
This commit modifies updateCommitTx to error with ErrLinkShuttingDown
when we try to send a ContractUpdate on the htlcUpdates chan and the
link has closed the quit chan. It also changes the order of the call
to ackDownStreamPackets and contract update call for consistency since
the packets should be acknowledged before the link goes down.
2020-03-25 11:53:21 -04:00
nsa
f757bf48bd channeldb: use RemoteCommitment in NextLocalHtlcIndex
This commit changes the fallback in NextLocalHtlcIndex to
RemoteCommitment since the LocalHtlcIndex field lags behind
on the LocalCommitment. Without this bug fix, open circuits
would get prematurely trimmed, resulting in more erroneous
logs. A test case is included to check that the fix works.
2020-03-25 11:49:16 -04:00
Oliver Gugger
eb531d0449
htlcswitch: add causing error to log and err msg 2020-03-24 10:00:59 +01:00
Olaoluwa Osuntokun
4e68914e9d
htlcswitch: convert to use new kvdb abstraction 2020-03-18 19:34:55 -07:00
Johan T. Halseth
fd93c568ea
config+link: disable watchtower for anchors 2020-03-09 12:59:34 +01:00
Johan T. Halseth
5d5069c477
Merge pull request #3691 from halseth/link-bandwitch-amt-aware
lnwallet: Make available balance HTLC fee aware
2020-02-20 17:56:20 +01:00
carla
c0a4923dc1
htlcswitch: add htlc notifier test 2020-02-19 18:13:18 +02:00
carla
71fdd755b4
htlcswitch: notify local receive settles 2020-02-19 18:06:00 +02:00
carla
6bd0de257a
htlcswitch: notify incoming link failures
This commit adds link failure notifications for failures which occur
on our incoming link. These failures may be receives which we failed or
forwards which we could not parse.
2020-02-19 18:05:49 +02:00
carla
22d370aa51
htlcswitch: notify send forward failures and settles
Add notifications for local initiated sends settles and forwarding
failures. As with link failures, local send settles and forwarding
failures are reported directly to the router so must have their own
notification handling.
2020-02-19 18:05:45 +02:00
carla
79a890fa48
htlcswitch: notify outgoing link failures for local sends
Notify link failures for our own payments. Separate handling code is
required for local payment link failures because we do not pass these
failures back through the switch (like we do for link failures for
forwards), but rather send them straight back to the router. Our own
sends have the payment ID saved in the incoming htlc ID of the packet's
incoming circuit. This change replaces that value with for the sake
of consistent notifying of sends and receives from our node.
2020-02-19 18:05:12 +02:00
carla
937062b6d3
htlcswitch: refactor handleLocalDispatch
Split handleLocalDispatch into an extra handleLocalAddHTLC function so
we can easily notify an error should one occur adding the htlc.
2020-02-19 18:04:51 +02:00
carla
fc0ee06a99
htlcswitch: add notifications for forwards
This commit adds notifications for htlcs which are forwarded through
our node. Forwards are notified when the htlc is added on our ougoing
link, settles when we send a settle message to the downstream peer.
If a failure occurs, we check whether it occurred at our node, then
notify a link or forwarding failure accordingly.

Note that this change also adds forward event notifications for sends
which are initiated by our node because the handling code for adding
a htlc which originates from our node is the same as that for handling
forwards. Htlcs for our locally initiated sends have our internal pid
set in the incoming htlcs id field, so we extract this value and notify
with a zero htlc id to be consistent with receives (which have zero
outgoing circuits). Subsequent settles or failures are not noitfied
for local sends in this commit, and will be handled in a follow up.
2020-02-19 18:03:22 +02:00
carla
b70080a267
htlcswitch: failAddPacket with full packet information
This commit sets more fields on the htlcPacket created to fail adding
a htlc packet to the switch for notification purposes. This new data is
copied by value from the original packet. The packet is then failed
back to the peer that forwarded us the packet, which is handled by
handledownstream packet. The values added to the packet are not used
in the handling of a failed packet.
2020-02-19 17:51:53 +02:00
carla
abf780bf03
multi: add htlcNotifier interface to switch and link
In this commit, a htlcNotifier interface is added to allow for easy
unit testing. Instances of the HtlcNotifier are added to the server,
switch and link.
2020-02-19 17:50:28 +02:00
carla
2074820d85
htlcswitch: add htlcnotifier
This commit adds a HTLCNotifier to htlcswitch which HTLC events
will be piped through to provide clients with subscriptions to
HTLC level events.

The event types added are forward events (which occur for sends
from and forwards through our node), forward failues (when a
send or forward fails down the line), settles for forwards or
receives to our node and link failures which occur when a htlc
is failed at our node (which may occur for a send, receive or
foreward).
2020-02-19 17:50:19 +02:00
Johan T. Halseth
9ff79ae595
lnwallet/channel: account for HTLC fee when reporting available balance 2020-02-19 12:27:42 +01:00
Johan T. Halseth
5e89d5b6c2
link+lnwallet: move bandwidth channel reserve validation into channel
Since we want to handle the edge case where paying the HTLC fee would
take the initiator below the reserve, we move the subtraction of the
reserve into availableBalance where this calculation will be performed.
2020-02-19 12:27:42 +01:00
Olaoluwa Osuntokun
fce472e820
Merge pull request #3876 from breez/allow-timeouted-initiated-htlc
contractcourt: keep channels with timed-out initiated htlcs.
2020-02-17 14:08:44 -08:00
Roei Erez
0407b37fce contractcourt+switch: keep channels with timed-out initiated htlcs.
This commit enables the user to specify he is not interested in
automatically close channels with pending payments that their
corresponding htlcs have timed-out.
By requiring a configurable grace period uptime of our node
before closing such channels, we give a chance to the other node to
properly cancel the htlc and avoid unnecessary on-chain transaction.
In mobile it is very important for the user experience as otherwise
channels will be force closed more frequently.
2020-02-16 09:08:03 +02:00
carla
1ad395ec3f
htlcswitch: add failure details to incoming failures
This commit adds LinkErrors with failure details to htlcs which fail on
our incoming link. This change is made with the intention of notifying
detailed htlc failure reasons in sendHTLCError. The FailureDetail
interface is implemented on FailureResolutionResults so that they can
directly be used to enrich LinkErrors. sendHtlcError is updated to
take a LinkError in preparation for the addition of a htlcnotifier
which will notify the detail of the error.
2020-02-06 19:43:39 +02:00
carla
74e0d545fe
htlcswitch: add linkError field to htlcpacket
This commit adds a linkError field to track the value of failures
which occur at our node. This field is set when local payments or
multi hop htlcs fail in the switch or on our outgoing link. This
addition is required for the addition of a htlc notifier which will
notify these failures in handleDownstreamPacket.

The passing of link error to failAddPacket removes the need for an
additional error field, because the link error's failure detail will
contain any additional metadata. In the places where the failure detail
does not cover all the metadata that was previously supplied by addr
err, the error is logged before calling failAddPacket so that this
change does not reduce the amount of information we log.
2020-02-06 19:43:29 +02:00
carla
9390d3bbfd
htlcswitch: replace outgoing failure with interface
Add a FailureDetail interface which allows us have different kinds of
failures for link errors. This interface will be used to cover failures
that occur when on invoice payment, because the errors have already
been enumerated in the invoices package.
2020-02-06 19:43:23 +02:00
carla
bdd9411bbd
htlcswitch: rename FailureDetail to OutgoingFailure
Rename FailureDetail in a separate commit so that a FailureDetail
interface can be introduced in the following commit.
OutgoingFailureOnionDecode is renamed to OutgoingFailureDecodeError
to specifically indicate that we could not decode the wire
failure that our payment experienced.
2020-02-06 19:43:14 +02:00