Commit graph

5340 commits

Author SHA1 Message Date
Jeffrey Czyz
6a708e2d9f
Test verification with experimental offer TLVs
Offer metadata is generated from the offer TLVs and should included
those in the experimental range. When verifying invoice request and
invoice messages, these TLVs must be included. Similarly, OfferId
construction should included these TLVs as well. Modify the BOLT12
verification tests to cover these TLVs.
2024-11-04 18:00:23 -06:00
Jeffrey Czyz
e01e731ff7
Parse experimental offer TLV records
The BOLT12 spec defines an experimental TLV range that are allowed in
offer messages. Allow this range when parsing an offer and include those
bytes in any invoice requests. Also include those bytes when computing
an OfferId and verifying that an InvoiceRequest is for a valid Offer.
2024-11-04 18:00:23 -06:00
Jeffrey Czyz
38e9457d97
Remove unnecessary destructure 2024-11-04 18:00:22 -06:00
Jeffrey Czyz
bcc7c1dc1d
Include experimental TLV records when verifying
Upcoming commits will allow parsing BOLT12 messages that include TLV
records in the experimental range. Include these ranges when verifying
messages since they will be included in the message bytes.
2024-11-04 18:00:22 -06:00
Jeffrey Czyz
63c687f0d9
Pass bytes instead of TlvStream to verify
Passing bytes directly to InvoiceContents::verify improves readability
as then a TlvStream for each TLV record range can be created from the
bytes instead of needing to clone the TlvStream upfront. In an upcoming
commit, the experimental TLV record range will utilize this.
2024-11-04 18:00:22 -06:00
Jeffrey Czyz
1eb5baa00c
Function for iterating over Offer TLV records
Add a utility function for iterating over Offer TLV records contained in
any valid TLV stream bytes. Using a common function ensures that
experimental TLV records are included once they are supported.
2024-11-04 18:00:22 -06:00
Jeffrey Czyz
771aa8ee24
Separate bytes for experimental TLVs
When constructing UnsignedInvoiceRequest or UnsignedBolt12Invoice, use a
separate field for experimental TLV bytes. This allows for properly
inserting the signature TLVs before the experimental TLVs when signing.
2024-11-04 18:00:15 -06:00
Jeffrey Czyz
e23f89ce43
Remove unneeded Eq and PartialEq derives
TlvRecord has a few fields, but comparing only the record_bytes is
sufficient for equality since the other fields are initialized from it.
Remove the Eq and PartialEq derives as they compare these other fields.
2024-10-29 18:31:43 -05:00
Jeffrey Czyz
a77300129c
Add optional lifetime to tlv_stream macro
Using the tlv_stream macro without a type needing a reference results in
a compilation error because of an unused lifetime parameter. To avoid
this, add an optional lifetime parameter to the macro. This allows for
experimental TLVs, which will be empty initially, and TLVs of entirely
primitive types.
2024-10-29 18:31:43 -05:00
Jeffrey Czyz
bbdd8738a8
Add parsing tests for unknown BOLT12 TLVs 2024-10-29 18:31:43 -05:00
Matt Corallo
605952cefd
Merge pull request #3301 from dunxen/2024-9-fixnevertypefallback
Add an explicit_type TLV syntax for avoiding certain cases of type inference
2024-10-02 14:29:09 +00:00
Duncan Dean
c0d84e85c7
Add an explicit_type TLV syntax for avoiding certain cases of type inference
This new syntax is used to fix "dependency on fallback of ! -> ()".
This avoids cases where code compiles with a fallback of the
never type leading to the unit type. The behaviour in Rust edition 2024
would make this a compile error.

See: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/builtin/static.DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK.html#
2024-10-02 13:08:04 +02:00
Matt Corallo
4147de2cf0
Merge pull request #3324 from tnull/2024-09-rustfmt-util-1
`rustfmt`: Run on `util/*` (1/2)
2024-10-01 15:33:17 +00:00
Matt Corallo
c7627dfd61
Merge pull request #3311 from TheBlueMatt/2024-09-3010-followups
Quick #3010 followups
2024-09-30 21:21:20 +00:00
Matt Corallo
d156b2e30e Call ChannelMessageHandler::message_received without peer lock
While `message_received` purports to be called on every message,
prior to the message, doing so on `Init` messages means we have to
call `message_received` while holding the per-peer mutex, which
can cause some lock contention.

Instead, here, we call `message_received` after processing `Init`
messages (which is probably more useful anyway - the peer isn't
really "connected" until we've processed the `Init` messages),
allowing us to call it unlocked.
2024-09-30 18:57:52 +00:00
Matt Corallo
b8695b0c83 Check that we aren't reading a second message in BOLT 12 retry test
`creates_and_pays_for_offer_with_retry` intends to check that we
re-send a BOLT 12 `invoice_request` in response to a
`message_received` call, but doesn't actually test that there were
no messages in the outbound buffer after the initial send, which we
do here.
2024-09-30 18:57:52 +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
Elias Rohrer
7e276f2c32
rustfmt: Run on util/persist.rs 2024-09-19 10:09:22 +02:00
Elias Rohrer
873b35a328
rustfmt: Prepare util/persist.rs 2024-09-19 10:09:19 +02:00
Elias Rohrer
c1495effae
rustfmt: Run on util/message_signing.rs 2024-09-19 09:40:37 +02:00
Elias Rohrer
77536453e2
rustfmt: Run on util/macro_logger.rs 2024-09-19 09:40:23 +02:00
Elias Rohrer
9c6c9abb0e
rustfmt: Run on util/logger.rs 2024-09-19 09:34:17 +02:00
Elias Rohrer
f26001f2ea
rustfmt: Run on util/indexed_map.rs 2024-09-19 09:33:57 +02:00
Elias Rohrer
8fb3c3f16e
rustfmt: Run on util/fuzz_wrappers.rs 2024-09-19 09:33:34 +02:00
Elias Rohrer
32b55bb85d
rustfmt: Run on util/errors.rs 2024-09-19 09:33:13 +02:00
Elias Rohrer
fff097a476
rustfmt: Run on util/config.rs 2024-09-19 09:32:38 +02:00
Elias Rohrer
8e506301ca
rustfmt: Run on util/byte_utils.rs 2024-09-19 09:32:24 +02:00
Elias Rohrer
8e2c0e22de
rustfmt: Run on util/base32.rs 2024-09-19 09:31:49 +02:00
Elias Rohrer
95fd1f7bc7
rustfmt: Run on util/atomic_counter.rs 2024-09-19 09:31:21 +02: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