Commit graph

7660 commits

Author SHA1 Message Date
Valentine Wallace
6f0190d144
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct private to the module.
2024-08-15 13:04:07 -04:00
Valentine Wallace
c563c150f0
Add accessor methods for inner blinded path fields. 2024-08-15 13:04:04 -04:00
Valentine Wallace
10449b96de
Move public_intro_node util into Blinded{Message,Payment}Path
Helps move towards making the BlindedPath struct private.
2024-08-15 13:04:04 -04:00
Valentine Wallace
cbc25fbcf0
Move compact blinded path util to message paths only.
It's only used for message paths, so let's move it there to help make the
BlindedPath struct private.
2024-08-15 13:04:04 -04:00
Valentine Wallace
4dba7a314c
Expose blinded paths' advance_path_by_one methods.
Useful for LDK users that are using the onion messages module, like LNDK.
2024-08-15 13:04:04 -04:00
Valentine Wallace
e741a9a8e7
Add BlindedMessagePath type to disambiguate from blinded payment paths. 2024-08-15 13:04:01 -04:00
Valentine Wallace
caa836e8e5
Add BlindedPaymentPath type, to disambiguate from message paths.
Next up, we'll add a BlindedMessagePath type so the API is clear which type of
path is expected in each context.
2024-08-15 13:03:56 -04:00
Matt Corallo
33e69958e0
Merge pull request #3192 from jkczyz/2024-07-invoice-error-auth
Authenticate `InvoiceError` messages
2024-08-14 18:28:39 +00:00
Jeffrey Czyz
075a2e36b9
Make PaymentFailureReason downgradable
The PaymentFailureReason variants for invoice request failures will
cause downgrades to break. Instead, use a new TLV for the reason and
continue to write the old TLV, only use None for the new reasons.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
bb94320e40
Make PaymentFailureReason upgradable
This allows downgrading to version 0.0.124 or later and using None for a
PaymentFailureReason that was added after.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
1563186c2b
Add PaymentFailureReason::InvoiceRequestRejected
Instead of re-using PaymentFailureReason::RecipientRejected, define a
new InvoiceRequestRejected variant for when an InvoiceError is received
instead of a Bolt12Invoice. This allows user to differentiate the cause
of the failure.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
457ba24ee5
Add PaymentFailureReason::InvoiceRequestExpired
Now that Event::PaymentFailed is generated when an InvoiceRequest times
out, define a new PaymentFailureReason for this situation.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
f00b782a1c
Add pending changelog for Event::PaymentFailed 2024-08-14 10:55:59 -05:00
Jeffrey Czyz
a9e6363063
Remove Event::InvoiceRequestFailed
Now that Event::PaymentFailed has an option payment_hash, it can be used
in replace of Event::InvoiceRequestFailed. This allows for including a
reason when abandoning a payment before an invoice is received.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
14153edeed
Make payment_hash optional in Event::PaymentFailed
When abandoning a BOLT12 payment before a Bolt12Invoice is received, an
Event::InvoiceRequestFailed is generated and the abandonment reason is
lost. Make payment_hash optional in Event::PaymentFailed so that
Event::InvoiceRequestFailed can be removed in favor of it.
2024-08-14 10:55:58 -05:00
Jeffrey Czyz
4567ce501a
Test Bolt12Invoice with unknown required features 2024-08-14 10:55:58 -05:00
Jeffrey Czyz
16bbb7b3dc
Remove unused macro param 2024-08-14 10:55:58 -05:00
Jeffrey Czyz
19dec4b36f
Add InvoiceBuilder::features_unchecked
In order to test handling of unknown required features in a
Bolt12Invoice, add a test-only function to allow setting arbitrary
feature bits.
2024-08-14 10:55:58 -05:00
Jeffrey Czyz
05db67b5c3
Use a smaller bit for UnknownFeature
When testing Bolt12Invoice unknown require feature handling, a large
feature bit can cause SendError::TooBigPacket when creating an onion
message. Use a smaller feature bit for UnknownFeature, which also has
the added benefit of reducing test output.
2024-08-14 10:55:55 -05:00
Jeffrey Czyz
e4ca166e62
Move BOLT12 invoice features check
When handling a BOLT12 invoice, and invoice error is sent if the invoice
contains unknown required features. However, since the payment is still
in state AwaitingInvoice, abandoning it results in losing the reason
since an InvoiceRequestFailed event would be generated. Move the check
to PendingOutboundPayments such that the payment is first moved to state
InvoiceReceived so that a PaymentFailed event is generated instead.
2024-08-14 10:42:18 -05:00
Jeffrey Czyz
cfd098048e
Don't include HMAC in Refund paths
Refunds are typically communicated via QR code, where a smaller size is
desirable. Make the HMAC in OutboundPayment data optional such that it
is elided from blinded paths used in refunds. This prevents abandoning
refunds if the reader sends an invoice_error instead of an invoice
message. However, this use case isn't necessary as the corresponding
outbound payment will either timeout when the refund expires or can be
explicitly abandoned by the creator.
2024-08-14 10:42:18 -05:00
Jeffrey Czyz
fbaf093ff4
Don't use UserAbandoned reason for auto-failing
A BOLT12 payment may be abandoned when handling the invoice or when
receiving an InvoiceError message. When abandoning the payment, don't
use UserAbandoned as the reason since that is meant for when the user
calls ChannelManager::abandon_payment.
2024-08-14 10:42:18 -05:00
Jeffrey Czyz
144d4882ad
Don't abandon payments for duplicate invoices
When making an outbound BOLT12 payment, multiple invoices may be
received for the same payment id. Instead of abandoning the payment when
a duplicate invoice received, simply ignore it without responding with
an InvoiceError. This prevents abandoning in-progress payments and
sending unnecessary onion messages.
2024-08-14 10:42:17 -05:00
Jeffrey Czyz
bb445a3973
Authenticate payment_id from OffersContext
Before abandoning a payment when receiving an InvoiceError, verify that
the PaymentId included in the OffersContext with the included HMAC. This
prevents a malicious actor sending an InvoiceError with a known payment
id from abandoning our payment.
2024-08-14 10:42:17 -05:00
Jeffrey Czyz
0ca9faf078
Add an HMAC to OffersContext::OutboundPayment
When receiving an InvoiceError in response to an InvoiceRequest, the
corresponding payment should be abandoned. Add an HMAC to
OffersContext::OutboundPayment such that the payment ID can be
authenticated prior to abandoning the payment.
2024-08-14 10:42:17 -05:00
Jeffrey Czyz
8119fbfaf9
Add Sha256 HMAC (de)serialization
An HMAC needs to be included in OffersContext::OutboundPayment to
authenticate the included PaymentId. Implement Readable and Writeable to
allow for this.
2024-08-14 10:42:17 -05:00
Jeffrey Czyz
f52bd0b8e3
HMAC construction and verification for PaymentID
When receiving an InvoiceError in response to an InvoiceRequest, the
corresponding payment should be abandoned. Add functions for
constructing and verifying an HMAC over a Payment ID to allow for this.
2024-08-14 10:42:17 -05:00
valentinewallace
5ab40b2f3c
Merge pull request #3212 from dunxen/2024-07-sensible-balances
Accuracy fixes and differentiating sources for `Balance`
2024-08-14 11:22:05 -04:00
Matt Corallo
398314b720
Merge pull request #3234 from TheBlueMatt/2024-08-lightning-dep-inv
Swap the dep order between `lightning` and `lightning-invoice`
2024-08-14 14:27:39 +00:00
Matt Corallo
fc21640b1f
Merge pull request #3020 from tnull/2024-04-drop-electrsd-autodownload-for-good
Drop `electrsd`'s auto-download feature for good
2024-08-13 23:23:43 +00:00
Elias Rohrer
4320f483f2
Enable caching for bitcoind/electrs in CI 2024-08-13 15:02:46 +02:00
Matt Corallo
ae59d1dfb2 rustfmt new files added in the past few commits
The past handful of commits were mostly moving code around, so to
aid reviewers violated our `rustfmt` rules. Here we rectify that by
`rustfmt`'ing the newly-added files.
2024-08-13 12:55:19 +00:00
Matt Corallo
30879ed035 Prepare to rustfmt newly added files
In the next commit we'll `rustfmt` newly-added files, but before
we do so we clean up some code so that the resulting files won't be
quite as absurd. We also exclude the new `invoice_utils.rs` file,
as it needs quite substantial cleanups.
2024-08-13 12:55:19 +00:00
Matt Corallo
9c93bd56c2 Provide the signer with a full RawBolt11Invoice to sign
Now that the `lightning` crate depends on the `lightning-invoice`
crate, there's no reason to have the `sign_invoice` method take raw
base32 field elements as we can now give it a real
`RawBolt11Invoice`, which we do here.

This simplifies the interface and avoids a
serialization-deserialization roundtrip when signing invoices in a
validating signer.

FIxes #3227
2024-08-13 12:55:19 +00:00
Matt Corallo
a741a57249 Swap the dep order between lightning and lightning-invoice
`lightning-invoice` previously had a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

Here we finally rectify this issue, swapping the dependency order
and making `lightning` depend on `lightning-invoice` rather than
the other way around.

This moves various utilities which were in `lightning-invoice` but
relied on `lightning` payment types to make payments to where they
belong (the `lightning` crate), but doesn't bother with integrating
them well in their new home.
2024-08-13 12:55:18 +00:00
Matt Corallo
1eba737f44 Add a lightning-types dependency to lightning-invoice
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes tees us up for the final step, adding a
`lightning-types` dependency to `lightning-invoice` and using it
for imports rather than the `lightning` crate.
2024-08-13 12:54:59 +00:00
Matt Corallo
1f01f2ef67 Use check_added_monitors test utility in invoice utils tests
In a coming commit, the `lightning-invoice::utils` module will move
to the `lightning` crate, causing its tests to be included in the
global lockorder tests done in that crate. This should be fine,
except that the `lightning-invoice::utils` module currently holds
the `added_monitors` lock too long causing lockorder violations.

Instead, this commit replaces the legacy monitors-added test with
the `check_added_monitors` test utility.
2024-08-13 12:54:59 +00:00
Matt Corallo
3b3774ee69 Move UntrustedString and PrintableString to lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the `UntrustedString` and
`PrintableString` types to `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
0c5922e92a Move Features into lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the `Features` types from
`lightning` to `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
954b7be85a Replace usages of Features::is_subset and remove it
It turns out all the places we use `Features::is_subset` we could
as well be using `Features::requires_unknown_bits_from`. Further,
in the next commit `Features` will move to a different crate so any
methods which the `lightning` crate uses will need to be public. As
the `is_subset` API is prety confusing (it doesn't consider
optional/required bits, only whether the bits themselves are
strictly a subset) it'd be nice to not have to expose it, which is
enabled here.
2024-08-13 12:54:59 +00:00
Matt Corallo
b97d742f91 Move Rout{ingFees,eHint{,Hop}} to lightning-types
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes one more step, moving the routing types
`lightning-invoice` uses into `lightning-types`.
2024-08-13 12:54:59 +00:00
Matt Corallo
4624caf5a2 Move Payment{Hash,Preimage,Secret} into a new crate
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This is the first step towards fixing that - moving the common
types we need into a new `lightning-types` crate which both can
depend on.

Since we're using a new crate and can't depend on the existing
`lightning` hex utility to implement `Display`, we also take this
opportunity to switch to the new `Display` impl macro in
`hex_conservative`.
2024-08-13 12:54:59 +00:00
Duncan Dean
d6c540df12
Test claimable balance is expected for forwarded/outbound payments 2024-08-13 13:26:57 +02:00
Duncan Dean
728192ecdc
Indicate source of balances
Introduce the `BalanceSource` enum to differentiate between force-close,
coop-close, and HTLCs in `Balance::ClaimableAwaitingConfirmations`.
2024-08-13 13:26:57 +02:00
Matt Corallo
8b729b606f
Explain how rounded millisat values are included in overall balance 2024-08-13 13:26:57 +02:00
Duncan Dean
fe73ce789b
Test rounded msat balances 2024-08-13 13:26:57 +02:00
Matt Corallo
f5a614eb0b
Include rounded msat balances in Balance::ClaimableOnChannelClose
If we're gonna push users towards using `Balance` to determine
their current balances, we really need to provide more information,
including msat balances.

Here we add rounded-out msat balances to the pre-close balance
information
2024-08-13 13:26:57 +02:00
Matt Corallo
a39357e08a
Add tx fee information to Balance::ClaimableOnChannelClose
`Balance::ClaimableOnChannelClose` excludes the commitment
transaction fee, which makes it hard to use for current balance
calculation. Here we add it, setting the value to zero for inbound
channels (i.e. ones for which we don't pay the fee).
2024-08-13 13:26:57 +02:00
Matt Corallo
f1f28c6010
Move commitment tx fee calculation helpers to chan_utils
These don't really belong in `channel` as they're now used in other
parts of the codebase.
2024-08-13 13:26:57 +02:00
Matt Corallo
9e147a6213
Drop chan_utils self-import
There's no reason to `use` a module within that module to refer to
that module...
2024-08-13 13:26:57 +02:00