Commit graph

5010 commits

Author SHA1 Message Date
Matt Corallo
928c9b806e Support reading the new payment_metadata field in invoices
This adds support for reading the new `PaymentMetadata` BOLT11
invoice field, giving us access to the `Vec<u8>` storing arbitrary
bytes we have to send to the recipient.
2023-04-19 02:57:19 +00:00
Matt Corallo
1b29a55e17 Unset the optional bit for a feature when setting the required bit
There is no reason to set both, and this currently makes testing
the new BOLT invoice tests slightly harder, so we just unset it.
2023-04-19 02:57:19 +00:00
Matt Corallo
35b597a4c2 Add features module-level documentation for missing features 2023-04-19 02:57:19 +00:00
Matt Corallo
6ce239cdb9 Define the PaymentMetadata feature to be used in invoices 2023-04-07 19:57:46 +00:00
Jeffrey Czyz
1ceb41e08b
Merge pull request #2023 from futurepaul/fallback-to-address
add `Fallback` getter that returns `Address`
2023-04-07 14:39:32 -05:00
Matt Corallo
f30dc859e7
Merge pull request #2170 from TheBlueMatt/2023-04-silent-merge-conflict
Fix silent merge conflict between new test and payment refactor
2023-04-07 18:27:33 +00:00
Wilmer Paulino
a5ecb85171
Merge pull request #2162 from jkczyz/2023-04-invoice-hash 2023-04-07 10:11:36 -07:00
Matt Corallo
8a743693ba Fix silent merge conflict between new test and payment refactor 2023-04-07 16:30:25 +00:00
Matt Corallo
568a20b832
Merge pull request #2148 from TheBlueMatt/2023-04-claim-from-closed
Allow claiming a payment if a channel with an HTLC has closed
2023-04-07 16:17:25 +00:00
Matt Corallo
1016e1f605
Merge pull request #2139 from TheBlueMatt/2023-03-metadata-prefactors
Add a new `RecipientOnionFields` and replace `PaymentSecret` with it
2023-04-07 16:14:30 +00:00
Matt Corallo
c8441d2f2d
Merge pull request #2165 from wpaulino/fix-bp-channel-pending-panic-flake
Use signal for handling ChannelPending in test_background_event_handling
2023-04-07 16:08:34 +00:00
Jeffrey Czyz
39befa16b4
Expose a BOLT 12 Invoice's signable_hash
This is useful as an identifier for downstream clients like VLS.
2023-04-06 23:15:31 -05:00
Jeffrey Czyz
821c79da98
Expose a BOLT 11 Invoice's signable_hash
Otherwise, an Invoice must first be converted to a SignedRawInvoice to
obtain the hash.
2023-04-06 23:15:25 -05:00
Jeffrey Czyz
854d650b5b
Linkify lightning-invoice docs 2023-04-06 23:13:05 -05:00
Wilmer Paulino
5037298361
Use signal for handling ChannelPending in test_background_event_handling
This fixes two potential panics within the test if the
`BackgroundProcessor` for `nodes[0]` consumed the `ChannelPending` event
prior to us consuming it manually in `end_open_channel`. The first panic
would happen within the event handler, since `ChannelPending` was not
being handled. The second panic would happen upon expecting the
`ChannelPending` event after handling `nodes[1]`'s `funding_signed` if
the `BackgroundProcessor` handled the event first. To ensure we still
reliably receive a `ChannelPending` event once possible, we let the
`BackgroundProcessor` consume the event and notify it.
2023-04-06 15:10:12 -07:00
Matt Corallo
5c6a39bd5b
Merge pull request #2163 from TheBlueMatt/2023-04-less-lock
Avoid holding a `per_peer_state` lock while claiming from a monitor
2023-04-06 21:53:49 +00:00
Matt Corallo
4a8d01dd19 Add a claim_deadline field to PaymentClaimable with guarantees
Now that we guarantee `claim_payment` will always succeed we have
to let the user know what the deadline is. We still fail payments
if they haven't been claimed in time, which we now expose in
`PaymentClaimable`.
2023-04-06 18:12:36 +00:00
Matt Corallo
b189df579f Avoid holding a per_peer_state lock while claiming from a monitor
There's no reason to hold a lock on `per_peer_state` while we're
claiming from a since-closed channel via a `ChannelMonitorUpdate`,
which we stop doing here.
2023-04-06 18:10:06 +00:00
Matt Corallo
ba1349982b
Merge pull request #2101 from TheBlueMatt/2023-03-one-less-sig
Support future removal of redundant per-HTLC signatures in `CMU`s
2023-04-06 18:07:55 +00:00
Paul Miller
cf0a90b8c0
Fallback: add Address getter and use bitcoin types 2023-04-06 10:49:14 -05:00
Matt Corallo
8fcbe64128
Merge pull request #2145 from TheBlueMatt/2023-04-async-bp-cleanups
Add test coverage of async BP and fix minor bug
2023-04-05 16:55:51 +00:00
Matt Corallo
77b1a22296 Correct documentation of payment_id in events 2023-04-05 16:32:10 +00:00
Matt Corallo
36235c38f1 Pipe the new RecipientOnionFields through send pipeline
This passes the new `RecipientOnionFields` through the internal
sending APIs, ensuring we have access to the full struct when we
go to construct the sending onion so that we can include any new
fields added there.
2023-04-05 16:28:14 +00:00
Matt Corallo
bf87a59e91 Add a RecipientOnionFields argument to spontaneous payment sends
While most lightning nodes don't (currently) support providing a
payment secret or payment metadata for spontaneous payments,
there's no specific technical reason why we shouldn't support
sending those fields to a recipient.

Further, when we eventually move to allowing custom TLV entries in
the recipient's onion TLV stream, we'll want to support it for
spontaneous payments as well.

Here we simply add the new `RecipientOnionFields` struct as an
argument to the spontaneous payment send methods. We don't yet
plumb it through the payment sending logic, which will come when we
plumb the new struct through the sending logic to replace the
existing payment secret arguments.
2023-04-05 16:28:14 +00:00
Matt Corallo
dddb2e28c1 Replace PaymentSecret with RecipientOnionFields in the pub API
This moves the public payment sending API from passing an explicit
`PaymentSecret` to a new `RecipientOnionFields` struct (which
currently only contains the `PaymentSecret`). This gives us
substantial additional flexibility as we look at add both
`PaymentMetadata`, a new (well, year-or-two-old) BOLT11 invoice
extension to provide additional data sent to the recipient.

In the future, we should also add the ability to add custom TLV
entries in the `RecipientOnionFields` struct.
2023-04-05 16:28:14 +00:00
Matt Corallo
2f798f6cc0 Remove the PaymentSecret field from HTLCSource::OutboundRoute
Many of the fields in `HTLCSource::OutboundRoute` are used to
rebuild the pending-outbound-payment map on reload if the
`ChannelManager` was not serialized though `ChannelMonitor`(s)
were after an HTLC was sent. As of 0.0.114, however, such payments
are not retryable without allowing them to fail and doing a full,
fresh, send.

Thus, some of the fields can be safely removed - we only really
care about having enough information to provide the user a failure
event, not being able to retry.

Here we drop one such field - the `payment_secret`, making our
`ChannelMonitorUpdate`s another handful of bytes smaller.
2023-04-05 16:28:14 +00:00
Matt Corallo
ab255895ee Allow claiming a payment if a channel with an HTLC has closed
Previously, LDK would refuse to claim a payment if a channel on
which the payment was received had been closed between when the
HTLC was received and when we went to claim it. This makes sense in
the payment case - why pay an on-chain fee to claim the HTLC when
presumably the sender may retry later. Long ago it also reduced
total code in the claim pipeline.

However, this doesn't make sense if you're trying to do an atomic
swap or some other protocol that requires atomicity with some other
action - if your money got claimed elsewhere you need to be able to
claim the HTLC in lightning no matter what. Further, this is an
over-optimization - there should be a very, very low likelihood
that a channel closes between when we receive the last HTLC for a
payment and the user goes to claim the payment. Since we now have
code to handle this anyway we should allow it.

Fixes #2017.
2023-04-04 23:08:46 +00:00
Matt Corallo
068d2c65cb Add an async version of BP's test_channel_manager_persist_error
This gives us coverage of an async BP returning an error.
2023-04-04 20:59:56 +00:00
Matt Corallo
2bc55b22d3 Make BP's not_pruning_network_graph_until... test dual async-sync 2023-04-04 20:59:56 +00:00
Matt Corallo
f0b928b06d Make BP's test_payment_path_scoring dual sync/async.
This finally gives us a bit of test coverage of the async BP, which
was embarrassingly missing until now.
2023-04-04 20:59:56 +00:00
Matt Corallo
ca367f5d08 Ensure background-processor exits after any sleep future says to
If the user's sleep future passed to an async background processor
only returns true for exiting once and then reverts back to false,
we should exit anyway when we get a chance to. We do to this here
by always ensuring we check the exit flag even when only polling
sleep futures with no intent to (yet) exit. This is utilized in the
tests added in the coming commit(s).
2023-04-04 20:59:56 +00:00
Matt Corallo
8676c5aa4e Don't immediately exit BP if ChannelManager is persistable
If `ChannelManager` is persistable before the async background
processor even starts, it may not even get around to overwriting
the `should_exit` flag before testing it, and the default value is
(incorrectly) true, causing an immediate unconditional exit.

The default value should simply be false.

Fixes #2140
2023-04-04 20:59:56 +00:00
Matt Corallo
fcf1282975 Make lightning-background-processor test failures more debugable
Instead of asserting a `Result` `is_ok`, we should always simply
`unwrap` to get a backgrace, and we should avoid doing so if the
thread is already panicking.
2023-04-04 20:59:56 +00:00
valentinewallace
bdb3fb3b6c
Merge pull request #2150 from TonyGiorgio/esplora-0.4
lightning-transaction-sync: Bump esplora to 0.4
2023-04-04 15:49:44 -04:00
Matt Corallo
825a9bcebc
Merge pull request #2147 from TheBlueMatt/2023-04-rgs-log-some
Add some trivial logging during RGS update processing.
2023-04-04 19:07:24 +00:00
Tony Giorgio
c3fac44303
lightning-transaction-sync: Bump esplora to 0.4 2023-04-04 12:28:15 -05:00
Matt Corallo
09f5e50ed2
Merge pull request #2005 from arik-so/2023-01-taproot-message-types
Update messages for Taproot types.
2023-04-04 16:38:04 +00:00
Matt Corallo
6897e5c604 Add some trivial logging during RGS update processing.
Rather than being totally silent, we need to at least note that we
are processing an RGS update when doing so in the logs, which we do
here.

Fixes #1981.
2023-04-04 16:37:35 +00:00
Arik Sosman
bc97b82de4
Add Taproot CI test. 2023-04-03 13:17:12 -07:00
Arik Sosman
15dbe55e67
Update the RevokeAndACK message for Taproot support. 2023-04-03 13:17:12 -07:00
Arik Sosman
fe25bbb44e
Update the CommitmentSigned message for Taproot support. 2023-04-03 13:17:12 -07:00
Arik Sosman
5c79c8e2b8
Update the FundingSigned message for Taproot support. 2023-04-03 13:17:12 -07:00
Arik Sosman
0219a8def0
Update the FundingCreated message for Taproot support. 2023-04-03 13:17:12 -07:00
Arik Sosman
64a800720e
Update the AcceptChannel message for Taproot support. 2023-04-03 13:17:12 -07:00
Arik Sosman
6080ce8004
Introduce MuSig2-related types for Taproot channels. 2023-04-03 13:17:08 -07:00
Matt Corallo
3b8bf93251
Merge pull request #2090 from TheBlueMatt/2023-03-mon-wake-bp
Wake background-processor on async monitor update completion
2023-04-03 20:12:46 +00:00
Matt Corallo
7ca3709727
Merge pull request #2098 from tnull/2023-03-add-channel-pending-event
Add `ChannelPending` event emitted upon `funding_signed`
2023-04-03 18:26:18 +00:00
Matt Corallo
34e176b1ad
Merge pull request #2143 from get10101/chore/convenient-confirm
Implement `chain::Confirm` without mandating any owned values
2023-04-03 17:58:54 +00:00
Elias Rohrer
9873c7dad8
Add ChannelPending event emitted upon funding_signed
Currently, users don't have good way of being notified when channel open
negotiations have succeeded and new channels are pending confirmation on
chain. To this end, we add a new `ChannelPending` event that is emitted
when send or receive a `funding_signed` message, i.e., at the last
moment before waiting for the confirmation period.

We track whether the event had previously been emitted in `Channel` and
remove it from `internal_funding_created` entirely. Hence, we now
only emit the event after ChannelMonitorUpdate completion, or upon
channel reestablish. This mitigates a race condition where where we
wouldn't persist the event *and* wouldn't regenerate it on restart,
therefore potentially losing it, if async CMU wouldn't complete before
ChannelManager persistence.
2023-04-03 19:04:32 +02:00
Matt Corallo
94a11f7791 Expose an option to substantially reduce sleep time in futures BP
Some users have suggested that waking every 100ms can be
CPU-intensive in deployments with hundreds or thousands of nodes
all running on the same machine. Thus, we add an option to the
futures-based `background-processor` to avoid waking every 100ms to
check for iOS having backgrounded our app and cut our TCP sockets.

This cuts the normal sleep time down from 100ms to 10s, for those
who turn it on.
2023-04-03 16:49:54 +00:00