Commit graph

4229 commits

Author SHA1 Message Date
Matt Corallo
7bc2a148b2 Fix handling of duplicate initial ChannelMonitor writing
In e06484b0f4, we added specific
handling for outbound-channel initial monitor updates failing -
in such a case we have a counterparty who tried to open a second
channel with the same funding info we just gave them, causing us
to force-close our outbound channel as it shows up as
duplicate-funding. Its largely harmless as it leads to a spurious
force-closure of a channel with a peer doing something absurd,
however it causes the `full_stack_target` fuzzer to fail.

Sadly, in 574c77e7bc, as we were
dropping handling of `PermanentFailure` handling for updates, we
accidentally dropped handling for initial updates as well.

Here we fix the issue (again) and add a test.
2023-12-29 06:27:31 +00:00
Matt Corallo
5eea3058c9 Do not panic if a peer learns our funding info before we fund
We'd previously assumed that LDK would receive
`funding_transaction_generated` prior to our peer learning the txid
and panicked if the peer tried to open a redundant channel to us
with the same funding outpoint.

While this assumption is generally safe, some users may have
out-of-band protocols where they notify their LSP about a funding
outpoint first, or this may be violated in the future with
collaborative transaction construction protocols, i.e. the upcoming
dual-funding protocol.
2023-12-29 06:27:31 +00:00
Matt Corallo
bfe911dadc Drop now-unused fields from MsgHandleErrInternal 2023-12-29 06:27:31 +00:00
Matt Corallo
080865dff9 Move ChannelClosed generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we remove `issue_channel_close_events` by moving
`ChannelClosed` event generation into `finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
ee5b8c7003 Move DiscardFunding generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we move the first of the two events, `DiscardFunding`, into
`finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
396c36b6ea Consider MONITOR_UPDATE_IN_PROGRESS as unbroadcasted funding
If we promote our channel to `AwaitingChannelReady` after adding
funding info, but still have `MONITOR_UPDATE_IN_PROGRESS` set, we
haven't broadcasted the funding transaction yet and thus should
return values from `unbroadcasted_funding[_txid]` and generate a
`DiscardFunding` event.
2023-12-29 06:27:31 +00:00
Matt Corallo
c6e4debee9 Bump versions to 0.0.119/lightning-invoice 0.27 2023-12-15 23:53:40 +00:00
Matt Corallo
ef2156ae8b
Merge pull request #2798 from TheBlueMatt/2023-12-119-bindings-upstream
Small API cleanups pre-0.0.119
2023-12-15 23:40:57 +00:00
Wilmer Paulino
f5e87d8441
Merge pull request #2795 from TheBlueMatt/2023-11-robuster-chan-to-peer
Move channel -> peer tracking to OutPoints from Channel IDs
2023-12-15 15:36:52 -08:00
Matt Corallo
642240e867 Use correct default value when comparing to htlc_maximum_msat
62f8669654 added two
`htlc_maximum_msat.unwrap_or`s, but used a default value of 0,
spuriously causing all HTLCs to fail if we don't have an htlc
maximum value. This should be mostly harmless, but we should fix it
anyway.
2023-12-15 22:32:24 +00:00
Matt Corallo
bb0ddad00d Make FinalOnionHopData public
In 4b5db8c3ce, `channelmanager::PendingHTLCRouting` was made
public, exposing a `FinalOnionHopData` field to the world. However,
`FinalOnionHopData` was left crate-private, making the enum
impossible to construct.

There isn't a strong reason for this (even though the
`FinalOnionHopData` API is somewhat confusing, being separated from
the rest of the onion structs), so we expose it here.
2023-12-15 22:31:51 +00:00
Jeffrey Czyz
37319a6193
Fix build warning 2023-12-15 15:40:10 -06:00
Jeffrey Czyz
164c8553e5
Use one-hop blinded paths only for announced nodes
To avoid exposing a node's identity in a blinded path, only create
one-hop blinded paths if the node has been announced, and thus has
public channels. Otherwise, there is no way to route a payment to the
node, exposing its identity needlessly.
2023-12-15 15:40:10 -06:00
Jeffrey Czyz
16ee24086c
DRY up OffersMessage::InvoiceRequest handling 2023-12-15 15:40:10 -06:00
Jeffrey Czyz
827833c933
Multi-hop blinded payment paths in ChannelManager
When constructing blinded payment paths for Bolt12Invoice, delegate to
Router::create_blinded_payment_paths which may produce multi-hop blinded
paths. Fallback to one-hop blinded paths if the Router fails or returns
no paths.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
62f8669654
Add create_blinded_payment_paths to Router
The Router trait is used to find a Route for paying a node. Expand the
interface with a create_blinded_payment paths method for creating such
paths to a recipient node.

Provide an implementation for DefaultRouter that creates two-hop
blinded paths where the recipient's peers serve as the introduction
nodes.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
edb5892030
CounterpartyForwardingInfo to PaymentRelay mapping 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
4da08623a6
Fix broken doc link in create_refund_builder 2023-12-15 15:40:09 -06:00
Jeffrey Czyz
606304aa32
Multi-hop blinded paths in ChannelManager
When constructing blinded paths for Offer and Refund, delegate to
MessageRouter::create_blinded_paths which may produce multi-hop blinded
paths. Fallback to one-hop blinded paths if the MessageRouter fails or
returns no paths.

Likewise, do the same for InvoiceRequest and Bolt12Invoice reply paths.
2023-12-15 15:40:09 -06:00
Jeffrey Czyz
dcd8d58346
Use CLTV_FAR_FAR_AWAY in PaymentConstraints
When finding a route through a blinded path, a random CLTV offset may be
added to the path in order to preserve privacy. This needs to be
accounted for in the blinded path's PaymentConstraints. Add
CLTV_FAR_FAR_AWAY to the max_cltv_expiry constraint to allow for such
offsets.
2023-12-15 15:37:18 -06:00
Matt Corallo
e9452c701b Consistently clean up when failing in internal_funding_created
When we fail to accept a counterparty's funding for various
reasons, we should ensure we call the correct cleanup methods in
`internal_funding_created` to remove the temporary data for the
channel in our various internal structs (primarily the SCID alias
map).

This adds the missing cleanup, using `convert_chan_phase_err`
consistently in all the error paths.

This also ensures we get a `ChannelClosed` event when relevant.
2023-12-15 21:08:14 +00:00
Jeffrey Czyz
c558ccd6a9
Fix create_one_hop_blinded_payment_path docs 2023-12-15 14:52:07 -06:00
Jeffrey Czyz
bedc2c64fc
Require any Router also implements MessageRouter
ChannelManager is parameterized by a Router in order to find routes when
sending and retrying payments. For the offers flow, it needs to be able
to construct blinded paths (e.g., in the offer and in reply paths).
Instead of adding yet another parameter to ChannelManager, require that
any Router also implements MessageRouter. Implement this for
DefaultRouter by delegating to a DefaultMessageRouter.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
97049daac2
Add create_blinded_paths to MessageRouter
The MessageRouter trait is used to find an OnionMessagePath to a
Destination (e.g., to a BlindedPath). Expand the interface with a
create_blinded_paths method for creating such paths to a recipient.
Provide a default implementation creating two-hop blinded paths where
the recipient's peers serve as introduction nodes.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
ffb0d83298
Add RouteBlinding feature flag
The RouteBlinding feature flag is signals support for relaying payments
over blinded paths. It is used for paying BOLT 12 invoices, which are
required to included at least one blinded path.
2023-12-15 14:52:07 -06:00
Jeffrey Czyz
ee026d4357
Re-order AnchorsZeroFeeHtlcTx in module docs/tests
Move AnchorsZeroFeeHtlcTx after Wumbo to keep order by feature bit.
Also, update setting order and comment in tests.
2023-12-15 14:52:07 -06:00
Matt Corallo
c92db69183
Merge pull request #2656 from TheBlueMatt/2023-09-scoring-decay-timer
Stop decaying liquidity information during scoring
2023-12-15 20:06:30 +00:00
Elias Rohrer
e1897de606
Merge pull request #2779 from G8XSU/2706-stop
Stop cleaning monitor updates on new block connect
2023-12-15 09:28:31 +01:00
Gursharan Singh
ef0909627d
Stop cleaning monitor updates on new block connect
Previously, we used to cleanup monitor updates at both consolidation
threshold and new block connects. With this change we will only
cleanup when our consolidation criteria is met. Also, we remove
monitor read from cleanup logic, in case of update consolidation.
Note: In case of channel-closing monitor update, we still need to
read the old monitor before persisting the new one in order to
determine the cleanup range.
2023-12-14 10:29:12 -08:00
Matt Corallo
f8fb70a765 Drop fake time advancing in scoring tests
Now that we use explicit times passed to decay methods, there's no
reason to make calls to `SinceEpoch::advance` in scoring tests.
2023-12-13 23:26:09 +00:00
Matt Corallo
18b42319bc Drop half-life-based bucket decay in update_history_buckets
Because we decay the bucket information in the background, there's
not much reason to try to decay them immediately prior to updating,
and in removing that we can also clean up a good bit of dead code,
which we do here.
2023-12-13 23:26:09 +00:00
Matt Corallo
81389dee30 Drop warning about mixing no-std and std ProbabilisticScorers
Now that the serialization format of `no-std` and `std`
`ProbabilisticScorer`s both just use `Duration` since UNIX epoch
and don't care about time except when decaying, we don't need to
warn users to not mix the scorers across `no-std` and `std` flags.

Fixes #2539
2023-12-13 23:26:09 +00:00
Matt Corallo
40b4094e87 Add a benchmark for decaying a 100k channel scorer's liquidity info
This is a good gut-check to ensure we don't end up taking a ton of
time decaying channel liquidity info.

It currently clocks in around 1.25ms on an i7-1360P.
2023-12-13 23:26:09 +00:00
Matt Corallo
512f44cf15 Drop now-trivial decayed_offset_msat helper utility
As we now no longer decay bounds information when fetching them,
there is no need to have a decaying-fetching helper utility.
2023-12-13 23:26:09 +00:00
Matt Corallo
d15a354f77 Drop now-unused T: Time bound on ProbabilisticScorer
Now that we don't access time via the `Time` trait in
`ProbabilisticScorer`, we can finally drop the `Time` bound
entirely, removing the `ProbabilisticScorerUsingTime` and type
alias indirection and replacing it with a simple struct.
2023-12-13 23:26:09 +00:00
Matt Corallo
22888425f7 Use Duration based time info in scoring rather than Time
In the coming commits, the `T: Time` bound on `ProbabilisticScorer`
will be removed. In order to enable that, we need to switch over to
using the `ScoreUpdate`-provided current time (as a `Duration`
since the unix epoch), making the `T` bound entirely unused.
2023-12-13 23:26:09 +00:00
Matt Corallo
d54c93065a Pipe Duration-based time information through scoring pipeline
In the coming commits, the `T: Time` bound on `ProbabilisticScorer`
will be removed. In order to enable that, we need to pass the
current time (as a `Duration` since the unix epoch) through the
score updating pipeline, allowing us to keep the
`*last_updated_time` fields up-to-date as we go.
2023-12-13 23:26:09 +00:00
Matt Corallo
5ac68c1af3 Update history bucket last_update time immediately on update
Now that we aren't decaying during scoring, when we set the
last_updated time in the history bucket logic doesn't matter, so
we should just update it when we've just updated the history
buckets.
2023-12-13 23:26:09 +00:00
Matt Corallo
6f8838fe70 Stop decaying liquidity information during bounds-based scoring
Because scoring is an incredibly performance-sensitive operation,
doing liquidity information decay (and especially fetching the
current time!) during scoring isn't really a great idea. Now that
we decay liquidity information in the background, we don't have any
reason to decay during scoring, and we ultimately remove it
entirely here.
2023-12-13 23:26:09 +00:00
Matt Corallo
35b49645c4 Stop decaying historical liquidity information during scoring
Because scoring is an incredibly performance-sensitive operation,
doing liquidity information decay (and especially fetching the
current time!) during scoring isn't really a great idea. Now that
we decay liquidity information in the background, we don't have any
reason to decay during scoring, and we remove the historical bucket
liquidity decaying here.
2023-12-13 23:26:09 +00:00
Matt Corallo
9659c06955 Impl decaying in ProbabilisticScorer::decay_liquidity_certainty
This implements decaying in the `ProbabilisticScorer`'s
`ScoreLookup::decay_liquidity_certainty` implementation, using
floats for accuracy since we're no longer particularly
time-sensitive. Further, it (finally) removes score entries which
have decayed to zero.
2023-12-13 23:26:09 +00:00
Matt Corallo
f0f8194719 Track historical liquidity update time separately from the bounds
In the next commit, we'll start to use the new
`ScoreUpdate::decay_liquidity_certainty` to decay our bounds in the
background. This will result in the `last_updated` field getting
updated regularly on decay, rather than only on update. While this
isn't an issue for the regular liquidity bounds, it poses a problem
for the historical liquidity buckets, which are decayed on a
separate (and by default much longer) timer. If we didn't move to
tracking their decays separately, we'd never let the `last_updated`
field get old enough for the historical buckets to decay at all.

Instead, here we introduce a new `Duration` in the
`ChannelLiquidity` which tracks the last time the historical
liquidity buckets were last updated. We initialize it to a copy of
`last_updated` on deserialization if it is missing.
2023-12-13 23:26:09 +00:00
Matt Corallo
b84842a904 Add a scoring decay method to the ScoreUpdate trait
Rather than relying on fetching the current time during
routefinding, here we introduce a new trait method to `ScoreUpdate`
to do so. This largely mirrors what we do with the `NetworkGraph`,
and allows us to take on much more expensive operations (floating
point exponentiation) in our decaying.
2023-12-13 23:26:09 +00:00
Matt Corallo
a866ba7ee3 cfg-gate async signing logic
We are intending to release without having completed our async
signing logic, which sadly means we need to cfg-gate it to ensure
we restore the previous state of panicking on signer errors, rather
than putting us in a stuck state with no way to recover.

Here we add a new `async_signing` cfg flag and use it to gate all
the new logic from #2558 effectively reverting commits
1da29290e7 through
014a336e59.
2023-12-13 22:58:34 +00:00
Matt Corallo
6c366cf35f Pass the current time through ScoreUpDate methods
In the coming commits, we'll stop relying on fetching the time
during routefetching, preferring to decay score data in the
background instead.

The first step towards this - passing the current time through into
the scorer when updating.
2023-12-13 18:36:40 +00:00
Matt Corallo
6471eb050e Depend on libm in no-std for powf(64)
In the next commits we'll need `f64`'s `powf`, which is only
available in `std`. For `no-std`, here we depend on `libm` (a
`rust-lang` org project), which we can use for `powf`.
2023-12-13 18:36:40 +00:00
valentinewallace
9856fb6710
Merge pull request #2688 from valentinewallace/2023-10-multihop-blinded-recv
Support receiving to multi-hop blinded paths
2023-12-13 10:31:02 -05:00
Matt Corallo
0dbf17b781
Merge pull request #2703 from wpaulino/retryable-commitment-broadcast
Refactor commitment broadcast to always go through OnchainTxHandler
2023-12-13 05:15:54 +00:00
Valentine Wallace
6b66271acf
Add missing keysend preimage check on inbound onion read. 2023-12-12 18:42:38 -05:00
Valentine Wallace
63ebde1d2e
Add test coverage for serialization of malformed HTLCs.
in Channel and ChannelManager.
2023-12-12 18:38:59 -05:00