Commit Graph

204 Commits

Author SHA1 Message Date
bb956e127e server+htlcswitch: check waiting-close fwdpkgs in reforwardResponses
Previously, the Switch would not check waiting-close channels' fwdpkgs
for settles or fails to reforward. This could result in a force close
in a rare edge case if a restart occurred at the wrong time. Now,
waiting-close fwdpkgs are checked and the issue is avoided.
2022-09-30 14:40:38 -04:00
0735522194 multi: fix make fmt 2022-08-23 22:10:24 +08:00
1e556aa189 multi: thread through the new max fee field for co-op close
In this commit, we parse the new max fee field, and pass it through the
switch, all the way to the peer where it's ultimately passed into the
chan closer state machine.
2022-07-26 17:23:16 -07:00
13c15e8038 server+htlcswitch: prevent privacy leaks, allow alias routing
This intent of this change is to prevent privacy leaks when routing
with aliases and also to allow routing when using an alias. The
aliases are our aliases.

Introduces are two maps:

* aliasToReal:
  This is an N->1 mapping for a channel. The keys are the set of
  aliases and the value is the confirmed, on-chain SCID.

* baseIndex:
  This is also an N->1 mapping for a channel. The keys are the set
  of aliases and the value is the "base" SCID (whatever is in the
  OpenChannel.ShortChannelID field). There is also a base->base
  mapping, so not all keys are aliases.

The above maps are populated when a link is added to the switch and
when the channel has confirmed on-chain. The maps are not removed
from if the link is removed, but this is fine since forwarding won't
occur.

* getLinkByMapping
  This function is introduced to adhere to the spec requirements that
  using the confirmed SCID of a private, scid-alias-feature-bit
  channel does not work. Lnd implements a stricter version of the spec
  and disallows this behavior if the feature-bit was negotiated, rather
  than just the channel type. The old, privacy-leak behavior is
  preserved.

The spec also requires that if we must fail back an HTLC, the
ChannelUpdate must use the SCID of whatever was in the onion, to avoid
a privacy leak. This is also done by passing in the relevant SCID to
the mailbox and link. Lnd will also cancel back on the "incoming" side
if the InterceptableSwitch was used or if the link failed to decrypt
the onion. In this case, we are cautious and replace the SCID if an
alias exists.
2022-07-07 17:10:28 -04:00
407184ac51 htlcswitch: add linkStopIndex to cleanly shutdown ChannelLink
With this, extra calls to RemoveLink will wait for the link to
fully stop. This is accomplished by a map that stores a single stop
channel that callers to RemoveLink will listen on. This map is not
consulted when the Switch is shutting down and calls Stop on each
individual link. Though that could be added in the future, it is
not necessary.
2022-06-30 15:02:57 -04:00
87a486f1f9 htlcswitch: remove synchronous link handoff, special-case keystone err
This allows Switch-initiated payments to be failed back if they don't
make it into a commitment. Prior to this commit, a Switch-initiated
HTLC could get "lost" meaning the circuit wouldn't get deleted except
if conditions were "right" and the network result store would never
be made aware of the HTLC's fate. Switch-initiated HTLC's are now
passed to the link's mailbox to ensure they can be failed back.

This change also special-cases the ErrDuplicateKeystone error from
OpenCircuits(...) so that callers of updateCommitTx() in the link
don't send an Error to the peer if they encounter the keystone error.
With the first async change, the keystone error should now always
be recoverable.
2022-05-11 13:49:37 -04:00
f7b3da4bb2 htlcswitch+lntest: modify Switch to persist resolution messages
Include unit tests for the Switch, and integration tests that
exercise the persistence logic.
2022-04-29 16:40:19 -04:00
7dfe4018ce multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
1ad6bbfbc2 multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
895a2e497b multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
ffee7d1bcf multi: fix newly detected linter issues 2022-02-10 11:02:02 +01:00
530a2059e5 multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
692ea25295 Merge pull request #5642 from guggero/in-memory-graph
In-memory graph cache for faster pathfinding
2021-10-04 11:20:23 +02:00
702b3a3258 multi: introduce config-level DustThreshold for defining threshold 2021-09-30 13:44:35 -04:00
3897baff0a htlcswitch: call evaluateDustThreshold in SendHTLC, handlePacketForward
This commit makes SendHTLC (we are the source) evaluate the dust
threshold of the outgoing channel against the default threshold of
500K satoshis. If the threshold is exceeded by adding this HTLC, we
fail backwards. It also makes handlePacketForward (we are forwarding)
evaluate the dust threshold of the incoming channel and the outgoing
channel and fails backwards if either channel's dust sum exceeds the
default threshold.
2021-09-30 13:44:34 -04:00
15d3f62d5e multi: use cache for source channels 2021-09-29 17:00:04 +02:00
11cf4216e4 multi: move all channelstate operations to ChannelStateDB 2021-09-29 17:00:03 +02:00
7bde1662e2 multi: move breach arbiter and utxo nursery into contractcourt package
In this commit, we take an initial step towards converting the existing
breach arbiter and utxo nursery logic into contract resolvers by moving
the files as is, into the `contractcourt` pacakge.

This commit is primarily move only, though we had to massage some
interfaces and config names along the way to make things compile and the
tests run properly.
2021-09-27 19:10:31 -07:00
995b9a711f trivial: typo fix 2021-09-23 13:24:15 +08:00
1274e31dfb htlcswitch: remove unused function in switch 2021-09-23 13:24:14 +08:00
22848df07a htlcswitch: fix docs on LookupCircuit 2021-09-23 13:24:14 +08:00
3204e2d74b multi: add shutdown logs in subservers
This commit adds a simple shutdown to every subserver to assist
debugging.
2021-09-15 19:52:03 +08:00
23a4fad4ac htlcswitch+peer: CreateAndAddLink in switch, add messageSwitch to peer
This commit allows the peer to be tested without relying on a raw
htlcswitch.Switch pointer. This is accomplished by using a messageSwitch
interface and adding the CreateAndAddLink method to the
htlcswitch.Switch.
2021-08-10 17:15:52 -04:00
e72468646c htlcswitch+peer: embed ChannelUpdateHandler in ChannelLink
GetLink, GetLinksByInterface now use ChannelUpdateHandler.
2021-08-10 17:15:52 -04:00
051cd8793a htlcswitch: introduce and embed packetHandler interface in ChannelLink
This will allow separating the now-private *htlcPacket methods from
the publicly-used ChannelLink interface methods.
2021-08-10 17:15:51 -04:00
db3819fcef Merge pull request #5236 from offerm/preimage-to-settleevent
feature: expose preimage in forward+settle event
2021-07-09 14:35:11 -07:00
2c4dbfa19f feature: expose preimage in forward+settle event
Until now, clients of SubscribeHTLCEvents didn't have access to the settled preimage. The API allows to intercept forward event and to be updated on forward events however the forward+settle event does not include the payment preimage. This pr changes allows it.
2021-06-15 22:01:24 +03:00
14c851c8fc kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
a9f19b100b router+switch: rename paymentID->attemptID
To distinguish the attempt's unique ID from the overall payment
identifier, we name it attemptID everywhere, and note that the
paymentHash argument won't be the actual payment hash for AMP payments.
2021-04-27 08:27:33 +02:00
1a35c0055b htlcswitch: log with format 2020-12-08 13:54:41 +01:00
4d645ef97f htlcswitch: add debug logs for fetching network result 2020-11-24 14:14:49 +01:00
2a358327f4 multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
2020-11-05 17:57:12 +01:00
49df2d6f8b lnrpc: expose forwarding channel for htlcs in ListChannels 2020-10-16 09:03:24 +02:00
90a59fe70f router: call CleanStore on startup 2020-10-06 10:46:04 +02:00
2236813c95 htlcswitch: randomize non-strict forwarding 2020-09-29 11:05:53 +02:00
85b53c357f htlcswitch: use kvdb.View for loading fwdpkgs
Not necessary to open a write tx.
2020-08-13 14:36:48 +02:00
1a6701122c htlcswitch: change ForwardPackets to return error
As part of the preparation to the switch interceptor feature, this
function is changed  to return error instead of error channel that
is closed automatically.
Returning an error channel has become complex to maintain and
implement when adding more asynchronous flows to the switch.
The change doesn't affect the current behavior which logs the
errors as before.
2020-06-18 12:48:21 +03:00
8119dc7a88 htlcswitch: rename to getLocalLink
Align function name with the contained logic.
2020-05-20 08:03:52 +02:00
e00840e2ab htlcswitch: return local add failure to caller
Fixes a pre-existing issue where nil was returned when a failure had
occurred during commiting of the circuit.
2020-05-20 08:03:50 +02:00
c325bf8c57 htlcswitch: sync link hand-off
This commit extends the link with a new synchronous delivery point for
local UpdateAddHTLC messages. The switch method SendHTLC is updated to
use this delivery point and thereby becomes a synchronous call.

For MPP payments, synchronous hand-off is important. Otherwise the next
pathfinding round could start without the channel balance updated yet.
2020-05-20 08:03:48 +02:00
7afb43a012 htlcswitch: bypass main loop for local sends
There is no concurrent access in this code path, so there is no need to
pass the call through the main event loop.
2020-05-20 08:03:40 +02:00
fe35d35458 htlcswitch: simplify local sends
Embed forward method into SendHTLC and remove redundant type check.
2020-05-20 08:03:38 +02:00
341308327e htlcswitch: refactor handleLocalDispatch
Move creation of the goroutine as a preparation for sync local routing
2020-05-13 17:47:19 +02:00
704ce02712 Merge pull request #3018 from cryptagoras/log-htlcsuccess
htlcswitch/switch: log successfully forwarded HTLCs
2020-05-11 17:55:45 -07:00
0f734b769e htlcswitch/switch: log successfully forwarded HTLCs 2020-05-10 01:52:36 +03:00
556e3525ea misc: fix error formatting in multiple files 2020-04-24 19:15:08 +02:00
37dca27a3d htlcswitch: thread clock from switch to mailbox 2020-04-14 10:49:26 -07:00
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
12bbf28e65 htlcswitch: make handleBatchFwdErrors a pure function 2020-04-14 10:48:23 -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