Commit Graph

8427 Commits

Author SHA1 Message Date
Elias Rohrer
323571db90
rustfmt: Drop lightning-invoice/src/de.rs from exclusion list 2024-11-14 11:46:25 +01:00
Elias Rohrer
97537c5ac9
rustfmt: Run on lightning-invoice/src/de.rs 2024-11-14 11:46:24 +01:00
Elias Rohrer
f4d0584a36
rustfmt: Prepare lightning-invoice/src/de.rs 2024-11-14 11:45:45 +01:00
Gursharan Singh
4322b19e61
Merge pull request #3368 from TheBlueMatt/2024-10-decayed-non-null
Don't interpret decayed data as we've failed to send tiny values
2024-11-12 18:50:46 -08:00
Matt Corallo
c99d3d785d Stop using a constant for monitor update_ids after closure
Because `ChannelManager` doesn't have a corresponding `Channel`
after the channels are closed, we'd always used an `update_id` of
`u64::MAX` for any `ChannelMonitorUpdate`s we need to build after
the channel is closed.

This completely breaks the abstraction of `update_id`s and leaks
into persistence logic - because we might have more than one
`ChannelMonitorUpdate` with the same (`u64::MAX`) value, suddenly
instead of being able to safely use `update_id` as IDs, the
`MonitorUpdatingPersister` has to have special logic to handle
this.

Worse, because we don't have a unique ID with which to refer to
post-close `ChannelMonitorUpdate`s we cannot track when they
complete async persistence. This means we cannot properly support
async persist for forwarded payments where the inbound edge has hit
the chain prior to the preimage coming to us.

Here we rectify this by using consistent `update_id`s even after a
channel has closed. In order to do so we have to keep some state
for all channels for which the `ChannelMonitor` has not been
archived (after which point we can be confident we will not need to
update them). While this violates our long-standing policy of
having no state at all in `ChannelManager`s for closed channels,
its only a `(ChannelId, u64)` pair per channel, so shouldn't be
problematic for any of our users (as they already store a whole
honkin `ChannelMonitor` for these channels anyway).

While limited changes are made to the connection-count-limiting
logic, reviewers should carefully analyze the interactions the new
map created here has with that logic.
2024-11-13 01:24:06 +00:00
Matt Corallo
3f36890912 Prefer to use MonitorUpdateRegeneratedOnStartup where possible
In the next commit we'll drop the magic `u64::MAX`
`ChannelMonitorUpdate::update_id` value used when we don't know the
`ChannelMonitor`'s `latest_update_id` (i.e. when the channel is
closed). In order to do so, we will store further information about
`ChannelMonitor`s in the per-peer structure, keyed by the
counterparty's node ID, which will be used when applying
`ChannelMonitorUpdate`s to closed channels.

By taking advantage of the change in the previous commit, that
information is now reliably available when we generate the
`ChannelMonitorUpdate` (when claiming HTLCs), but in order to
ensure it is available when applying the `ChannelMonitorUpdate` we
need to use `BackgroundEvent::MonitorUpdateRegeneratedOnStartup`
instead of
`BackgroundEvent::ClosedMonitorUpdateRegeneratedOnStartup` where
possible.

Here we do this, leaving `ClosedMonitorUpdateRegeneratedOnStartup`
only used to ensure very old channels (created in 0.0.118 or
earlier) which are not in the `ChannelManager` are force-closed on
startup.
2024-11-13 01:24:06 +00:00
Matt Corallo
6f023f8f08 Req the counterparty node id when claiming against a closed chan
Currently we store in-flight `ChannelMonitorUpdate`s in the
per-peer structure in `ChannelManager`. This is nice and simple as
we're generally updating it when we're updating other per-peer
data, so we already have the relevant lock(s) and map entries.

Sadly, when we're claiming an HTLC against a closed channel, we
didn't have the `counterparty_node_id` available until it was
added in 0.0.124 (and now we only have it for HTLCs which were
forwarded in 0.0.124). This means we can't look up the per-peer
structure when claiming old HTLCs, making it difficult to track the
new `ChannelMonitorUpdate` as in-flight.

While we could transition the in-flight `ChannelMonitorUpdate`
tracking to a new global map indexed by `OutPoint`, doing so would
result in a major lock which would be highly contended across
channels with different peers.

Instead, as we move towards tracking in-flight
`ChannelMonitorUpdate`s for closed channels we'll keep our existing
storage, leaving only the `counterparty_node_id` issue to contend
with.

Here we simply accept the issue, requiring that
`counterparty_node_id` be available when claiming HTLCs against a
closed channel. On startup, we explicitly check for any forwarded
HTLCs which came from a closed channel where the forward happened
prior to 0.0.124, failing to deserialize, or logging an warning if
the channel is still open (implying things may work out, but panics
may occur if the channel closes prior to HTLC resolution).

While this is a somewhat dissapointing resolution, LDK nodes which
forward HTLCs are generally fairly well-upgraded, so it is not
anticipated to be an issue in practice.
2024-11-13 01:24:06 +00:00
Matt Corallo
70add1448b
Merge pull request #3264 from jkczyz/2024-08-remove-user-provided-payer-id
Disallow user-provided `payer_signing_pubkey`
2024-11-12 20:23:45 +00:00
Jeffrey Czyz
20ef217985
Expand Bolt11InvoiceParameters docs for no-std use 2024-11-12 12:28:52 -06:00
Jeffrey Czyz
e9051f84f2
Explain no-std Bolt11Invoice::duration_since_epoch 2024-11-12 12:24:52 -06:00
Elias Rohrer
f152689d0a
Merge pull request #3283 from TheBlueMatt/2024-07-human-readable-names-resolution
Support paying directly to Human Readable Names using bLIP 32
2024-11-12 18:30:01 +01:00
Matt Corallo
cbdb8cb0cb Set the dns_resolution feature in OMDomainResolver
`OMDomainResolver` actually does support building DNSSECProofs, so
should be setting the `dns_resolution` `NodeFeature` flag.
2024-11-12 15:53:35 +00:00
Matt Corallo
8e941426cf Add a lightning-dns-resolver crate which answers bLIP 32 queries
When a lightning node wishes to send payments to a BIP 353 human
readable name (using BOLT 12), it first has to resolve that name to
a DNS TXT record. bLIP 32 defines a way to do so over onion
messages, and this completes our implementation thereof by adding
the server side.

It operates by simply accepting new messages and spawning tokio
tasks to do DNS lookups using the `dnsse_prover` crate. It also
contains full end-to-end tests of the BIP 353 -> BOLT 12 -> payment
logic using the new server code to do the resolution.

Note that because we now have a workspace crate which sets the
"lightning/dnssec" feature in its `dev-dependencies`, a naive
`cargo test` will test the "dnssec" feature.
2024-11-12 15:53:35 +00:00
Matt Corallo
2bbb3b7083 Use ChannelManager as DNSResolverMessageHandler by default
Now that `ChannelManager` supports using bLIP 32 to resolve BIP 353
Human Readable Names we should encourage users to use that feature
by making the "default" (in various type aliases) to use
`ChannelManager` as the `DNSResolverMessageHandler`.
2024-11-12 15:53:35 +00:00
Matt Corallo
99d00930a4 Support paying Human Readable Names directly from ChannelManager
Now that we have the ability to resolve BIP 353 Human Readable
Names directly and have tracking for outbound payments waiting on
an offer resolution, we can implement full BIP 353 support in
`ChannelManager`.

Users will need one or more known nodes which offer DNS resolution
service over onion messages using bLIP 32, which they pass to
`ChannelManager::pay_for_offer_from_human_readable_name`, as well
as the `HumanReadableName` itself.

From there, `ChannelManager` asks the DNS resolver to provide a
DNSSEC proof, which it verifies, parses into an `Offer`, and then
pays.

For those who wish to support on-chain fallbacks, sadly, this will
not work, and they'll still have to use `OMNameResolver` directly
in order to use their existing `bitcoin:` URI parsing.
2024-11-12 15:53:34 +00:00
Matt Corallo
8d8416b956 Store the source HumanReadableName in InvoiceRequestFields
When we receive a payment to an offer we issued resolved with a
human readable name, it may have been resolved using a wildcard
DNS entry which we want to map to a specific recipient account
locally. To do this, we need the human readable name from the
`InvoiceRequest` in the `PaymentClaim{able,ed}`, which we pipe
through here using `InvoiceRequestFields`.
2024-11-12 15:53:12 +00:00
Matt Corallo
e447b49136 Add support for storing a source HRN in BOLT 12 invoice_requests
When we resolve a Human Readable Name to a BOLT 12 `offer`, we may
end up resolving to a wildcard DNS name covering all possible
`user` parts. In that case, if we just blindly pay the `offer`, the
recipient would have no way to tell which `user` we paid.

Instead, BOLT 12 defines a field to include the HRN resolved in the
`invoice_request`, which we implement here.

We also take this opportunity to remove constant parameters from
the `outbound_payment.rs` interface to `channelmanager.rs`
2024-11-12 15:53:12 +00:00
Matt Corallo
46df35b0ff Add a new AwaitingOffer outbound payment state for BIP 353 2024-11-12 15:53:12 +00:00
Matt Corallo
a39e274e3d Skip the implicit trailing . in HumanReadableName's domain
Domain names implicitly have a trailing `.`, which we require in
bLIP 32 but generally shouldn't be exposing to the user in
`HumanReadableName`s (after all, they're human-readable). Here we
make sure the trailing `.` is dropped in `HumanReadableName`s
before we re-add them when building the bLIP 32 messages.
2024-11-12 15:53:12 +00:00
Matt Corallo
b0bd4371d9
Merge pull request #3383 from valentinewallace/2024-09-blinded-keysend-verify
Verify blinded keysend payments
2024-11-12 15:00:46 +00:00
Jeffrey Czyz
716758f5a3
Fix incorrect expect message 2024-11-11 16:32:28 -06:00
Jeffrey Czyz
c331b67137
Remove NodeSigner::sign_bolt12_invoice_request
Now that invoice requests are signed using transient keys only, remove
the corresponding signing method from NodeSigner since it is never used.
2024-11-11 16:18:11 -06:00
Jeffrey Czyz
5af0cf1c04
Remove PayerSigningPubkeyStrategy
Now that InvoiceRequest::payer_signing_pubkey is always a derived
pubkey, there is no longer a need for PayerSigningPubkeyStrategy.
2024-11-11 16:18:11 -06:00
Jeffrey Czyz
d596b4e635
Disallow user-provided payer_signing_pubkey
When creating an InvoiceRequests, users may choose to either use a
transient signing pubkey generated by LDK or provide a static one.
Disallow the latter as it allows users to reuse the same pubkey, which
results in poor sender privacy.
2024-11-11 16:18:11 -06:00
Jeffrey Czyz
ad487e7232
Replace spaces with tabs 2024-11-11 16:18:10 -06:00
Matt Corallo
739c412bc1
Merge pull request #3389 from jkczyz/2024-10-bolt11-invoice-utils
Add `ChannelManager::create_bolt11_invoice`
2024-11-11 14:35:08 +00:00
Valentine Wallace
9cc6969314
Verify blinded keysend payment secrets
If we're receiving a keysend to a blinded path, then we created the payment
secret within. Using our inbound_payment_key, we can decrypt the payment secret
bytes to get the payment's min_cltv_expiry_delta and min amount, to verify the
payment is valid. However, if we're receiving an MPP keysend *not* to a blinded
path, then we did not create the payment secret and shouldn't verify it since
it's only used to correlate MPP parts.

Therefore, store whether the payment secret is recipient-generated in our pending
inbound payment data so we know whether to verify it or not.
2024-11-08 17:08:27 -05:00
Jeffrey Czyz
7878801be7
Update BOLT11 docs in ChannelManager
Update ChannelManager docs to use create_bolt11_invoice and correct
references to modules in the lightning-invoice crate that no longer
exist.
2024-11-08 12:14:57 -06:00
Jeffrey Czyz
2a4a470c98
Test new behavior in create_bolt11_invoice
Bolt11InvoiceParameters allows for setting currency and
duration_since_epoch. If currency is not set, test that the one
corresponding to ChannelManager's chain hash is usd. If
duration_since_epoch, is not set then highest seen timestamp is used in
non-std compilations.
2024-11-08 12:14:51 -06:00
Jeffrey Czyz
b6ceafb4f6
Deprecate functions in invoice_utils module
ChannelManager::create_bolt11_invoice is a simpler and more flexible way
of creating a BOLT11 invoice, so deprecate the corresponding functions
in the invoice_utils module.
2024-11-08 12:06:45 -06:00
Jeffrey Czyz
ce0e182ea5
Use ChannelManager::create_bolt11_invoice in tests
The utility methods in in invoice_utils will be removed or deprecated in
an upcoming commit.
2024-11-08 12:06:19 -06:00
Jeffrey Czyz
3c6896c9fa
Add a BOLT11 invoice utility to ChannelManager
Now that the lightning crate depends on the lightning_invoice crate, the
utility functions previously living in the latter can be implemented on
ChannelManager. Additionally, the parameters are now moved to a struct
in order to remove the increasingly combinatorial blow-up of methods.

The new Bolt11InvoiceParameters is used to determine what values to set
in the invoice. Using None for any given parameter results in a
reasonable the default or a behavior determined by the ChannelManager as
detailed in the documentation.
2024-11-08 11:56:59 -06:00
Jeffrey Czyz
284cb28af2
Remove currency support from invoice_utils
When creating an invoice using a ChannelManager, payments for a specific
ChainHash / Network are only valid. Use the one from the ChannelManager
instead of allowing arbitrary ones in the form of a Currency.
2024-11-08 11:44:00 -06:00
Valentine Wallace
34c2f25806
Support verifying payment_secrets for inbound static invoice payments
Add a new payment type for this, because normally the payment hash is factored
into the payment secrets we create for invoices, but static invoices don't have
a payment hash since they are paid via keysend.
2024-11-08 10:28:53 -05:00
Valentine Wallace
45f88ee7f9
Add new inbound payment key for spontaneous payments
This key will be used in upcoming commits for encrypting metadata bytes for
spontaneous payments' payment secrets, to be included in the blinded paths of
static invoices for async payments. We need a new type of payment secret for
these payments because they don't have an a prior known payment hash, see the
next commit.
2024-11-08 10:28:53 -05:00
Valentine Wallace
02316d28f1
Remove pending_inbound_payments map from ChannelManager
LDK versions prior to 0.0.104 had stateful inbound payments written in this
map. In 0.0.104, we added support for stateless inbound payments with
deterministically generated payment secrets, and maintained deprecated support
for stateful inbound payments until 0.0.116. After 0.0.116, no further inbound
payments could have been written into this map.
2024-11-08 10:28:29 -05:00
Jeffrey Czyz
0ea225cfe7
Remove no-std support from invoice_utils functions
The upcoming ChannelManager::create_bolt11_invoice will not support
setting a specific creation time, so remove that functionality from the
invoice_utils functions. This will avoid duplicate code when
deprecating.
2024-11-07 17:08:35 -06:00
Matt Corallo
5718baaed9
Merge pull request #3397 from vincenzopalazzo/macros/amount-less-refactoring
[RFC] rename pay_parameters for no amount invoice
2024-11-07 22:13:57 +00:00
Matt Corallo
61a60d543c
Merge pull request #3402 from tnull/2024-11-pin-indexmap
Pin `indexmap` back to account for `hashbrown` MSRV bump
2024-11-07 22:12:19 +00:00
Matt Corallo
6bf218198f
Merge pull request #3399 from TheBlueMatt/2024-11-fuzz-assert
Drop broken debug assertion on peer buffer lengths
2024-11-07 21:43:12 +00:00
Matt Corallo
fcc59730a1
Merge pull request #3395 from mhrheaume/mhr/process_events_docs
Updated docs on `PeerManager::process_events`.
2024-11-07 17:54:03 +00:00
Elias Rohrer
e12ee9d120
Pin indexmap back to account for hashbrown MSRV bump
`indexmap` 2.6.0 upgraded to `hashbrown` 0.15, which unfortunately
bumped their MSRV to rustc 1.65 with the 0.15.1 release. So we pin
`indexmap` to 2.5.0 to fix our MSRV CI.
2024-11-07 14:35:12 +01:00
Elias Rohrer
c35adff51d
Merge pull request #3388 from TheBlueMatt/2024-10-counter-test
Add additional test coverage of `NetworkGraph` counters
2024-11-07 11:07:32 +01:00
Jeffrey Czyz
2a954020c6
Combine import statements 2024-11-06 12:04:15 -06:00
Jeffrey Czyz
65790b6718
Add Description::empty constructor
When creating a default Bolt11InvoiceParameters, having an infallible
constructor avoids an unwrap.
2024-11-06 11:53:46 -06:00
Jeffrey Czyz
1e52c33c07
Merge pull request #3401 from tnull/2024-11-update-fuzz-readme
Update `fuzz` README to account for additional required `RUSTFLAGS`
2024-11-06 10:07:53 -06:00
Elias Rohrer
d13c2bd829
Update fuzz README to account for additional required RUSTFLAGS 2024-11-06 14:27:26 +01:00
Vincenzo Palazzo
c2c670b2b5
rename pay_parameters for no amount invoice
This commit renames the function `pay_parameters_for_zero_amount_invoice`
to `pay_parameters_for_variable_amount_invoice`.

The term "variable amount" is used to align with
the naming convention in the LDK node, helping to avoid
confusion between similar packages.

Fixes: https://github.com/lightningdevkit/rust-lightning/issues/2879
Replaces: https://github.com/lightningdevkit/rust-lightning/pull/2979
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-11-06 11:08:25 +01:00
Matthew Rheaume
9d071068a3 Updated docs on PeerManager::process_events.
Try to make it a bit more clear that there are downsides to solely
relying on `lightning-net-tokio`, and it's still recommended to
occasionally call this function in a separate loop.
2024-11-05 12:17:14 -08:00
Matt Corallo
ebf1de5bc7 Build per_peer_state immediately in ChannelManager deser
Instead of first building a map from peers to a list of channels
then pulling out of that to build the `per_peer_state`, we build
`per_peer_state` immediately and store channels in it immediately.

This avoids an unnecessary map indirection but also gives us
access to the new fields in `per_peer_state` when reading
`Channel`s which we'll need in a coming commit.
2024-11-05 20:13:48 +00:00