Commit graph

3896 commits

Author SHA1 Message Date
Max Fang
5019b31b28 lightning-net-tokio: Allow custom smart pointers 2022-07-19 21:57:12 -07:00
Matt Corallo
5023ff05a8
Merge pull request #1610 from TheBlueMatt/2022-07-no-rand-path-selection 2022-07-19 16:56:36 +00:00
Matt Corallo
ff8d3f7ba4 Reduce default max_channel_saturation_power_of_half to 2 (max 1/4)
Saturating a channel beyond 1/4 of its capacity seems like a more
reasonable threshold for avoiding a path than 1/2, especially given
we should still be willing to send a payment with a lower
saturation limit if it comes to that.

This requires an (obvious) change to some router tests, but also
requires a change to the `fake_network_test`, opting to simply
remove some over-limit test code there - `fake_network_test` was
our first ever functional test, and while it worked great to ensure
LDK worked at all on day one, we now have a rather large breadth
of functional tests, and a broad "does it work at all" test is no
longer all that useful.
2022-07-19 15:16:35 +00:00
Matt Corallo
985153e128 Make route path selection optimize strictly for cost / amount
Currently, after we've selected a number of candidate paths, we
construct a route from a random set of paths repeatedly, and then
select the route with the lowest total cost. In the vast majority
of cases this ends up doing a bunch of additional work in order to
select the path(s) with the total lowest cost, with some vague
attempt at randomization that doesn't actually work.

Instead, here, we simply sort available paths by `cost / amount`
and select the top paths. This ends up in practice having the same
end result with substantially less complexity. In some rare cases
it gets a better result, which also would have been achieved
through more random trials. This implies there may in such cases be
a potential privacy loss, but not a substantial one, given our path
selection is ultimately mostly deterministic in many cases (or, if
it is not, then privacy is achieved through randomization at the
scorer level).
2022-07-19 15:16:35 +00:00
Matt Corallo
0c3a47c016 Fix tracking of collected value across pathfinding iterations
If we end up "paying" for an `htlc_minimum_msat` with fees, we
increment `already_collected_value_msat` by more than the amount
of the path that we collected (who's `value_contribution_msat` is
higher than the total payment amount, despite having been reduced
down to the payment amount).

This throws off our total value collection target, though in the
coming commit(s) it would also throw off our path selection
calculations.
2022-07-19 15:16:35 +00:00
Matt Corallo
9d35026cb6
Merge pull request #1618 from wpaulino/gossip-sync-constructors
Add convenient GossipSync variant constructors
2022-07-15 19:12:41 +00:00
Wilmer Paulino
6877539af4
Add convenient GossipSync variant constructors
These constructors fill in the missing types for each variant so that
users don't have to turbofish them manually.
2022-07-15 10:32:16 -07:00
Matt Corallo
f75b6cb9a8
Merge pull request #1600 from TheBlueMatt/2022-07-explicit-avoid-retries 2022-07-15 13:51:05 +00:00
Matt Corallo
a3547e29e5 Change default "impossibility penalty" to one Bitcoin
In general we should avoid taking paths that we are confident will
not work as much possible, but we should be willing to try each
payment at least once, even if its over a channel that failed
recently. A full Bitcoin penalty for such a channel seems
reasonable - lightning fees are unlikely to ever reach that point
so such channels will be scored much worse than any other potential
path, while still being below `u64::max_value()`.
2022-07-14 18:37:26 +00:00
Matt Corallo
ec2b1ced07 Make the ProbabilisticScorer impossibility penalty configurable
When we consider sending an HTLC over a given channel impossible
due to our current knowledge of the channel's liquidity, we
currently always assign a penalty of `u64::max_value()`. However,
because we now refuse to retry a payment along the same path in
the router itself, we can now make this value configurable. This
allows users to have a relatively high knowledge decay interval
without the side-effect of refusing to try the only available path
in cases where a channel is intermittently available.
2022-07-14 18:37:25 +00:00
Matt Corallo
93e645daf4 Track channels which a given payment part failed to traverse
When an HTLC fails, we currently rely on the scorer learning the
failed channel and assigning an infinite (`u64::max_value()`)
penalty to the channel so as to avoid retrying over the exact same
path (if there's only one available path). This is common when
trying to pay a mobile client behind an LSP if the mobile client is
currently offline.

This leads to the scorer being overly conservative in some cases -
returning `u64::max_value()` when a given path hasn't been tried
for a given payment may not be the best decision, even if that
channel failed 50 minutes ago.

By tracking channels which failed on a payment part level and
explicitly refusing to route over them we can relax the
requirements on the scorer, allowing it to make different decisions
on how to treat channels that failed relatively recently without
causing payments to retry the same path forever.

This does have the drawback that it could allow two separate part
of a payment to traverse the same path even though that path just
failed, however this should only occur if the payment is going to
fail anyway, at least as long as the scorer is properly learning.

Closes #1241, superseding #1252.
2022-07-14 18:37:25 +00:00
Matt Corallo
5cca9a0696
Merge pull request #1605 from TheBlueMatt/2022-07-smaller-mpp-parts
Avoid saturating channels before we split payments
2022-07-14 18:33:53 +00:00
Jeffrey Czyz
b76040718f
Merge pull request #1543 from jkczyz/2022-06-network-graph-bindings
Look-up functions for `ReadOnlyNetworkGraph`
2022-07-14 11:57:08 -05:00
Jeffrey Czyz
2da49530e7
Look-up functions for ReadOnlyNetworkGraph
ReadOnlyNetworkGraph uses BTreeMap to store its nodes and channels, but
these data structures are not supported by C bindings. Expose look-up
functions on these maps in lieu of such support.
2022-07-14 10:26:42 -05:00
Matt Corallo
2eb93f4664
Merge pull request #1615 from TheBlueMatt/2022-07-screw-dependabot
Rip out dependabot - its worse than useless - its annoying
2022-07-14 00:53:17 +00:00
Matt Corallo
a911ca84eb Rip out dependabot - its worse than useless - its annoying
Dependabot has a ton of issues with its rust integration that makes
it wholly useless, and very annoying:
 * It has no concept of MSRV, opening PRs that are not going to pass
   CI.
 * It has no concept of patch-level - if we depend on tokio 1.X,
   that means any version of tokio > 1.X, but dependabot insists on
   opening a PR to "update us" to tokio 1.X + 1, even though it
   doesn't impact what version of our users use (and often violates
   MSRV).
 * It has no concept of dependencies that rely on each other,
   causing it to open a PR to update us to bitcoin_hashes X + 1,
   even though we're still depending on rust-bitcoin Y which
   depends on bitcoin_hashes X, causing build failure.
 * It hogs CI resources, getting CI run twice, once for the branch
   once for the PR.
 * It creates branches directly on the rust-lightning repo, making
   it look like the work is somehow connected to the
   lightningdevkit project, even though it isn't, and spamming the
   local clones of project contributors.

At the end of the day, dependabot has never meaningfully
contributed to notifying us of an important dependency, and,
really, we don't have enough dependencies for it to matter.
2022-07-13 20:04:54 +00:00
Matt Corallo
0627c0c88a Fix some test theoretical lock inversions
In the next commit we add lockorder testing based on the line each
mutex was created on rather than the particular mutex instance.
This causes some additional test failure because of lockorder
inversions for the same mutex across different tests, which is
fixed here.
2022-07-13 19:28:29 +00:00
Matt Corallo
e6d40a7c0e Add a test of the new channel saturation limit 2022-07-13 18:36:50 +00:00
Matt Corallo
a02982fbba Relax the channel saturation limit if we can't find enough paths
In order to avoid failing to find paths due to the new channel
saturation limit, if we fail to find enough paths, we simply
disable the saturation limit for further path finding iterations.

Because we can now increase the maximum sent over a given channel
during routefinding, we may now generate redundant paths for the
same payment. Because this is wasteful in the network, we add an
additional pass during routefinding to merge redundant paths.

Note that two tests which previously attempted to send exactly the
available liquidity over a channel which charged an absolute fee
need updating - in those cases the router will first collect a path
that is saturation-limited, then attempt to collect a second path
without a saturation limit while stil honoring the existing
utilized capacity on the channel, causing failure as the absolute
fee must be included.
2022-07-13 18:36:50 +00:00
Matt Corallo
bd6b710328 Avoid saturating channels before we split payments
Currently we only opt to split a payment into an MPP if we have
completely and totally used a channel's available capacity (up to
the announced htlc_max or on-chain capacity, whichever is lower).
This is obviously destined to fail as channels are unlikely to have
their full capacity available.

Here we do the minimum viable fix by simply limiting channels to
only using up to a configurable power-of-1/2. We default this new
configuration knob to 1 (1/2 of the channel) so as to avoid a
substantial change but in the future we may consider changing this
to 2 (1/4) or even 3 (1/8).
2022-07-13 18:36:50 +00:00
Matt Corallo
2a3bf03f0c
Merge pull request #1552 from dunxen/2022-06-checkminrelayfee
Add min feerate checks
2022-07-13 16:49:16 +00:00
Duncan Dean
7bc6d0e606
Make all internal signatures accept LowerBoundedFeeEstimator 2022-07-13 15:00:51 +02:00
Duncan Dean
9c0c3b0c95
Add LowerBoundedFeeEstimator to set FeeEstimator min rates
`LowerBoundedFeeEstimator` is a wrapper for `Deref`s to `FeeEstimator`s
that limits the get_est_sat_per_1000_weight() method to no less than 253
sats/kW.
2022-07-13 15:00:50 +02:00
Matt Corallo
fda3819699
Merge pull request #1542 from ViktorTigerstrom/2022-06-prepare-maps-for-channels-per-peer
Preparations for storing channels per peer
2022-07-12 18:03:11 -07:00
Viktor Tigerström
fa7f170a73 Add ChannelManager:id_to_peer map coverage test 2022-07-12 17:47:08 +02:00
Viktor Tigerström
4058861730 Add id_to_peer map 2022-07-12 17:47:08 +02:00
Matt Corallo
5c06d1d9c8
Merge pull request #1603 from TheBlueMatt/2022-07-no-backwards-time
Avoid panicking on wallclock time going backwards across restart
2022-07-11 14:07:18 -07:00
Jeffrey Czyz
29e34c8a10
Merge pull request #1596 from jurvis/jurvis/give-chanmon-counterparty-id
Make ChannelMonitor aware of counterparty's node id
2022-07-11 13:51:55 -05:00
Matt Corallo
497fd65ae9 Avoid panicking on wallclock time going backwards across restart
Because we serialize `Instant`s using wallclock time in
`ProbabilisticScorer`, if time goes backwards across restarts we
may end up with `Instant`s in the future, which causes rustc prior
to 1.60 to panic when calculating durations. Here we simply avoid
this by setting the time to `now` if we get a time in the future.
2022-07-11 18:49:22 +00:00
jurvis
2d493364db
Add counterparty_node_id to ChannelMonitor 2022-07-09 12:47:29 -07:00
Jeffrey Czyz
c726b4e561
Merge pull request #1602 from TheBlueMatt/2022-07-109-rel-missing-force-close
Add missing note about renaming force-close methods in 109 changelog
2022-07-08 14:34:13 -05:00
Matt Corallo
ad2e92a3fb
Merge pull request #1592 from tnull/2022-07-manual-penalty
Allow to set manual node penalties
2022-07-08 12:29:25 -07:00
Matt Corallo
469adbd7df Add missing note about renaming force-close methods in 109 changelog 2022-07-08 14:15:46 +00:00
Jeffrey Czyz
4e5f74a6f3
Merge pull request #1567 from tnull/2022-06-send-probe
Add simple probing API
2022-07-07 09:27:14 -05:00
Viktor Tigerström
872c0378f7 Rename short_to_id map to short_to_chan_info
As the map values are no longer only `channel_id`s, but also a
`counterparty_node_id`s, the map is renamed to better correspond to
whats actually stored in the map.
2022-07-07 13:38:31 +02:00
Viktor Tigerström
908e898dcd Add counterparty_node_id to short_to_id map 2022-07-07 13:34:18 +02:00
Elias Rohrer
eb8bce0d16 Add send_probe and introduce probing cookies
When we send payment probes, we generate the [`PaymentHash`] based on a
probing cookie secret and a random [`PaymentId`]. This allows us to
discern probes from real payments, without keeping additional state.
2022-07-07 09:02:29 +02:00
Matt Corallo
e254912a20
Merge pull request #1599 from TheBlueMatt/2022-07-fuzz-warns
Drop unused imports in fuzzing test cases
2022-07-06 12:26:14 -07:00
Matt Corallo
f58f2eb0fa Drop unused imports in fuzzing test cases 2022-07-06 16:18:30 +00:00
Elias Rohrer
790abc540d Refactor max_mpp_path_count to max_path_count
Using this field just for MPP doesn't make sense when it could
intuitively also be used to indicate single-path payments. We therefore
rename `max_mpp_path_count` to `max_path_count` and make sure that a
value of 1 ensures MPP is not even tried.
2022-07-06 08:06:35 +02:00
Matt Corallo
e403999ffd
Merge pull request #1588 from TheBlueMatt/2022-06-ffs-dumb-ser
Do not execute the default_value expr until we need it in TLV deser
2022-07-05 13:46:43 -07:00
Matt Corallo
f1b9bd34b8 Do not execute the default_value expr until we need it in TLV deser
This fixes an insta-panic in `ChannelMonitor` deserialization where
we always `unwrap` a previous value to determine the default value
of a later field. However, because we always ran the `unwrap`
before the previous field is read, we'd always panic.

The fix is rather simple - use a `OptionDeserWrapper` for
`default_value` fields and only fill in the default value if no
value was read while walking the TLV stream.

The only complexity comes from our desire to support
`read_tlv_field` calls that use an explicit field rather than an
`Option` of some sort, which requires some statement which can
assign both an `OptionDeserWrapper<T>` variable and a `T` variable.
We settle on `x = t.into()` and implement `From<T> for
OptionDeserWrapper<T>` which works, though it requires users to
specify types explicitly due to Rust determining expression types
prior to macro execution, completely guessing with no knowlege for
integer expressions (see
https://github.com/rust-lang/rust/issues/91369).
2022-07-05 17:32:21 +00:00
Matt Corallo
a3f181af2d
Merge pull request #1586 from TheBlueMatt/2022-06-0.0.109
Fix date on 0.0.109 release notes
2022-07-05 10:30:26 -07:00
Matt Corallo
dcc445fa85
Merge pull request #1589 from TheBlueMatt/2022-07-sec-policy
Add security policy with PGP keys
2022-07-05 10:30:17 -07:00
Elias Rohrer
1ddc6f1089 Allow to set manual node penalties
A user might want to explicitly penalize or prioritize a particular
node. We now allow them to do so by specifying a manual penalty
override for a given node that is then returned by the scorer.
2022-07-05 16:39:53 +02:00
Matt Corallo
92919c8f37 Add security policy with PGP keys
Closes #1246.
2022-07-05 14:25:51 +00:00
Matt Corallo
daeb5a6291
Merge pull request #1553 from wvanlint/dns_hostname
Adds DNS hostname to NetAddress
2022-07-05 07:24:17 -07:00
Willem Van Lint
c30dcf183c Adds DNS hostname to NetAddress 2022-07-04 10:19:16 -07:00
Matt Corallo
d246e61379 [fuzz] Update auto-generated target list 2022-07-01 20:55:26 +00:00
Matt Corallo
c9a52d6ecf [fuzz] Add a ChannelDetails msg target 2022-07-01 20:55:26 +00:00