Commit graph

7981 commits

Author SHA1 Message Date
valentinewallace
3dedbd5ecb
Merge pull request #3172 from tnull/2024-07-revert-gossip-query-patch
Revert "Signal `GossipQuery` support when using `IgnoringMessagHandler`"
2024-07-15 13:39:54 -04:00
Elias Rohrer
b3a58e6db6
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.
2024-07-15 14:19:57 +02:00
Elias Rohrer
12e4efa0ff
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.
2024-07-15 13:55:48 +02:00
Elias Rohrer
5e163da8d4
rustfmt: Drop lightning-custom-message/src/lib.rs from excluded
.. files
2024-07-15 13:55:39 +02:00
Elias Rohrer
9c2f4cb6ce
rustfmt: Run on lightning-block-sync/src/lib.rs 2024-07-15 13:55:39 +02:00
Elias Rohrer
43abde8d73
rustfmt: Run on lightning-block-sync/src/utils.rs 2024-07-15 13:55:39 +02:00
Elias Rohrer
ad7021ae30
rustfmt: Run on lightning-block-sync/src/test_utils.rs 2024-07-15 13:55:39 +02:00
Elias Rohrer
3ef5f18ebb
rustfmt: Run on lightning-block-sync/src/rpc.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
634821a95d
rustfmt: Run on lightning-block-sync/src/rest.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
26cacb60b5
rustfmt: Run on lightning-block-sync/src/poll.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
fb57e04057
rustfmt: Run on lightning-block-sync/src/init.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
310ad9a0eb
rustfmt: Run on lightning-block-sync/src/http.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
8975979fcd
rustfmt: Run on lightning-block-sync/src/gossip.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
16614963c1
Prepare lightning-block-sync/src/gossip.rs 2024-07-15 13:55:38 +02:00
Elias Rohrer
20669aeb71
rustfmt: Run on lightning-block-sync/src/convert.rs 2024-07-15 13:55:37 +02:00
Elias Rohrer
2f9bdc729c
Prepare convert.rs 2024-07-15 13:55:37 +02:00
Matt Corallo
dd5d297d64
Merge pull request #3138 from tnull/2024-06-rustfmt-bp
`rustfmt`: Run on `lightning-background-processor`
2024-07-14 11:15:13 -07:00
shaavan
957b33712a Introduce tests to check verify reply path diversification 2024-07-12 19:45:16 +05:30
Harshit Verma
b93ec25813 Fixes Sensei broken link
Issue: https://github.com/lightningdevkit/rust-lightning/issues/3148
2024-07-12 17:00:27 +05:30
Duncan Dean
99aa6e27f6
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.
2024-07-12 11:48:15 +02:00
Elias Rohrer
5a39cc2b19
Revert "Signal GossipQuery support when using IgnoringMessagHandler"
This reverts commit 843079df72.
2024-07-12 10:49:16 +02:00
Jeffrey Czyz
c8fd681d4f
Refactor initial route finding to separate method
This will be used later in send_payment_for_bolt12_invoice instead of
find_route_and_send_payment as it will allow for returning
RetryableSendFailure when path finding fails.
2024-07-11 18:05:10 -05:00
Jeffrey Czyz
aa55366b37
Add Bolt12PaymentError::SendingFailed variant
Instead of returning Ok when path finding fails, allow returning a
RetryableSendFailure from send_payment_for_bolt12_invoice. Follow up
commits will return such failures.
2024-07-11 18:01:20 -05:00
shaavan
887e99900c Update extract_invoice to also return the reply_path.
- This will be utilised in the following commit for a test.
2024-07-11 19:14:53 +05:30
shaavan
afabf7bc44 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.
2024-07-11 19:12:34 +05:30
Matt Corallo
f689e01b35 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.
2024-07-10 19:38:02 +00:00
Matt Corallo
bed1fb073b 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.
2024-07-10 19:38:02 +00:00
Matt Corallo
9566c272c8 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.
2024-07-10 19:38:02 +00:00
Matt Corallo
98f9e8bbf8 Store source/target node_counters 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.
2024-07-10 19:38:02 +00:00
Matt Corallo
3e902401e0 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.
2024-07-10 19:38:02 +00:00
Matt Corallo
df9c15de75 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.
2024-07-10 19:38:02 +00:00
valentinewallace
78c0eaae55
Merge pull request #3104 from TheBlueMatt/2024-06-routing-counters 2024-07-10 10:03:53 -04:00
Matt Corallo
4f5e17b54d 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
5fb66377ef 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
43d250dadc 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
c34980c47f Use NodeCounters NodeIds 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
04dad438d7 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
c6cd3c8176 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.
2024-07-10 01:31:48 +00:00
Matt Corallo
6035c83a1d
Merge pull request #3085 from shaavan/issue2837
Introduce RecipientData and use it to allow abandon failed payments
2024-07-09 09:16:15 -07:00
Matt Corallo
1a71725450
Merge pull request #3161 from vincenzopalazzo/macros/fix-docs
meta: update docs to reflect the code
2024-07-09 08:28:07 -07:00
Vincenzo Palazzo
eb7f2e3459
meta: update docs to reflect the code
The code documentation is outdated after the commit 935a716cc6

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-07-09 16:55:38 +02:00
Matt Corallo
f48a273211
Merge pull request #3149 from alecchendev/2024-06-async-sign-cs-raa-order
Fix bug failing CS-RAA resend order on pending commitment signatures
2024-07-09 06:48:08 -07:00
shaavan
42c096c491 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.
2024-07-09 17:27:11 +05:30
shaavan
fbe9dfa938 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.
2024-07-09 17:27:08 +05:30
Elias Rohrer
438515d2c4
rustfmt: Run on lightning-background-processor/src/lib.rs 2024-07-09 10:26:00 +02:00
Elias Rohrer
a60f7a7fcf
Prepare lightning-background-processor/src/lib.rs 2024-07-09 10:25:47 +02:00
Alec Chen
315193daec Fix bug failing CS-RAA resend order on pending commitment signatures 2024-07-08 17:35:25 -07:00
Matt Corallo
bcacf85a79
Merge pull request #3120 from TheBlueMatt/2023-11-mon-claim-bug
Block monitor updates to ensure preimages are in each MPP part
2024-07-08 13:50:06 -07:00
shaavan
7f82cde861 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.
2024-07-09 01:45:13 +05:30
shaavan
7e2fde7054 Remove path_id from Responder, and OnionMessageResponse struct
1. The path_id will be removed from the codebase in the following
   commits.
2024-07-09 01:44:14 +05:30