Commit Graph

172 Commits

Author SHA1 Message Date
Joost Jager
bacd92418a
invoices: use lntypes.Hash and lntypes.Preimage
Previously chainhash.Hash was used, which converts to/from string in
reversed format. Payment hashes and preimages are supposed to be
non-reversed.
2019-02-01 09:42:29 +01:00
Joost Jager
9e012ecc93
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input
interface and implementations in a separate package along with all their
dependencies from lnwallet.
2019-01-31 13:25:33 +01:00
orbitalturtle
08750f180b multi: deprecate IncorrectHtlcAmount onion error
In this commit, we deprecate the `IncorrectHtlcAmount` onion error.
We'll still decode this error to use when retrying paths, but we'll no
longer send this ourselves. The `UnknownPaymentHash` error has been
amended to also include the value of the payment as well. This allows us
to worry about one less error.
2019-01-29 18:21:13 -08:00
Johan T. Halseth
480f43f1dc
lnwallet/channel: add lnwire<->PaymentDescriptor FeeUpdate conversion
This commit adds conversion between the lnwire.UpdateFee message and the
new FeeUpdate PaymentDescriptor. We re-purpose the existing Amount field
in the PaymentDescriptor stuct to hold the feerate.
2019-01-10 12:26:33 +01:00
Joost Jager
5515713b88
channeldb: convert settled boolean to state
This commit is a preparation for the addition of new invoice
states. A database migration is not needed because we keep
the same field length and values.
2019-01-04 07:53:55 +01:00
Olaoluwa Osuntokun
152fc8b1f1
Merge pull request #2329 from Roasbeef/global-sig-pool
multi: replace per channel sigPool with global daemon level sigPool
2018-12-17 16:33:56 -08:00
Wilmer Paulino
e71151f56a htlcswitch/link: return FinalFailExpiryTooSoon for last htlc
In this commit, we fix a minor discrepancy with the spec. We should
return a FinalFailExpiryTooSoon error, rather than a
FinalFailIncorrectCltvExpiry error, when the last HTLC of a route (exit
hop) has an expiration height that is deemed too soon by the final
destination of the HTLC.
2018-12-17 15:26:11 -05:00
Olaoluwa Osuntokun
fa160f559c
multi: replace per channel sigPool with global daemon level sigPool
In this commit, we remove the per channel `sigPool` within the
`lnwallet.LightningChannel` struct. With this change, we ensure that as
the number of channels grows, the number of gouroutines idling in the
sigPool stays constant. It's the case that currently on the daemon, most
channels are likely inactive, with only a hand full actually
consistently carrying out channel updates. As a result, this change
should reduce the amount of idle CPU usage, as we have less active
goroutines in select loops.

In order to make this change, the `SigPool` itself has been publicly
exported such that outside callers can make a `SigPool` and pass it into
newly created channels. Since the sig pool now lives outside the
channel, we were also able to do away with the Stop() method on the
channel all together.

Finally, the server is the sub-system that is currently responsible for
managing the `SigPool` within lnd.
2018-12-16 15:40:14 -08:00
Johan T. Halseth
a9bd6100ff
htlcswitch/link: remove handled TODO 2018-11-21 10:28:57 +01:00
Johan T. Halseth
676a1b1407
lnwallet+link: make ChanSyncMsg take channel state as arg
This lets us get the channel reestablish message without creating the LightningChannel struct first.
2018-11-21 10:28:56 +01:00
Joost Jager
1d97cf1229
htlcswitch+routing: implement expiry_too_far failure
In this commit we add a check to HtlcSatifiesPolicy to verify that the
time lock for the outgoing htlc that is requested in the onion packet
isn't too far in the future.

Without this check, anyone could force an unreasonably long time lock on
the forwarding node.
2018-10-15 08:51:08 +02:00
Olaoluwa Osuntokun
5cf911a762
Merge pull request #1764 from cfromknecht/isolate-fwdpkg-to-live-links
htlcswitch/link: only resovle+gc fwdpkgs for live channels
2018-08-24 17:42:44 -07:00
Conner Fromknecht
211a0299e9
htlcswitch/link: only resovle+gc fwdpkgs for live channels 2018-08-21 19:10:16 -07:00
Conner Fromknecht
81b4af2ec8
htlcswitch/link: cleanup spurious fail/settle responses 2018-08-21 17:13:58 -07:00
Conner Fromknecht
3fb6a310f8
htlcswitch/link: remove circuit deletion forgiveness
This commit removes the concept of "circuit deletion
forgivness" from the link. This was originally
implemented due to the strict semantics of the original
DeleteCircuit implementation, which would fail if we tried
to delete unknown circuits. Forgivness is used on startup
to ignore this error in case the circuits had already been
deleted before shutting down.

Now that the circuit deletion has been relaxed, this
behavior is no longer necessary, as requests to delete
unknown (or previously deleted) circuits will be ignored.

This is necessary for future changes regarding switch
cleanup, which may attempt to cleanup already deleted
circuits.
2018-08-20 16:45:42 -07:00
Conner Fromknecht
0fef1c71fe
htlcswitch/link: pass link quit to ForwardPackets 2018-08-10 11:42:26 -07:00
Conner Fromknecht
b507d265b4
htlcswitch/link: only update contract signals on start if live link 2018-08-10 11:42:25 -07:00
Olaoluwa Osuntokun
d3b1b9aa98
Merge pull request #1668 from cfromknecht/interface-tickers
Ticker Package
2018-08-09 20:55:25 -07:00
Wilmer Paulino
9d2eeb6304
multi: update to latest fee estimation interface 2018-08-09 17:29:52 -07:00
Conner Fromknecht
1c456a5144
htlcswitch/link: replace batch ticker with...
resumable ticker.Ticker interface
2018-08-09 02:48:06 -07:00
Conner Fromknecht
cf2c371042
multi: fix linting errors 2018-08-02 18:20:50 -07:00
Olaoluwa Osuntokun
1e39cfc65f
Merge pull request #1364 from halseth/data-loss-protect
Data loss protection
2018-07-31 20:53:42 -07:00
Johan T. Halseth
ebed786b2a
htlcswitch/link: inspect sync errors, force close channel
This commit makes the link inspect the error encountered during channel
sync, force closing the channel if we detect a remote data loss.
2018-07-31 15:16:23 +02:00
Conner Fromknecht
5af19bb2b4
htlcswitch/link: reusable BatchTicker
This commit modifies the default BatchTicker
implementation such that it will generate a
new ticker with each call to Start(). This
allows us to create a new ticker after
releasing an old one due to the batch
being empty.
2018-07-30 22:33:37 -07:00
Conner Fromknecht
bd9a6bd625
htlcswitch/link: conditional batch ticker
In this commit, we prevent the htlcManager from
being woken up by the batchTicker when there is no
work to be done. Profiling has shown a significant
portion of CPU time idling, since the batch ticker
endlessly demands resources. We resolve this by only
selecting on the batch ticker when we have a
non-empty batch of downstream packets from the
switch.
2018-07-30 21:44:49 -07:00
Conner Fromknecht
d76bacee0e
htlcswitch/link: send FailFinalExpiryTooSoon from exit hop
This commit corrects our exit hop logic to return
FailFinalExpiryTooSoon if the following check is true:
   pd.Timeout-expiryGraceDelta <= heightNow

Previously we returned FailFinalIncorrectCltvExpiry, which
should only be returned if the packet was misconstructed.
2018-07-27 15:52:09 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Olaoluwa Osuntokun
a32f2b79da
htlcswitch: modify the InvoiceDatabase interface to allow specifying final payment amt
In this commit, we modify the InvoiceDatabase slightly to allow the link
to record what the final payment about for an invoice was. It may be the
case that the invoice actually had no specified value, or that the payer
paid more than necessary. As a result, it's important that our on-disk
records properly reflect this.

To fix this issue, the SettleInvoice method now also accepts the final
amount paid.

Fixes #856.
2018-07-06 12:21:55 -07:00
Olaoluwa Osuntokun
0a045f8651
Merge pull request #1482 from cfromknecht/uniform-fee-update-timeout
htlcswitch/link: correct bias in fee update backoff
2018-07-03 22:27:22 -05:00
Olaoluwa Osuntokun
3ad15c5f42
hltcswitch: use a logClosure to delay spew evaluation until log print time 2018-06-30 17:15:04 -05:00
Conner Fromknecht
5fa8124aa1
htlcswitch/link: correct bias in fee update backoff
This commit corrects the distribution used to
schedule a link's randomized backoff for fee
updates. Currently, our algorithm biases the
lowest value in the range, with probability
equal to lower/upper, or the ratio of the lower
bound to the upper. This distribution is skewed
more heavily as lower approaches upper.

The solution is to sample a random value in the
range upper-lower, then add this to our lower
bound. The effect is a uniformly distributed
timeout in [lower, upper).
2018-06-30 10:22:38 -07:00
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