Commit graph

5315 commits

Author SHA1 Message Date
Matt Corallo
ebde296abd Parse and handle DNSResolverMessages in OnionMessenger
This adds the requisite message parsing and handling code for the
new DNSSEC messages to `OnionMessenger`.
2024-09-30 16:19:33 +00:00
Matt Corallo
1cf0393056 Add DNS(SEC) query and proof messages and onion message handler
This creates the initial DNSSEC proof and query messages in a new
module in `onion_message`, as well as a new message handler to
handle them.

In the coming commits, a default implementation will be added which
verifies DNSSEC proofs which can be used to resolve BIP 353 URIs
without relying on anything outside of the lightning network.
2024-09-30 16:19:31 +00:00
Matt Corallo
151a8a1aaf Add a MessageContext::DNSResolution to protect against probing
When we make a DNSSEC query with a reply path, we don't want to
allow the DNS resolver to attempt to respond to various nodes to
try to detect (through timining or other analysis) whether we were
the one who made the query. Thus, we need to include a nonce in the
context in our reply path, which we set up here by creating a new
context type for DNS resolutions.
2024-09-30 16:19:31 +00:00
Matt Corallo
bc5213dfef Minor gossip.rs rustfmt cleanups
Just a few minor updates to `gossip.rs` to reduce code verticality
and simplify things a bit.
2024-09-26 06:45:50 +00:00
Elias Rohrer
22b82d36e2
rustfmt: Run on routing/gossip.rs 2024-09-24 13:51:52 +09:00
Elias Rohrer
a0d0f02ed0
Merge pull request #3303 from TheBlueMatt/2024-09-inbound-payment-id
Add a `PaymentId` for inbound payments
2024-09-24 13:38:16 +09:00
Matt Corallo
23109b66e9
Merge pull request #3310 from TheBlueMatt/2024-09-unlocked-checksig
Validate `channel_update` signatures without holding a graph lock
2024-09-24 03:13:51 +00:00
Matt Corallo
131849f383 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.
2024-09-23 03:48:29 +00:00
Jeffrey Czyz
cad09855bf
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.
2024-09-23 12:22:01 +09:00
Jeffrey Czyz
bde331fe94
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.
2024-09-23 12:22:00 +09:00
Jeffrey Czyz
04c51b380d
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.
2024-09-23 12:21:35 +09:00
Matt Corallo
aaf529d193 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.
2024-09-23 01:24:28 +00:00
Matt Corallo
aa09c33a17 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.
2024-09-23 01:24:28 +00:00
Matt Corallo
803366a41a 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.
2024-09-23 01:24:28 +00:00
Matt Corallo
cdd1298a38
Merge pull request #3289 from tnull/2024-09-fix-rgs-bp-builds
Fix builds of `lightning-rapid-gossip-sync` and `lightning-background-processor` crates
2024-09-18 14:31:18 +00:00
Elias Rohrer
545b037827
Drop no-std feature
We drop the `lightning/no-std` feature and just take
`hashbrown`,`possiblyrandom` and `libm` as required dependencies.
2024-09-18 09:07:58 +02:00
Valentine Wallace
487d6a09a7
Fix silent rebase conflict that broke tests
429cbe1a06 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
1059f5ffc5 did not get the memo and used the old
method name, breaking the test build.
2024-09-17 17:24:42 -04:00
Matt Corallo
815d255aa8
Merge pull request #3319 from tnull/2024-09-rustfmt-sync
`rustfmt`: Run on `lightning/src/sync/*`
2024-09-17 19:37:51 +00:00
Matt Corallo
866cedf17a
Merge pull request #3313 from valentinewallace/2024-09-fix-offer-double-pay
Don't pay a duplicate BOLT 12 invoice if `ChannelManager` is stale
2024-09-17 17:38:04 +00:00
Valentine Wallace
fbb3ab2704
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.
2024-09-17 09:52:49 -04:00
Elias Rohrer
8746a80977
rustfmt: Run on sync/mod.rs 2024-09-17 13:07:28 +02:00
Elias Rohrer
6f1949b0d6
rustfmt: Run on sync/test_lockorder_checks.rs 2024-09-17 13:06:29 +02:00
Elias Rohrer
e3fb566e05
rustfmt: Run on sync/nostd_sync.rs 2024-09-17 13:05:40 +02:00
Elias Rohrer
2cb1664cf6
rustfmt: Run on sync/fairrwlock.rs 2024-09-17 13:04:35 +02:00
Elias Rohrer
9962e4b497
rustfmt: Run on sync/debug_sync.rs 2024-09-17 13:03:25 +02:00
Jeffrey Czyz
e11025f94d
Rename Refund::payer_id
For consistency with Offer::issuer_signing_pubkey, rename
Refund::payer_id to use "signing_pubkey" instead of "id".
2024-09-16 13:56:47 -05:00
Jeffrey Czyz
dd8f744257
Rename InvoiceRequest::payer_id
For consistency with Offer::issuer_signing_pubkey, rename
InvoiceRequest::payer_id to use "signing_pubkey" instead of "id".
2024-09-16 13:56:46 -05:00
Jeffrey Czyz
de29295bb4
Update offer test vectors from latest spec changes 2024-09-16 13:56:46 -05:00
Jeffrey Czyz
cfe84305cd
Use unsigned invoice types in docs 2024-09-16 13:56:46 -05:00
Jeffrey Czyz
a466f2e2f4
Add issuer_signing_pubkey to Bolt12Invoice
Useful for determining if the signing_pubkey is the
issuer_signing_pubkey or is from a blinded path.
2024-09-16 13:56:46 -05:00
Jeffrey Czyz
73512709e7
Re-write Offer::issuer_signing_pubkey documentation 2024-09-16 13:56:46 -05:00
Jeffrey Czyz
df58f26ada
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.
2024-09-16 13:56:41 -05:00
Valentine Wallace
3c2da4147c
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.
2024-09-16 13:34:03 -04:00
Valentine Wallace
8c356d8658
Test utils: use full import path in reload_node macro. 2024-09-16 13:34:03 -04:00
Elias Rohrer
802f5a65b4
rustfmt: Run on crypto/mod.rs 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
22d8beb529
rustfmt: Run on crypto/streams.rs 2024-09-16 12:38:51 +02:00
Elias Rohrer
bc8066bf9d
rustfmt: Run on crypto/poly1305.rs 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
03d8cff673
rustfmt: Run on crypto/chacha20.rs 2024-09-16 12:38:46 +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
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