Commit graph

2736 commits

Author SHA1 Message Date
Elias Rohrer
649144d25f
Account for leftover fee budget when retrying via check_retry_payment 2023-09-26 20:12:30 +02:00
Matt Corallo
39094d4472 Correct comment in shutdown_on_unfunded_channel
which described the script type incorrectly.
2023-09-26 16:37:40 +00:00
Matt Corallo
11b228b7b0 Correct ChannelUnavailable error docs on send_payment_with_route
Monitor update failure can no longer lead to a `ChannelUnavailable`
error, but more common cases such as the peer being disconnected
always could, so those should be documented clearer.
2023-09-26 16:37:19 +00:00
Elias Rohrer
ac57163895
Account for leftover fee budget when retrying PartialFailures 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
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
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
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
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
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
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
Evan Feenstra
30b74a6bcf public make_onion_message static method on OnionMessenger 2023-09-20 13:42:35 -07:00
Matt Corallo
36af1f06fa
Merge pull request #2534 from tnull/2023-08-upstream-preflight-probing
Upstream and fix preflight probing
2023-09-18 16:41:57 +00:00
Elias Rohrer
f75ac9addf
Expose AChannelManager trait and use it in lightning-invoice 2023-09-18 15:08:28 +02:00
Elias Rohrer
30e47ca56c
Probe up to second-to-last hop if last was provided by route hint
If the last hop was provided by route hint we assume it's not an announced channel.
If furthermore only a single route hint is provided we refrain from probing through
all the way to the end and instead probe up to the second-to-last channel.

Optimally we'd do this not based on above mentioned assumption but
rather by checking inclusion in our network graph. However, we don't
have access to our graph in `ChannelManager`.
2023-09-18 15:08:27 +02:00
Elias Rohrer
cdb8772202
Test preflight probing sends and skips if necessary 2023-09-18 15:08:27 +02:00
Elias Rohrer
20c842b496
Add preflight probing capabilities
We add a `ChannelManager::send_preflight_probes` method that can be used
to send pre-flight probes given some [`RouteParameters`]. Additionally,
we add convenience methods in for spontaneous probes and send pre-flight
probes for a given invoice.

As pre-flight probes might take up some of the available liquidity, we
here introduce that channels whose available liquidity is less than the
required amount times
`UserConfig::preflight_probing_liquidity_limit_multiplier` won't be used
to send pre-flight probes.

This commit is a more or less a carbon copy of the pre-flight
probing code recently added to LDK Node.
2023-09-18 15:08:27 +02:00
Elias Rohrer
c6a1a12aca
Include maybe_announced field in RouteHop
When sending preflight probes, we want to exclude last hops that are
possibly announced. To this end, we here include a new field in
`RouteHop` that will be `true` when we either def. know the hop to be
announced, or, if there exist public channels between the hop's
counterparties that this hop might refer to (i.e., be an alias for).
2023-09-18 15:08:27 +02:00
Matt Corallo
53c8f89ba9 Avoid unnecessarily cloning unsigned Transaction when broadcasting
Our `Trusted*` wrappers in `chan_utils` expose additional inner
fields by reference. However, because they were not explicitly
marked as returning a reference with the wrapped struct's
lifetimes, rustc was considering them to return a reference with
the wrapper struct's lifetime.

This is unnecessarily restrictive, and resulted in the addition of
a clone in 9850c5814a which we remove
here.
2023-09-15 20:41:48 +00:00
Matt Corallo
24db35eeea
Merge pull request #2568 from tnull/2023-09-housekeeping
Housekeeping: fix some warning and docs
2023-09-14 20:17:05 +00:00
Elias Rohrer
411a3f7d76
Fix unused import warning in shutdown_tests 2023-09-14 09:09:27 +02:00
Elias Rohrer
190867c373
Fix unused variable warning in monitor_tests 2023-09-14 09:09:27 +02:00
Matt Corallo
daf79f515f
Merge pull request #2413 from valentinewallace/2023-07-route-blinding
Route blinding MVP
2023-09-13 20:51:59 +00:00
Matt Corallo
286d1db2cd
Merge pull request #2521 from TheBlueMatt/2023-08-one-less-write
Avoid persisting ChannelManager in some cases and separate event from persist notifies
2023-09-13 15:40:12 +00:00
Elias Rohrer
758679af84
Set payment_secret when sending probes
Previously, we'd leave the payment secret field empty while sending
probes, which resulted in having them rejected
with `(PERM|invalid_onion_payload)` by Eclair nodes.

In order to mitigate the issue, we just set a random payment secret.
2023-09-13 11:52:45 +02:00
Elias Rohrer
88905126ae
Cleanup ChannelId re-export
`ChannelId` was weirdly listed in the re-export section of the docs and
reachable via multiple paths. Here we opt to make the `channel_id`
module private and leave only the `ChannelId` struct itself exposed.
2023-09-13 09:46:50 +02:00
Valentine Wallace
ebdc4ae80a
Only allow creating 1-hop blinded paths.
Useful until forwarding and receiving to multi-hop blinded paths is supported.
2023-09-12 18:12:03 -04:00
Valentine Wallace
3e377a1d2f
Test sending and receiving to 1-hop blinded paths 2023-09-12 18:12:03 -04:00
Valentine Wallace
070f7e0d5c
Support receiving to 1-hop blinded payment paths. 2023-09-12 18:11:59 -04:00
Valentine Wallace
154841b234
Parameterize InboundPayload reads with NodeSigner
This will be used in the next commit to deserialize encrypted TLVs for
receiving to 1-hop blinded paths.
2023-09-12 18:11:59 -04:00
Valentine Wallace
7b1e09134a
Support paying blinded paths. 2023-09-12 18:11:54 -04:00
Matt Corallo
ce94a5ec22 Skip persistence in the usual case handling channel_reestablish
When we handle an inbound `channel_reestablish` from our peers it
generally doesn't change any state and thus doesn't need a
`ChannelManager` persistence. Here we avoid said persistence where
possible.
2023-09-12 19:06:34 +00:00
Matt Corallo
9078c0dc5c Always persist the ChannelManager on a failed ChannelUpdate
If we receive a `ChannelUpdate` message which was invalid, it can
cause us to force-close the channel, which should result in a
`ChannelManager` persistence, though its not critical to do so.
2023-09-12 19:06:34 +00:00
Matt Corallo
e37b350408 Avoid persisting ChannelManager in response to peer connection
When a peer connects and we send some `channel_reestablish`
messages or create a `per_peer_state` entry there's really no
reason to need to persist the `ChannelManager`. None of the
possible actions we take immediately result in a change to the
persisted contents of a `ChannelManager`, only the peer's later
`channel_reestablish` message does.
2023-09-12 19:06:34 +00:00
Matt Corallo
71bafecafc Move a handful of channel messages to notify-without-persist
Many channel related messages don't actually change the channel
state in a way that changes the persisted channel. For example,
an `update_add_htlc` or `update_fail_htlc` message simply adds the
change to a queue, changing the channel state when we receive a
`commitment_signed` message.

In these cases there's really no reason to wake the background
processor at all - there's no response message and there's no state
update. However, note that if we close the channel we should
persist the `ChannelManager`. If we send an error message without
closing the channel, we should wake the background processor
without persisting.

Here we move to the appropriate `NotifyOption` on some of the
simpler channel message handlers.
2023-09-12 19:06:34 +00:00