Commit graph

7689 commits

Author SHA1 Message Date
Alec Chen
1f7f3a366c 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.
2024-07-15 14:28:17 -07:00
Matt Corallo
4bd4f19526
Merge pull request #3165 from Harshit933/link-fix
Fixes `Sensei` broken link
2024-07-15 12:17:09 -07:00
Alec Chen
1fa67d9434 Add logger as parameter in creating ChannelContext 2024-07-15 11:41:22 -07:00
Alec Chen
9c2a050a35 Return an error if we fail to advance our commitment number 2024-07-15 11:41:19 -07:00
Matt Corallo
e0f797460e Drop unnecessary strict feature from lightning-invoice
99aa6e27f6 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.
2024-07-15 18:34:31 +00:00
Matt Corallo
ddb40bd04c
Merge pull request #3173 from dunxen/2024-07-cargocheckcfg
Use native check-cfg lint in cargo beta
2024-07-15 11:33:08 -07:00
Alec Chen
516e5e6f58 Split HolderCommitmentPoint::advance off into separate function 2024-07-15 11:30:37 -07:00
Matt Corallo
161c40ffbb
Merge pull request #3180 from tnull/2024-07-use-upstreamed-merkle-validation
Electrum: Use upstreamed `validate_merkle_proof`
2024-07-15 11:16:40 -07:00
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