Commit graph

5385 commits

Author SHA1 Message Date
Matt Corallo
7790e30880 Store info about claimed payments, incl HTLCs in ChannelMonitors
When we claim an MPP payment, then crash before persisting all the
relevant `ChannelMonitor`s, we rely on the payment data being
available in the `ChannelManager` on restart to re-claim any parts
that haven't yet been claimed. This is fine as long as the
`ChannelManager` was persisted before the `PaymentClaimable` event
was processed, which is generally the case in our
`lightning-background-processor`, but may not be in other cases or
in a somewhat rare race.

In order to fix this, we need to track where all the MPP parts of
a payment are in the `ChannelMonitor`, allowing us to re-claim any
missing pieces without reference to any `ChannelManager` data.

Further, in order to properly generate a `PaymentClaimed` event
against the re-started claim, we have to store various payment
metadata with the HTLC list as well.

Here we store the required MPP parts and metadata in
`ChannelMonitor`s and make them available to `ChannelManager` on
load.
2024-10-24 17:44:33 +00:00
Matt Corallo
b8661ef6cf Pass info about claimed payments, incl HTLCs to ChannelMonitors
When we claim an MPP payment, then crash before persisting all the
relevant `ChannelMonitor`s, we rely on the payment data being
available in the `ChannelManager` on restart to re-claim any parts
that haven't yet been claimed. This is fine as long as the
`ChannelManager` was persisted before the `PaymentClaimable` event
was processed, which is generally the case in our
`lightning-background-processor`, but may not be in other cases or
in a somewhat rare race.

In order to fix this, we need to track where all the MPP parts of
a payment are in the `ChannelMonitor`, allowing us to re-claim any
missing pieces without reference to any `ChannelManager` data.

Further, in order to properly generate a `PaymentClaimed` event
against the re-started claim, we have to store various payment
metadata with the HTLC list as well.

Here we take the first step, building a list of MPP parts and
metadata in `ChannelManager` and passing it through to
`ChannelMonitor` in the `ChannelMonitorUpdate`s.
2024-10-24 17:44:33 +00:00
Matt Corallo
d9175f454b Use a struct to track MPP parts pending claiming
When we started tracking which channels had MPP parts claimed
durably on-disk in their `ChannelMonitor`, we did so with a tuple.
This was fine in that it was only ever accessed in two places, but
as we will start tracking it through to the `ChannelMonitor`s
themselves in the coming commit(s), it is useful to have it in a
struct instead.
2024-10-24 17:44:33 +00:00
Matt Corallo
a65d37b48b Add missing inbound_payment_id_secret write in ChannelManager
In aa09c33a17 we added a new secret
in `ChannelManager` with which to derive inbound `PaymentId`s. We
added read support for the new field, but forgot to add writing
support for it. Here we fix this oversight.
2024-10-23 16:15:01 +00:00
Matt Corallo
3c868dd311
Merge pull request #3142 from TheBlueMatt/2024-06-robust-updates
Reliably deliver gossip messages from our `ChannelMessageHandler`
2024-10-23 00:12:03 +00:00
Matt Corallo
b2bcfca30e
Merge pull request #3376 from yellowred/yellowred/monitor_update_name_pub
Make monitor update name public
2024-10-22 17:13:05 +00:00
olegkubrakov
01529dcba6 Make monitor update name public
These structs are meant for MonitoringUpdatingPersister implementation, but some
external implementations may still reuse them, so going to make them public.
2024-10-22 10:03:51 -07:00
G8XSU
2e118415e0
Implement to_lower_hex() Display/Debug for OfferId. 2024-10-21 15:41:42 -07:00
G8XSU
c75730a55f
Implement to_lower_hex() Display/Debug for PaymentId. 2024-10-21 15:40:02 -07:00
Matt Corallo
260322ea72
Merge pull request #3370 from dunxen/2024-10-dry-funding-created-signed
DRY `funding_created()` and `funding_signed()` for V1 channels
2024-10-21 19:25:18 +00:00
Duncan Dean
2db1aa27b6
DRY funding_created() and funding_signed() for V1 channels
There is a decent amount of shared code in these two methods so we make
an attempt to share that code here by introducing the
`InitialRemoteCommitmentReceiver` trait. This trait will also come in
handy when we need similar commitment_signed handling behaviour for
dual-funded channels.
2024-10-21 16:25:22 +02:00
Matt Corallo
1e0f43f108
Merge pull request #3356 from jkczyz/2024-10-inflight-scoring
Don't over-penalize channels with inflight HTLCs
2024-10-19 13:41:11 +00:00
Jeffrey Czyz
0305000850
Use total_inflight_amount_msat for probability fns
Rename parameters used when calculating success probability to make it
clear that the total mount in-flight should be used rather than the
payment amount.
2024-10-18 18:28:40 -05:00
Jeffrey Czyz
572fab7591
Correct comments in avoids_saturating_channels 2024-10-18 18:28:40 -05:00
Jeffrey Czyz
7fa6770a7a
Correct base_penalty_amount_multiplier_msat docs
Commit df52da7b31 modified
ProbabilisticScorer to apply some penalty amount multipliers to the
total amount flowing over the channel. However, the commit updated the
docs for base_penalty_amount_multiplier_msat even though that behavior
didn't change. This commit reverts those docs.
2024-10-18 18:28:40 -05:00
Jeffrey Czyz
866588c20f
Don't over-penalize channels with inflight HTLCs
Commit df52da7b31 modified
ProbabilisticScorer to apply some penalty amount multipliers (e.g.,
liquidity_penalty_amount_multiplier_msat) to the total amount flowing
over the channel (i.e., including inflight HTLCs), not just the payment
in question. This led to over-penalizing in-use channels. Instead, only
apply the total amount when calculating success probability.
2024-10-18 18:28:40 -05:00
Gursharan Singh
608209ef19
Merge pull request #3359 from TheBlueMatt/2024-10-less-types-re-export
Remove deprecated re-exports
2024-10-18 14:35:49 -07:00
Matt Corallo
c5be7aa285
Merge pull request #3297 from TheBlueMatt/2024-09-cleanup-package
Cleanup `PackageTemplate`a bit
2024-10-18 17:44:29 +00:00
Matt Corallo
20db790c53 Add a test for the fee-bump rate of timeout HTLC claims on cp txn
In a previous commit we updated the fee-bump-rate of claims against
HTLC timeouts on counterparty commitment transactions so that
instead of immediately attempting to bump every block we consider
the fact that we actually have at least `MIN_CLTV_EXPIRY_DELTA`
blocks to do so, and bumping at the appropriate rate given that.

Here we test that by adding an extra check to an existing test
that we do not bump in the very next block after the HTLC timeout
claim was initially broadcasted.
2024-10-18 16:23:27 +00:00
Matt Corallo
6ae33dc1e0 Set correct counterparty_spendable_height for outb local HTLCs
For outbound HTLCs, the counterparty can spend the output
immediately. This fixes the `counterparty_spendable_height` in the
`PackageTemplate` claiming outbound HTLCs on local commitment
transactions, which was previously spuriously set to the HTLC
timeout (at which point *we* can claim the HTLC).
2024-10-18 16:23:27 +00:00
Matt Corallo
b5b38603fd Stop exporting lightning::ln::features
Now that the module only contains some implementations of
serialization for the `lightning_types::features` structs, there's
no reason for it to be public.
2024-10-17 19:39:12 +00:00
Matt Corallo
f4b23115f6 Add a test of gossip message buffer limiting in PeerManager
This adds a simple test that the gossip message buffer in
`PeerManager` is limited, including the new behavior of bypassing
the limit when the broadcast comes from the
`ChannelMessageHandler`.
2024-10-17 19:09:15 +00:00
Matt Corallo
21904ffcb5 Add a constructor for the test SocketDescriptor and hang_writes
In testing, its useful to be able to tell the `SocketDescriptor` to
pretend the system network buffer is full, which we add here by
creating a new `hang_writes` flag. In order to simplify
constructing, we also add a new constructor which existing tests
are moved to.
2024-10-17 19:09:15 +00:00
Matt Corallo
bcad2571ac Fix the establish_connection utility method for a 2nd connection
The `establish_connection` method should work for more than one
connection per `PeerManager`, which we fix here.
2024-10-17 19:09:15 +00:00
Matt Corallo
1b711ed15f Reliably deliver gossip messages from our ChannelMessageHandler
When our `ChannelMessageHandler` creates gossip broadcast
`MessageSendEvent`s, we generally want these to be reliably
delivered to all our peers, even if there's not much buffer space
available.

Here we do this by passing an extra flag to `forward_broadcast_msg`
which indicates where the message came from, then ignoring the
buffer-full criteria when the flag is set.
2024-10-17 19:09:15 +00:00
Matt Corallo
d557334e31 Rename soonest_conf_deadline to counterparty_spendable_height
This renames the field in `PackageTemplate` which describes the
height at which a counterparty can make a claim to an output to
match its actual use.

Previously it had been set based on when a counterparty can claim
an output but also used for other purposes. In the previous commit
we cleaned up its use for fee-bumping-rate, so here we can rename
it as it is now only used as the `counteraprty_spendable_height`.
2024-10-17 18:34:33 +00:00
Matt Corallo
be915872c5 Clean up PackageTemplate::get_height_timer to consider type
`PackageTemplate::get_height_timer` is used to decide when to next
bump our feerate on claims which need to make it on chain within
some window. It does so by comparing the current height with some
deadline and increasing the bump rate as the deadline approaches.

However, the deadline used is the `counterparty_spendable_height`,
which is the height at which the counterparty might be able to
spend the same output, irrespective of why. This doesn't make sense
for all output types, for example outbound HTLCs are spendable by
our counteraprty immediately (by revealing the preimage), but we
don't need to get our HTLC timeout claims confirmed immedaitely,
as we actually have `MIN_CLTV_EXPIRY` blocks before the inbound
edge of a forwarded HTLC becomes claimable by our (other)
counterparty.

Thus, here, we adapt `get_height_timer` to look at the type of
output being claimed, and adjust the rate at which we bump the fee
according to the real deadline.
2024-10-17 18:34:33 +00:00
Matt Corallo
303a0c9a4e Stop passing current height to PackageTemplate::build_package
Now that we don't store the confirmation height of the inputs
being spent, passing the current height to
`PackageTemplate::build_package` is useless - we only use it to set
the height at which we should next bump the fee, but we just want
it to be "next block", so we might as well use `0` and avoid the
extra argument. Further, in one case we were already passing `0`,
so passing the argument is just confusing as we can't rely on it
being set.

Note that this does remove an assertion that we never merge
packages that were crated at different heights, and in the future
we may wish to do that (as there's no specific reason not to), but
we do not currently change the behavior.
2024-10-17 18:34:33 +00:00
Matt Corallo
8c4794df87 Drop unused PackageTemplate::height_original
This has never been used, and its set to a fixed value of zero for
HTLCs on local commitment transactions making it impossible to rely
on so might as well remove it.
2024-10-17 18:34:33 +00:00
Matt Corallo
4a7b01aea7
Merge pull request #3371 from tnull/2024-10-allow-to-set-payment-and-description-hash
Invoice utils: allow to set both description hash and payment hash
2024-10-17 15:33:22 +00:00
Matt Corallo
a19edbc32d Rename PackageTemplate::timelock counteraprty_spendable_height
This function was very confusing - its used to determine by when
we have to stop aggregating this claim with others as it starts to
be at risk of pinning due to the counterparty's ability to spend
the output.

It is not ever used as a timelock for a transaction, and thus its
name is very confusing.

Instead we rename it `counterparty_spendable_height`.
2024-10-16 21:04:48 +00:00
Matt Corallo
2f549eeb80 Rename claim cleaning match bool for accuracy
We don't actually care if a confirmed transaction claimed other
outputs, only that it claimed a superset of the outputs in the
pending claim we're looking at. Thus, the variable to detect that
is renamed `is_claim_subset_of_tx` instead of `are_sets_equal`.
2024-10-16 21:04:48 +00:00
Elias Rohrer
43fd78b0b9
Invoice utils: allow to set both description hash and payment hash 2024-10-16 17:04:38 +02:00
optout
f22b011f93 Signer extended with method to sign prev funding transaction input 2024-10-15 23:13:14 +02:00
Gursharan Singh
0db051b75a
Merge pull request #3329 from arik-so/monitor_archive_docs_followup
Document monitor archival idempotency requirement (#3276 followup)
2024-10-15 13:54:46 -07:00
Matt Corallo
57dcc7d762 Deprecate the lightning::util::string re-export from types
Like we've done for `features` and `payment`, here we mark the
`lightning::util::string` re-export as deprecated.
2024-10-15 14:33:03 +00:00
Matt Corallo
50b5a6efa7 Drop the Payment{Hash,Preimage,Secret} re-exports in lightning
These re-exports were deprecated in 0.0.124 in favor of the
`lightning::types::payment::*` paths, which we use here.
2024-10-15 14:33:03 +00:00
Matt Corallo
64c12431b7 Drop lightning::ln::features::* type aliases
These were deprecated in 0.0.124, and we drop them here in favor of
`lightning::types::features::*`.
2024-10-13 13:52:56 +00:00
Arik Sosman
268675a743
Document monitor archival idempotency requirement. 2024-10-11 09:44:38 -07:00
Matt Corallo
ad19d93180
Merge pull request #3349 from TheBlueMatt/2024-10-3270-followups
Minor #3270 Followups
2024-10-11 13:47:39 +00:00
Matt Corallo
a952d2d3d3
Merge pull request #3346 from TheBlueMatt/2024-10-dns-feature-flag
Add support for parsing the dns_resolver feature bit
2024-10-08 19:46:11 +00:00
Matt Corallo
f94bf98612
Merge pull request #3235 from Mirebella/add-local-balance-msats
Add `last_local_balance_msats` field
2024-10-08 17:56:46 +00:00
Mirebella
5d48d588ef Add Event::ChannelClosed::last_local_balance_msats
Users commonly want to know what their balance was when a channel
was closed, which this provides in a somewhat simplified manner.

It does not consider pending HTLCs and will always overstate our
balance by transaction fees.
2024-10-08 15:28:58 +00:00
Matt Corallo
0abf068ad1 Drop one unnecessary allocation added in aa2f6b47df
In aa2f6b47df we refactored
`lightning-invoice` de/serialization to use the new version of
`bech32`, but ended up adding one unnecessary allocation in our
offers logic, which we drop here.
2024-10-03 17:23:32 +00:00
Matt Corallo
bc1931bd0b
Merge pull request #3270 from optout21/bech32-iterser
Upgrade bech32 dependency (iterative)
2024-10-03 17:02:55 +00:00
optout
aa2f6b47df
Upgrade bech32 dependency, bech32 serialization improvements 2024-10-02 21:21:07 +02:00
Matt Corallo
457b634d09 Allow a DNSResolverMessageHandler to set dns_resolver feature
A `DNSResolverMessageHandler` which handles resolution requests
should want the `NodeFeatures` included in the node's
`node_announcement` to include `dns_resolver` to indicate to the
world that it provides that service. Here we enable this by
requesting extra feature flags from the `DNSResolverMessageHandler`
in the features `OnionMessenger`, in turn, provides to
`PeerManager` (which builds the `node_announcement`).
2024-10-02 18:24:40 +00:00
Arik
d49a08a824
Merge pull request #3179 from TheBlueMatt/2024-07-human-readable-names-resolution-1
Add the core functionality required to resolve Human Readable Names
2024-10-02 10:00:13 -07:00
Matt Corallo
605952cefd
Merge pull request #3301 from dunxen/2024-9-fixnevertypefallback
Add an explicit_type TLV syntax for avoiding certain cases of type inference
2024-10-02 14:29:09 +00:00
Duncan Dean
c0d84e85c7
Add an explicit_type TLV syntax for avoiding certain cases of type inference
This new syntax is used to fix "dependency on fallback of ! -> ()".
This avoids cases where code compiles with a fallback of the
never type leading to the unit type. The behaviour in Rust edition 2024
would make this a compile error.

See: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/builtin/static.DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK.html#
2024-10-02 13:08:04 +02:00