Commit graph

3090 commits

Author SHA1 Message Date
valentinewallace
186cd047f8
Merge pull request #2158 from TheBlueMatt/2023-04-handle_err_more-check
Test for extra locks held in `handle_error` unconditionally
2023-04-07 16:19:27 -04:00
Matt Corallo
6ce239cdb9 Define the PaymentMetadata feature to be used in invoices 2023-04-07 19:57:46 +00:00
Alec Chen
432f0e678e Create PaymentFailureReason enum 2023-04-07 13:45:11 -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
9e6e20ff61 Split up comically long error return 2023-04-07 04:54:07 +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
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
Matt Corallo
2e39e08c05 Test for extra locks held in handle_error unconditionally
`handle_error` must be called without `per_peer_state` mutex or
`pending_events` mutex locks held or we may risk deadlocks.
Previously we checked this in debug builds in the error path, but
not in the success path.

As it turns out, `funding_transaction_generated`'s error path does
hold a `per_peer_state` lock, which we fix here as well as move the
tests to happen unconditionally.
2023-04-06 03:25:16 +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
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
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
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
6890e43342 Wake the background processor if an async monitor update completes
If the `ChainMonitor` gets an async monitor update completion, this
means the `ChannelManager` needs to be polled for event processing.
Here we wake it using the new multi-`Future`-await `Sleeper`, or
the existing `select` block in the async BP.

Fixes #2052.
2023-04-03 16:49:54 +00:00
Matt Corallo
3acf7e2c9d Drop the dummy no-std Condvar which never sleeps
In `no-std`, we exposed `wait` functions which rely on a dummy
`Condvar` which never actually sleeps. This is somwhat nonsensical,
not to mention confusing to users. Instead, we simply remove the
`wait` methods in `no-std` builds.
2023-04-03 16:49:54 +00:00
Matt Corallo
efcb5e02dc Move the pub wait methods from ChannelManager to Future
Rather than having three ways to await a `ChannelManager` being
persistable, this moves to just exposing the awaitable `Future` and
having sleep functions on that.
2023-04-03 16:49:54 +00:00
Matt Corallo
b455fb5e77 Implement the ability to block on multiple futures at once
In the next commits we'll be adding a second notify pipeline - from
the `ChainMonitor` back to the background processor. This will
cause the `background-processor` to need to await multiple wakers
at once, which we cannot do in the current scheme without taking on
a full async runtime.

Building a multi-future waiter isn't so bad, and notably will allow
us to remove the existing sleep pipeline entirely, reducing the
complexity of our wakers implementation by only having one notify
path to consider.
2023-04-03 16:49:54 +00:00
Matt Corallo
328407351c Do not bound callbacks by Send when building for no-std
`Send` is rather useless on a `no-std` target - we don't have
threads and are just needlessly restricting ourselves, so here we
skip it for the wakers callback.
2023-04-03 16:49:54 +00:00
Matt Corallo
a1b5a1bba3 Add CondVar::wait_{timeout_,}while to debug_sync
These are useful, but we previously couldn't use them due to our
MSRV. Now that we can, we should use them, so we expose them via
our normal debug_sync wrappers.
2023-04-03 16:49:54 +00:00
Lucas Soriano del Pino
beb1d9a2bd
Implement chain::Confirm without mandating any owned values 2023-04-03 21:12:44 +10:00
Matt Corallo
783e8188a7
Merge pull request #2136 from marctyndel/2023-03-paymentforwarded-expose-amount-forwarded
Expose amount forwarded in `PaymentForwarded` event
2023-03-30 18:15:23 +00:00
Matt Corallo
a9534fe6b5
Merge pull request #2059 from wpaulino/broadcast-missing-anchors-event
Queue BackgroundEvent to force close channels upon ChannelManager::read
2023-03-29 21:54:58 +00:00
Marc Tyndel
ee2cb8ef21 add outbound_amount_forwarded_msat field to PaymentForwarded event 2023-03-29 14:42:35 -04:00
valentinewallace
723c1a62ca
Merge pull request #2062 from alecchendev/2023-02-allow-overshoot-mpp
Allow overshooting final htlc amount and expiry
2023-03-29 11:37:51 -04:00
Wilmer Paulino
2166c8a2c4
Ignore lockorder violation on same callsite with different construction
As long as the lock order on such locks is still valid, we should allow
them regardless of whether they were constructed at the same location or
not. Note that we can only really enforce this if we require one lock
call per line, or if we have access to symbol columns (as we do on Linux
and macOS). We opt for a smaller patch by relying on the latter.

This was previously triggered by some recent test changes to
`test_manager_serialize_deserialize_inconsistent_monitor`. When the
test ends and a node is dropped causing us to persist each, we'd detect
a possible lockorder violation deadlock across three different `Mutex`
instances that are held at the same location when serializing our
`per_peer_states` in `ChannelManager::write`.

The presumed lockorder violation happens because the first `Mutex` held
shares the same construction location with the third one, while the
second `Mutex` has a different construction location. When we hold the
second one, we consider the first as a dependency, and then consider the
second as a dependency when holding the third, causing a circular
dependency (since the third shares the same construction location as the
first).

This isn't considered a lockorder violation that could result in a
deadlock as the comment suggests inline though, since we are under a
dependent write lock which no one else can have access to.
2023-03-28 17:27:47 -07:00
Alec Chen
1d31b0e84e Use onion amount amt_to_forward for MPP set calculation
If routing nodes take less fees and pay the final node more than
`amt_to_forward`, the receiver may see that `total_msat` has been met
before all of the sender's intended HTLCs have arrived. The receiver
may then prematurely claim the payment and release the payment hash,
allowing routing nodes to claim the remaining HTLCs. Using the onion
value `amt_to_forward` to determine when `total_msat` has been met
allows the sender to control the set total.
2023-03-28 17:21:09 -05:00
Alec Chen
ee57738ca8 Allow overshooting final cltv_expiry
Final nodes previously had stricter requirements on HTLC contents
matching onion value compared to intermediate nodes. This allowed
for probing, i.e. the last intermediate node could overshoot the
value by a small amount and conclude from the acceptance or rejection
of the HTLC whether the next node was the destination. This also
applies to the msat amount, however this change was already present.
2023-03-28 17:21:09 -05:00
Alec Chen
f3d8e58374 Allow overshooting total_msat for an MPP
While retrying a failed path of an MPP, a node may want to overshoot
the `total_msat` in order to use a path with an `htlc_minimum_msat`
greater than the remaining value being sent. This commit no longer
fails MPPs that overshoot the `total_msat`, however it does fail
HTLCs with the same payment hash that are received *after* a
payment has become claimable.
2023-03-28 17:21:09 -05:00
Alec Chen
b9f4ebdd28 Add total_value_received to ClaimableHTLC for claim validation
This is pre-work for allowing nodes to overshoot onion values and
changing validation for MPP completion. This adds a field to
`ClaimableHTLC` that is separate from the onion values, which
represents the actual received amount reported in `PaymentClaimable`
which is what we want to validate against when a user goes to claim.
2023-03-28 17:21:09 -05:00
Wilmer Paulino
23e233ba25
Expose HTLC transaction locktime in BumpTransactionEvent::HTLCResolution
While users could easily figure it out based on the set of HTLC
descriptors included within, we already track it within the
`OnchainTxHandler`, so we might as well expose it to users as a
nice-to-have. It's also yet another thing they must get right to ensure
their HTLC transaction broadcasts are valid.
2023-03-28 12:42:25 -07:00
Wilmer Paulino
68122bd09d
Set transaction locktime on malleable packages to discourage fee sniping
This only applies to all malleable packages on channels pre-dating
anchors and malleables packages for counterparty commitments
post-anchors. Malleables packages for holder commitments post-anchors
should have their transaction locktime applied manually by the consumer
of `BumpTransactionEvent::HTLCResolution` events.
2023-03-28 12:42:23 -07:00
Wilmer Paulino
2ac09711d3
Re-work PackageSolvingData::absolute_tx_timelock
Previously, this would return the earliest height the output could be
confirmed, which seems to no longer be useful. The only use of the
method was to determine whether we should delay a package to a future
block. Instead, we choose to return the absolute locktime the
transaction spending the output should have, which better corresponds to
the method name and still supports the delay functionality mentioned.

Doing so also allows us to expose the locktime required for HTLC
transactions we need to broadcast based on our own commitments for
anchor channels.
2023-03-28 12:15:54 -07:00
Matt Corallo
2d4bf974e5
Merge pull request #2083 from wpaulino/events-module
Move events.rs into its own top-level module
2023-03-28 16:37:55 +00:00