]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
2 months agoDon't send InvoiceError on failed authentication
Jeffrey Czyz [Wed, 3 Jul 2024 15:50:02 +0000 (10:50 -0500)]
Don't send InvoiceError on failed authentication

When an invoice or invoice request cannot be authenticated from an
OffersContext, simply do not respond instead of sending an InvoiceError
message. According to BOLT4, messages sent over a blinded path not
intended for its use MUST be ignored.

2 months agoAuthenticate Bolt12Invoice using OfferContext
Jeffrey Czyz [Tue, 2 Jul 2024 22:27:39 +0000 (17:27 -0500)]
Authenticate Bolt12Invoice using OfferContext

When a Bolt12Invoice is handled with an OfferContext, use the
containing payment_id to verify that it is for a pending outbound
payment. Only invoices for refunds without any blinded paths can be
verified without an OfferContext.

2 months agoAdd docs to Metadata::without_keys
Jeffrey Czyz [Thu, 18 Jul 2024 22:53:39 +0000 (17:53 -0500)]
Add docs to Metadata::without_keys

2 months agoRename InvoiceRequest::verify
Jeffrey Czyz [Fri, 19 Jul 2024 14:56:11 +0000 (09:56 -0500)]
Rename InvoiceRequest::verify

2 months agoElide metadata from Offer with derived keys
Jeffrey Czyz [Thu, 20 Jun 2024 16:43:57 +0000 (11:43 -0500)]
Elide metadata from Offer with derived keys

When an Offer uses blinded paths, its metadata consists of a nonce used
to derive its signing keys. Now that the blinded paths contain this
nonce, elide the metadata as it is now redundant. This saves space and
also makes it impossible to derive the signing keys if an invoice
request is received with the incorrect nonce. The nonce shouldn't be
revealed in this case either to prevent de-anonymization attacks.

2 months agoAuthenticate InvoiceRequest using OfferContext
Jeffrey Czyz [Tue, 2 Jul 2024 21:55:59 +0000 (16:55 -0500)]
Authenticate InvoiceRequest using OfferContext

When an InvoiceRequest is handled with an OfferContext, use the
containing nonce to verify that it is for a valid Offer. Otherwise, fall
back to using Offer::metadata, which also contains the nonce. The latter
is useful for supporting offers without blinded paths or those created
prior to including an OffersContext in their blinded paths.

2 months agoAdd OffersContext::InvoiceRequest
Jeffrey Czyz [Wed, 3 Jul 2024 18:47:07 +0000 (13:47 -0500)]
Add OffersContext::InvoiceRequest

To authenticate that an InvoiceRequest is for a valid Offer, include the
nonce from the Offer::metadata in the Offer::paths. This can be used to
prevent de-anonymization attacks where an attacker sends requests using
self-constructed paths to nodes near the Offer::paths' introduction
nodes.

2 months agoFix OffersContext::Unknown docs
Jeffrey Czyz [Thu, 18 Jul 2024 22:34:51 +0000 (17:34 -0500)]
Fix OffersContext::Unknown docs

2 months agoFix grammar
Jeffrey Czyz [Thu, 18 Jul 2024 22:33:00 +0000 (17:33 -0500)]
Fix grammar

2 months agoExpand OffersContext::OutboundPayment docs
Jeffrey Czyz [Tue, 9 Jul 2024 18:41:42 +0000 (13:41 -0500)]
Expand OffersContext::OutboundPayment docs

2 months agoWrap docs at 100 characters
Jeffrey Czyz [Tue, 9 Jul 2024 18:34:14 +0000 (13:34 -0500)]
Wrap docs at 100 characters

2 months agoClean up MessageContext docs
Jeffrey Czyz [Tue, 9 Jul 2024 18:31:34 +0000 (13:31 -0500)]
Clean up MessageContext docs

2 months agoAssert and document valid Metadata states
Jeffrey Czyz [Thu, 11 Jul 2024 19:00:38 +0000 (14:00 -0500)]
Assert and document valid Metadata states

Metadata is an internal type used within Offer messages. For any
constructed message, Metadata::Bytes is always used. The other variants
are used during construction or verification time. Document this and
debug_assert!(false) accordingly.

2 months agoAdd InvoiceRequest::verify_using_recipient_data
Jeffrey Czyz [Thu, 20 Jun 2024 00:18:26 +0000 (19:18 -0500)]
Add InvoiceRequest::verify_using_recipient_data

Invoice requests are authenticated by checking the metadata in the
corresponding offer. For offers using blinded paths, this will simply be
a 128-bit nonce. Allows checking this nonce explicitly instead of the
metadata. This will be used by an upcoming change that includes the
nonce in the offer's blinded paths instead of the metadata, which
mitigate de-anonymization attacks.

2 months agoPass Nonce directly to OfferBuilder
Jeffrey Czyz [Wed, 19 Jun 2024 17:42:16 +0000 (12:42 -0500)]
Pass Nonce directly to OfferBuilder

When using OfferBuilder::deriving_signing_pubkey, the nonce generated
needs to be the same one included in any OfferBuilder::paths. This is
because the nonce is used along with the offer TLVs to derive a signing
pubkey and will soon be elided from the metadata entirely.

2 months agoMove Nonce to a separate offers sub-module
Jeffrey Czyz [Wed, 19 Jun 2024 16:51:53 +0000 (11:51 -0500)]
Move Nonce to a separate offers sub-module

Nonce is used when constructing Offer::metadata and will soon be need
when constructing BlindedPath for use in authentication. Move it to
separate module now that it is public and will be more widely used.

2 months agoReorder imports
Jeffrey Czyz [Wed, 19 Jun 2024 16:40:34 +0000 (11:40 -0500)]
Reorder imports

2 months agoChange Nonce visibility to pub
Jeffrey Czyz [Wed, 19 Jun 2024 16:29:20 +0000 (11:29 -0500)]
Change Nonce visibility to pub

A nonce is generated in OfferBuilder::deriving_signing_pubkey from an
EntropySource for use in Offer::metadata. The same nonce will need to be
included as recipient data in any blinded paths in the Offer. Increase
the visibility to allow for this.

2 months agoMerge pull request #3024 from jbesraa/funding-signed-event
Elias Rohrer [Mon, 22 Jul 2024 13:47:59 +0000 (15:47 +0200)]
Merge pull request #3024 from jbesraa/funding-signed-event

Funding signed event

2 months agoMerge pull request #3152 from alecchendev/2024-06-async-commit-secret-raa
Matt Corallo [Thu, 18 Jul 2024 15:17:57 +0000 (15:17 +0000)]
Merge pull request #3152 from alecchendev/2024-06-async-commit-secret-raa

Handle fallible commitment secret

2 months agoMerge pull request #2995 from tnull/2024-04-fallible-event-handler
Matt Corallo [Thu, 18 Jul 2024 15:07:07 +0000 (15:07 +0000)]
Merge pull request #2995 from tnull/2024-04-fallible-event-handler

Make event handling fallible

2 months agoDocument `Failure Behavior and Persistence` for every event type
Elias Rohrer [Mon, 8 Jul 2024 13:43:18 +0000 (15:43 +0200)]
Document `Failure Behavior and Persistence` for every event type

2 months agoAdd simple test for event replaying
Elias Rohrer [Mon, 8 Jul 2024 12:51:03 +0000 (14:51 +0200)]
Add simple test for event replaying

2 months agoHandle fallible events in `OnionMessenger`
Elias Rohrer [Tue, 2 Jul 2024 10:04:33 +0000 (12:04 +0200)]
Handle fallible events in `OnionMessenger`

Previously, we would just fire-and-forget in `OnionMessenger`'s event
handling. Since we now introduced the possibility of event handling
failures, we here adapt the event handling logic to retain any
events which we failed to handle to have them replayed upon the next
invocation of `process_pending_events`/`process_pending_events_async`.

2 months agoMake event handling fallible
Elias Rohrer [Mon, 15 Apr 2024 08:35:52 +0000 (10:35 +0200)]
Make event handling fallible

Previously, we would require our users to handle all events
successfully inline or panic will trying to do so. If they would exit
the `EventHandler` any other way we'd forget about the event and
wouldn't replay them after restart.

Here, we implement fallible event handling, allowing the user to return
`Err(())` which signals to our event providers they should abort event
processing and replay any unhandled events later (i.e., in the next
invocation).

2 months agoHold sep. Mutexes for pending `intercepted_msgs`/`peer_connected` events
Elias Rohrer [Tue, 2 Jul 2024 09:11:40 +0000 (11:11 +0200)]
Hold sep. Mutexes for pending `intercepted_msgs`/`peer_connected` events

This is a minor refactor that will allow us to access the individual
event queue Mutexes separately, allowing us to drop the locks earlier
when processing them individually.

2 months agoMerge pull request #3160 from TheBlueMatt/2024-07-better-enum-upgradable-ser
Matt Corallo [Wed, 17 Jul 2024 18:05:22 +0000 (18:05 +0000)]
Merge pull request #3160 from TheBlueMatt/2024-07-better-enum-upgradable-ser

Make `impl_writeable_tlv_based_enum*` actually upgradable

2 months agoTest fallible commitment secret
Alec Chen [Tue, 2 Jul 2024 01:33:25 +0000 (18:33 -0700)]
Test fallible commitment secret

2 months agoMerge pull request #3187 from TheBlueMatt/2024-07-routing-nits
Matt Corallo [Wed, 17 Jul 2024 17:12:00 +0000 (17:12 +0000)]
Merge pull request #3187 from TheBlueMatt/2024-07-routing-nits

#2803 nits

2 months agoMerge pull request #3136 from tnull/2024-06-rustfmt-lightning-block-sync
Matt Corallo [Wed, 17 Jul 2024 15:51:42 +0000 (15:51 +0000)]
Merge pull request #3136 from tnull/2024-06-rustfmt-lightning-block-sync

Run `rustfmt` on `lightning-block-sync`

2 months agoAdd pending changelog entry for the previous commit 2024-07-better-enum-upgradable-ser
Matt Corallo [Mon, 8 Jul 2024 20:43:51 +0000 (20:43 +0000)]
Add pending changelog entry for the previous commit

2 months agoMake `impl_writeable_tlv_based_enum*` actually upgradable
Matt Corallo [Mon, 8 Jul 2024 19:21:19 +0000 (19:21 +0000)]
Make `impl_writeable_tlv_based_enum*` actually upgradable

In cc78b77c715d6ef62693d4c1bc7190da990ec0fa it was discovered that
`impl_writeable_tlv_based_enum_upgradable` wasn't actually
upgradable - tuple variants weren't written with length-prefixes,
causing downgrades with new tuple variants to be unreadable by
older clients as they wouldn't know where to stop reading.

This was fixed by simply assuming that any new variants will be
non-tuple variants with a length prefix, but no code write-side
changes were made, allowing new code to freely continue to use the
broken tuple-variant serialization.

Here we address this be defining yet more serialization macros
which aren't broken, and convert existing usage of the existing
macros using non-length-prefixed tuple variants to renamed
`*_legacy` macros.

Note that this changes the serialization format of
`impl_writeable_tlv_based_enum[_upgradable]` when tuple fields are
written, and as such deliberately changes the call semantics for
such tuples.

Only the serialization format of `MessageContext` is changed here
which is fine as it has not yet reached a release of LDK.

2 months agoDrop excess `()`s in `router.rs` 2024-07-routing-nits
Matt Corallo [Wed, 17 Jul 2024 14:08:50 +0000 (14:08 +0000)]
Drop excess `()`s in `router.rs`

2 months agoMarginally improve comments around cache lines in `gossip.rs`
Matt Corallo [Wed, 17 Jul 2024 14:08:39 +0000 (14:08 +0000)]
Marginally improve comments around cache lines in `gossip.rs`

2 months agoMerge pull request #2803 from TheBlueMatt/2023-12-routing-dist-vec
Matt Corallo [Wed, 17 Jul 2024 14:06:05 +0000 (14:06 +0000)]
Merge pull request #2803 from TheBlueMatt/2023-12-routing-dist-vec

Misc routing optimization

2 months agoHandle fallible `release_commitment_secret`
Alec Chen [Tue, 2 Jul 2024 01:13:49 +0000 (18:13 -0700)]
Handle fallible `release_commitment_secret`

2 months agoMerge pull request #3087 from shaavan/reply_path_diversity
Matt Corallo [Tue, 16 Jul 2024 19:29:08 +0000 (19:29 +0000)]
Merge pull request #3087 from shaavan/reply_path_diversity

Allow blinded path diversification by expanding `create_blinded_paths`

2 months agoMerge pull request #3185 from tnull/2024-07-clarify-max-description-length
Matt Corallo [Tue, 16 Jul 2024 15:24:45 +0000 (08:24 -0700)]
Merge pull request #3185 from tnull/2024-07-clarify-max-description-length

Clarify maximum length of an invoice description

2 months agoMerge pull request #3183 from TheBlueMatt/2024-07-no-strict
Matt Corallo [Tue, 16 Jul 2024 13:31:52 +0000 (06:31 -0700)]
Merge pull request #3183 from TheBlueMatt/2024-07-no-strict

Drop unnecessary `strict` feature from `lightning-invoice`

2 months agoMerge pull request #3150 from alecchendev/2024-06-async-commit-point-raa
Matt Corallo [Tue, 16 Jul 2024 13:30:57 +0000 (06:30 -0700)]
Merge pull request #3150 from alecchendev/2024-06-async-commit-point-raa

Handle fallible per commitment point for RAA

2 months agoClarify maximum length of an invoice description
Elias Rohrer [Tue, 16 Jul 2024 08:28:58 +0000 (10:28 +0200)]
Clarify maximum length of an invoice description

We previously stated in the docs that the invoice description can be at most `1023`
bytes long, which is wrong. According to BOLT 11 it's at most 1023*5 bits (639 bytes) long.

2 months agoTest async get per commitment point for revoke_and_ack
Alec Chen [Sun, 30 Jun 2024 23:05:48 +0000 (16:05 -0700)]
Test async get per commitment point for revoke_and_ack

Note: this does not test the CS -> RAA resend ordering, because this
requires handling async get_per_commitment_point for channel
reestablishment, which will be addressed in a follow up PR.

2 months agoAllow failing revoke_and_ack if commitment point is not available
Alec Chen [Sat, 29 Jun 2024 22:41:27 +0000 (15:41 -0700)]
Allow failing revoke_and_ack if commitment point is not available

2 months agoChange get_per_commitment_point to return result type
Alec Chen [Wed, 5 Jun 2024 22:40:38 +0000 (17:40 -0500)]
Change get_per_commitment_point to return result type

Includes simple changes to test util signers and tests, as well as
handling the error case for get_per_commitment_point in
HolderCommitmentPoint. This leaves a couple `.expect`s in places
that will be addressed in a separate PR for handling funding.

2 months agoMerge pull request #3165 from Harshit933/link-fix
Matt Corallo [Mon, 15 Jul 2024 19:17:09 +0000 (12:17 -0700)]
Merge pull request #3165 from Harshit933/link-fix

Fixes `Sensei` broken link

2 months agoAdd logger as parameter in creating ChannelContext
Alec Chen [Thu, 30 May 2024 20:25:29 +0000 (15:25 -0500)]
Add logger as parameter in creating ChannelContext

2 months agoReturn an error if we fail to advance our commitment number
Alec Chen [Tue, 18 Jun 2024 21:48:23 +0000 (14:48 -0700)]
Return an error if we fail to advance our commitment number

2 months agoDrop unnecessary `strict` feature from `lightning-invoice` 2024-07-no-strict
Matt Corallo [Mon, 15 Jul 2024 18:34:04 +0000 (18:34 +0000)]
Drop unnecessary `strict` feature from `lightning-invoice`

99aa6e27f616c96dda2b49d09bafbc0b982251e0 detected that we had an
undefined feature in `lightning-invoice` called `strict`, which was
used to turn on `deny(warnings)`. It resolved that by adding the
feature to the `Cargo.toml`, but we actually don't need it - our CI
already builds with `-Dwarnings`, so any warnings should be
rejected during CI and there's not a lot of value in having a
(public) feature to do the same.

2 months agoMerge pull request #3173 from dunxen/2024-07-cargocheckcfg
Matt Corallo [Mon, 15 Jul 2024 18:33:08 +0000 (11:33 -0700)]
Merge pull request #3173 from dunxen/2024-07-cargocheckcfg

Use native check-cfg lint in cargo beta

2 months agoSplit HolderCommitmentPoint::advance off into separate function
Alec Chen [Tue, 18 Jun 2024 21:26:25 +0000 (14:26 -0700)]
Split HolderCommitmentPoint::advance off into separate function

2 months agoMerge pull request #3180 from tnull/2024-07-use-upstreamed-merkle-validation
Matt Corallo [Mon, 15 Jul 2024 18:16:40 +0000 (11:16 -0700)]
Merge pull request #3180 from tnull/2024-07-use-upstreamed-merkle-validation

Electrum: Use upstreamed `validate_merkle_proof`

2 months agoMerge pull request #3172 from tnull/2024-07-revert-gossip-query-patch
valentinewallace [Mon, 15 Jul 2024 17:39:54 +0000 (13:39 -0400)]
Merge pull request #3172 from tnull/2024-07-revert-gossip-query-patch

Revert "Signal `GossipQuery` support when using `IgnoringMessagHandler`"

2 months agoUse upstreamed `validate_merkle_proof`
Elias Rohrer [Mon, 15 Jul 2024 11:43:22 +0000 (13:43 +0200)]
Use upstreamed `validate_merkle_proof`

We previously upstreamed the `validate_merkle_proof` utility method,
which shipped with `electrum-client` 0.19.0.

Since we upgraded to that version recently, we can now drop our local
code and use the upstreamed version.

2 months agoDrop `lightning-background-processor/src/lib.rs` from exclusion list
Elias Rohrer [Mon, 15 Jul 2024 11:55:48 +0000 (13:55 +0200)]
Drop `lightning-background-processor/src/lib.rs` from exclusion list

We previously forgot to drop it (or it snuck back in during rebasing),
so we drop `lightning-background-processor` from the rustfmt exclusion
list.

2 months ago`rustfmt`: Drop `lightning-custom-message/src/lib.rs` from excluded
Elias Rohrer [Thu, 20 Jun 2024 09:10:43 +0000 (11:10 +0200)]
`rustfmt`: Drop `lightning-custom-message/src/lib.rs` from excluded

.. files

2 months ago`rustfmt`: Run on `lightning-block-sync/src/lib.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:10:11 +0000 (11:10 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/lib.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/utils.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:09:46 +0000 (11:09 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/utils.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/test_utils.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:09:15 +0000 (11:09 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/test_utils.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/rpc.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:08:58 +0000 (11:08 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/rpc.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/rest.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:08:32 +0000 (11:08 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/rest.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/poll.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:07:59 +0000 (11:07 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/poll.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/init.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:07:29 +0000 (11:07 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/init.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/http.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:07:02 +0000 (11:07 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/http.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/gossip.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:06:20 +0000 (11:06 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/gossip.rs`

2 months agoPrepare `lightning-block-sync/src/gossip.rs`
Elias Rohrer [Tue, 9 Jul 2024 08:04:23 +0000 (10:04 +0200)]
Prepare `lightning-block-sync/src/gossip.rs`

2 months ago`rustfmt`: Run on `lightning-block-sync/src/convert.rs`
Elias Rohrer [Thu, 20 Jun 2024 09:05:30 +0000 (11:05 +0200)]
`rustfmt`: Run on `lightning-block-sync/src/convert.rs`

2 months agoPrepare `convert.rs`
Elias Rohrer [Mon, 1 Jul 2024 09:13:11 +0000 (11:13 +0200)]
Prepare `convert.rs`

2 months agoMerge pull request #3138 from tnull/2024-06-rustfmt-bp
Matt Corallo [Sun, 14 Jul 2024 18:15:13 +0000 (11:15 -0700)]
Merge pull request #3138 from tnull/2024-06-rustfmt-bp

`rustfmt`: Run on `lightning-background-processor`

2 months agoIntroduce tests to check verify reply path diversification
shaavan [Fri, 5 Jul 2024 13:12:39 +0000 (18:42 +0530)]
Introduce tests to check verify reply path diversification

2 months agoFixes `Sensei` broken link
Harshit Verma [Tue, 9 Jul 2024 17:24:14 +0000 (22:54 +0530)]
Fixes `Sensei` broken link

Issue: https://github.com/lightningdevkit/rust-lightning/issues/3148

2 months agoUse native check-cfg lint in cargo beta
Duncan Dean [Fri, 12 Jul 2024 09:23:50 +0000 (11:23 +0200)]
Use native check-cfg lint in cargo beta

This uses the newly introduced conditional configuration checks that are
now configurable withint Cargo (beta).

This allows us to get rid of our custom python script that checks for
expected features and cfgs.

This does introduce a warning regarding the unknown lint in Cargo
versions prior to the current beta, but since these are not rustc errors,
they won't break any builds with the "-D warnings" RUSTFLAG.

Moving to this lint actually exposed the "strict" feature not being
present in the lightning-invoice crate, as our python script didnt
correctly parse the cfg_attr where it appeared.

2 months agoRevert "Signal `GossipQuery` support when using `IgnoringMessagHandler`"
Elias Rohrer [Fri, 12 Jul 2024 08:49:16 +0000 (10:49 +0200)]
Revert "Signal `GossipQuery` support when using `IgnoringMessagHandler`"

This reverts commit 843079df72435b8a117e8b12b42492391409259f.

2 months agoUpdate extract_invoice to also return the reply_path.
shaavan [Fri, 5 Jul 2024 12:49:15 +0000 (18:19 +0530)]
Update extract_invoice to also return the reply_path.

- This will be utilised in the following commit for a test.

2 months agoExpand `create_blinded_path` Functionality for Enhanced Path Diversification
shaavan [Mon, 10 Jun 2024 13:45:19 +0000 (19:15 +0530)]
Expand `create_blinded_path` Functionality for Enhanced Path Diversification

- Previously, the `create_blinded_path` function was limited to
  returning a single `BlindedPath`, which restricted the usage of
  `blinded_paths`.
- This commit extends the `create_blinded_path` function to return
  the entire blinded path vector generated by the `MessageRouter`'s
  `create_blinded_paths`.
- The updated functionality is integrated across the codebase, enabling
  the sending of Offers Response messages, such as `InvoiceRequest`
  (in `pay_for_offer`) and `Invoice` (in `request_refund_payment`),
  utilizing multiple reply paths.

2 months agoLayout channel info to ensure routing uses cache lines well 2023-12-routing-dist-vec
Matt Corallo [Sat, 9 Dec 2023 21:22:52 +0000 (21:22 +0000)]
Layout channel info to ensure routing uses cache lines well

Because we scan per-channel information in the hot inner loop of
our routefinding immediately after looking a channel up in a
`HashMap`, we end up spending a nontrivial portion of our
routefinding time waiting on memory to be read in.

While there is only so much we can do about that, ensuring the
channel information that we care about is sitting on one or
adjacent cache lines avoids paying that penalty twice. Thus, here
we manually lay out `ChannelInfo` and `ChannelUpdateInfo` and set
them to 128b and 32b alignment, respectively. This wastes some
space in memory in our network graph, but improves routing
performance in return.

2 months agoConsolidate `candidate` access in `add_entry` during routing
Matt Corallo [Fri, 8 Dec 2023 19:43:17 +0000 (19:43 +0000)]
Consolidate `candidate` access in `add_entry` during routing

Because fetching fields from the `$candidate` often implies an
indirect read, grouping them together may result in one or two
fewer memory loads, so we do so here.

2 months agoSomewhat optimize the generic `Features::requires_unknown_bits`
Matt Corallo [Fri, 8 Dec 2023 05:44:32 +0000 (05:44 +0000)]
Somewhat optimize the generic `Features::requires_unknown_bits`

It turns out we spend several percent of our routefinding time just
checking if nodes and channels require unknown features
byte-by-byte. While the cost is almost certainly dominated by the
memory read latency, avoiding doing the checks byte-by-byte should
reduce the branch count slightly, which may reduce the overhead.

2 months agoStore source/target `node_counter`s in `DirectionalChannelInfo`
Matt Corallo [Fri, 8 Dec 2023 01:49:20 +0000 (01:49 +0000)]
Store source/target `node_counter`s in `DirectionalChannelInfo`

Because we now have some slack space in `PathBuildingHop`, we can
use it to cache some additional hot values. Here we use it to
cache the source and target `node_counter`s for public channels,
effectively prefetching the values from the channel state.

2 months agoDRY redundant calls to `$candidate.htlc_minimum_msat()` in routing
Matt Corallo [Fri, 8 Dec 2023 01:49:08 +0000 (01:49 +0000)]
DRY redundant calls to `$candidate.htlc_minimum_msat()` in routing

While LLVM should inline and elide the redundant calls, because the
router is rather large LLVM can decide against inlining in some
cases where it would be an nice win.

Thus, its worth DRY'ing the redundant calls explicitly.

2 months agoCache whether a node is a first-hop target in the per-node state
Matt Corallo [Sun, 10 Dec 2023 03:28:37 +0000 (03:28 +0000)]
Cache whether a node is a first-hop target in the per-node state

When processing the main loop during routefinding, for each node,
we check whether it happens to be our peer in one of our channels.
This ensures we never fail to find a route that takes a hop through
a private channel of ours, to a private node, then through
invoice-provided route hints to reach the ultimate payee.

Because this is incredibly hot code, doing a full `HashMap` lookup
to check if each node is a first-hop target ends up eating a good
chunk of time during routing. Luckily, we can trivially avoid this
cost.

Because we're already looking up the per-node state in the `dist`
map, we can store a bool in each first-hop target's state, avoiding
the lookup unless we know its going to succeed.

This requires storing a dummy entry in `dist`, which feels somewhat
strange, but is ultimately fine as we should never be looking at
per-node state unless we've already found a path to that node,
updating the fields in doign so.

2 months agoMerge pull request #3104 from TheBlueMatt/2024-06-routing-counters
valentinewallace [Wed, 10 Jul 2024 14:03:53 +0000 (10:03 -0400)]
Merge pull request #3104 from TheBlueMatt/2024-06-routing-counters

2 months agoMove blinded path introduction point resolution to a helper method 2024-06-routing-counters
Matt Corallo [Wed, 10 Jul 2024 01:22:32 +0000 (01:22 +0000)]
Move blinded path introduction point resolution to a helper method

This marginally reduces the size of `get_route` by moving a the
blinded path introduction point resolution and blinded path checks
into a helper method.

2 months agoAlign `PathBuildingHop` to 128b, now that we store them in a `Vec`
Matt Corallo [Thu, 7 Dec 2023 23:40:26 +0000 (23:40 +0000)]
Align `PathBuildingHop` to 128b, now that we store them in a `Vec`

Now that `PathBuildingHop` is stored in a `Vec` (as `Option`s),
rather than `HashMap` entries, they can grow to fill a full two
cache lines without a memory access performance cost. In the next
commit we'll take advantage of this somewhat, but here we update
the assertions and drop the `repr(C)`, allowing rust to lay the
memory out as it wishes.

2 months agoDrop the `dist` `HashMap` in routing, replacing it with a `Vec`.
Matt Corallo [Mon, 24 Jun 2024 23:50:29 +0000 (23:50 +0000)]
Drop the `dist` `HashMap` in routing, replacing it with a `Vec`.

Now that we have unique, dense, 32-bit identifiers for all the
nodes in our network graph, we can store the per-node information
when routing in a simple `Vec` rather than a `HashMap`. This avoids
the overhead of hashing and table scanning entirely, for a nice
"simple" optimization win.

2 months agoUse `NodeCounters` `NodeId`s as the blinded path intro references
Matt Corallo [Sat, 1 Jun 2024 22:45:04 +0000 (22:45 +0000)]
Use `NodeCounters` `NodeId`s as the blinded path intro references

The router's `introduction_node_id_cache` is used to cache the
`NodeId`s of blinded path introduction points so that we don't
have to look them up every time we go around the main router loop.
When using it, if the introduction point isn't a public node we
then look up the introduction in our first-hops map.

In either case, we have to end up with a reference to a `NodeId`
that outlives our `dist` map.

Here we consolidate both the initial cache building and the
first-hops map lookup to one place, storing only a reference to a
`NodeId` either in the `NetworkGraph` or in the new `NodeCounters`
to get the required lifetime without needing to reference into the
first-hops map.

We then take this opportunity to avoid `clone`ing the first-hops
map entries as we now no longer reference into it.

2 months agoDrop `private_hop_key_cache` in favor of `NodeCounters`
Matt Corallo [Sat, 1 Jun 2024 18:19:45 +0000 (18:19 +0000)]
Drop `private_hop_key_cache` in favor of `NodeCounters`

With the new `NodeCounters` have have a all the `NodeId`s we'll
need during routing, so there's no need to keep the
`private_hop_key_cache` which existed to provide references to
`NodeId`s which are needed during routing.

2 months agoAdd a new `NodeCounters` utility to track counters when routing
Matt Corallo [Tue, 19 Mar 2024 19:29:06 +0000 (19:29 +0000)]
Add a new `NodeCounters` utility to track counters when routing

In the next commit we'll stop using `NodeId`s to look up nodes when
routing, instead using the new per-node counters. Here we take the
first step, adding a local struct which tracks temporary counters
for route hints/source/destination nodes.

Because we must ensure we have a 1-to-1 mapping from node ids to
`node_counter`s, even across first-hop and last-hop hints, we have
to be careful to check the network graph first, then a new
`private_node_id_to_node_counter` map to ensure we only ever end up
with one counter per node id.

2 months agoMerge pull request #3085 from shaavan/issue2837
Matt Corallo [Tue, 9 Jul 2024 16:16:15 +0000 (09:16 -0700)]
Merge pull request #3085 from shaavan/issue2837

Introduce RecipientData and use it to allow abandon failed payments

2 months agoMerge pull request #3161 from vincenzopalazzo/macros/fix-docs
Matt Corallo [Tue, 9 Jul 2024 15:28:07 +0000 (08:28 -0700)]
Merge pull request #3161 from vincenzopalazzo/macros/fix-docs

meta: update docs to reflect the code

2 months agometa: update docs to reflect the code
Vincenzo Palazzo [Tue, 9 Jul 2024 10:00:56 +0000 (12:00 +0200)]
meta: update docs to reflect the code

The code documentation is outdated after the commit 935a716cc6c4fada075e2b740a70bb1b7b349d49

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2 months agoMerge pull request #3149 from alecchendev/2024-06-async-sign-cs-raa-order
Matt Corallo [Tue, 9 Jul 2024 13:48:08 +0000 (06:48 -0700)]
Merge pull request #3149 from alecchendev/2024-06-async-sign-cs-raa-order

Fix bug failing CS-RAA resend order on pending commitment signatures

2 months agoAllow create_blinded_paths functions to accept MessageContext as input field
shaavan [Sat, 15 Jun 2024 13:52:56 +0000 (19:22 +0530)]
Allow create_blinded_paths functions to accept MessageContext as input field

- Enabled `create_blinded_paths` to accept `MessageContext` TLVs as
  an input field.
- `MessageContext` is intended to be sent along with the `reply_path`
   to the counterparty.
- Added `MessageContext` in the `create_blinded_paths` flow, optionally
  appending it within the `reply_path`.
- Updated tests to verify the new feature.

2 months agoUpdate handle_message to accept OffersContext data as an input field
shaavan [Sat, 15 Jun 2024 13:52:28 +0000 (19:22 +0530)]
Update handle_message to accept OffersContext data as an input field

1. Handling Offers Data:
   - Updated `handle_message` to accept `OffersContext` data as an input field.
   - If it is present, it will be utilized by the handler to
     abandon outbound payments that have failed for any reason.

2. Consistency in Custom Message Handling:
   - Updated `handle_custom_message` to accept optional custom data.
     for consistency.
   - Note: `custom_data` will remain unused in this PR.

2 months ago`rustfmt`: Run on `lightning-background-processor/src/lib.rs`
Elias Rohrer [Thu, 20 Jun 2024 12:11:14 +0000 (14:11 +0200)]
`rustfmt`: Run on `lightning-background-processor/src/lib.rs`

2 months agoPrepare `lightning-background-processor/src/lib.rs`
Elias Rohrer [Tue, 9 Jul 2024 08:19:08 +0000 (10:19 +0200)]
Prepare `lightning-background-processor/src/lib.rs`

2 months agoFix bug failing CS-RAA resend order on pending commitment signatures
Alec Chen [Sun, 30 Jun 2024 20:55:18 +0000 (13:55 -0700)]
Fix bug failing CS-RAA resend order on pending commitment signatures

2 months agoMerge pull request #3120 from TheBlueMatt/2023-11-mon-claim-bug
Matt Corallo [Mon, 8 Jul 2024 20:50:06 +0000 (13:50 -0700)]
Merge pull request #3120 from TheBlueMatt/2023-11-mon-claim-bug

Block monitor updates to ensure preimages are in each MPP part

2 months agoIntroduce MessageContext in ReceiveTlvs
shaavan [Fri, 14 Jun 2024 12:36:05 +0000 (18:06 +0530)]
Introduce MessageContext in ReceiveTlvs

1. New Enum for Enhanced Data Handling:
   - Introduced the `MessageContext` enum, which allows the node to include
     additional context data along with the `reply_path` sent to the counterparty.
   - The node anticipates receiving this data back for further processing.

2. Variants in MessageContext:
   - The `MessageContext` enum includes two variants: "Offers" and
     "Context"
   - One of the variants, `Offers`, holds the `payment_id`
     of the associated Outbound BOLT12 Payment.

3. Future Usage:
   - This enum will be utilized in a subsequent commit to abandon outbound
     payments that have failed to complete for various reasons.

2 months agoRemove path_id from Responder, and OnionMessageResponse struct
shaavan [Tue, 18 Jun 2024 17:03:02 +0000 (22:33 +0530)]
Remove path_id from Responder, and OnionMessageResponse struct

1. The path_id will be removed from the codebase in the following
   commits.

2 months agoTest the new `RAAMonitorUpdateBlockingAction::ClaimedMPPPayment` 2023-11-mon-claim-bug
Matt Corallo [Thu, 13 Jun 2024 01:26:08 +0000 (01:26 +0000)]
Test the new `RAAMonitorUpdateBlockingAction::ClaimedMPPPayment`