Commit Graph

141 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
2196d9375e
htlcswitch: obtain the min final CLTV delta directly from the InvoiceDatabase
In this commit, we modify the existing logic that would attempt to read
the min CLTV information from the invoice directly. With this route, we
avoid any sort of DB index modifications, as this information is already
stored within the payment request, which is already available to the
outside callers. By modifying the InvoiceDatabase interface, we avoid
having to make the switch aware of what the "primary" chain is.
2018-06-29 16:03:13 -07:00
Olaoluwa Osuntokun
3a47c41c6b
Merge pull request #1448 from Roasbeef/check-invoice-min-final
channeldb+htlcswitch: use the final min cltv delta in the invoice when link at exit hop
2018-06-28 18:39:33 -07:00
Olaoluwa Osuntokun
a2f0d6d38e
htlcswitch: use the delta within the time lock, not the default policy at exit node
In this commit, we fix a lingering bug within the link when we're the
exit node for a particular payment. Before this commit, we would assert
that the invoice gives us enough of a delta based on our current routing
policy. However, if the invoice was generated with a lower delta, or
we've changed from the default routing policy, then this would case us
to fail back any payments sent to us.

We fix this by instead using the newly available final CLTV delta
information within the extracted invoice.

Fixes #1431.
2018-06-26 19:50:04 -07:00
Olaoluwa Osuntokun
ec7cfc6906
Merge pull request #1447 from Roasbeef/forwarding-timelock-fix
routing+htlcswitch: finalize switch of CLTV delta directionality in path finding and link forwarding
2018-06-26 19:47:46 -07:00
Conner Fromknecht
66c4240234
htlcswitch/link: add WaitForShutdown method for testing 2018-06-26 18:28:54 -07:00
Olaoluwa Osuntokun
bdecc5bea9
htlcswitch: update forwarding policy verification to use new time lock info 2018-06-26 17:29:42 -07:00
Olaoluwa Osuntokun
7b4c150983
htlcswitch: add new incoming+outgoing timeout fields to htlcPacket 2018-06-26 17:29:41 -07:00
Olaoluwa Osuntokun
2bb5931bb7
htlcswitch: move timelock policy verification logic to HtlcSatifiesPolicy
In this commit, we extract the time lock policy verification logic from
the processRemoteAdds method to the HtlcSatifiesPolicy method. With this
change, we fix a lingering bug within the link: we'll no longer verify
time lock polices within the incoming link, instead we'll verify it at
forwarding time like we should. This is a bug left over from the switch
of what the CLTV delta denotes in the channel update message we made
within the spec sometime last year.
2018-06-26 17:29:41 -07:00
Olaoluwa Osuntokun
74ec9147b1
htlcswitch: extend the HtlcSatifiesPolicy to also accept timelock/height info
In this commit, we extend the existing HtlcSatifiesPolicy method to also
accept timelock and height information. This is required as an upcoming
commit will fix an existing bug in the forwarding logic wherein we use
the time lock policies of the incoming node rather than that of the
outgoing node.
2018-06-26 17:29:40 -07:00
yohei okada
7b37cbd2d9
htlcswitch: add basic table driven tests for ExpectedFee 2018-06-15 17:29:02 +09: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
Conner Fromknecht
4380c67124
htlcswitch/link: upgrade to use lnpeer.Peer.SendMessage 2018-06-08 16:29:49 -07:00
Olaoluwa Osuntokun
4bde4c1c26
Merge pull request #1333 from Roasbeef/min-fee-rate
funding+htlcswitch: enforce min fee rate of 253 sat/kw on commitments
2018-06-06 21:00:13 -07:00
Conner Fromknecht
c180065a84
htlcswitch/link: remove deadlock in htlc validation
This commit removes a possible deadlock in the switch,
which can be triggered under certain failure conditions.
Previously, we would acquire the link's read lock for
the duration of HtlcSatisfiesPolicy, though we only
need to use it grab the current policy. The deadlock could
be caused in the cases where we attempt to log the failure,
which access the read-protected ShortChanID method.
2018-06-06 18:11:36 -07:00
Olaoluwa Osuntokun
8f68d0e605
funding+htlcswitch: enforce min fee rate of 253 sat/kw on commitments
In this commit, we add and enforce a min fee rate for commitment
transactions created, and also any updates we propose to the remote
party. It's important to note that this is only a temporary patch, as
nodes can dynamically raise their min fee rate whenever their mempool is
saturated.

Fixes #1330.
2018-06-05 17:50:50 -07:00
Johan T. Halseth
f95ae1cdd6
htlcswitch/link: add failed variable to ensure exit 2018-05-25 06:58:24 +02:00
Johan T. Halseth
49fd3f34d4
htlcswitch/link: settle with fake preimage if BogusSettle active 2018-05-25 06:58:24 +02:00
Johan T. Halseth
fbec83699c
htlcswitch/link: make fail() call OnChannelFailure with LinkFailureError
Adds a new closure OnChannelFailure to the link config, which is called
when the link fails. This function closure should use the given
LinkFailureError to properly force close the channel, send an error to
the peer, and disconnect the peer.
2018-05-25 06:58:23 +02:00
Conner Fromknecht
3e46a5e815
htlcswitch/link: fix UpdateShortChanID 2018-05-09 16:07:25 -07:00
Olaoluwa Osuntokun
ddcbb40898
Merge pull request #1206 from wpaulino/temp-chan-failure-update
htlcswitch+server: ensure we always send an update w/ a TempChannelFailure
2018-05-08 19:33:20 -07:00
Conner Fromknecht
de9de771bb
htlcswitch/link: ensure circuits are committed in-order
This commit makes the call to forwardBatch after locking
in Adds synchronous. This ensures that circuits for any Add
packets are added to the switch in the same order that they
are prescribed in the channel state. Though it is very unlikely
this case would arise, it may happen under more greater loads.

In addition, this also makes some trivial optimizations wrt. to
not spawning unnecessary goroutines if no settle/fail packets
are locked in.
2018-05-08 16:37:35 -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
littleskunk
d2a6c4eec9 htlcswitch: typo fix 2018-05-07 21:33:32 -07:00
Olaoluwa Osuntokun
ddd12eff9c
htlcswitch: move link trimming to link start up
In this commit, we fix a race in the set of TestChannelLinkTrimCircuits*
tests. Before this commit, we would trim the circuits in the htlcManager
goroutine. However, this was problematic as the scheduling order of
goroutines isn't predictable. Instead, we'll now trim the circuits in
the Start method.

Additionally, we fix a series of off-by-2 bugs in the tests themselves.
2018-05-03 20:11:52 -07:00
Conner Fromknecht
42a9a78180
htlcswitch/link: trim fix 2018-05-02 01:12:18 -07:00
Conner Fromknecht
a36e1e6278
htlcswitch/link: adds HodlFlag breakpoints
This commit inserts an initial set of HodlFlags into
their correct places within the switch. In lieu of the
existing HtlcHodl mode, it is been replaced with a
configurable HodlMask, which is a bitvector representing
the desired breakpoints. This will allow for fine grained
testing of the switch's internals, since we can create
arbitrary delays inside a otherwise asynchronous system.
2018-05-02 00:18:51 -07:00
Johan T. Halseth
bc6b8a7eeb
htlcswitch/link: rename UnilateralClose -> RemoteUnilateralClose 2018-04-25 09:37:22 +02:00
Dimitris Tsapakidis
4009f7f874 multi: fix typos in comments 2018-04-17 19:03:27 -07:00
Olaoluwa Osuntokun
7037d55f65
htlcswitch: perform fee related checks at forwarding time
In this commit, we fix a very old, lingering bug within the link. When
accepting an HTLC we are meant to validate the fee against the
constraints of the *outgoing* link. This is due to the fact that we're
offering a payment transit service on our outgoing link. Before this
commit, we would use the policies of the *incoming* link. This would at
times lead to odd routing errors as we would go to route, get an error
update and then route again, repeating the process.

With this commit, we'll properly use the incoming link for timelock
related constraints, and the outgoing link for fee related constraints.
We do this by introducing a new HtlcSatisfiesPolicy method in the link.
This method should return a non-nil error if the link can carry the HTLC
as it satisfies its current forwarding policy. We'll use this method now
at *forwarding* time to ensure that we only forward to links that
actually accept the policy. This fixes a number of bugs that existed
before that could result in a link accepting an HTLC that actually
violated its policy. In the case that the policy is violated for *all*
links, we take care to return the error returned by the *target* link so
the caller can update their sending accordingly.

In this commit, we also remove the prior linkControl channel in the
channelLink. Instead, of sending a message to update the internal link
policy, we'll use a mutex in place. This simplifies the code, and also
adds some necessary refactoring in anticipation of the next follow up
commit.
2018-04-06 14:52:00 -07:00
Olaoluwa Osuntokun
b3bc374ba1
htlcswitch: send a direct Error if we get a known channel error on validate commit 2018-04-04 17:41:47 -07:00
Olaoluwa Osuntokun
0dbd325fd0
htlcswitch: synchronously send the error to the peer on commitment verify fail
In this commit, we fix a slight bug in lnd. Before this commit, we would
send the error to the remote peer, but in an async manner. As a result,
it was possible for the connections to be closed _before_ the error
actually reached the remote party. The fix is simple: wait for the error
to be returned when sending the message. This ensures that the error
reaches the remote party before we kill the connection.
2018-04-04 17:38:35 -07:00
Olaoluwa Osuntokun
5984cbd4ff
htlcswitch: allow overpaying for incoming payments
In this commit, we relax the constraints on accepting an exit hop
payment a bit. We'll now accept any incoming payment that _at least_
pays the invoice amount. This puts us further inline with the
specification, which recommends that nodes accept overpayment by a
certain margin.

Fixes #1002.
2018-04-02 15:58:56 -07:00
Conner Fromknecht
d13a566284
htlcswitch/link: DecodeOnionObfuscator -> ExtractErrorEncrypter 2018-03-13 16:33:28 -07:00
Olaoluwa Osuntokun
8988a07bce
htlcswitch: eliminate unnecessary indentation in processRemoteAdds
In this commit, we remove a ton of unnecessary indentation in the
processRemoteAdds method. Before this commit, we had a switch statement
on the type of the entry. This was required before when the method was
generic, but now since we already know that it’s an Add, we no longer
require such a statement.
2018-03-12 18:58:46 -07:00
Olaoluwa Osuntokun
069311c47f
htlcswitch: log dangling circuits in unable to create new commitment 2018-03-12 18:58:45 -07:00
Olaoluwa Osuntokun
bdd01cccb2
htlcswitch: remove getBandwidthCmd as it's no longer needed 2018-03-12 18:58:45 -07:00
Olaoluwa Osuntokun
1af8fa9367
htlcswitch: add additional comments and logging 2018-03-12 18:58:44 -07:00
Olaoluwa Osuntokun
c285bb5814 htlcswitch+peer: remove DecodeHopIterator from ChannelLinkConfig
In this commit, we remove the DecodeHopIterator method from the
ChannelLinkConfig struct. We do this as we no longer use this method,
since we only ever use the DecodeHopIterators method now.
2018-03-12 18:58:08 -07:00
Johan T. Halseth
33762e0f81
htlcswitch/link: fail channel on lnwire.Error 2018-03-11 17:21:23 +01:00
Conner Fromknecht
101ad09e9f
htlcswitch/link: batches processing of locked in htlcs 2018-03-09 21:08:43 -08:00
Conner Fromknecht
1fe7c6d431
htlcswitch/link: integrate persistence changes to lnwallet APIs 2018-03-09 17:35:53 -08:00
Olaoluwa Osuntokun
649be5ee0b
Merge pull request #775 from cfromknecht/sphinx-replay
Switch Persistence [1/4]: Infra for Sphinx Batched Decoding and Replay Protection
2018-03-08 23:03:01 -05:00
Conner Fromknecht
27df8d8ad1
htlcswitch/link: extract error encrypter from hop iterator 2018-03-08 21:12:04 -05:00
Olaoluwa Osuntokun
7031b5d217
htlcswitch: modify forwarding fee assertion to compare emperical fees
In this commit, we fix a bug that was uncovered by the recent change to
lnwire.MilliSatoshi. Rather than manually compute the diff in fees,
we’ll directly compare the fee that is given against the fee that we
expect.
2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun
473dfd115b
htlcswitch: add set of tests for the forwarding log 2018-03-06 13:56:11 -05:00
Olaoluwa Osuntokun
6f11fee1a4
htlcswitch: when forwarding htlcs, set the incomingHtlcAmt 2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun
d377ffafdd
htlcswitch: populate the incoming+outgoing in the payment circuit 2018-03-06 13:56:10 -05:00
Johan T. Halseth
80277c0517
htlcswitch: use fee rate types instead of btcutil.Amount for fee rates 2018-02-26 22:42:25 +01:00
Johan T. Halseth
e6f7a46d90
htlcswitch: don't return negative value from Bandwidth()
This commits prevents the Bandwith() method from returning
a negative value if the channel reserve is larger than
the actual available balance.
2018-02-08 18:35:24 -05:00