Commit graph

5087 commits

Author SHA1 Message Date
Alan Cohen
fcba0193ee
Fix README typo 2023-04-21 13:20:35 -04:00
Matt Corallo
9d5adfcd10
Merge pull request #2205 from wpaulino/sign-ecdsa-with-noncedata
Generate local signatures with additional randomness
2023-04-20 21:53:13 +00:00
Wilmer Paulino
86531e5ceb
Use new feature to gate test vectors behind
To match the local signatures found in test vectors, we must make sure
we don't use any additional randomess when generating signatures, as
we'll arrive at a different signature otherwise.
2023-04-20 12:14:28 -07:00
Wilmer Paulino
16edbd4196
Sign gossip messages without grinding low R signatures
Gossip messages always use signatures in their compact form, so grinding
for low R signatures is unnecessary.
2023-04-20 12:14:24 -07:00
Wilmer Paulino
78b967f5b0
Generate local signatures with additional randomness
Previously, our local signatures would always be deterministic, whether
we'd grind for low R value signatures or not. For peers supporting
SegWit, Bitcoin Core will generally use a transaction's witness-txid, as
opposed to its txid, to advertise transactions. Therefore, to ensure a
transaction has the best chance to propagate across node mempools in the
network, each of its broadcast attempts should have a unique/distinct
witness-txid, which we can achieve by introducing random nonce data when
generating local signatures, such that they are no longer deterministic.
2023-04-20 12:14:21 -07:00
Wilmer Paulino
2c5bd1c56f
Implement EntropySource for InMemorySigner
This allows the `InMemorySigner` to produce its own randomness, which we
plan to use when generating signatures in future work.

We can no longer derive `Clone` due to the `AtomicCounter`, so we opt to
implement it manually.
2023-04-20 12:14:19 -07:00
Matt Corallo
a7600dcd58
Merge pull request #2206 from jkczyz/2023-04-invoice-description
Expose description from Invoice's offer/refund
2023-04-20 18:18:28 +00:00
Jeffrey Czyz
42a772d675
Expose description from Invoice's offer/refund
This will allow clients like VLS to check the description for an invoice
as part of verification.
2023-04-20 08:41:07 -05:00
Matt Corallo
b8ed4d2608
Merge pull request #1989 from jkczyz/2023-01-stateless-offers
Stateless BOLT 12 message verification
2023-04-20 04:25:21 +00:00
Jeffrey Czyz
8afe694020
DRY up InvoiceFields construction 2023-04-19 21:31:08 -05:00
Jeffrey Czyz
c8a847ae11
Support responding to refunds with transient keys 2023-04-19 21:31:07 -05:00
Jeffrey Czyz
e1a6bc3cad
Extract keys from Offer::metadata to sign Invoice
For offers where the signing pubkey is derived, the keys need to be
extracted from the Offer::metadata in order to sign an invoice.
Parameterize InvoiceBuilder such that a build_and_sign method is
available for this situation.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
259aa9aac3
DRY up verification of invreq TLV records 2023-04-19 21:31:07 -05:00
Jeffrey Czyz
2298af4d0b
Stateless verification of Invoice for Refund
Stateless verification of Invoice for Offer

Verify that an Invoice was produced from a Refund constructed by the
payer using the payer metadata reflected in the Invoice. The payer
metadata consists of a 128-bit encrypted nonce and possibly a 256-bit
HMAC over the nonce and Refund TLV records (excluding the payer id)
using an ExpandedKey.

Thus, the HMAC can be reproduced from the refund bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the payer id.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
1a7540f2c9
Refund metadata and payer id derivation
Add support for deriving a transient payer id for each Refund from an
ExpandedKey and a nonce. This facilitates payer privacy by not tying any
Refund to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
022eadc4db
Stateless verification of Invoice for Offer
Verify that an Invoice was produced from an InvoiceRequest constructed
by the payer using the payer metadata reflected in the Invoice. The
payer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and InvoiceRequest TLV records (excluding
the payer id) using an ExpandedKey.

Thus, the HMAC can be reproduced from the invoice request bytes using
the nonce and the original ExpandedKey, and then checked against the
metadata. If metadata does not contain an HMAC, then the reproduced HMAC
was used to form the signing keys, and thus can be checked against the
payer id.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
9bd43e077f
Fix builder docs in offers module 2023-04-19 21:31:06 -05:00
Jeffrey Czyz
3880e69237
InvoiceRequest metadata and payer id derivation
Add support for deriving a transient payer id for each InvoiceRequest
from an ExpandedKey and a nonce. This facilitates payer privacy by not
tying any InvoiceRequest to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.
2023-04-19 21:31:06 -05:00
Jeffrey Czyz
e15044b889
Refactor InvoiceRequestContents fields into a sub-struct
InvoiceRequestBuilder has a field containing InvoiceRequestContents.
When deriving the payer_id from the remaining fields, a struct is needed
without payer_id as it not optional. Refactor InvoiceRequestContents to
have an inner struct without the payer_id such that
InvoiceRequestBuilder can use it instead.
2023-04-19 21:31:06 -05:00
Jeffrey Czyz
dd2ccd2322
Stateless verification of InvoiceRequest
Verify that an InvoiceRequest was produced from an Offer constructed by
the recipient using the Offer metadata reflected in the InvoiceRequest.
The Offer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and Offer TLV records (excluding the signing
pubkey) using an ExpandedKey.

Thus, the HMAC can be reproduced from the offer bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the signing
pubkey.
2023-04-19 21:30:40 -05:00
Matt Corallo
8d50c919cf
Merge pull request #2203 from wpaulino/retry-untractable-packages
Retry untractable packages
2023-04-20 02:20:34 +00:00
Jeffrey Czyz
b2e87ff25b
TlvStream range iterator
Add an iterator that yields TlvRecords over a range of a TlvStream.
Useful for verifying that, e.g., an InvoiceRequest was sent in response
to an Offer constructed by the intended recipient.
2023-04-19 21:08:05 -05:00
Jeffrey Czyz
1cad430e14
Offer metadata and signing pubkey derivation
Add support for deriving a transient signing pubkey for each Offer from
an ExpandedKey and a nonce. This facilitates recipient privacy by not
tying any Offer to any other nor to the recipient's node id.

Additionally, support stateless Offer verification by setting its
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an InvoiceRequest.
2023-04-19 21:06:37 -05:00
Wilmer Paulino
a3b416a32c
Make PackageTemplate::height_timer non-optional
Now that we leverage a package's `height_timer` even for untractable
packages, there's no need to have it be an `Option` anymore. We aim to
not break compatibility by keeping the deserialization of such as an
`option`, and use the package's `height_original` when not present. This
allows us to retry packages from older `ChannelMonitor` versions that
have had a failed initial package broadcast.
2023-04-19 16:49:37 -07:00
Wilmer Paulino
4828817f3f
Use existing height timer to retry untractable packages
Untractable packages are those which cannot have their fees updated once
signed, hence why they weren't retried. There's no harm in retrying
these packages by simply re-broadcasting them though, as the fee market
could have spontaneously spiked when we first broadcast it, leading to
our transaction not propagating throughout node mempools unless
broadcast manually.
2023-04-19 16:49:35 -07:00
Matt Corallo
2e15df730f
Merge pull request #2127 from TheBlueMatt/2023-03-payment-metadata
Support sending `PaymentMetadata` in HTLCs
2023-04-19 17:17:49 +00:00
Matt Corallo
ef8e3770a9 Fix variable name typo 2023-04-19 14:55:48 +00:00
Matt Corallo
934a5349f8 Update and clarify the reasons for HTLCDestination::FailedPayment 2023-04-19 14:55:48 +00:00
Matt Corallo
a41d75fb08 Add some tests of payment metadata being sent and received 2023-04-19 14:55:48 +00:00
Matt Corallo
e1e79031be Expose the RecipientOnionFields in Event::PaymentClaimable
This finally completes the piping of the `payment_metadata` from
from the BOLT11 invoice on the sending side all the way through the
onion sending + receiving ends to the user on the receive events.
2023-04-19 14:55:42 +00:00
Matt Corallo
9c55adaa4a Pipe received payment_metadata through the HTLC receipt pipeline
When we receive an HTLC, we want to pass the `payment_metadata`
through to the `PaymentClaimable` event. This does most of the
internal refactoring required to do so - storing a
`RecipientOnionFields` in the inbound HTLC tracking structs,
including the `payment_metadata`.

In the future this struct will allow us to do MPP keysend receipts
(as it now stores an Optional `payment_secret` for all inbound
payments) as well as custom TLV receipts (as the struct is
extensible to store additional fields and the internal API supports
filtering for fields which are consistent across HTLCs).
2023-04-19 14:55:42 +00:00
Matt Corallo
3dd05ab261 continue automatically after fail_htlc in receiving an HTLC
If we receive an HTLC and are processing it a potential MPP part,
we always continue in the per-HTLC loop if we call the `fail_htlc`
macro, thus its nice to actually do the `continue` therein rather
than at the callsites.
2023-04-19 14:55:42 +00:00
Matt Corallo
c1e6a74e0b Add a debug_assert the newly-documented (but existing) requirement
If we add an entry to `claimable_payments` we have to ensure we
actually accept the HTLC we're considering, otherwise we'll end up
with an empty `claimable_payments` entry.
2023-04-19 14:55:02 +00:00
Matt Corallo
f57221be60 Make claimable_payments map value a struct, rather than a tuple
This makes the `claimable_payments` code more upgradable allowing
us to add new fields in the coming commit(s).
2023-04-19 02:57:19 +00:00
Matt Corallo
ee9afd315d Add a payment_metadata field to RecipientOnionFields
This adds the new `payment_metadata` to `RecipientOnionFields`,
passing the metadata from BOLT11 invoices through the send pipeline
and finally copying them info the onion when sending HTLCs.

This completes send-side support for the new payment metadata
feature.
2023-04-19 02:57:19 +00:00
Matt Corallo
a90a35bcbb Deserialize payment metadata fields in the onion final hop data 2023-04-19 02:57:19 +00:00
Matt Corallo
8ed6e64913 Support setting the new payment metadata field in invoices
This adds support for setting the new payment metadata field in
BOLT11 invoices, using a new type flag on the builder to enforce
transition correctness.

We allow users to set the payment metadata as either optional or
required, defaulting to optional so that invoice parsing does not
fail if the sender does not support payment metadata fields.
2023-04-19 02:57:19 +00:00
Matt Corallo
928c9b806e Support reading the new payment_metadata field in invoices
This adds support for reading the new `PaymentMetadata` BOLT11
invoice field, giving us access to the `Vec<u8>` storing arbitrary
bytes we have to send to the recipient.
2023-04-19 02:57:19 +00:00
Matt Corallo
1b29a55e17 Unset the optional bit for a feature when setting the required bit
There is no reason to set both, and this currently makes testing
the new BOLT invoice tests slightly harder, so we just unset it.
2023-04-19 02:57:19 +00:00
Matt Corallo
35b597a4c2 Add features module-level documentation for missing features 2023-04-19 02:57:19 +00:00
Jeffrey Czyz
336fc023ed
Add another ExpandedKey derivation for Offers
To support transient signing pubkeys and payer ids for Offers, add
another key derivation to ExpandedKey. Also useful for constructing
metadata for stateless message authentication.
2023-04-18 13:30:32 -05:00
Jeffrey Czyz
fd426a0018
Add missing UnknownRequiredFeatures tests 2023-04-18 13:30:32 -05:00
Jeffrey Czyz
ce7a02d1e0
Common offers test_utils module
Move utility functions used across all offers modules into a common
module. Avoids duplicating larger utilities such as payment_path across
more than one module.
2023-04-18 13:30:10 -05:00
Matt Corallo
a332bfcdc2
Merge pull request #2198 from TheBlueMatt/2023-04-fewer-disables
Only disable channels ~10 min after disconnect, rather than one
2023-04-18 15:56:58 +00:00
Matt Corallo
89e063b793 Only disable channels ~10 min after disconnect, rather than one
We correctly send out a gossip channel disable update after one
full time tick being down (1-2 minutes). This is pretty nice in
that it avoids nodes trying to route through our nodes too often
if they're down. Other nodes have a much longer time window,
causing them to have much less aggressive channel disables. Sadly,
at one minute it's not super uncommon for tor nodes to get disabled
(once a day or so on two nodes I looked at), and this causes the
lightning terminal scorer to consider the LDK node unstable (even
though it's the one doing the disabling - so is online). This
causes user frustration and makes LDK look bad (even though it's
probably failing fewer payments).

Given this, and future switches to block-based `channel_update`
timestamp fields, it makes sense to go ahead and switch to delaying
channel disable announcements for 10 minutes. This puts us more in
line with other implementations and reduces gossip spam, at the
cost of less reliable payments.

Fixes #2175, at least the currently visible parts.
2023-04-18 04:31:52 +00:00
Matt Corallo
6e7000c5e7 Set channel_update disable bit based on staged even for onions
When generating a `channel_update` either in response to a fee
configuration change or an HTLC failure, we currently poll the
channel to check if the peer's connected when setting the disabled
bit in the `channel_update`. This could cause cases where we set
the disable bit even though the peer *just* disconnected, and don't
generate a followup broadcast `channel_update` with the disabled
bit unset.

While a node generally shouldn't rebroadcast a `channel_update` it
received in an onion, there's nothing inherently stopping them from
doing so. Obviously in the fee-update case we expect the message to
propagate.

Luckily, since we already "stage" disable-changed updates, we can
check the staged state and use that to set the disabled bit in all
`channel_update` cases.
2023-04-18 04:20:10 +00:00
Matt Corallo
2ebbe6f304
Merge pull request #2138 from swilliamson5/replace-our-max-htlcs-constant
Replace `OUR_MAX_HTLCS` with config knob
2023-04-17 21:58:07 +00:00
Matt Corallo
68149a204f
Merge pull request #2196 from wpaulino/ci-ignore-master-cancel-prev
Prevent unnecessary CI workflow runs
2023-04-17 21:54:55 +00:00
Matt Corallo
bd25a8192f
Merge pull request #2195 from TheBlueMatt/2023-04-115-bindings-upstream 2023-04-17 21:25:37 +00:00
Wilmer Paulino
d63006dcc0
Cancel in-progress jobs on updated push
At times, PRs can go through multiple pushes in a short amount of time,
spawning a workflow run for each. Most of the time, there's no need to
let the previous jobs running if the code itself has changed (e.g., via
a force push), and we'd benefit from having those slots be used by other
PRs/branches instead.
2023-04-17 11:32:53 -07:00