Commit graph

415 commits

Author SHA1 Message Date
Jeffrey Czyz
9596cc7110
Increase default liquidity_penalty_multiplier_msat
Using a larger multiplier gives more reasonable penalties for larger
success probabilities.
2022-03-25 11:31:04 -05:00
Jeffrey Czyz
c6348cb552
Move max penalty cap in ProbabilisticScorer
This reduce a branch in the 0 and u6::max_value cases.
2022-03-25 09:35:35 -05:00
Jeffrey Czyz
4ea18e3232
Fix overflow in ProbabilisticScorer
When a routing hint is given in an invoice, the effective capacity of
the channel is assumed to be infinite (i.e., u64::max_value) if the hop
is private. Adding 1 to this in the success probability calculation will
cause an overflow and ultimately an `index out of bounds panic` in
log10_times_1024. This was not an issue with using log10 because the use
of f64 would give infinite which casts to 0 for u64.
2022-03-25 09:16:22 -05:00
Jeffrey Czyz
5b36449c59
Add a base penalty to ProbabilisticScorer
ProbabilisticScorer tends to prefer longer routes to shorter ones. Make
the default scoring behavior include a customizable base penalty to
avoid longer routes.
2022-03-25 09:12:49 -05:00
Jeffrey Czyz
188f919a15
Don't serialize FixedPenaltyScorer parameters
Serializing scorer parameters makes it difficult to experiment with
different settings.
2022-03-25 08:53:19 -05:00
Matt Corallo
216225c00b
Merge pull request #1359 from tnull/2022-03-real-random-shuffle
Randomize candidate paths during route selection.
2022-03-24 23:13:12 +00:00
Matt Corallo
4e89e5741b
Merge pull request #1380 from TheBlueMatt/2022-03-skip-redundant-sig-checks
Skip `channel_update` signature checks if we have a newer state
2022-03-24 22:51:17 +00:00
Matt Corallo
63ca72e5b0 Skip channel_update signature checks if we have a newer state
`channel_update` messages already have their signatures checked
with the network graph write lock held, so there's no reason to
check the signatures before doing other quicker checks first,
including checking if we're already aware of a newer update for the
channel.

This reduces common-case CPU usage as `channel_update`s are sent
rather liberally over the p2p network to gossip them.
2022-03-24 17:21:30 +00:00
Elias Rohrer
ff7ec0c645 Minor refactor for sort / add, and some nits.
- `sort_by_key` to `sort_unstable_by_key`
- `checked_add() .. max_value()` to `saturating_add()`
- Some typos and nits
2022-03-24 09:12:44 -06:00
Elias Rohrer
b11dcf9ba8 Randomize candidate paths during route selection. 2022-03-24 09:12:26 -06:00
Matt Corallo
f6fa8e9c5b
Merge pull request #1370 from TheBlueMatt/2022-03-pref-first-hop-chans
Avoid needless MPP on multiple channels to the same first-hop
2022-03-23 22:44:37 +00:00
Matt Corallo
fcfd683312
Merge pull request #1360 from tnull/2022-03-loopless-random-walks
Avoid looping CLTV shadow routes.
2022-03-23 21:40:25 +00:00
Matt Corallo
b010aeb5f1
Merge pull request #1326 from Psycho-Pirate/peers
Added option to send remote IP to peers
2022-03-23 21:02:17 +00:00
Matt Corallo
b1bc07802e Avoid needless MPP on multiple channels to the same first-hop
When we have many channels to the same first-hop, many of which do
not have sufficient balance to make the requested payment, but when
some do, instead of simply using the available channel balance we
may switch to MPP, potentially with many, many paths.

Instead, we should seek to use the smallest channel which can
easily handle the requested payment, which we do here by sorting
the first_hops in our router before beginning the graph search.

Note that the "real" fix for this should be to instead decide which
channel to use at HTLC-send time, as most other nodes do during
relay, but this provides a minimal fix without needing to do the
rather-large work of refactoring our HTLC send+relay pipelines.

Issues with overly-aggressive MPP on many channels were reported by
Cash App.
2022-03-23 21:01:49 +00:00
Elias Rohrer
11c3120309 Avoid looping CLTV shadow routes. 2022-03-23 12:21:48 -06:00
Matt Corallo
cb1d795559
Merge pull request #1374 from TheBlueMatt/2022-03-bindings-cleanups
Trivial Bindings Cleanups
2022-03-23 00:46:31 +00:00
psycho-pirate
20a81e5c14 added network address in methods, filter_address function with tests and updated documentation 2022-03-23 04:44:28 +05:30
Matt Corallo
5588f2fa5d Use impl<bounds> instead of a where clause to help bindings 2022-03-21 20:09:30 +00:00
Matt Corallo
3cca221f8b Send a gossip_timestamp_filter on connect to enable gossip sync
On connection, if our peer supports gossip queries, and we never
send a `gossip_timestamp_filter`, our peer is supposed to never
send us gossip outside of explicit queries. Thus, we'll end up
always having stale gossip information after the first few
connections we make to peers.

The solution is to send a dummy `gossip_timestamp_filter`
immediately after connecting to peers.
2022-03-17 22:18:33 +00:00
Matt Corallo
b1fb7fdb9b Rename RoutingMessageHandler::sync_routing_table peer_connected
Its somewhat strange to have a trait method which is named after
the intended action, rather than the action that occurred, leaving
it up to the implementor what action they want to take.
2022-03-17 22:04:48 +00:00
Matt Corallo
c244c781f6
Merge pull request #1358 from TheBlueMatt/2022-03-max-cltv
Make `max_total_cltv_expiry_delta` include the final CLTV
2022-03-17 05:13:56 +00:00
Matt Corallo
bb4413cc65 Make max_total_cltv_expiry_delta include the final CLTV
This fixes an integer underflow found by the `router` fuzz target
in CI.
2022-03-16 22:10:46 +00:00
Matt Corallo
fef8acf70c Make routing benchmark robust against path changes
If the scoring in the routing benchmark causes us to take a
different path from the original scan, we may end up deciding that
the only path to a node has a too-high total CLTV delta, causing us
to panic in the benchmarking phase.

Here we simply check for that possibility and remove paths that
fail post-scoring.
2022-03-16 22:10:46 +00:00
Jeffrey Czyz
ca163c3fae
Merge pull request #1331 from TheBlueMatt/2022-02-no-copy-invoice-fields
Use &mut self in invoice updaters, not take-self-return-Self
2022-03-11 14:26:02 -06:00
Matt Corallo
b1cd5a7434
Merge pull request #1311 from TheBlueMatt/2022-02-0conf-part-1
Support for SCID Aliases
2022-03-10 00:47:23 +00:00
Matt Corallo
b2629afd88 Track SCID aliases from our counterparty and use them in invoices
New `funding_locked` messages can include SCID aliases which our
counterparty will recognize as "ours" for the purposes of relaying
transactions to us. This avoids telling the world about our
on-chain transactions every time we want to receive a payment, and
will allow for receiving payments before the funding transaction
appears on-chain.

Here we store the new SCID aliases and use them in invoices instead
of he "standard" SCIDs.
2022-03-09 19:14:38 +00:00
Elias Rohrer
e92b5a7ebd Add a random per-path CLTV offset for privacy. 2022-03-09 11:13:47 -06:00
Jeffrey Czyz
1a734492d9
Merge pull request #1347 from jkczyz/2022-03-log-approximation
Use log approximation in ProbabilisticScorer
2022-03-09 10:19:25 -06:00
Jeffrey Czyz
d70292d6c8
Fix compilation warnings with --features=no-std 2022-03-08 23:23:25 -06:00
Jeffrey Czyz
7f83c559b4
Use log approximation in ProbabilisticScorer
Since f64::log10 exists in std but not core, unconditionally use log
approximation so --feature=no-std will compile.
2022-03-08 23:22:38 -06:00
Matt Corallo
60f7977ea8 Add Clone to a few structs which contain only a few fields
Specifically, `PhantomRouteHints`, `FixedPenaltyScorer`, and
`ScoringParamters`.
2022-03-03 18:10:59 +00:00
Matt Corallo
797a648b6c Merge branch '2022-02-fix-multi-hop-hint-panic' into 2022-02-0.0.105-sec 2022-03-01 02:23:07 +00:00
Matt Corallo
bd1b761655 Correct default value for A* heuristic for non-public nodes
This doesn't (appear) to change behavior, however if we have a
non-public node, we assign an A* heuristic of max-u32 fees, which
may result in us de-prioritizing the path in some rare cases around
multi-hop route hints which compete with public nodes.
2022-02-28 22:07:54 +00:00
Matt Corallo
19ebc8081a Fix panic when routing through multiple private last-hops
When we added support for routing through a multi-hop invoice hint
we failed to remove an assertion that we always are able to fill
in features for each hop except the last one. However, when a
multi-hop invoice hint is used, we will not have features for any
of the hinted hops, causing us to panic.
2022-02-28 22:07:54 +00:00
Matt Corallo
5208f0c72a
Merge pull request #1303 from jkczyz/2022-02-docs-with-features
Generate docs with features for docs.rs
2022-02-28 21:00:05 +00:00
Matt Corallo
4b77ce1959
Merge pull request #1318 from jurvis/jurvis/2022-02-log-router-penalty-data-4
Implement custom debug for PathBuildingHop
2022-02-24 19:50:51 +00:00
Jurvis Tan
a3c2dfdcbc
Implement custom debug for PathBuildingHop
Add other fields to log for PathBuildingHop

Use DebugStruct to print PathBuildingHop

Fix PathBuildingHop visibility

Add more useful fee print-outs

Remove Features<NodeContext> from hop print-out

Remove logging fields we don’t need

Add fields to log back to PathBuildingHop
2022-02-23 17:50:59 -08:00
Matt Corallo
b7d57ea83e Use &mut self in invoice updaters, not take-self-return-Self
The take-self-return-Self idiom in Rust is substantially less
usable than it is in Java, where its more common. Because we have
to take self by move, it prevents using the update methods to
actually update features, something we occasionally want to do.

See, eg, the change in lightning-invoice where we previously had
to copy and re-create an entire vec of fields just to update the
features field, which is nuts.

There are a few places where this makes things a little less clean,
but the tradeoff to enable more effecient and broader uses of the
update methods seems worth it.
2022-02-23 20:17:36 +00:00
valentinewallace
23f1ec80d3
Merge pull request #1309 from TheBlueMatt/2022-02-first-hop-log
Specify whether we have first-hop hints when routing
2022-02-22 12:23:32 -05:00
Jeffrey Czyz
63e3486e8d
Unhide struct docs in scoring module
The docs were hidden since a type alias should be used. However, the
alias docs don't contain much useful information and don't link to the
corresponding struct.
2022-02-18 15:34:07 -06:00
Matt Corallo
637e0d34ca Specify whether we have first-hop hints when routing
This is incredibly useful when debugging issues with the router,
and is somewhat of an oversight currently.
2022-02-18 19:20:18 +00:00
Matt Corallo
acb4c539f7 Drop fuzztarget feature entirely
Some time ago we started transitioning to `cfg(fuzzing)` instead of
exposing a full feature. Here we complete the transition.
2022-02-18 17:03:04 +00:00
Matt Corallo
c8e3078ff7 Make router benchmarks more realistic by not running test-only code
`cargo bench` sets `cfg(test)`, causing us to hit some test-only
code in the router when benchmarking, throwing off our benchmarks
substantially. Here we swap from the `unstable` feature to a more
clearly internal feature (`_bench_unstable`) and also checking for
it when enabling test-only code.
2022-02-10 22:28:38 +00:00
Jeffrey Czyz
d5db85ecc5
Add ProbabilisticScorer benchmarks 2022-02-02 20:22:27 -06:00
Jeffrey Czyz
28faf89df3
Deprecate Scorer in favor of ProbabilisticScorer 2022-02-02 20:22:27 -06:00
Jeffrey Czyz
2e730cdc9c
Decay channel liquidity balance offsets
ProbabilisticScorer uses successful and unsuccessful payments to gain
more certainty of a channel's liquidity balance. Decay this knowledge
over time to indicate decreasing certainty about the liquidity balance.
2022-02-02 20:22:27 -06:00
Jeffrey Czyz
68d791ad84
Probabilistic channel scoring
Add a Score implementation based on "Optimally Reliable & Cheap Payment
Flows on the Lightning Network" by Rene Pickhardt and Stefan Richter[1].
Given the uncertainty of channel liquidity balances, probability
distributions are defined based on knowledge learned from successful and
unsuccessful attempts. Then the negative log of the success probability
is used to determine the cost of routing a specific HTLC amount through
a channel.

[1]: https://arxiv.org/abs/2107.05322
2022-02-02 19:47:12 -06:00
Jeffrey Czyz
1aaf5fc5d0
Effective channel capacity for router and scoring
A channel's capacity may be inferred or learned and is used to make
routing decisions, including as a parameter to channel scoring. Define
an EffectiveCapacity for this purpose. Score::channel_penalty_msat takes
the effective capacity (less in-flight HTLCs for the same payment), and
never None. Thus, for hops given in an invoice, the effective capacity
is now considered (near) infinite if over a private channel or based on
learned information if over a public channel.

If a Score implementations needs the effective capacity when updating a
channel's score, i.e. in payment_path_failed or payment_path_successful,
it can access the channel's EffectiveCapacity via the NetworkGraph by
first looking up the channel and then specifying which direction is
desired using ChannelInfo::as_directed.
2022-02-02 19:46:58 -06:00
Jeffrey Czyz
d924c5d6ed
Benchmark zero-penalty scorer 2022-01-24 19:32:53 -06:00
Jeffrey Czyz
4512fd3685
Benchmark router using a scorer seeded with data
Scorers may have different performance characteristics after seeing
failed and successful paths. Seed the scorer with some random data
before executing the benchmark in order to exercise such behavior.
2022-01-24 19:32:47 -06:00