Commit graph

4070 commits

Author SHA1 Message Date
Matt Corallo
79b55f0815
Merge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs
Remove scary disconenct warnings on PeerManager new connection fns
2022-07-25 21:56:40 +00:00
Matt Corallo
d8cca9806c
Merge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit
Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator
2022-07-25 21:11:07 +00:00
Matt Corallo
1988cb22cc
Merge pull request #1519 from tnull/2022-06-require-htlc-max
Make `htlc_maximum_msat` a required field.
2022-07-25 21:04:54 +00:00
Matt Corallo
7f80972e1f Rename amount penalty to liquidity_penalty_amount_multiplier_msat
This makes our `ProbabilisticScorer` field names more consistent,
as we add more types of penalties, referring to a penalty as only
the "amount penalty" no longer makes sense - we not have several
amount multiplier penalties.
2022-07-25 19:22:24 +00:00
Matt Corallo
fe39a89ab3 Add a per-amount base penalty in the ProbabilisticScorer
There's not much reason to not have a per-hop-per-amount penalty in
the `ProbabilisticScorer` to go along with the per-hop penalty to
let it scale up to larger amounts, so we add one here.

Notably, we use a divisor of 2^30 instead of 2^20 (like the
equivalent liquidity penalty) as it allows for more flexibility,
and there's not really any reason to worry about us not being able
to create high enough penalties.

Closes #1616
2022-07-25 19:22:24 +00:00
Elias Rohrer
8b86ed7c52 Test serialization of ChannelInfo and NodeInfo 2022-07-25 20:39:06 +02:00
Elias Rohrer
8f4c951b1f Don't fail read NodeInfo for inv. NetAddress
Fixes a deserialization incompatibility introduced with #1553.
2022-07-25 20:38:18 +02:00
Elias Rohrer
b0e8b739b7 Make htlc_maximum_msat a required field. 2022-07-25 20:35:51 +02:00
Matt Corallo
af7e9b608d Change LowerBoundedFeeEstimator fn name to make it hard to swap
This change the method name on `LowerBoundedFeeEstimator` to
further differentiate it from the generic `FeeEstimator` trait.
2022-07-25 18:33:10 +00:00
Matt Corallo
a491200f96 Avoid blanket implementing FeeEstimator for Deref<FeeEstimator>
This simplifies things for bindings (and, to some extent,
downstream users) by exploiting the fact that we can always "clone"
a reference to a struct by dereferencing and then creating a new
reference.
2022-07-25 18:33:10 +00:00
Matt Corallo
ca9357147e Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator
This should make it somewhat more difficult to accidentally use a
straight fee estimator when we actually want a
LowerBoundedFeeEstimator by not having the types be exchangeable at
all.
2022-07-25 18:33:10 +00:00
jurvis
ac842ed9dd
Send failure event if we fail to handle a HTLC
In `ChannelManager::fail_htlc_backwards_internal`, we push a `HTLCHandlingFailed`
containing some information about the HTLC
2022-07-25 11:28:51 -07:00
Matt Corallo
19b5a48dde Remove scary disconenct warnings on PeerManager new connection fns
In 4703d4e725 we changed
PeerManager::socket_disconnected to no longer require that sockets
which the PeerManager decided to disconnect not be disconnected.
However, we forgot to remove the scary warnings on the
`new_{inbound,outbound}_connection` functions which warned of the
old behavior.

We do so here.
2022-07-25 18:21:00 +00:00
jurvis
5bccd2eee2
Add utils to handle HTLC handling failure reason
We add `HTLCHandlingFailedConditions` to express the failure parameters,
that will be enforced by a new macro, `expect_pending_htlcs_forwardable_conditions`.
2022-07-25 10:26:38 -07:00
jurvis
17e6c374c5
Add HTLCHandlingFailed event
Adds a HTLCHandlingFailed that expresses failure by our node to process
a specific HTLC. A HTLCDestination enum is defined to express the
possible cases that causes the handling to fail.
2022-07-25 10:22:43 -07:00
Matt Corallo
f26e8541a5
Merge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash
Reuse `BlockHash` from `validate_pow()`
2022-07-22 15:36:25 +00:00
Duncan Dean
e256b3498e
Reuse BlockHash from validate_pow()
The `validate_pow()` method now returns the BlockHash since rust-bitcoin
v0.26.2 thanks to jkczyz's PR (rust-bitcoin/rust-bitcoin/pull/572).
2022-07-22 11:45:06 +02:00
Matt Corallo
834fe6357d
Merge pull request #1420 from TheBlueMatt/2022-04-moar-lockorder
Expand lockorder testing to look at mutexes, not specific instances
2022-07-21 02:29:16 +00:00
Matt Corallo
ff20203724 Swap HashSets with custom Hash in debug_sync for HashMaps 2022-07-20 22:08:59 +00:00
Matt Corallo
6f2c008751 Expand lockorder testing to look at mutexes, not specific instances
Our existing lockorder inversion checks look at specific instances
of mutexes rather than the general mutex itself. This changes that
behavior to look at the instruction pointer at which a mutex was
created and treat all mutexes which were created at the same
location as equivalent.

This allows us to detect lockorder inversions which occur across
tests, though it does substantially reduce parallelism during test
runs.
2022-07-20 22:08:59 +00:00
Matt Corallo
625cda108c Construct all ChannelMonitor mutexes in the same function
When we add lockorder detection based on mutex construction site
rather than mutex instance in the next commit, ChannelMonitor's
PartialEq implementation causes spurious failures. This is caused
by the lockorder detection logic considering the ChannelMonitor
inner mutex to be two distinct mutexes - one when monitors are
deserialized and one when monitors are created fresh. Instead, we
attempt to tell the lockorder detection logic that they are the
same by ensuring they're constructed in the same place - in this
case a util method.
2022-07-20 22:08:59 +00:00
Matt Corallo
661b7343e8
Merge pull request #1624 from tnull/2022-07-fix-doc
Fix 'not a hyperlink' doc warning
2022-07-20 17:38:42 +00:00
valentinewallace
507d7595ca
Merge pull request #1623 from lexe-tech/custom-smart-pointers
lightning-net-tokio: Allow custom smart pointers
2022-07-20 13:07:20 -04:00
Elias Rohrer
97e6682d58 Fix 'not a hyperlink' doc warning 2022-07-20 14:57:31 +02:00
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