]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
2 months agoMerge pull request #3303 from TheBlueMatt/2024-09-inbound-payment-id
Elias Rohrer [Tue, 24 Sep 2024 04:38:16 +0000 (13:38 +0900)]
Merge pull request #3303 from TheBlueMatt/2024-09-inbound-payment-id

Add a `PaymentId` for inbound payments

2 months agoMerge pull request #3310 from TheBlueMatt/2024-09-unlocked-checksig
Matt Corallo [Tue, 24 Sep 2024 03:13:51 +0000 (03:13 +0000)]
Merge pull request #3310 from TheBlueMatt/2024-09-unlocked-checksig

Validate `channel_update` signatures without holding a graph lock

2 months agoMerge pull request #3326 from jkczyz/2024-09-split-router
Elias Rohrer [Tue, 24 Sep 2024 02:47:45 +0000 (11:47 +0900)]
Merge pull request #3326 from jkczyz/2024-09-split-router

Decouple `MessageRouter` from `Router`

2 months agoValidate `channel_update` signatures without holding a graph lock 2024-09-unlocked-checksig
Matt Corallo [Wed, 11 Sep 2024 23:36:29 +0000 (23:36 +0000)]
Validate `channel_update` signatures without holding a graph lock

We often process many gossip messages in parallel across different
peer connections, making the `NetworkGraph` mutexes fairly
contention-sensitive (not to mention the potential that we want to
send a payment and need to find a path to do so).

Because we need to look up a node's public key to validate a
signature on `channel_update` messages, we always need to take a
`NetworkGraph::channels` lock before we can validate the message.

For simplicity, and to avoid taking a lock twice, we'd always
validated the `channel_update` signature while holding the same
lock, but here we address the contention issues by doing a
`channel_update` validation in three stages.

First we take a read lock on `NetworkGraph::channels` and check if
the `channel_update` is new, then release the lock and validate the
message signature, and finally take a write lock, (re-check if the
`channel_update` is new) and update the graph.

2 months agoDe-couple MessageRouter from Router
Jeffrey Czyz [Wed, 18 Sep 2024 17:40:48 +0000 (12:40 -0500)]
De-couple MessageRouter from Router

Now that ChannelManager is parameterized by both a MessageRouter and a
Router, Router implementations no longer need to implement
MessageRouter, too.

2 months agoExpand DefaultRouter's privacy docs
Jeffrey Czyz [Wed, 18 Sep 2024 17:06:26 +0000 (12:06 -0500)]
Expand DefaultRouter's privacy docs

DefaultRouter::create_blinded_payment_paths may creat a one-hop blinded
path with the recipient as the introduction node. Update the privacy
section of DefaultRouter's docs to indicate this as is done in the docs
for DefaultMessageRouter.

2 months agoParameterize ChannelManager with MessageRouter
Jeffrey Czyz [Wed, 18 Sep 2024 16:52:38 +0000 (11:52 -0500)]
Parameterize ChannelManager with MessageRouter

ChannelManager is parameterized by a Router, which must also implement
MessageRouter. Instead, add a MessageRouter parameter such that the
Router and MessageRouter traits can be de-coupled. This simplifies using
something other than DefaultMessageRouter, which DefaultRouter currently
delegates to.

2 months agoAdd a `PaymentId` for inbound payments 2024-09-inbound-payment-id
Matt Corallo [Thu, 12 Sep 2024 18:36:58 +0000 (18:36 +0000)]
Add a `PaymentId` for inbound payments

We expect our users to have fully idempotent `Event` handling as we
may replay events on restart for one of a number of reasons. This
isn't a big deal as long as all our events have some kind of
identifier users can use to check if the `Event` has already been
handled.

For outbound payments, this is the `PaymentId` they provide in the
send methods, however for inbound payments we don't have a great
option.

`PaymentHash` largely suffices - users can simply always claim in
response to a `PaymentClaimable` of sufficient value and treat a
`PaymentClaimed` event as duplicate any time they see a second one
for the same `PaymentHash`. This mostly works, but may result in
accepting duplicative payments if someone (incorrectly) pays twice
for the same `PaymentHash`.

Users could also fail for duplicative `PaymentClaimable` events of
the same `PaymentHash`, but doing so may result in spuriously
failing a payment if the `PaymentClaimable` event is a replay and
they never saw a corresponding `PaymentClaimed` event.

While none of this will result in spuriously thinking they've been
paid when they have not, it does result in some pretty awkward
semantics which we'd rather avoid our users having to deal with.

Instead, here, we add a new `PaymentId` which is simply an HMAC of
the HTLCs (as Channel ID, HTLC ID pairs) which were included in the
payment.

2 months agoAdd an `inbound_payment_id_secret` to `ChannelManager`
Matt Corallo [Sun, 8 Sep 2024 16:38:22 +0000 (16:38 +0000)]
Add an `inbound_payment_id_secret` to `ChannelManager`

In the next commit we'll start generating `PaymentId`s for inbound
payments randomly by HMAC'ing the HTLC set of the payment. Here we
start by defining the HMAC secret for these HMACs.

This requires one small test adaptation and a full_stack_target
fuzz change because it changes the RNG consumption.

2 months agoDo not check the ordering of HTLCs in `PaymentClaim[able,ed]`
Matt Corallo [Sun, 8 Sep 2024 16:09:12 +0000 (16:09 +0000)]
Do not check the ordering of HTLCs in `PaymentClaim[able,ed]`

In the next commit we'll change the order of HTLCs in
`PaymentClaim[able,ed]` events. This shouldn't break anything, but
our current functional tests check that the HTLCs are provided in
the order they expect (the order they were received). Instead, here
we only validate that each claimed HTLC matches one expected path.

2 months agoMerge pull request #3327 from TheBlueMatt/2024-09-local-ci-rustfmt
Elias Rohrer [Thu, 19 Sep 2024 07:30:23 +0000 (09:30 +0200)]
Merge pull request #3327 from TheBlueMatt/2024-09-local-ci-rustfmt

Only attempt to `rustfmt` files checked into git

2 months agoOnly attempt to `rustfmt` files checked into git 2024-09-local-ci-rustfmt
Matt Corallo [Wed, 18 Sep 2024 18:03:11 +0000 (18:03 +0000)]
Only attempt to `rustfmt` files checked into git

This avoids `rustfmt` failing on Rust files generated by dependent
crates in `target`, eg

```
+ rustfmt --edition 2021 --check ./target/debug/build/thiserror-8230374e07b5c05a/out/probe.rs
Diff in /home/matt/rust-lightning-3/target/debug/build/thiserror-8230374e07b5c05a/out/probe.rs at line 1:

-    #![feature(provide_any)]
+#![feature(provide_any)]

-    use std::any::{Demand, Provider};
+use std::any::{Demand, Provider};

-    fn _f<'a, P: Provider>(p: &'a P, demand: &mut Demand<'a>) {
-        p.provide(demand);
-    }
+fn _f<'a, P: Provider>(p: &'a P, demand: &mut Demand<'a>) {
+ p.provide(demand);
+}
```

2 months agoRe-order imports
Jeffrey Czyz [Wed, 18 Sep 2024 16:08:29 +0000 (11:08 -0500)]
Re-order imports

2 months agoMerge pull request #3289 from tnull/2024-09-fix-rgs-bp-builds
Matt Corallo [Wed, 18 Sep 2024 14:31:18 +0000 (14:31 +0000)]
Merge pull request #3289 from tnull/2024-09-fix-rgs-bp-builds

Fix builds of `lightning-rapid-gossip-sync` and `lightning-background-processor` crates

2 months agoDrop `no-std` feature
Elias Rohrer [Fri, 13 Sep 2024 11:14:40 +0000 (13:14 +0200)]
Drop `no-std` feature

We drop the `lightning/no-std` feature and just take
`hashbrown`,`possiblyrandom` and `libm` as required dependencies.

2 months agoCheck workspace members with default features individually in CI
Elias Rohrer [Wed, 4 Sep 2024 09:10:13 +0000 (11:10 +0200)]
Check workspace members with default features individually in CI

Previously, we would only check the workspace as a whole. This however
would mean that we would check/test crates with `lightning`'s default
features enabled, allowing failures-to-build under the crates own
default features to slip through, if they didn't explicitly enable
`lightning/std`, for example.

Here, we extend the CI to check the workspace as a whole but then run
checks, tests, and doc generation on the workspace members individually,
asserting that all of them build even when not built as part of the same
workspace as `lightning`.

2 months agoRe-add optional `std` feature dependencies to fix RGS and BP builds
Elias Rohrer [Wed, 4 Sep 2024 08:53:37 +0000 (10:53 +0200)]
Re-add optional `std` feature dependencies to fix RGS and BP builds

We previously removed these, leading to failure to build under default
features including `std`.

2 months agoMerge pull request #3321 from valentinewallace/2024-09-fix-main
Matt Corallo [Tue, 17 Sep 2024 21:45:30 +0000 (21:45 +0000)]
Merge pull request #3321 from valentinewallace/2024-09-fix-main

Fix silent rebase conflict that broke tests

2 months agoFix silent rebase conflict that broke tests
Valentine Wallace [Tue, 17 Sep 2024 21:24:39 +0000 (17:24 -0400)]
Fix silent rebase conflict that broke tests

429cbe1a060a5ee7abb421c65d2cf5e503909215 merged a PR that renamed
Offer::signing_pubkey to Offer::issuer_signing_pubkey. However, there was a
silent rebase conflict and a test added as part of
1059f5ffc55d3c21bf4d3ae82fe185f588a53116 did not get the memo and used the old
method name, breaking the test build.

3 months agoMerge pull request #3319 from tnull/2024-09-rustfmt-sync
Matt Corallo [Tue, 17 Sep 2024 19:37:51 +0000 (19:37 +0000)]
Merge pull request #3319 from tnull/2024-09-rustfmt-sync

`rustfmt`: Run on `lightning/src/sync/*`

3 months agoMerge pull request #3313 from valentinewallace/2024-09-fix-offer-double-pay
Matt Corallo [Tue, 17 Sep 2024 17:38:04 +0000 (17:38 +0000)]
Merge pull request #3313 from valentinewallace/2024-09-fix-offer-double-pay

Don't pay a duplicate BOLT 12 invoice if `ChannelManager` is stale

3 months agoMerge pull request #3218 from jkczyz/2024-07-offers-spec-update
Matt Corallo [Tue, 17 Sep 2024 14:01:43 +0000 (14:01 +0000)]
Merge pull request #3218 from jkczyz/2024-07-offers-spec-update

Rename `Offer::signing_pubkey` to `Offer::issuer_id`

3 months agoFix bug where we double-pay an offer due to stale manager
Valentine Wallace [Mon, 16 Sep 2024 16:26:16 +0000 (12:26 -0400)]
Fix bug where we double-pay an offer due to stale manager

This fixes the following bug:
- An outbound payment is AwaitingInvoice
- We receive an invoice and lock the HTLCs into the relevant ChannelMonitors
- The monitors are successfully persisted, but the ChannelManager fails to
  persist, so the outbound payment remains AwaitingInvoice
- We restart, causing the channels to close due to a stale ChannelManager
- We receive a duplicate invoice, and attempt to pay it again due to the
  payment still being AwaitingInvoice in the stale ChannelManager

After the fix for this, we will notice that the payment is already locked into
the monitor on startup and transition the incorrectly-AwaitingInvoice payment
to Retryable, which prevents double-paying on duplicate invoice receipt.

3 months ago`rustfmt`: Drop `sync/mod.rs` from exclusion list
Elias Rohrer [Tue, 17 Sep 2024 11:07:52 +0000 (13:07 +0200)]
`rustfmt`: Drop `sync/mod.rs` from exclusion list

3 months ago`rustfmt`: Run on `sync/mod.rs`
Elias Rohrer [Tue, 17 Sep 2024 11:07:28 +0000 (13:07 +0200)]
`rustfmt`: Run on `sync/mod.rs`

3 months ago`rustfmt`: Drop `sync/test_lockorder_checks.rs` from exclusion list
Elias Rohrer [Tue, 17 Sep 2024 11:06:51 +0000 (13:06 +0200)]
`rustfmt`: Drop `sync/test_lockorder_checks.rs` from exclusion list

3 months ago`rustfmt`: Run on `sync/test_lockorder_checks.rs`
Elias Rohrer [Tue, 17 Sep 2024 11:06:29 +0000 (13:06 +0200)]
`rustfmt`: Run on `sync/test_lockorder_checks.rs`

3 months ago`rustfmt`: Drop `sync/nostd_sync.rs` from exclusion list
Elias Rohrer [Tue, 17 Sep 2024 11:06:00 +0000 (13:06 +0200)]
`rustfmt`: Drop `sync/nostd_sync.rs` from exclusion list

3 months ago`rustfmt`: Run on `sync/nostd_sync.rs`
Elias Rohrer [Tue, 17 Sep 2024 11:05:40 +0000 (13:05 +0200)]
`rustfmt`: Run on `sync/nostd_sync.rs`

3 months ago`rustfmt`: Drop `sync/fairrwlock.rs` from exclusion list
Elias Rohrer [Tue, 17 Sep 2024 11:04:55 +0000 (13:04 +0200)]
`rustfmt`: Drop `sync/fairrwlock.rs` from exclusion list

3 months ago`rustfmt`: Run on `sync/fairrwlock.rs`
Elias Rohrer [Tue, 17 Sep 2024 11:04:35 +0000 (13:04 +0200)]
`rustfmt`: Run on `sync/fairrwlock.rs`

3 months ago`rustfmt`: Drop `sync/debug_sync.rs` from exclusion list
Elias Rohrer [Tue, 17 Sep 2024 11:03:59 +0000 (13:03 +0200)]
`rustfmt`: Drop `sync/debug_sync.rs` from exclusion list

3 months ago`rustfmt`: Run on `sync/debug_sync.rs`
Elias Rohrer [Tue, 17 Sep 2024 11:03:25 +0000 (13:03 +0200)]
`rustfmt`: Run on `sync/debug_sync.rs`

3 months agoRename Refund::payer_id
Jeffrey Czyz [Wed, 14 Aug 2024 20:36:18 +0000 (15:36 -0500)]
Rename Refund::payer_id

For consistency with Offer::issuer_signing_pubkey, rename
Refund::payer_id to use "signing_pubkey" instead of "id".

3 months agoRename InvoiceRequest::payer_id
Jeffrey Czyz [Wed, 14 Aug 2024 20:33:28 +0000 (15:33 -0500)]
Rename InvoiceRequest::payer_id

For consistency with Offer::issuer_signing_pubkey, rename
InvoiceRequest::payer_id to use "signing_pubkey" instead of "id".

3 months agoUpdate offer test vectors from latest spec changes
Jeffrey Czyz [Thu, 1 Aug 2024 22:46:53 +0000 (17:46 -0500)]
Update offer test vectors from latest spec changes

3 months agoUse unsigned invoice types in docs
Jeffrey Czyz [Thu, 8 Aug 2024 17:36:48 +0000 (12:36 -0500)]
Use unsigned invoice types in docs

3 months agoAdd issuer_signing_pubkey to Bolt12Invoice
Jeffrey Czyz [Thu, 1 Aug 2024 22:25:44 +0000 (17:25 -0500)]
Add issuer_signing_pubkey to Bolt12Invoice

Useful for determining if the signing_pubkey is the
issuer_signing_pubkey or is from a blinded path.

3 months agoRe-write Offer::issuer_signing_pubkey documentation
Jeffrey Czyz [Thu, 1 Aug 2024 22:25:14 +0000 (17:25 -0500)]
Re-write Offer::issuer_signing_pubkey documentation

3 months agoRename Offer::signing_pubkey to Offer::issuer_signing_pubkey
Jeffrey Czyz [Thu, 1 Aug 2024 15:56:51 +0000 (10:56 -0500)]
Rename Offer::signing_pubkey to Offer::issuer_signing_pubkey

The spec was recently changed to use offer_issuer_id instead of
offer_node_id. LDK always used signing_pubkey to avoid confusion with a
node_id. Rename it to issuer_signing_pubkey now as InvoiceRequest and
Bolt12Invoice will have similarly named methods in upcoming commits.

3 months agoMove monitor<>outbound_payments startup htlc syncing code.
Valentine Wallace [Mon, 16 Sep 2024 16:11:59 +0000 (12:11 -0400)]
Move monitor<>outbound_payments startup htlc syncing code.

Move the code that ensures that HTLCs locked into ChannelMonitors are
synchronized with the ChannelManager's OutboundPayments store to the
outbound_payments module.

This is useful both because ChannelManager::read is very long/confusing method,
so it's nice to encapsulate some of its functionality, and because we need to
fix an existing bug in this logic where we may risk double-paying an offer due
to outbound_payments being stale on startup. See the next commit for this
bugfix.

3 months agoTest utils: use full import path in reload_node macro.
Valentine Wallace [Thu, 12 Sep 2024 17:18:03 +0000 (13:18 -0400)]
Test utils: use full import path in reload_node macro.

3 months agoMerge pull request #3315 from tnull/2024-09-rustfmt-crypto
Matt Corallo [Mon, 16 Sep 2024 15:02:46 +0000 (15:02 +0000)]
Merge pull request #3315 from tnull/2024-09-rustfmt-crypto

`rustfmt`: Run on `crypto` module

3 months ago`rustfmt`: Drop `crypto/mod.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:29:54 +0000 (12:29 +0200)]
`rustfmt`: Drop `crypto/mod.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/mod.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:29:35 +0000 (12:29 +0200)]
`rustfmt`: Run on `crypto/mod.rs`

3 months ago`rustfmt`: Drop `crypto/utils.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:29:15 +0000 (12:29 +0200)]
`rustfmt`: Drop `crypto/utils.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/utils.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:28:41 +0000 (12:28 +0200)]
`rustfmt`: Run on `crypto/utils.rs`

3 months ago`rustfmt`: Drop `crypto/streams.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:28:09 +0000 (12:28 +0200)]
`rustfmt`: Drop `crypto/streams.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/streams.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:27:34 +0000 (12:27 +0200)]
`rustfmt`: Run on `crypto/streams.rs`

3 months ago`rustfmt`: Drop `crypto/poly1305.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:27:00 +0000 (12:27 +0200)]
`rustfmt`: Drop `crypto/poly1305.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/poly1305.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:26:29 +0000 (12:26 +0200)]
`rustfmt`: Run on `crypto/poly1305.rs`

3 months ago`rustfmt`: Drop `crypto/chacha20poly1305.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:24:26 +0000 (12:24 +0200)]
`rustfmt`: Drop `crypto/chacha20poly1305.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/chacha20poly1305rfc.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:24:00 +0000 (12:24 +0200)]
`rustfmt`: Run on `crypto/chacha20poly1305rfc.rs`

3 months ago`rustfmt`: Drop `crypto/chacha20.rs` from exclusion list
Elias Rohrer [Mon, 16 Sep 2024 10:23:09 +0000 (12:23 +0200)]
`rustfmt`: Drop `crypto/chacha20.rs` from exclusion list

3 months ago`rustfmt`: Run on `crypto/chacha20.rs`
Elias Rohrer [Mon, 16 Sep 2024 10:22:48 +0000 (12:22 +0200)]
`rustfmt`: Run on `crypto/chacha20.rs`

3 months agoMerge pull request #3314 from G8XSU/event-logging
Elias Rohrer [Mon, 16 Sep 2024 09:14:27 +0000 (11:14 +0200)]
Merge pull request #3314 from G8XSU/event-logging

Add logging around event processing.

3 months agoMerge pull request #3140 from valentinewallace/2024-06-pay-static-invoice
Matt Corallo [Sun, 15 Sep 2024 16:58:46 +0000 (16:58 +0000)]
Merge pull request #3140 from valentinewallace/2024-06-pay-static-invoice

Support paying static invoices

3 months agoAdd logging around event processing.
G8XSU [Fri, 13 Sep 2024 18:30:49 +0000 (11:30 -0700)]
Add logging around event processing.

Currently we don't have any visibility if BackgroundProcessor
takes considerably more of time to process events, adding logs
to help debug such issues.

3 months agoRemove payment_release_secret from async payments messages.
Valentine Wallace [Wed, 11 Sep 2024 14:20:58 +0000 (10:20 -0400)]
Remove payment_release_secret from async payments messages.

This field isn't necessary because we already authenticate the messages via the
blinded reply paths payment_id, nonce and HMAC.

3 months agoDocument PendingOutboundPayment::{Static}InvoiceReceived semantics.
Valentine Wallace [Tue, 10 Sep 2024 22:50:04 +0000 (18:50 -0400)]
Document PendingOutboundPayment::{Static}InvoiceReceived semantics.

While these variants may sound similar, they are very different. One is so
temporary it's never even persisted to disk, the other is a state we will stay
in for hours or days. See added docs for more info.

3 months agoAdd new Bolt12PaymentError for failed blinded path creation.
Valentine Wallace [Fri, 6 Sep 2024 19:28:43 +0000 (15:28 -0400)]
Add new Bolt12PaymentError for failed blinded path creation.

Currently used when initiating an async payment via held_htlc_available OM. This
OM needs a reply path back to us, so use this error for our invoice_error OM if
we fail to create said reply path.

3 months agoVerify inbound ReleaseHeldHtlc messages via hmac.
Valentine Wallace [Thu, 5 Sep 2024 21:32:08 +0000 (17:32 -0400)]
Verify inbound ReleaseHeldHtlc messages via hmac.

See AsyncPaymentsContext::hmac, but this prevents the recipient from
deanonymizing us. Without this, if they are able to guess the correct payment
id, then they could create a blinded path to us and confirm our identity.

We also move the PAYMENT_HASH_HMAC_INPUT const to use &[7; 16], which is safe
because this const was added since the last release. This ordering reads more
smoothly.

3 months agoRename Payment{Hash,Id} hmac creation/verification methods for offers.
Valentine Wallace [Thu, 5 Sep 2024 20:40:51 +0000 (16:40 -0400)]
Rename Payment{Hash,Id} hmac creation/verification methods for offers.

We want to specify that these methods are only to be used in an outbound offers
payment context, because we'll be adding similar methods for the outbound async
payments context in upcoming commits.

3 months agoDon't trigger manager persistence on unexpected release_htlc message.
Valentine Wallace [Thu, 29 Aug 2024 19:37:24 +0000 (15:37 -0400)]
Don't trigger manager persistence on unexpected release_htlc message.

If someone sends us an unexpected or duplicate release_held_htlc onion message,
we should simply ignore it and not persist the entire ChannelManager in
response.

3 months agoCorrect docs on payment id in RecentPaymentDetails.
Valentine Wallace [Tue, 20 Aug 2024 19:45:24 +0000 (15:45 -0400)]
Correct docs on payment id in RecentPaymentDetails.

3 months agoSupport abandoning pending outbound async payments.
Valentine Wallace [Thu, 20 Jun 2024 20:28:36 +0000 (16:28 -0400)]
Support abandoning pending outbound async payments.

Async payments may have very high expires because we may be waiting for days
for the recipient to come online, so it's important that users be able to
abandon these payments early if needed.

3 months agoTimeout expired outbound async payments.
Valentine Wallace [Thu, 20 Jun 2024 19:21:20 +0000 (15:21 -0400)]
Timeout expired outbound async payments.

3 months agoSupport sending async payments as an always-online sender.
Valentine Wallace [Wed, 4 Sep 2024 19:24:26 +0000 (15:24 -0400)]
Support sending async payments as an always-online sender.

Async receive is not yet supported.

Here we process inbound release_htlc onion messages, check that they actually
correspond to one of our outbound payments, and actually forward the HTLCs.
Valid release_htlc receipt indicates that the recipient has now come online to
receive.

3 months agoSplit off send_payment_for_bolt12_invoice_internal util.
Valentine Wallace [Wed, 4 Sep 2024 19:00:38 +0000 (15:00 -0400)]
Split off send_payment_for_bolt12_invoice_internal util.

This new util will be able to send to both static and non-static BOLT 12
invoices.

3 months agoSet max path len on receipt of static invoice.
Valentine Wallace [Thu, 29 Aug 2024 19:12:41 +0000 (15:12 -0400)]
Set max path len on receipt of static invoice.

Because we may receive a static invoice to pay days before the recipient
actually comes back online to receive the payment, it's good to do as many
checks as we can up-front. Here we ensure that the blinded paths provided
in the invoice won't cause us to exceed the maximum onion packet size.

3 months agoError on static invoice with unknown required features.
Valentine Wallace [Thu, 29 Aug 2024 19:00:08 +0000 (15:00 -0400)]
Error on static invoice with unknown required features.

3 months agoDRY handling when initiating payment to BOLT 12 invoice.
Valentine Wallace [Thu, 29 Aug 2024 18:53:12 +0000 (14:53 -0400)]
DRY handling when initiating payment to BOLT 12 invoice.

3 months agoSupport initiating an async payment to a static invoice.
Valentine Wallace [Thu, 29 Aug 2024 18:37:45 +0000 (14:37 -0400)]
Support initiating an async payment to a static invoice.

Supported when the sender is an always-online node. Here we send the initial
held_htlc_available onion message upon receipt of a static invoice, next we'll
need to actually send HTLCs upon getting a response to said OM.

3 months agoRelease pending async payments to PeerManager.
Valentine Wallace [Thu, 29 Aug 2024 18:25:40 +0000 (14:25 -0400)]
Release pending async payments to PeerManager.

3 months agoPass full message context into ChanMan blinded path util.
Valentine Wallace [Wed, 10 Jul 2024 18:58:11 +0000 (14:58 -0400)]
Pass full message context into ChanMan blinded path util.

Allows us to repurpose this util to create blinded paths in an async payments
message context while maintaining support for the offers context.

3 months agoStore async payment data in PendingOutboundPayment.
Valentine Wallace [Wed, 10 Jul 2024 18:55:34 +0000 (14:55 -0400)]
Store async payment data in PendingOutboundPayment.

Adds a pending outbound payment variant for async payments, which indicates
that we have received a static invoice to pay and have generated a keysend preimage
for the eventual payment. When the recipient comes back online, we'll
transition from this new state to Retryable and actually forward the HTLCs.

3 months agoSupport creating PaymentParameters from static invoices.
Valentine Wallace [Thu, 13 Jun 2024 21:12:03 +0000 (17:12 -0400)]
Support creating PaymentParameters from static invoices.

3 months agoSupport checking that a static invoice matches an outbound invreq.
Valentine Wallace [Thu, 13 Jun 2024 20:16:47 +0000 (16:16 -0400)]
Support checking that a static invoice matches an outbound invreq.

Useful for ensuring that an inbound static invoice matches one of our outbound
invreqs, otherwise it is an unexpected invoice and should be ignored and not
paid.

3 months agoMerge pull request #3243 from dunxen/2024-08-reremove-balancemsat
Matt Corallo [Fri, 13 Sep 2024 14:09:17 +0000 (14:09 +0000)]
Merge pull request #3243 from dunxen/2024-08-reremove-balancemsat

Remove AvailableBalances::balance_msat

3 months agoMerge pull request #3302 from TheBlueMatt/2024-09-atomic-cleanups
Elias Rohrer [Thu, 12 Sep 2024 16:48:09 +0000 (18:48 +0200)]
Merge pull request #3302 from TheBlueMatt/2024-09-atomic-cleanups

Simplify and fix AtomicCounter

3 months agoStore AsyncPaymentsMessages for later sending
Valentine Wallace [Thu, 13 Jun 2024 15:25:20 +0000 (11:25 -0400)]
Store AsyncPaymentsMessages for later sending

Upcoming commits will support sending and receiving held_htlc_available and
release_held_htlc messages. These messages need to be enqueued so that they can
be released in ChannelManager's implementation of AsyncPaymentsMessageHandler
to OnionMessenger for sending.

3 months agoPass context into held_htlc_available message handling.
Valentine Wallace [Wed, 10 Jul 2024 17:58:53 +0000 (13:58 -0400)]
Pass context into held_htlc_available message handling.

Useful for using the payment_id within to look up the corresponding outbound
async payment so we know we can safely release the HTLCs to the now-onlinen
recipient.

3 months agoAdd MessageContext for async payments.
Valentine Wallace [Wed, 10 Jul 2024 17:54:05 +0000 (13:54 -0400)]
Add MessageContext for async payments.

This context will be used in reply paths for outbound held_htlc_available
messages, so we can authenticate the corresponding release_held_htlc messages.

3 months agoTweak debug_assert message for parsed onion messages.
Valentine Wallace [Fri, 12 Jul 2024 20:19:53 +0000 (16:19 -0400)]
Tweak debug_assert message for parsed onion messages.

More specific.

3 months agoMerge pull request #3010 from shaavan/issue2836
Matt Corallo [Thu, 12 Sep 2024 15:12:39 +0000 (15:12 +0000)]
Merge pull request #3010 from shaavan/issue2836

Introduce Retry InvoiceRequest Flow

3 months agoRename `AtomicCounter::get_increment` to simply `next` 2024-09-atomic-cleanups
Matt Corallo [Mon, 9 Sep 2024 13:42:54 +0000 (13:42 +0000)]
Rename `AtomicCounter::get_increment` to simply `next`

Its a counter, `next` is super clear, `get_increment` is a bit
less so.

3 months agoSimplify and fix `AtomicCounter`
Matt Corallo [Sun, 8 Sep 2024 19:05:28 +0000 (19:05 +0000)]
Simplify and fix `AtomicCounter`

`AtomicCounter` was slightly race-y on 32-bit platforms because it
increments the high `AtomicUsize` independently from the low
`AtomicUsize`, leading to a potential race where another thread
could observe the low increment but not the high increment and see
a value of 0 twice.

This isn't a big deal because (a) most platforms are 64-bit these
days, (b) 32-bit platforms aren't super likely to have their
counter overflow 32 bits anyway, and (c) the two writes are
back-to-back so having another thread read during that window is
very unlikely.

However, we can also optimize the counter somewhat by using the
`target_has_atomic = "64"` cfg flag, which we do here, allowing us
to use `AtomicU64` even on 32-bit platforms where 64-bit atomics
are available.

This changes some test behavior slightly, which requires
adaptation.

Fixes #3000

3 months agoIntroduce handle_message_received test
shaavan [Thu, 11 Jul 2024 14:55:32 +0000 (20:25 +0530)]
Introduce handle_message_received test

- Add a test to verify the functionality of the handle_message_received
  function.
- Ensure the test covers scenarios where InvoiceRequest messages are retried
  for PendingOutboundPayments after a simulated connection loss.

3 months agoIntroduce message_received in ChannelMessageHandler
shaavan [Mon, 10 Jun 2024 11:46:08 +0000 (17:16 +0530)]
Introduce message_received in ChannelMessageHandler

- Introduce the `message_received` function to manage the
  behavior when a message is received from any peer.
- This function is used within `ChannelManager` to retry `InvoiceRequest`
  messages if we haven't received the corresponding invoice yet.
- This change makes the offer communication robust against sudden
  connection drops where the initial attempt to send the message
  might have failed.

3 months agoIntroduce enqueue_invoice_request Function
shaavan [Thu, 25 Jul 2024 10:09:26 +0000 (15:39 +0530)]
Introduce enqueue_invoice_request Function

1. Separate the logic of forming `invoice_request` messages from
   `invoice_request` and `reply_paths` and enqueueing them into a
   separate function.
2. This logic will be reused in the following commit when reforming
   `invoice_request` messages for retrying.

3 months agoIntroduce RetryableInvoiceRequest in AwaitingInvoice
shaavan [Mon, 10 Jun 2024 11:52:09 +0000 (17:22 +0530)]
Introduce RetryableInvoiceRequest in AwaitingInvoice

1. To enable the retry of the Invoice Request message, it's necessary
   to store the essential data required to recreate the message.
2. A new struct is introduced to manage this data, ensuring the
   InvoiceRequest message can be reliably recreated for retries.
3. The addition of an `awaiting_invoice` flag allows tracking of
   retryable invoice requests, preventing the need to lock the
   `pending_outbound_payment` mutex.

3 months agoRefactor `channel_update` processing logic into local fns
Matt Corallo [Wed, 11 Sep 2024 23:29:07 +0000 (23:29 +0000)]
Refactor `channel_update` processing logic into local fns

In the next commit we'll move to checking `channel_update`s in
three steps - first we check if the `channel_update` is new and the
latest for a channel, then we check the signature, and finally we
update our local state. This allows us to avoid holding a lock on
`NetworkGraph::channels` while validating the message signature.

Here we do a quick prefactor to make that simpler - moving the
validation logic of `channel_update` that we'll do in step one (and
repeat in step three) into a local function. We also take this
opportunity to do one static check unlocked which we had been doing
while holding a `channel` lock.

3 months agoMerge pull request #3291 from tnull/2024-09-add-their-node-id-routing-msg-handler
Matt Corallo [Wed, 11 Sep 2024 22:25:41 +0000 (22:25 +0000)]
Merge pull request #3291 from tnull/2024-09-add-their-node-id-routing-msg-handler

Add node id to remaining `RoutingMessageHandler::handle_` methods

3 months agoMerge pull request #3163 from shaavan/invoice_reply_path
Matt Corallo [Wed, 11 Sep 2024 20:17:54 +0000 (20:17 +0000)]
Merge pull request #3163 from shaavan/invoice_reply_path

Introduce Reply Paths for BOLT12 Invoice in Offers Flow.

3 months agoDon't rely on route-fetching rand in `blinded_path_with_custom_tlv`
Matt Corallo [Sun, 8 Sep 2024 20:13:40 +0000 (20:13 +0000)]
Don't rely on route-fetching rand in `blinded_path_with_custom_tlv`

`blinded_path_with_custom_tlv` indirectly relied on route CLTV
randomization when sending because nodes were at substantially
different block heights after setup. Instead we make sure all nodes
are at the same height which makes the test more robust.

3 months agoDrop `Debug` on `InMemorySigner` (and `EntropySource`)
Matt Corallo [Wed, 11 Sep 2024 20:00:26 +0000 (20:00 +0000)]
Drop `Debug` on `InMemorySigner` (and `EntropySource`)

`InMemorySigner` has various private keys in it which makes
`Debug` either useless or dangerous (because most keys won't log
anything, but if they did we'd risk logging private key material).

3 months agoRefactor: Take `their_node_id` by value across all handler interfaces
Elias Rohrer [Wed, 11 Sep 2024 14:06:44 +0000 (16:06 +0200)]
Refactor: Take `their_node_id` by value across all handler interfaces

In order to maintain interface consistency, we refactor all message
handler interfaces to take `PublicKey` rather than `&PublicKey`, as the
difference in efficiency should be negigible and the former is easier to
handle in binding languages.

Over time, we also want to move (no pun intended) towards all messaging
interfaces using move semantics, so dropping the reference for
`PublicKey` is the first step in this direction.

3 months agoAdd node id to remaining `RoutingMessageHandler::handle_` methods
Elias Rohrer [Wed, 4 Sep 2024 13:39:20 +0000 (15:39 +0200)]
Add node id to remaining `RoutingMessageHandler::handle_` methods

Previously, some `RoutingMessageHandler::handle_` methods (in particular
the ones handling node and channel announcements, as well as channel
updates, omitted the `their_node_id` argument. This didn't allow
implementors to discern *who* sent a particular method.

Here, we add `their_node_id: Option<&PublicKey>` to have them learn who
sent a message, and set `None` if our own node it the originator of a
broadcast operation.

3 months agoUpdate Offers Test to Verify BOLT12 Invoice Reply Paths
shaavan [Thu, 29 Aug 2024 11:36:18 +0000 (17:06 +0530)]
Update Offers Test to Verify BOLT12 Invoice Reply Paths

1. Updated the Offers Test to check the reply paths in BOLT12 Invoices.
2. Changed the `extract_invoice` return type from `Option<BlindedMessagePath>`
   to `BlindedMessagePath` since all BOLT12Invoices now have a corresponding
   reply path by default.

3 months agoAdd reply_path to BOLT12Invoices in Offers Flow
shaavan [Fri, 6 Sep 2024 12:21:37 +0000 (17:51 +0530)]
Add reply_path to BOLT12Invoices in Offers Flow

1. Introduced reply_path in BOLT12Invoices to address a gap in error handling.
   Previously, if a BOLT12Invoice sent in the offers flow generated an Invoice Error,
   the payer had no way to send this error back to the payee.
2. By adding a reply_path to the Invoice Message, the payer can now communicate
   any errors back to the payee, ensuring better error handling and communication
   within the offers flow.