Commit graph

5280 commits

Author SHA1 Message Date
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
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
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
Matt Corallo
6a34baa270
Include an outbound_payment flag in MaybeTimeoutClaimableHTLC
When the user is fetching their current balances after forwarding a
payment (before it clears), they'll see a
`MaybePreimageClaimableHTLC` and a `MaybeTimeoutClaimableHTLC` but
if they sum up their balance using
`Balance::claimable_amount_satoshis` neither will be included.

Obviously, exactly one of the two balances should be included - one
of the two resolutions should happen in our favor. This causes our
visible balance to fluctuate up and down by the full value of any
HTLCs we're in the middle of forwarding, which is incredibly
confusing to see. If we want to stop the fluctuations, we need to
pick one of the two balances to include. The obvious candidate is
`MaybeTimeoutClaimableHTLC` as it is the lower of the two, and
represents our balance without the fee we'd receive from the
forward.

Sadly, if we always include it, we'll end up also including any
HTLCs which we've sent but which haven't yet been claimed by their
recipient, which is the wrong behavior.

Luckily, we have access to the `Option<HTLCSource>` while walking
HTLCs, which allows us to add an `outbound_payment` flag to
`MaybeTimeoutClaimableHTLC`. This allows us to only include
forwarded payments in `claimable_amount_satoshis`.

Sadly, even with this in place our balance still fluctuates by the
changes in the commitment transaction fees we have to pay during
forwarding, but addressing that is left for later.
2024-08-13 13:26:56 +02:00
Matt Corallo
bc1c026712
Merge pull request #3210 from tcharding/07-31-rm-hex-dep
Remove explicit dependency on hex-conservative
2024-08-12 17:11:56 +00:00
Matt Corallo
9de7c1db3b Stop relying on a Cloneable NetworkGraph ref in DefaultRouter
While there's not really much harm in requiring a `Clone`able
reference (they almost always are), it does make our bindings
struggle a bit as they don't support multi-trait bounds (as it
would require synthesizing a new C trait, which the bindings don't
do automatically). Luckily, there's really no reason for it, and we
can just call the `DefaultMessageRouter` directly when we want to
route a message.

We've carried this patch for a while on the bindings branch, but
there's not a strong reason it can't go upstream.
2024-08-12 01:03:42 +00:00
Matt Corallo
4950f3cfc8
Merge pull request #3214 from TheBlueMatt/2024-07-chan-by-val
Make `funding_transaction_generated` take a `ChannelId` by value
2024-08-12 00:40:16 +00:00
Tobin C. Harding
eac1b87e65
Use bitcoin::hex instead of bitcoin::hashes::hex
Use the `hex-conservative` crate directly from `bitcoin` instead of from
`hashes`. Although it makes no real difference it is slightly more clear
and more terse.
2024-08-09 08:20:15 +10:00
Tobin C. Harding
aeee8fe31e
Remove explicit dependency on hex-conservative
The `hex` crate is re-exported by `rust-bitcoin` so we can get it from
there instead of explicitly depending on it. Doing so reduces the
maintenance burden and helps reduce the likelyhood of getting two
versions in the dependency graph.
2024-08-09 08:20:09 +10:00
Duncan Dean
779b194825
Set default ChannelHandshakeLimits::min_funding_satoshis to 1000
The original default value of 0 was inconsistent with the minimum requirement
of 1000 satoshis in ChannelHandshakeConfig::their_channel_reserve_proportional_millionths.
2024-08-08 20:04:20 +02:00
Matt Corallo
1d9d911d1c
Merge pull request #3194 from tnull/2024-07-om-event-notifier
Add `Notifier` to `OnionMessenger`
2024-08-08 17:04:32 +00:00
Elias Rohrer
c1c133ccda
Merge pull request #3230 from TheBlueMatt/2024-08-old-doc-tweaks
Minor doc tweaks to `MonitorHolder`
2024-08-08 09:17:27 +02:00
Elias Rohrer
2dd8c2b3de
Add Notifier to OnionMessenger 2024-08-08 09:10:41 +02:00
Matt Corallo
fd8f4ace7b
Merge pull request #3231 from tcharding/08-08-rm-blockdata
Stop using `blockdata` module
2024-08-08 00:40:02 +00:00
cooltexture
5b603139db
Fix #3209
There was a issue with the ci/check-compiles.sh.
It would return a warning due to links not being enclosed in <>.
Fixed the issue by enclosing the links.
2024-08-07 23:54:11 +02:00
Tobin C. Harding
b02f3134d8
Run contrib/run-rustfmt.sh
No other changes other than those introduced by the script.
2024-08-08 07:17:18 +10:00
Tobin C. Harding
e9b20cee43
Do not use bitcoin::blockdata
The `rust-bitcoin` project is working towards making the public API
separate from the directory structure; eventually the
`bitcoin::blockdata` will go away, to make maintenance easier here stop
using the `blockdata` module.

Do not run the formatter, so as to make review easier. This patch was
created mechanically using:

search-and-replace bitcoin::blockdata bitcoin

and having defined

```bash
search-and-replace () {
        if (($# != 2))
        then
                echo "Usage: $0 <this> <that>"
                return
        fi
        local this="$1"
        local that="$2"
        for file in $(git grep -l "$this")
        do
                perl -pi -e "s/$this/$that/g" "$file"
        done
}
```
2024-08-08 07:13:26 +10:00
Matt Corallo
7a42d8e4fe Minor doc tweaks to MonitorHolder
036c31c9d0 introduced some minor doc
changes but failed to imrpove the docs that is was changing fully
which this does. Suggested by @tnull in review.
2024-08-07 14:31:01 +00:00
Matt Corallo
8eff6507f7
Merge pull request #3219 from dunxen/2024-08-PR2989-followups
Fix remaining feedback and other nits for 2989
2024-08-06 14:54:01 +00:00
Elias Rohrer
3d76753a10
Merge pull request #3225 from TheBlueMatt/2024-08-3019-followups
Clean up `CommonOpenChannelFields` docs slightly
2024-08-06 02:53:30 -05:00
valentinewallace
3071bbb92e
Merge pull request #3224 from TheBlueMatt/2024-08-deprecate-send_payment
Mark ChannelManager::send_payment_with_route as deprecated and take `Route` by value
2024-08-05 12:12:42 -07:00
Matt Corallo
47351806c5 Clean up CommonOpenChannelFields docs slightly 2024-08-05 15:18:57 +00:00
Matt Corallo
c7419b4323
Merge pull request #3019 from benthecarman/is-public
Add more information to OpenChannelRequest Event
2024-08-05 15:11:27 +00:00
Matt Corallo
1ff249516d Make funding_transaction_generated take a ChannelId by value
`ChannelId` is just a 32-byte array, so there's not a lot of value
in passing it by reference to `funding_transaction_generated`,
which we fix here.

This is also nice for bindings as languages like Java can better
analyze whether the `ChannelManager` ends up with a reference to
the `ChannelId`.
2024-08-04 18:16:22 +00:00
Matt Corallo
753a7ac8f2 Make send_payment_with_route take Route by value
Now that `ChannelManager::send_payment_with_route` is deprecated,
we don't care too much about making it as effecient as possible, so
there's not much cost to making it take `Route` by value. This
avoids bindings being unsure if the by-reference `Route` passed
needs to outlive the `ChannelManager` itself or if it only needs to
outlive the method call, creating some call overhead by forcing a
`Route::clone`, but avoiding a memory leak.
2024-08-04 18:08:49 +00:00
Matt Corallo
bebd9d0fed Mark ChannelManager::send_payment_with_route as deprecated
We probably should have done this long ago a release or two after
adding `send_payment`, but we didn't and the second best time is
now.

`send_payment_with_route` has particularly hard to use retry
semantics that make it unsuitable for real use. Once we get the
last of our users off of it, we'll want to remove it (or at least
mark it test-only), but we should start by deprecating it.
2024-08-04 16:53:27 +00:00
Duncan Dean
016d7e1a2f
Fix remaining feedback and other nits for 2989 2024-08-02 12:10:45 +02:00
Jeffrey Czyz
88343366ca
Replace use of OffersContext::Unknown with None
Now that ChannelManager uses a known OffersContext when creating blinded
paths, OffersContext::Unknown is no longer needed. Remove it and update
OffersMessageHandler to us an Option, which is more idiomatic for
signifying whether a message was delivered with or without an
OffersContext.
2024-07-30 16:06:25 -05:00