Commit Graph

112 Commits

Author SHA1 Message Date
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
nsa
7e84892c21
htlcswitch: account for channel reserve in Bandwidth 2018-02-08 18:35:23 -05:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
Olaoluwa Osuntokun
18741831dd
Merge pull request #485 from halseth/fix-negative-balance
Use remoteACKed index when calculating availableBalance.
2018-02-05 16:23:17 -08:00
Olaoluwa Osuntokun
30dbbd69a0
funding+htlcswitch: dynamically update short chan id of existing link
In this commit, we fix an existing bug that would result in some
payments getting “stuck”. This would happen if one side restarted
before the channel was fully locked in. In this case, since upon
re-connection, the link will get added to the switch with a *short
channel ID of zero*. If A then tries to make a multi-hop payment
through B, B will fail to forward the payment, as it’ll mistakenly
think that the payment originated from a local-subsystem as the channel
ID is zero. A short channel ID of zero is used to map local payments
back to their caller.

With fix this by allowing the funding manager to dynamically update the
short channel ID of a link after it discovers the short channel ID.

In this commit, we fix a second instance of reported “stuck” payments
by users.
2018-02-03 18:14:15 -08:00
Johan T. Halseth
9b7b3fa3b6
channellink: make BatchTicker and BatchSize configurable
This commit introduces a new Ticker interface, that can be used
to control when the batch timer should tick. This is done to be
able to more easily control the ticker during tests. The batch
timer is wrapped in the new BatchTicker struct, and made part
of the config together with BatchSize.
2018-02-02 21:16:36 -05:00
Wilmer Paulino
f0d6d31ca4
htlcswitch: allow sending htlcs when paying invoices with a zero amount 2018-01-27 19:05:23 -05:00
Olaoluwa Osuntokun
f8adab1f1c
test: add comprehensive integration tests for on-chain HTLC handling
In this commit, we add 6 new integration tests to test the various
actions that may need to be performed when either side goes on-chain to
fully resolve HTLC’s. Many of the tests are mirrors of each other as
they test sweeping/resolving HTLC’s from both commitment transactions.
2018-01-22 19:20:02 -08:00
Olaoluwa Osuntokun
96fbc7da84
htlcswitch: fix deadlock during chainWatcher notifications 2018-01-22 19:19:59 -08:00
Olaoluwa Osuntokun
239416f242
htlcswitch: update to use new event stream from the chainWatcher 2018-01-22 19:19:51 -08:00
Olaoluwa Osuntokun
703057c821
htlcswitch: with debughtlc+hodlhtlc mode, skip all HTLC level checks 2018-01-22 19:19:41 -08:00
Olaoluwa Osuntokun
dbe76a1507
htlcswitch: upon restart, examine all active HTLC's, settle those that we can
In this commit, we address a lingering TODO: before this if we had a
set of HTLC’s that we knew the pre-image to on our commitment
transaction after a restart, then we wouldn’t attempt to settle them.
With this new change, we’ll check that we didn’t already retransmit the
settles for them, and check the preimage cache to see if we already
know the preimage. If we do, then we’ll immediately settle them.
2018-01-22 19:19:40 -08:00
Olaoluwa Osuntokun
ca4eb970ec
htlcswitch: move channel re-sync into distinct function 2018-01-22 19:19:40 -08:00
Olaoluwa Osuntokun
2d133acaeb
htlcswitch: after each new state update, notify callers to set of new HTLC's 2018-01-22 19:19:39 -08:00
Olaoluwa Osuntokun
1418d672f9
htlcswitch: notify the ChainArbitrator of fresh signals upon link creation 2018-01-22 19:19:39 -08:00
Olaoluwa Osuntokun
f2642a70db
htlcswitch: once we discover a pre-image, add it to the witness cache
In this commit, we add some additional logic to the case when we
receive a pre-image from an upstream peer. We’ll immediately add it to
the witness cache, as an incoming HTLC might be waiting on-chain to
fully resolve the HTLC with knowledge of the newly discovered
pre-image.
2018-01-22 19:19:39 -08:00
Johan T. Halseth
9bdb483757
htlcswitch/link: make MinHTLC non-changable
This commit specifies that the MinHTLC value for a link is static
over the lifetime of a channel, and don't process the field
during a policyUpdate.
2018-01-12 22:56:29 +01:00
Olaoluwa Osuntokun
912366ada5
htlcswitch: fix notifier goroutine leak by cancelling epoch when htlcManager exits
Before this commit, if the htlcManager unexpectedly exited (due to a
protocol error, etc), the underlying block epoch notification intent
that was created for it would never be cancelled. This would result in
tens, or hundreds of goroutine leaks as the client would never consume
those notifications.

To fix this, we move cancellation of the block epoch intent from the
Stop() method of the channel link, to the defer statement at the top of
the htlcManager.
2018-01-08 19:50:24 -08:00
Olaoluwa Osuntokun
dbf6a511fc
htlcswitch: if we detect an InvalidCommitSigError, send over detailed error
In this commit, we add an additional case when handling a failed
commitment signature. If we detect that it’s a InvalidCommitSigError,
then we’ll send over an lnwire.Error message with the full details. We
don’t yet properly dispatch this error on the reciting side, but that
will be done in a follow up a commit.
2018-01-08 19:50:23 -08:00
Olaoluwa Osuntokun
e2fe4c2955
htlcswitch: reject duplicate payments to same invoice
In this commit, we modify the way the link handles HTLC’s that it
detects is destined for itself. Before this commit if a payment hash
came across for an invoice we’d already settled, then we’d gladly
accept the payment _again_. As we’d like to enforce the norm that an
invoice is NEVER to be used twice, this commit modifies that behavior
to instead reject an incoming payment that attempts to re-use an
invoice.

Fixes #560.
2018-01-04 14:23:37 -06:00
Jim Posen
88dc73adb0 htlcswitch: Fix failure error handling on outgoing adds. 2017-12-14 17:53:58 -08:00
Jim Posen
6ea533275c htlcswitch: Remove obsolete fields from htlcPacket. 2017-12-14 17:53:58 -08:00
Jim Posen
40fb0ddcfc htlcswitch: Assign each pending payment a unique ID.
This simplifies the pending payment handling code because it allows it
be handled in nearly the same way as forwarded HTLCs by treating an
empty channel ID as local dispatch.
2017-12-14 17:53:58 -08:00
Jim Posen
4a29fbdab2 htlcswitch: Rename htlcPacket fields for clarity.
The src/dest terminology for routing packets is kind of confusing
because the source HTLC may not be the source of the packet for
settles/fails traversing the circuit in the opposite direction. This
changes the nomenclature to incoming/outgoing and always references
the HTLCs themselves.
2017-12-14 17:53:58 -08:00
Jim Posen
317b44e220 lnwallet: Change channel update methods to accept HTLC ID.
Previously, some methods on a LightningChannel like SettleHTLC and
FailHTLC would identify HTLCs by payment hash. This would not always
work correctly if there are multiple HTLCs with the same payment hash,
so instead we change these methods to identify HTLCs by their unique
identifiers instead.
2017-12-14 17:53:58 -08:00
Jim Posen
1328e61c00 htlcswitch: Change circuit map keys to (channel ID, HTLC ID).
This changes the circuit map internals and API to reference circuits
by a primary key of (channel ID, HTLC ID) instead of paymnet
hash. This is because each circuit has a unique offered HTLC, but
there may be multiple circuits for a payment hash with different
source or destination channels.
2017-12-14 17:53:58 -08:00
Jim Posen
bc8d674958 htlcswitch: Remove constructor functions for htlcPacket.
The constructor functions have no additional logic other than passing
function parameters into struct fields. Given the large function
signatures, it is more clear to directly construct the htlcPacket in
client code than call a function with lots of positional arguments.
2017-12-14 17:53:58 -08:00
Olaoluwa Osuntokun
4cca23264d
htlcswitch: add new default case when handling UpdateFailMalformedHLTC
In this commit, we modify the existing logic to handle
UpdateFailMalformedHLTC message from an incoming peer. Rather than fail
the Chanel if they give us an invalid failure code, we’ll instead treat
it as a temporary channel failure so we can continue to forward the
error.
2017-12-12 11:42:47 -08:00
Olaoluwa Osuntokun
c3d345b575
htlcswitch: don't add UpdateFee to channel if not able to forward
This commit is a follow up to a prior commit which skipped sending the
commitment sig message (and sending out the update fee) message if the
channel wasn’t yet able to forward any HTLC’s. We’ll modify the prior
commit to not add the fee update to the channel at all. Otherwise, we
risk a state desynchronization.
2017-12-10 16:19:21 -08:00
Ben Congdon
720a8c7e96 htlcswitch: Only send UpdateFee message when channel is eligible
This commit adds a check to `updateChannelFee` which skipssending the
`update_fee` message when the channel is not eligable for forwarding
messages (likely due to the channel's `RemoteNextRevocation` not yet
being set).

This addresses #470.
2017-12-10 10:46:30 -08:00