Commit graph

5936 commits

Author SHA1 Message Date
Matt Corallo
94140b91d8 Bump versions to 0.0.117-alpha2/invoice 0.25.0-alpha2 2023-09-26 20:21:08 +00:00
Matt Corallo
1ac53ed02b
Merge pull request #2417 from tnull/2023-07-max-total-fee
Add config option to set maximum total routing fee
2023-09-26 20:07:52 +00:00
Elias Rohrer
6765767cbc
Test max_total_routing_fee_msat handling when retrying overpaid paths
We setup an MPP scenario with two paths in which we need to overpay to
reach `htlc_minimum_msat`. We then fail the overpaid path and check that
on retry our `max_total_routing_fee_msat` only accounts for the path
fees, but not for the fees overpaid in the first attempt.
2023-09-26 20:12:31 +02:00
Elias Rohrer
7895943953
Check max_total_routing_fee is accounted for in test_threaded_payment_retries 2023-09-26 20:12:30 +02:00
Elias Rohrer
26b515c13c
Check max_total_routing_fee is reduced in mpp_retry test
We check that the `RouteParameters::max_total_routing_fee` field is reduced accordingly
to our previously used fees.
2023-09-26 20:12:30 +02:00
Elias Rohrer
649144d25f
Account for leftover fee budget when retrying via check_retry_payment 2023-09-26 20:12:30 +02:00
Matt Corallo
827b17c7df
Merge pull request #2597 from TheBlueMatt/2023-09-finish-force-close-deadlocks
Fix potential peer_state deadlocks in `finish_force_close_channel`
2023-09-26 16:36:16 +00:00
Elias Rohrer
ac57163895
Account for leftover fee budget when retrying PartialFailures 2023-09-26 09:44:05 +02:00
Elias Rohrer
b1a878fe81
Test we adhere to max_total_routing_fee_msat 2023-09-26 09:44:05 +02:00
Elias Rohrer
ca40d8a6fb
Consider RouteParameters::max_total_routing_fee_msat in get_route
We exclude any candidate hops if we find that using them would let the
aggregated path routing fees exceed `max_total_routing_fee_msat`.

Moreover, we return an error if the aggregated fees over all paths of
the selected route would surpass `max_total_routing_fee_msat`.
2023-09-26 09:44:05 +02:00
Elias Rohrer
d7e2ff6220
Introduce RouteParameters::max_total_routing_fee_msat
Currently, users have no means to upper-bound the total fees accruing
when finding a route. Here, we add a corresponding field to
`RouteParameters` which will be used to limit the candidate set during
path finding in the following commits.
2023-09-26 09:44:04 +02:00
Matt Corallo
20e1c27334 Provide some test coverage of shutdown msgs for unfunded chans
We have code to handle receiving `shutdown` messages on unfudned
channels. However, it had no test coverage, which we add here.
2023-09-26 00:38:17 +00:00
Matt Corallo
d6cd197adc Fix potential peer_state deadlocks in finish_force_close_channel
`ChannelManager::finish_force_close_channel` exists to do cleanups
which must happen without the `per_peer_state` mutex held. However,
because it lacked lock assertions, several changes snuck in
recently which resulted in it running with peer-state locks held,
risking a deadlock if some HTLCs need to be failed.
2023-09-26 00:38:17 +00:00
Matt Corallo
ce7463486e
Merge pull request #2583 from Evanfeenstra/pub-make-onion
Pub make onion
2023-09-25 17:08:41 +00:00
Matt Corallo
0e83e91d7a
Merge pull request #2576 from valentinewallace/2023-09-fix-outbound-bp-fail-ev
Fix `PaymentPathFailed::payment_failed_permanently` on blinded path fail
2023-09-25 16:56:03 +00:00
Matt Corallo
a87f381a51
Merge pull request #2594 from benthecarman/debug-monitor-update-id
Implement Debug for MonitorUpdateId
2023-09-25 16:00:04 +00:00
benthecarman
66821a9e72
Implement Debug for MonitorUpdateId 2023-09-24 00:34:27 -05:00
Valentine Wallace
6299f7d14f
Blame outbound channel on UPDATE onion failure with 0-len update
We've run into this several times in the wild, likely due to
https://github.com/ElementsProject/lightning/issues/6200 wherein a node on the
path will error with 0x1000 but not provide a channel update (a spec
violation).

Previously, we would blame the inbound edge even though the buggy peer wanted
us to blame the outbound edge. Since this issue seems to be recurring and our
blaming the inbound edge is causing us to punish innocent channels, trust the
peer that the outbound edge is the one to blame.
2023-09-22 15:56:28 -04:00
Valentine Wallace
9df61dc0b8
Fix PaymentPathFailed::payment_failed_permanently on blinded path fail
Previously this value would be incorrectly set to true because we wouldn't
account for blinded hops when determining if we were processing the last hop's
failure packet.
2023-09-22 15:56:23 -04:00
Valentine Wallace
5f5119fa3d
Correct DecodedOnionFailure when processing we-are-intro-node path
We don't support sending to paths where we are the intro node yet, but may as
well set the failure correctly now.
2023-09-22 15:56:23 -04:00
Valentine Wallace
9c41f129c0
DecodedOnionFailure::payment_retryable -> ::payment_failed_permanently
Our ultimate goal with this field is to set
PaymentPathFailed::payment_failed_permanently, so use this name rather than
flipping a bool back and forth across methods.
2023-09-22 15:56:23 -04:00
Valentine Wallace
61ab1f8513
Struct-ify onion util internal result type
Improves readability.
2023-09-22 15:56:18 -04:00
Valentine Wallace
9ade8eb23b
Rename onion util internal var
This variable is ultimately for setting
PaymentPathFailed::payment_failed_permanently, so use this name rather than
flipping a bool back and forth.
2023-09-22 15:56:07 -04:00
Elias Rohrer
a37a16a3ce
Merge pull request #2589 from ErikDeSmedt/reexport_route_hint_hop
Reexport RouteHintHop
2023-09-22 09:09:41 +02:00
Matt Corallo
7ea280e98b
Merge pull request #2592 from TheBlueMatt/2023-09-117-alpha
Update crate version numbers to 0.0.117-alpha1/invoice 0.25-alpha1
2023-09-21 23:20:17 +00:00
Matt Corallo
c91debba1a
Merge pull request #2590 from TheBlueMatt/2023-09-default-score-params
Use `Default::default()` to construct `()` as a test scoring param
2023-09-21 20:40:13 +00:00
Matt Corallo
e01b51db67 Update crate version numbers to 0.0.117-alpha1/invoice 0.25-alpha1 2023-09-21 20:27:12 +00:00
Matt Corallo
4f4e84ef4d
Merge pull request #2562 from TheBlueMatt/2023-08-no-perm-fail
Drop the ChannelMonitorUpdateStatus::PermanentFailure variant
2023-09-21 20:22:16 +00:00
Matt Corallo
f254c56585 Add an UnrecoverableError variant to ChannelMonitorUpdateStatus
While there is no great way to handle a true failure to persist a
`ChannelMonitorUpdate`, it is confusing for users for there to be
no error variant at all on an I/O operation.

Thus, here we re-add the error variant removed over the past
handful of commits, but rather than handle it in a truly unsafe
way, we simply panic, optimizing for maximum mutex poisoning to
ensure any future operations fail and return immediately.

In the future, we may consider changing the handling of this to
instead set some "disconnect all peers and fail all operations"
bool to give the user a better chance to shutdown in a semi-orderly
fashion, but there's only so much that can be done in lightning if
we truly cannot persist new updates.
2023-09-21 19:12:31 +00:00
Matt Corallo
aa9c601774 Drop doc comments on ChainMonitor trait impl methods
In general, doc comments on trait impl blocks are not very visible
in rustdoc output, and unless they provide useful information they
should be elided.

Here we drop useless doc comments on `ChainMonitor`'s `Watch` impl
methods.
2023-09-21 19:04:41 +00:00
Matt Corallo
971f7a7e42 Drop error handling in handle_new_monitor_update
Now that `handle_new_monitor_update` can no longer return an error,
it similarly no longer needs any code to handle errors. Here we
remove that code, substantially reducing macro variants.
2023-09-21 19:04:41 +00:00
Matt Corallo
341163eeb5 Clean up code flow in ChannelManager
In the previous commit various dead code was removed. Here we
finish that cleanup by removing uneccessary indentation and syntax.
2023-09-21 19:04:41 +00:00
Matt Corallo
574c77e7bc Drop PermamentFailure persistence handling in ChannelManager 2023-09-21 19:04:41 +00:00
Matt Corallo
e5bd7920bd Update ChannelMonitorUpdateStatus documentation with async support
Since we now (almost) support async monitor update persistence, the
documentation on `ChannelMonitorUpdateStatus` can be updated to no
longer suggest users must keep a local copy that persists before
returning. However, because there are still a few remaining issues,
we note that async support is currently beta and explicily warn of
potential for funds-loss.

Fixes #1684
2023-09-21 19:04:41 +00:00
Matt Corallo
a96e2fe144 Rename MonitorEvent::CommitmentTxConfirmed to HolderForceClosed
The `MonitorEvent::CommitmentTxConfirmed` has always been a result
of us force-closing the channel, not the counterparty doing so.
Thus, it was always a bit of a misnomer. Worse, it carried over
into the channel's `ClosureReason` in the event API.

Here we simply rename it and use the proper `ClosureReason`.
2023-09-21 19:04:41 +00:00
Matt Corallo
6e115db22b Drop ChannelMonitorUpdate::UpdateFailed as its now unused 2023-09-21 19:04:41 +00:00
Matt Corallo
f24502e986 Drop channel_perm_failed tracking in ChainMonitor
Now that `PermanentFailure` is not a possible return value, we can
simply remove handling of it in `ChannelMonitor`.
2023-09-21 19:04:41 +00:00
Matt Corallo
23c5308bcb Drop the ChannelMonitorUpdateStatus::PermanentFailure variant
When a `ChannelMonitorUpdate` fails to apply, it generally means
we cannot reach our storage backend. This, in general, is a
critical issue, but is often only a transient issue.

Sadly, users see the failure variant and return it on any I/O
error, resulting in channel force-closures due to transient issues.

Users don't generally expect force-closes in most cases, and
luckily with async `ChannelMonitorUpdate`s supported we don't take
any risk by "delaying" the `ChannelMonitorUpdate` indefinitely.

Thus, here we drop the `PermanentFailure` variant entirely, making
all failures instead be "the update is in progress, but won't ever
complete", which is equivalent if we do not close the channel
automatically.
2023-09-21 19:04:05 +00:00
Matt Corallo
f2bb931ef9 Rewrite failure payment retry tests to avoid perm-fail storage
Two tests in the payment tests currently rely on failing to persist
ChannelMonitorUpdates as their method of failing payments before
they even get out the door.

In the coming commits we'll drop the persist failure error codes,
so here rewrite these tests to rely on trying to send more than is
available in a channel.
2023-09-21 17:58:47 +00:00
Erik De Smedt
d1d23ff073 Reexport RouteHintHop
Earlier @benthecarman re-exported `RouteHint` to make life-easier
for developpers that use `lightning-invoice` and don't use the
`lightning`-crate.

This only solved part of the issue. To create a `RouteHint` the
developer must also have access to `RouteHintHop`.

See also:
  PR https://github.com/lightningdevkit/rust-lightning/pull/2572
	commit 79b426f49b
2023-09-21 15:40:34 +02:00
Matt Corallo
6b0d94a302 Use Default::default() to construct () as a test scoring param
In bindings, we can't use unbounded generic types, and thus have to
rip out the `ScoreParams` and replace them with static
`ProbabilisticScoringFeeParams` universally. To make this easier,
using `Default::default()` everywhere allows the type to change out
from under the test without the test needing to change.
2023-09-21 01:44:23 +00:00
Matt Corallo
f2fe95e565
Merge pull request #2547 from TheBlueMatt/2023-04-nonlinear-scoring
Add an option to make the success probability estimation nonlinear
2023-09-20 22:21:02 +00:00
Evan Feenstra
30b74a6bcf public make_onion_message static method on OnionMessenger 2023-09-20 13:42:35 -07:00
Matt Corallo
f2b2920b13 Avoid unnecessary newline in middle of log statement 2023-09-20 18:32:21 +00:00
Matt Corallo
259ceb0ebf Add an option to make the success probability estimation nonlinear
Our "what is the success probability of paying over a channel with
the given liquidity bounds" calculation currently assumes the
probability of where the liquidity lies in a channel is constant
across the entire capacity of a channel. This is obviously a
somewhat dubious assumption given most nodes don't materially
rebalance and flows within the network often push liquidity
"towards the edges".

Here we add an option to consider this when scoring channels during
routefinding. Specifically, if a new `linear_success_probability`
flag is unset on `ProbabilisticScoringFeeParameters`, rather than
assuming a PDF of `1` (across the channel's capacity scaled from 0
to 1), we use `(x - 0.5)^2`.

This assumes liquidity is likely to be near the edges, which
matches experimental results. Further, calculating the CDF (i.e.
integral) between arbitrary points on the PDF is trivial, which we
do as our main scoring function.

While this (finally) introduces floats in our scoring, its not
practical to exponentiate using fixed-precision, and benchmarks
show this is a performance regression, but not a huge one, more
than made up for by the increase in payment success rates.
2023-09-20 18:32:21 +00:00
Matt Corallo
df52da7b31 Score in-flight amounts as amounts, not a capacity reduction
When we started considering the in-flight amounts when scoring, we
took the approach of considering the in-flight amount as an
effective reduction in the channel's total capacity. When we were
scoring using a flat success probability PDF, that was fine,
however in the next commit we'll move to a highly nonlinear one,
which makes this a pretty confusing heuristic.

Here, instead, we move to considering the in-flight amount as
simply an extension of the amount we're trying to send over the
channel, which is equivalent for the flat success probability PDF,
but makes much more sense in a nonlinear world.
2023-09-20 18:32:21 +00:00
Matt Corallo
5f98c39927 Scale the success probability of channels without info down by 75%
If we are examining a channel for which we have no information at
all, we traditionally assume the HTLC success probability is
proportional to the channel's capacity. While this may be the case,
it is not the case that a tiny payment over a huge channel is
guaranteed to succeed, as we assume. Rather, the probability of
such success is likely closer to 50% than 100%.

Here we try to capture this by simply scaling the success
probability for channels where we have no information down
linearly. We pick 75% as the upper bound rather arbitrarily - while
50% may be more accurate, its possible it would lead to an
over-reliance on channels which we have paid through in the past,
which aren't necessarily always the best candidates.

Note that we only do this scaling for the historical bucket
tracker, as there we can be confident we've never seen a successful
HTLC completion on the given channel. If we were to apply the same
scaling to the simple liquidity bounds based scoring we'd penalize
channels we've never tried over those we've only ever fails to pay
over, which is obviously not a good outcome.
2023-09-19 21:23:28 +00:00
Matt Corallo
75438900b2 Split out success probability calculation to allow for changes
Our "what is the success probability of paying over a channel with
the given liquidity bounds" calculation is reused in a few places,
and is a key assumption across our main score calculation and the
historical bucket score calculations.

Here we break it out into a function to make it easier to
experiment with different success probability calculations.

Note that this drops the numerator +1 in the liquidity scorer,
which was added to compensate for the divisor + 1 (which exists to
avoid divide-by-zero), making the new math slightly less correct
but not by any material amount.
2023-09-19 21:22:49 +00:00
Matt Corallo
7e7e7a0573
Merge pull request #2587 from wpaulino/anchors-fee-fixes
Anchor outputs fee fixes
2023-09-19 20:43:08 +00:00
Wilmer Paulino
9736c709c0
Sanity check fees on transactions produced by the bump event handler
We add a few debug assertions to ensure we don't overpay fees by 5% more
than expected.
2023-09-19 11:13:44 -07:00