Commit Graph

1081 Commits

Author SHA1 Message Date
Keagan McClelland
1422729f80
lnwallet+htlcswitch: define expanded NumPendingUpdates
This commit squashes the below operations for a net result where
we have an expanded capability of assessing pending updates. This
is made possible by packing the components into Duals in the prior
commits. We squash the operations to simplify review.

htlcswitch+lnwallet: rename PendingLocalUpdateCount

lnwallet: complete pending update queries API for LightningChannel

lnwallet+htlcswitch: consolidate NumPendingUpdates using ChannelParty

This commit makes the observation that we can cleanly define the
NumPendingUpdates function using a single expression by taking
advantage of the relevant fields being properly packed into Duals.
2024-08-28 14:03:00 -07:00
Keagan McClelland
a0515a16db
htlcswitch: extract error handling for syncChanStates 2024-08-28 13:46:52 -07:00
Eugene Siegel
99b86ba462
multi: extend lnpeer.Peer interface with Disconnect function
This will be used in the gossiper to disconnect from peers if their
ban score passes the ban threshold.
2024-08-27 14:11:06 -04:00
ffranr
1297e8f7c7
htlcswitch: add missing method doc 2024-08-22 18:33:24 +02:00
ffranr
7df093b3b1
multi: improve comment grammar 2024-08-22 18:33:24 +02:00
Oliver Gugger
e99e6662cf
multi: update linter, fix new issues 2024-08-20 19:14:44 +02:00
yyforyongyu
7aba5cbc0a
routing: fix linter complains 2024-08-07 22:19:23 +08:00
yyforyongyu
b998ce11f1
routing+htlcswitch: add new interface method HasAttemptResult 2024-08-07 22:18:51 +08:00
yyforyongyu
3b6e28d19b
channeldb+htlcswitch: make sure circuit is not nil in teardownCircuit 2024-08-07 22:17:59 +08:00
yyforyongyu
2fc79d8946
htlcswitch: handle forwarding settle and fail seperately
This commit adds two methods, `handlePacketFail` and
`handlePacketSettle` to handle the settle and fail packets differently.
2024-08-07 22:17:59 +08:00
yyforyongyu
6cb374aea6
htlcswitch: add new method handlePacketAdd
Simply moves the code into a new method so it's easier to follow the
method `handlePacketForward`.
2024-08-07 22:17:59 +08:00
yyforyongyu
21112cfdf8
htlcswitch: rename paymentID to attemptID for clarity 2024-08-07 22:17:58 +08:00
Oliver Gugger
11c7e20d0a
Merge pull request #8953 from ProofOfKeags/refactor/lnwallet-channel-channel-constraints-partition
[MICRO]: multi: break ChannelConstraints into two sub-structures
2024-08-05 02:08:52 -06:00
Olaoluwa Osuntokun
4a3c4e4ba7
Merge pull request #8497 from ziggie1984/shutdown-bugfix
routing: shutdown chanrouter correctly.
2024-08-01 16:48:50 -07:00
Keagan McClelland
e3a9d0acbe
multi: break ChannelConstraints into two sub-structures
This commit breaks the ChannelConstraints structure into two
sub-structures that reflect the fundamental differences in how
these parameters are used. On its face it may not seem necessary,
however the distinction introduced here is relevant for how we
will be implementing the Dynamic Commitments proposal.
2024-08-01 12:00:32 -07:00
Keagan McClelland
dc03637ae3
htlcswitch: rename for test parameters for accuracy 2024-08-01 11:56:50 -07:00
Keagan McClelland
f54c9ea8f7
htlcswitch: replace errors package implementation 2024-07-31 17:54:21 -07:00
Keagan McClelland
1f9cac5f80
htlcswitch: refactor dust handling to use ChannelParty 2024-07-31 14:50:27 -07:00
Keagan McClelland
0996e4f163
multi: refactor lnwallet/channel.go to use ChannelParty in select places
We also include changes to contractcourt, htlcswitch and peer to stitch the
boundaries together.
2024-07-31 14:50:26 -07:00
ziggie
02c1264c53
multi: prevent nil panics in stop methods.
With this PR we might call the stop method even when the start
method of a subsystem did not successfully finish therefore we
need to make sure we guard the stop methods for potential panics
if some variables are not initialized in the contructors of the
subsystems.
2024-07-31 14:43:34 +02:00
ziggie
08b68bbaf7
multi: Add atomic start/stop functions.
Make sure that each subsystem only starts and stop once. This makes
sure we don't close e.g. quit channels twice.
2024-07-31 13:12:19 +02:00
Oliver Gugger
ac4ef28926
Merge pull request #8824 from Crypt-iQ/precise_dust_limit
multi: include commitment fees in dust calculation
2024-07-31 03:13:31 -06:00
Eugene Siegel
d6001d033b
htlcswitch+lnwallet: calculate fee exposure as commit fees + dust
This commit expands the definition of the dust limit to take into
account commitment fees as well as dust HTLCs. The dust limit is now
known as a fee exposure threshold. Dust HTLCs are fees anyways so it
makes sense to account for commitment fees as well. The link has
been modified slightly to calculate dust. In the future, the switch
dust calculations can be removed.
2024-07-29 14:13:21 -04:00
Elle Mouton
65aef6a69c
htlcswitch: handle blinded path dummy hops
If a blinded path payload contains a signal that the following hop on
the path is a dummy hop, then we iteratively peel the dummy hops until
the final payload is reached.
2024-07-26 09:54:18 +02:00
Elle Mouton
b0d3e4dc0d
multi: extract path ID and total amt from received payment
We've covered all the logic for building a blinded path to ourselves and
putting that into an invoice - so now we start preparing to actually be
able to recognise the incoming payment as one from a blinded path we
created.

The incoming update_add_htlc will have an `encrypted_recipient_data`
blob for us that we would have put in the original invoice. From this we
extract the PathID which we wrote. We consider this the payment address
and we use this to derive the associated invoice location.

Blinded path payments will not include MPP records, so the payment
address and total payment amount must be gleaned from the pathID and new
totalAmtMsat onion field respectively.

This commit only covers the final hop payload of a hop in a blinded
path. Dummy hops will be handled in the following commit.
2024-07-26 09:54:18 +02:00
Elle Mouton
3d9c77d1fc
htlcswitch+refactor: add rHash and sphinx.Router to sphinxHopIterator
This will be required to construct a new hop iterator for when peeling
of dummy hops is done for route blinding.
2024-07-26 09:54:18 +02:00
Elle Mouton
c1c2e1c6ce
htlcswitch+refactor: continue modularising extractTLVPayload
We further break up the extracTLVPayload into more modular pieces. The
pieces are structured in such a way as to prepare for extracTLVPayload
being called in a recursive manner from within
`deriveBlindedRouteForwardingInfo` when we add the logic for handling
dummy hops in a later commit. With this refactor, we completey remove
the BlindingKit's DecryptAndValidateFwdInfo method.
2024-07-26 09:54:18 +02:00
Elle Mouton
55c25f427f
htlcswitch+refactor: continue modularising extractTLVPayload
In this refactor commit, we extract all the steps from extractTLVPayload
that have to do with parsing the payload from the sender and verifying
the presence of various fields from the sender.
2024-07-26 09:54:18 +02:00
Elle Mouton
a15e4bb55f
refactor+htlcswitch: method for TLV payload parsing logic
In preparation for calling the TLV payload parsing logic recursively for
when we need to peel dummy hops from an onion, this commit creates a new
extractTLVPayload function. This is a pure refactor.
2024-07-26 09:54:18 +02:00
Elle Mouton
4457ca2e66
record: stricter type for PaymentRelayInfo.BaseFee
In this commit, we update the PaymentRelayInfo struct's BaseFee member
to use a stricter type (lnwire.MilliSatoshi) instead of an ambigious
uint32.
2024-07-26 09:53:49 +02:00
Elle Mouton
4f5dd20f7e
go.mod: update lightning-onion dep 2024-07-26 09:53:48 +02:00
yyforyongyu
d992cf94d6
multi: add SpewLogClosure to avoid code repetition 2024-07-25 22:18:49 +08:00
yyforyongyu
b6049ff94b
multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
2024-07-25 21:25:23 +08:00
yyforyongyu
2608c0893e
multi: make sure missionControlStore catches done signal
This commit makes sure `missionControlStore` catches the shutdown signal
when draining the ticker. A few debug logs are added to aid the process.
2024-07-23 21:30:08 +08:00
Elle Mouton
ad0905f10e
record+htlcswitch: convert BlindedRouteData fields to optional
For the final hop in a blinded route, the SCID and RelayInfo fields will
_not_ be set. So these fields need to be converted to optional records.

The existing BlindedRouteData constructor is also renamed to
`NewNonFinalBlindedRouteData` in preparation for a
`NewFinalBlindedRouteData` constructor which will be used to construct
the blinded data for the final hop which will contain a much smaller set
of data. The SCID and RelayInfo parameters of the constructor are left
as non-pointers in order to force the caller to set them in the case
that the constructor is called for non-final nodes. The other option
would be to create a single constructor where all parameters are
optional but I think this makes it easier for the caller to make a
mistake.
2024-07-10 09:12:39 +02:00
yyforyongyu
8da68bb7db
multi: apply the new type lntypes.WeightUnit 2024-05-25 13:37:13 +08:00
Tom Kirkpatrick
3837c3f12e
lnwallet: add configurable cache for web fee estimator
Add fee.min-update-timeout and fee.max-update-timeout config options to
allow configuration of the web fee estimator cache.
2024-05-04 14:41:41 +08:00
Carla Kirk-Cohen
43687181f7
htlcswitch: convert blinded failures for blinded payments 2024-04-25 09:47:13 -04:00
Carla Kirk-Cohen
de9c9c028c
htlcswitch: set packet obfuscator for failures through switch
Set obfuscator for use in blinded error handling when we forward
failures through the switch.
2024-04-25 09:47:12 -04:00
Carla Kirk-Cohen
72260adddb
htlcswitch: create error obfuscator with wrapped type for blinded
Create our error encrypter with a wrapped type if we have a blinding
point present. Doing this in the iterator allows us to track this
information when we have both pieces of information available to us,
compared to trying to handle this later down the line:
- Downstream link on failure: we know that we've set a blinding point
  for out outgoing HTLC, but not whether we're introduction or not
- Upstream link on failure: once the failure packet has been sent
  through the switch, we no longer know whether we were the introduction
  point (without looking it up / examining our payload again /
  propagating this information through the switch).
2024-04-25 09:47:11 -04:00
Carla Kirk-Cohen
9f038c6191
htlcswitch: introduce wrapper type error encrypter to identify blinded
Introduce two wrapper types for our existing SphinxErrorEncrypter
that are used to represent error encrypters where we're a part of a
blinded route. These encrypters are functionally the same as a sphinx
encrypter, and are just used as "markers" so that we know that we
need to handle our error differently due to our different role.

We need to persist this information to account for restart cases where
we've resovled the outgoing HTLC, then restart and need to handle the
error for the incoming link. Specifically, this is relevant for:
- On chain resolution messages received after restart
- Forwarding packages that are re-forwarded after restart

This is also generally helpful, because we can store this information
in one place (the circuit) rather than trying to reconstruct it in
various places when forwarding the failure back over the switch.
2024-04-25 09:47:10 -04:00
Carla Kirk-Cohen
776c889267
multi: return route role from HopPayload
We need to know what role we're playing to be able to handle errors
correctly, but the information that we need for this is held by our
iterator:
- Whether we had a blinding point in update add (blinding kit)
- Whether we had a blinding point in payload

As we're now going to use the route role return value even when our
err!=nil, we rename the error to signal that we're using less
canonical golang here.

An alternative to this approach is to attach a RouteRole to our
ErrInvalidPayload. The downside of that approach is:
- Propagate context through parsing (whether we had updateAddHtlc)
- Clumsy handling for errors that are not of type ErrInvalidPayload
2024-04-25 09:46:31 -04:00
Carla Kirk-Cohen
b81a6f3d2f
htlcswitch: split parsing and validation of TLV payloads
When handling blinded errors, we need to know whether there was a
blinding key in our payload when we successfully parsed our payload
but then found an invalid set of fields. The combination of
parsing and validation in NewPayloadFromReader means that we don't know
whether a blinding point was available to us by the time the error is
returned.

This commit splits parsing and validation into two functions so that
we can take a look at what we actually pulled of the payload in between
parsing and TLV validation.
2024-04-25 09:15:58 -04:00
Carla Kirk-Cohen
4d051b4170
multi: handle all blinding point validation in ValidateParsedPayloadTypes
This commit moves all our validation related to the presence of fields
into ValidateParsedPayloadTypes so that we can handle them in a single
place. We draw the distinction between:
- Validation of the payload (and the context within it's being parsed,
  final hop / blinded hop etc)
- Processing and validation of encrypted data, where we perform
  additional cryptographic operations and validate that the fields
  contained in the blob are valid.

This helps draw the line more clearly between the two validation types,
rather than splitting some payload-releated blinded hop processing
into the encrypted data processing part. The downside of this approach
(vs doing the blinded path payload check _after_ payload validation)
is that we have to pass additional context into payload validation
(ie, whether we got a blinding point in our UpdateAddHtlc - as we
already do for isFinalHop).
2024-04-25 09:15:57 -04:00
Carla Kirk-Cohen
c2c0158c84
htlcswitch: handle malformed HTLC with invalid onion blinding code
This commit adds handling for malformed HTLC errors related to blinded
paths. We expect to receive these errors _within_ a blinded path,
because all non-introduction nodes are instructed to return malformed
errors for failures.

Note that we may actually switch back to a malformed error later on if
we too are a relaying node in the route, but we handle that case the
incoming link.
2024-04-25 09:15:56 -04:00
erik
df4ddcc573 multi: replace ioutil.TempDir 2024-04-25 11:24:41 +02:00
yyforyongyu
6ff6c86155
multi: merge DetermineFeePerKw and Estimate
This commit moves `DetermineFeePerKw` into the `Estimate` method on
`FeePreference`. A few callsites previously calling `DetermineFeePerKw`
without the max fee rate is now also temporarily fixed by forcing them
to use `Estimate` with the default sweeper max fee rate.
2024-04-19 21:33:21 +08:00
Carla Kirk-Cohen
7e4f3d3b1d
htlcswitch: reject HTLCs that use use as introduction if disabled
Reject any HTLCs that use us as an introduction point in a blinded
route if we have disabled route blinding. We have to do this after
we've processed the payload, because we only know we're an introduction
point once we've processed the payload itself.
2024-04-03 09:19:39 -04:00
Carla Kirk-Cohen
6d41037628
htlcswitch: set forwarding information from encrypted data
If we received a payload with a encrypted data point set, our forwarding
information should be set from the information in our encrypted blob.
This behavior is the same for introduction and relying nodes in a
blinded route.
2024-04-03 08:52:26 -04:00
Carla Kirk-Cohen
2029a06918
multi: return parsed types from payload
To separate blinded route parsing from payload parsing, we need to
return the parsed types map so that we can properly validate blinded
data payloads against what we saw in the onion.
2024-04-03 08:52:25 -04:00