Commit graph

5989 commits

Author SHA1 Message Date
Wilmer Paulino
33b745f54e
Use correct to_remote script in counterparty commitments
While our commitment transactions did use the correct `to_remote`
script, the `ChannelMonitor`'s was not as it is tracked separately. This
would lead to users never receiving an `Event::SpendableOutputs` with a
`StaticPaymentOutput` descriptor to claim the funds.

Luckily, any users affected which had channel closures confirmed by a
counterparty commitment just need to replay the closing transaction to
receive the event.
2023-09-29 13:46:56 -07:00
Matt Corallo
6016101ac8
Merge pull request #2609 from wpaulino/monitor-get-spendable-output
Allow retrieval of SpendableOutputDescriptors from relevant transactions
2023-09-29 01:29:47 +00:00
Matt Corallo
db41b87d31
Merge pull request #2604 from TheBlueMatt/2023-09-route-overpay-limit
Try to overpay the recipient if we fail to find a path at all and limit overpay
2023-09-29 00:19:04 +00:00
Wilmer Paulino
ffec24b3e3
Retrieve all possible spendable outputs from transactions
Assuming our keys haven't been compromised, and that random transactions
aren't learning of these scripts somehow and sending funds to them, it
was only possible for one spendable output to exist within a
transaction.

- `shutdown_script` can only exist in co-op close transactions.
- `counterparty_payment_script` can only exist in counterparty
  commitment transactions.
- `broadcasted_holder_revokable_script` can only exist in holder
  commitment/HTLC transactions.
- `destination_script` can exist in any other type of claim we support.

Now that we're exposing this API to users such that they can rescan any
relevant transactions, there's no harm in allowing them to claim more
funds from spendable outputs than we expected.
2023-09-28 14:25:30 -07:00
Wilmer Paulino
b8f80f8ab9
Allow retrieval of SpendableOutputDescriptors from relevant transactions
Currently, our API will only expose `SpendableOutputDescriptor`s once
after they are no longer under reorg risk (see `ANTI_REORG_DELAY`).
Users have often requested they'd like the ability to retrieve these in
some other way, either for historical purposes, or to handle replaying
any in the event of a failure.
2023-09-28 14:23:33 -07:00
Matt Corallo
fa48df6049 Log max routing fee before we start pathfinding
This may be useful in debugging routing failures in the future.
2023-09-28 20:39:36 +00:00
Matt Corallo
8effd86c21 Include any recipient overpayment amounts in the route fee limit
If the user told us to limit their total fee exposure, we should
do so including any potential overpayment to the recipient, which
is ultimately a part of the "fee" as far as the user is concerned.
2023-09-28 20:39:36 +00:00
Matt Corallo
f3e33f4074 Try to overpay the recipient if we fail to find a path at all
Previously we'd only try to overpay if we managed to find a path
to the recipient which was sufficient. However, if we fail to find
any path to the recipient at all we should still retry overpaying
the recipient. Ultimately we should be silling to pay whatever
reasonable performance penalty if the alternative is not finding a
path at all, which we do here.
2023-09-28 20:39:36 +00:00
Matt Corallo
5861dde692 Allow routefinding again due to HTLC limit based on >= not >
While this doesn't matter much in practice, if we go around again
when route-finding to try to meet an htlc_minimum_msat, we use the
`recommended_value_msat` which can work if we meet the
`htlc_minimum_msat` on a channel exactly, so using >= rather than >
can capture cases with 1msat more.
2023-09-28 20:39:36 +00:00
Matt Corallo
082a19b2d4
Merge pull request #2612 from TheBlueMatt/2023-09-namespace-split
Refer to top-level persistence namespaces as primary_namespace
2023-09-28 20:37:54 +00:00
Matt Corallo
1e6707dd9f
Merge pull request #2575 from tnull/2023-09-fix-debug-panic
Various router fixes and #2417 follow-ups
2023-09-28 20:30:29 +00:00
Matt Corallo
4ab6c551a0
Merge pull request #2611 from TheBlueMatt/2023-09-no-close-on-bad-update
Don't FC when a `channel_update` has a bogus `htlc_minimum_msat`
2023-09-28 19:06:24 +00:00
Matt Corallo
47e1148283 Update remaining references to primary/secondary namespaces
Update various variables, error strings, and the pending changelog
entry to refer to new namespace terminology.
2023-09-28 18:35:38 +00:00
Matt Corallo
1cb810358d Update storage constants to new PRIMARY/SECONDARY namespace terms 2023-09-28 18:35:38 +00:00
Matt Corallo
6765889423 Rename the persistence sub_namespace to secondary_namespace
With the top-level namespace now called "primary", "secondary"
makes more sense than "sub".
2023-09-28 18:35:38 +00:00
Elias Rohrer
be1088ac08
Don't retry overpaid values for PartialFailures
Previously, if an overpaid path would fail immediately, we'd retry a
`PartialFailure` with the full path amount, _including_ any overpayment.

Here, we now subtract the succeeded paths' values from the
net. value to exclude the overpaid amounts on retry.
2023-09-28 19:45:31 +02:00
Elias Rohrer
8c99e34b93
Assert query's and route's final_value_msat are equal 2023-09-28 19:45:31 +02:00
Elias Rohrer
fb2c959b40
Refactor mpp_retry[_overpay] tests to use SendEvent::from_event
.. as a follow-up from #2417.
2023-09-28 19:45:30 +02:00
Elias Rohrer
39c5bbc0bb
Make ignored candidate counts u32
.. as a follow-up from #2417.
2023-09-28 19:45:30 +02:00
Elias Rohrer
c480b0c857
Avoid adding duplicate hint candidates if they are first hops
If we have a direct channel to a node generating an invoice with route
hints, we'd previously happily add multiple candidates that all refer to
the same channel. To keep our candidate set small and unify our tracking
where possible, we now check if its `short_channel_id` is an
`outbound_scid_alias` of any of our first hops and refrain from adding
another candidate if it's the case.
2023-09-28 19:45:30 +02:00
Elias Rohrer
7a6d3097a6
Also add route hints if we are the source
Previously, we would only consider route hints if we had a direct
channel to the first node in the hint or if the first node in the hint
was part of the public network graph.

However, this left out the possiblity of us being part of the first hop,
especially if our own node is not announced and part of the graph.
2023-09-28 19:45:29 +02:00
Matt Corallo
3141630f78
Merge pull request #2607 from DhananjayPurohit/civkit-branch
Issue in adding rust lightning as dependency on windows
2023-09-28 16:54:44 +00:00
Matt Corallo
336d815dd6
Merge pull request #2606 from wpaulino/anchors-counterparty-htlc-claim-sequence
Use correct input sequence for HTLC claims from counterparty commitments
2023-09-28 16:32:18 +00:00
Matt Corallo
d66d38e5fb Log full channel_update messages received for our channels 2023-09-28 16:30:02 +00:00
Elias Rohrer
a8eef297fc
Extend logging of ignored candidates 2023-09-28 10:14:35 +02:00
Elias Rohrer
391da3f3b2
Use saturating_add when adding inflight HTLCs values
Previously this calculation could overflow, leading to panicking in `debug`.
2023-09-28 10:14:35 +02:00
DhananjayPurohit
cf0cef81b3 chore: remove time_utils.rs
No longer needed time_utils in lightning-invoice
2023-09-28 13:29:48 +05:30
Matt Corallo
18ef80f78a Refer to top-level persistence namespaces as primary_namespace
This fixes a bindings build error as `namespace` is a C++ keyword
which cannot be used as an argument, and while this could be fixed
in the bindings rather than here, separating the term `namespace`
between the concept (which refers to the primary and sub
namespaces) and the primary namespace makes the documentation more
readable.
2023-09-28 02:41:51 +00:00
Matt Corallo
910a00e3d0 Use Result<_, io::Error> over io::Result<_>
Personally I've always found the overload of a prelude enum to be
confusing, and never bothered to handle it properly in bindings as
a result. To avoid needing to do so now, we simply move the
newly-introduced `io::Result` usages over to
`Result<_, io::Error>`.
2023-09-28 02:41:51 +00:00
Matt Corallo
9123d6d41b Don't FC when a channel_update has a bogus htlc_minimum_msat
If a peer sends us a `channel_update` for our own channel with an
`htlc_minimum_msat` which is more than the channel's amount, that's
dumb, but there's no reason to force-close the channel. We don't
even use the field.

Here we simply drop the unnecessary check.
2023-09-28 00:47:43 +00:00
Matt Corallo
7b4fb9da88
Merge pull request #2570 from valentinewallace/2023-08-router-fuzz-fail
Fix router fuzz failure
2023-09-27 20:40:32 +00:00
Wilmer Paulino
3c83783800
Use correct input sequence for HTLC claims from counterparty commitments
HTLC outputs, like the `to_remote` output, in commitment transactions
with anchor outputs also have an additional `1 CSV` constraint on the
counterparty. When spending such outputs, their corresponding input
needs to have their sequence set to 1. This was done for HTLC claims
from holder commitments, but unfortunately not for counterparty
commitments as we were lacking test coverage.
2023-09-27 11:49:57 -07:00
Valentine Wallace
f3857d0f53
get_route: fix path value contribution to include min htlc overpay
Previously, the fuzzer hit a debug panic because we wouldn't include the amount
overpaid to meet a last hop's min_htlc in the total collected paths value. We
now include this value and also penalize hops along the overpaying path to
ensure that it gets deprioritized in path selection.
2023-09-27 13:19:51 -04:00
Valentine Wallace
ea38b938bb
get_route: fix path_min for first_hop<>network_node candidates
Previously, we would add a first_hop<>network_node channel that did not have
enough contribution amount to cover the next channel's min htlc plus fees,
because we were storing the next hop as having a path_min that did not include
fees, and would add a connecting first_hop node that did not have enough
contribution amount, leading to a debug panic upon invalid path construction.
2023-09-27 13:19:51 -04:00
Valentine Wallace
d83295ff5c
get_route: fix path_min for first_hop<>blinded_hint candidates
See previous commit, but the bug where we would underestimate how much a first
hop candidate needed to be able to relay was also present in blinded paths.
2023-09-27 13:19:51 -04:00
Valentine Wallace
2aacbae67a
get_route: fix path_min when adding first_hop<>route_hint candidates
Previously, we would add a candidate hop to the list of potential hops even
though its available contribution wasn't sufficient to meet the next hop's
min_htlc. We'd subsequently build an invalid path using this hop and hit a
debug assertion.
2023-09-27 13:19:51 -04:00
Valentine Wallace
5263b07b55
get_route: fix outdated var name
Previously this variable was a bool, but has since been updated to be an
Option, so rename accordingly.
2023-09-27 13:19:51 -04:00
Valentine Wallace
29c67d5246
Pathfinding: ignore blinded route hints where we are the intro node
See tests, but the fuzzer found several panics from not fully ignoring these
hints.

We should support these route hints eventually, but it will involve some
reworking of the Path/BlindedTail structs.
2023-09-27 13:19:49 -04:00
Valentine Wallace
b16d6a1e11
Remove trailing whitespace in get_route
Because my text editor loves to do that.
2023-09-27 09:37:21 -04:00
Valentine Wallace
7632cfe517
Refuse to pathfind when provided our_node_id matches internal dummy pk
The fuzzer managed to hit this and it causes some invalid paths to be generated
internally.
2023-09-27 09:37:21 -04:00
Valentine Wallace
6cfb052d98
Pathfinding: log when we ignore one hop blinded route hints 2023-09-27 09:37:21 -04:00
Matt Corallo
0f87ee8883
Merge pull request #2601 from TheBlueMatt/2023-09-117-alpha2
Bump versions to 0.0.117-alpha2/invoice 0.25.0-alpha2
2023-09-27 03:51:12 +00:00
Matt Corallo
c8e1916b77
Merge pull request #2603 from TheBlueMatt/2023-09-default-route-limit
Set a default max_total_routing_fee_msat of 1% + 50sats
2023-09-27 03:47:16 +00:00
Matt Corallo
7d5f137946
Merge pull request #2602 from TheBlueMatt/2023-09-descriptor-hash
Derive `Hash` for `SpendableOutputDescriptor`
2023-09-27 03:47:09 +00:00
Matt Corallo
bf9144039c
Merge pull request #2359 from domZippilli/2023-06-monitor-updating-persister
Monitor updating persister
2023-09-27 03:46:39 +00:00
Dom Zippilli
0430d3379a Add MonitorUpdatingPersister
MonitorUpdatingPersister is an implementation of Persister that stores
ChannelMonitorUpdates separately from ChannelMonitors. Its RFC is
in #2545, at https://github.com/orgs/lightningdevkit/discussions/2545.

Co-Authored-By: Elias Rohrer <dev@tnull.de>
2023-09-26 16:30:07 -07:00
Matt Corallo
3e1e393f61
Merge pull request #2486 from wvanlint/batch_channel_opens
Batch funding for v1 channel establishments
2023-09-26 22:54:12 +00:00
Matt Corallo
0c31c6f162 Set a default max_total_routing_fee_msat of 1% + 50sats
When using the normal default constructors, we should have some
fee maximum to ensure our default behavior is safe. Here we pick
1% + 50 sats to ensure we're always willing to pay
reasonabl(y high) fees, but not anything too wild.
2023-09-26 22:03:59 +00:00
Matt Corallo
793a1bf679 Derive Debug and Display for Route 2023-09-26 21:59:48 +00:00
Matt Corallo
8a42d55508 Derive Hash for SpendableOutputDescriptor
This allows for easy descriptor de-duplication before building a
claiming transaction.
2023-09-26 20:41:49 +00:00