Commit graph

3838 commits

Author SHA1 Message Date
Matt Corallo
620244dc2e
Merge pull request #2605 from wpaulino/anchors-monitor-track-to-remote-script
Use correct to_remote script in counterparty commitments
2023-09-29 22:06:58 +00:00
Jeffrey Czyz
92e5cb6805
Remove unused imports 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
5f58f8d127
Fix build warning for unused method 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
6bd962bc51
Remove an unnecessary enumerate 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
c7219e4683
Config-guard Event::InvoiceRequestFailed
The event cannot be generated publicly, so remove it for now to avoid
users needing to handle it.
2023-09-29 15:03:13 -07:00
Matt Corallo
d007d1b79f
Merge pull request #2628 from wvanlint/fix_multiple_shutdown_results
Fix handling multiple ShutdownResults
2023-09-29 21:25:51 +00:00
Wilmer Paulino
f464aa97c3
Expose witness_script for StaticPaymentOutputDescriptor 2023-09-29 14:22:04 -07:00
Wilmer Paulino
9f3bb7d7a5
Fix incorrect anchors counterparty_payment_script upon deserialization 2023-09-29 14:22:02 -07:00
Matt Corallo
b58f057345
Merge pull request #2622 from wpaulino/funding-and-commitment-tx-confirm-same-block
Avoid early return upon confirmation of channel funding
2023-09-29 21:06:55 +00:00
Matt Corallo
efbaa19a05
Merge pull request #2626 from TheBlueMatt/2023-09-revert-2476
Revert "Remove AvailableBalances::balance_msat"
2023-09-29 21:06:41 +00:00
Wilmer Paulino
3299d88595
Fix off-by-one max witness estimate for P2WPKH StaticPaymentDescriptor
We were not accounting for the extra byte denoting the number of items
in the witness stack.
2023-09-29 13:46:59 -07:00
Wilmer Paulino
fa2a2efef4
Support signing to_remote anchors variant for StaticPaymentOutput
`to_remote` outputs on commitment transactions with anchor outputs have
an additional `1 CSV` constraint on its spending condition,
transitioning away from the previous P2WPKH script to a P2WSH.

Since our `ChannelMonitor` was never updated to track the proper
`to_remote` script on anchor outputs channels, we also missed updating
our signer to handle the new script changes.
2023-09-29 13:46:59 -07:00
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
955e81086f
Merge pull request #2624 from wpaulino/2609-follow-up
Address 2609 follow-up comments
2023-09-29 20:07:16 +00:00
Willem Van Lint
db79ed07f4 Fix handling multiple ShutdownResults 2023-09-29 12:06:36 -07:00
Matt Corallo
fbc86cb564
Merge pull request #2623 from wpaulino/htlc-claim-receive-preimage-after-close
Claim HTLCs with preimage from currently confirmed commitment
2023-09-29 18:53:44 +00:00
Wilmer Paulino
92fcdd39e1
Avoid early return upon confirmation of channel funding
This early return is only possible if the channel requires a single
confirmation, allowing a `channel_ready` message to go out. This can be
problematic though if a commitment transaction (specifically from the
counterparty, as the channel would be immediately closed if a local
commitment is broadcast) also confirms within the same block. The
`ChannelMonitor` will detect both, but it won't inform the
`ChannelManager` at all. Luckily, while the channel still is considered
open to the `ChannelManager`, the `ChannelMonitor` will reject any
further updates to the channel state.
2023-09-29 11:46:25 -07:00
Matt Corallo
c7c4226e99 Revert "Remove AvailableBalances::balance_msat"
While removing the `balance_msat` field absolutely makes sense -
it is, at best, confusing - we really need a solid replacement for
it before we can do so. While one such replacement is in progress,
it is not complete and we'd like to not block our current release
on its completion.

This reverts commit ef5be580f5.
2023-09-29 18:32:25 +00:00
Wilmer Paulino
f267a30cc7
Only yield DelayedPaymentOutput descriptors once their delay expires
Otherwise, we could give users a descriptor ahead of time that will
result in an invalid transaction spend/broadcast.
2023-09-29 10:56:48 -07:00
Matt Corallo
5e871a7bfc
Merge pull request #2617 from wpaulino/no-persist-same-channel-update
Avoid persisting on same counterparty's ChannelUpdate
2023-09-29 17:39:49 +00:00
Elias Rohrer
a8fa5a1685
Merge pull request #2591 from TheBlueMatt/2023-09-2562-followups
Doc and comment followups to #2562
2023-09-29 19:08:36 +02:00
Wilmer Paulino
6cf0351462
Note required levels of descendant transactions in get_spendable_outputs
Three levels of descendant transactions starting from the channel's
funding transaction should cover all potential spendable outputs.

The first level covers the commitment transaction.

The second level covers the to_self claims, to_remote claims,
second-stage HTLC claims and justice transactions.

The third levels covers the justice transactions on second-stage HTLCs,
and to_self claims on second-stage HTLCs.
2023-09-29 10:01:21 -07:00
Wilmer Paulino
d82e6ba7a3
Test preimage claim after reorg of counterparty commitment
This test adds coverage for receiving a preimage after seeing a
counterparty commitment confirm, followed by a reorg and the
confirmation of a different commitment instead.

The first test covers the case where a holder commitment confirms after
the counterparty commitment reorg.

The second test covers the case where a previous counterparty commitment
confirms after the latest counterparty commitment reorg.
2023-09-29 09:58:38 -07:00
Wilmer Paulino
89fbbb3ce2
Claim HTLCs with preimage from currently confirmed commitment
We should always claim HTLCs from the currently confirmed commitment,
rather than always claiming from the latest or previous counterparty
commitment if we've seen either confirm onchain at a prior point.
2023-09-29 09:58:35 -07:00
Wilmer Paulino
c8c535412d
Avoid persisting on same counterparty's ChannelUpdate
Some nodes may rebroadcast their `ChannelUpdate` to their counterparty
on every connection establishment, which leads to us doing an additional
persist most of the time when nothing has changed. Now, we'll only
persist if we receive an update that changes anything.
2023-09-29 09:01:46 -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
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
34dd48c585 Add more details about async persistence completion/backgrounding
This clarifies somewhat that async persistence should run
indefinitely or keep trying via polling, and that either is
acceptable.
2023-09-28 20:45:55 +00: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
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
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