Commit graph

7897 commits

Author SHA1 Message Date
Elias Rohrer
a161834f90
rustfmt: Drop sync/fairrwlock.rs from exclusion list 2024-09-17 13:04:55 +02:00
Elias Rohrer
2cb1664cf6
rustfmt: Run on sync/fairrwlock.rs 2024-09-17 13:04:35 +02:00
Elias Rohrer
edcdc565c4
rustfmt: Drop sync/debug_sync.rs from exclusion list 2024-09-17 13:03:59 +02:00
Elias Rohrer
9962e4b497
rustfmt: Run on sync/debug_sync.rs 2024-09-17 13:03:25 +02:00
Matt Corallo
6662c5c7b9
Merge pull request #3315 from tnull/2024-09-rustfmt-crypto
`rustfmt`: Run on `crypto` module
2024-09-16 15:02:46 +00:00
Elias Rohrer
ac0ff872d4
rustfmt: Drop crypto/mod.rs from exclusion list 2024-09-16 12:38:51 +02:00
Elias Rohrer
802f5a65b4
rustfmt: Run on crypto/mod.rs 2024-09-16 12:38:51 +02:00
Elias Rohrer
7f19150c46
rustfmt: Drop crypto/utils.rs from exclusion list 2024-09-16 12:38:51 +02:00
Elias Rohrer
3fea0c2cac
rustfmt: Run on crypto/utils.rs 2024-09-16 12:38:51 +02:00
Elias Rohrer
f042c999ef
rustfmt: Drop crypto/streams.rs from exclusion list 2024-09-16 12:38:51 +02:00
Elias Rohrer
22d8beb529
rustfmt: Run on crypto/streams.rs 2024-09-16 12:38:51 +02:00
Elias Rohrer
29bab11e09
rustfmt: Drop crypto/poly1305.rs from exclusion list 2024-09-16 12:38:50 +02:00
Elias Rohrer
bc8066bf9d
rustfmt: Run on crypto/poly1305.rs 2024-09-16 12:38:50 +02:00
Elias Rohrer
959746d680
rustfmt: Drop crypto/chacha20poly1305.rs from exclusion list 2024-09-16 12:38:50 +02:00
Elias Rohrer
93756a8d26
rustfmt: Run on crypto/chacha20poly1305rfc.rs 2024-09-16 12:38:50 +02:00
Elias Rohrer
a8aabce23c
rustfmt: Drop crypto/chacha20.rs from exclusion list 2024-09-16 12:38:50 +02:00
Elias Rohrer
03d8cff673
rustfmt: Run on crypto/chacha20.rs 2024-09-16 12:38:46 +02:00
Elias Rohrer
02973ea6b1
Merge pull request #3314 from G8XSU/event-logging
Add logging around event processing.
2024-09-16 11:14:27 +02:00
Matt Corallo
22146a98df
Merge pull request #3140 from valentinewallace/2024-06-pay-static-invoice
Support paying static invoices
2024-09-15 16:58:46 +00:00
G8XSU
85eb8145fb
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.
2024-09-13 14:02:49 -07:00
Valentine Wallace
6e27aecb40
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
4bcf53e597
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
26d1582c3b
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
615eefb543
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
5a7f52313b
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
c4f3e2567b
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
7dd178738d
Correct docs on payment id in RecentPaymentDetails. 2024-09-13 10:40:06 -04:00
Valentine Wallace
6d415b15c2
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
985e6ac14a
Timeout expired outbound async payments. 2024-09-13 10:40:06 -04:00
Valentine Wallace
0297a1e4ee
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
69356e7686
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
8569830eb0
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.
2024-09-13 10:40:06 -04:00
Valentine Wallace
e4d7681cba
Error on static invoice with unknown required features. 2024-09-13 10:40:06 -04:00
Valentine Wallace
28269a7879
DRY handling when initiating payment to BOLT 12 invoice. 2024-09-13 10:40:05 -04:00
Valentine Wallace
b6f44798fc
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.
2024-09-13 10:40:05 -04:00
Valentine Wallace
c976e4cd14
Release pending async payments to PeerManager. 2024-09-13 10:40:05 -04:00
Valentine Wallace
7fb16ea20c
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.
2024-09-13 10:40:05 -04:00
Valentine Wallace
c3ed4a2687
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.
2024-09-13 10:40:05 -04:00
Valentine Wallace
ad63a706f2
Support creating PaymentParameters from static invoices. 2024-09-13 10:40:05 -04:00
Valentine Wallace
cff6e344f5
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.
2024-09-13 10:40:03 -04:00
Matt Corallo
f7cc40e2e4
Merge pull request #3243 from dunxen/2024-08-reremove-balancemsat
Remove AvailableBalances::balance_msat
2024-09-13 14:09:17 +00:00
Elias Rohrer
a75fdaba3b
Merge pull request #3302 from TheBlueMatt/2024-09-atomic-cleanups
Simplify and fix AtomicCounter
2024-09-12 18:48:09 +02:00
Valentine Wallace
3d5d64a2c8
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.
2024-09-12 11:16:03 -04:00
Valentine Wallace
e162278bc8
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.
2024-09-12 11:16:03 -04:00
Valentine Wallace
a3216acb7d
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.
2024-09-12 11:16:03 -04:00
Valentine Wallace
732ee149bb
Tweak debug_assert message for parsed onion messages.
More specific.
2024-09-12 11:16:03 -04:00
Matt Corallo
1059f5ffc5
Merge pull request #3010 from shaavan/issue2836
Introduce Retry InvoiceRequest Flow
2024-09-12 15:12:39 +00:00
Matt Corallo
1c2bd097a8 Rename AtomicCounter::get_increment to simply next
Its a counter, `next` is super clear, `get_increment` is a bit
less so.
2024-09-12 14:32:43 +00:00
Matt Corallo
2ab133d432 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
2024-09-12 14:32:43 +00:00
shaavan
b1cd8874cf 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.
2024-09-12 18:56:48 +05:30