Commit graph

837 commits

Author SHA1 Message Date
Matt Corallo
6c203d803e Stop relying on ChannelMonitor persistence after manager read
When we discover we've only partially claimed an MPP HTLC during
`ChannelManager` reading, we need to add the payment preimage to
all other `ChannelMonitor`s that were a part of the payment.

We previously did this with a direct call on the `ChannelMonitor`,
requiring users write the full `ChannelMonitor` to disk to ensure
that updated information made it.

This adds quite a bit of delay during initial startup - fully
resilvering each `ChannelMonitor` just to handle this one case is
incredibly excessive.

Over the past few commits we dropped the need to pass HTLCs
directly to the `ChannelMonitor`s using the background events to
provide `ChannelMonitorUpdate`s insetad.

Thus, here we finally drop the requirement to resilver
`ChannelMonitor`s on startup.
2024-10-24 17:44:33 +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
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
ebde296abd Parse and handle DNSResolverMessages in OnionMessenger
This adds the requisite message parsing and handling code for the
new DNSSEC messages to `OnionMessenger`.
2024-09-30 16:19:33 +00:00
Elias Rohrer
a0d0f02ed0
Merge pull request #3303 from TheBlueMatt/2024-09-inbound-payment-id
Add a `PaymentId` for inbound payments
2024-09-24 13:38:16 +09:00
Jeffrey Czyz
04c51b380d
Parameterize ChannelManager with MessageRouter
ChannelManager is parameterized by a Router, which must also implement
MessageRouter. Instead, add a MessageRouter parameter such that the
Router and MessageRouter traits can be de-coupled. This simplifies using
something other than DefaultMessageRouter, which DefaultRouter currently
delegates to.
2024-09-23 12:21:35 +09:00
Matt Corallo
aa09c33a17 Add an inbound_payment_id_secret to ChannelManager
In the next commit we'll start generating `PaymentId`s for inbound
payments randomly by HMAC'ing the HTLC set of the payment. Here we
start by defining the HMAC secret for these HMACs.

This requires one small test adaptation and a full_stack_target
fuzz change because it changes the RNG consumption.
2024-09-23 01:24:28 +00:00
Matt Corallo
cdd1298a38
Merge pull request #3289 from tnull/2024-09-fix-rgs-bp-builds
Fix builds of `lightning-rapid-gossip-sync` and `lightning-background-processor` crates
2024-09-18 14:31:18 +00:00
Elias Rohrer
545b037827
Drop no-std feature
We drop the `lightning/no-std` feature and just take
`hashbrown`,`possiblyrandom` and `libm` as required dependencies.
2024-09-18 09:07:58 +02:00
Jeffrey Czyz
dd8f744257
Rename InvoiceRequest::payer_id
For consistency with Offer::issuer_signing_pubkey, rename
InvoiceRequest::payer_id to use "signing_pubkey" instead of "id".
2024-09-16 13:56:46 -05:00
Matt Corallo
22146a98df
Merge pull request #3140 from valentinewallace/2024-06-pay-static-invoice
Support paying static invoices
2024-09-15 16:58:46 +00:00
Valentine Wallace
6e27aecb40
Remove payment_release_secret from async payments messages.
This field isn't necessary because we already authenticate the messages via the
blinded reply paths payment_id, nonce and HMAC.
2024-09-13 10:40:06 -04:00
Matt Corallo
f7cc40e2e4
Merge pull request #3243 from dunxen/2024-08-reremove-balancemsat
Remove AvailableBalances::balance_msat
2024-09-13 14:09:17 +00:00
Valentine Wallace
e162278bc8
Pass context into held_htlc_available message handling.
Useful for using the payment_id within to look up the corresponding outbound
async payment so we know we can safely release the HTLCs to the now-onlinen
recipient.
2024-09-12 11:16:03 -04:00
Elias Rohrer
b172942a75
Refactor: Take their_node_id by value across all handler interfaces
In order to maintain interface consistency, we refactor all message
handler interfaces to take `PublicKey` rather than `&PublicKey`, as the
difference in efficiency should be negigible and the former is easier to
handle in binding languages.

Over time, we also want to move (no pun intended) towards all messaging
interfaces using move semantics, so dropping the reference for
`PublicKey` is the first step in this direction.
2024-09-11 19:19:38 +02:00
Duncan Dean
59f16896d6
Remove AvailableBalances::balance_msat
The ChannelMonitor::get_claimable_balances and ChainMonitor::get_claimable_balances
methods provide a more straightforward approach to the balance of a channel, which
satisfies most use cases. The computation of AvailableBalances::balance_msat is
complex and originally had a different purpose that is not applicable
anymore.

Co-authored-by: Willem Van Lint <noreply@wvanlint.dev>
2024-09-09 19:37:03 +02:00
Matt Corallo
caf0daa2dd
Merge pull request #3257 from tnull/2024-08-fix-is-public
Rename instances of `is_public` to `is_announced`
2024-08-29 19:39:30 +00:00
Elias Rohrer
5928063789
Rename announced_channel to is_announced_for_forwarding
.. we rename the flag configuring whether we announce a channel or not.
2024-08-29 21:22:22 +02:00
Matt Corallo
b7064808ac
Merge pull request #3268 from TheBlueMatt/2024-08-moar-feerate-categories
Split up `ConfirmationTarget` even more
2024-08-28 13:15:13 +00:00
Matt Corallo
14720190b0 Split ConfirmationTarget::OnChainSweep into urgent and non-urgent
When we force-close a channel, occasionally its due to feerate
disagreements or other non-HTLC-related issues. In those cases,
there's no reason to use a very urgent feerate estimate - we don't
have any timers expiring soon.

Instead, we should give users the information they need to be more
economical on fees in this case, which we do here by splitting
`OnChainSweep` into `UrgentOnChainSweep` and
`NonUrgentOnChainSweep` `ConfirmationTarget`s.
2024-08-27 16:42:03 +00:00
Matt Corallo
f0de37ae1f Add a new ConfirmationTarget::MaximumFeeEstimate
When we broke `ConfirmationTarget` out into task-specific names, we
left `MaxDustHTLCExposure::FeeRateMultiplier` as using the "when we
broadcast feerate" as we were mostly concerned about the dust
thresholds on outbound channels where we pick the fee and drive our
own funds to dust.

In 51bf78d604, that changed to
include transaction fees on both inbound and outbound channels in
our dust exposure amount, but we continued to use
`ConfirmationTarget::OnChainSweep` for the fee estimator threshold.

While the `MaxDustHTLCExposure::FeeRateMultiplier` value is quite
conservative and shouldn't lead to force-closures unless feerate
estimates disagree by something like 500 sat/vB (with only one HTLC
active in a channel), this happened on Aug 22 when feerates spiked
from 4 sat/vB to over 1000 sat/vB in one block.

To avoid simple feerate estimate horizons causing this in the
future, here we add a new
`ConfirmationTarget::MaximumFeeEstimate` which is used for dust
calculations. This allows users to split out the estimates they use
for checking counterparty feerates from the estimates used for
actual broadcasting.
2024-08-27 16:36:54 +00:00
Matt Corallo
49dfa5a496
Merge pull request #3263 from TheBlueMatt/2024-08-bindings-om
Remove message type bound on `ResponseInstruction`
2024-08-23 03:04:19 +00:00
Matt Corallo
90361c18bf 1/3 Use MessageSendInstructions instead of PendingOnionMessage
Now that the `MessageRouter` can `create_blinded_paths` forcing
callers of the `OnionMessenger` to provide it with a reply path up
front is unnecessary complexity, doubly so in message handlers.

Here we take the first step towards untangling that, moving from
`PendingOnionMessage` to `MessageSendInstructions` for the outbound
message queue in `CustomMessageHandler`. Better, we can also drop
the `c_bindings`-specific message queue variant, unifying the APIs.
2024-08-22 22:27:44 +00:00
Matt Corallo
cd93a41bd6 Remove message type bound on ResponseInstruction
Our onion message handlers generally have one or more methods which
return a `ResponseInstruction` parameterized with the expected
message type (enum) of the message handler.

Sadly, that restriction is impossible to represent in our bindings -
our bindings concretize all LDK structs, enums, and traits into a
single concrete instance with generics set to our concrete trait
instances (which hold a jump table). This prevents us from having
multiple instances of `ResponseInstruction` structs for different
message types.

Our bindings do, however, support different parameterizations of
standard enums, including `Option`s and tuples.

In order to support bindings for the onion message handlers, we
are thus forced into std types bound by expected message types,
which we do here by making `ResponseInstruction` contain only the
instructions and generally using it as a two-tuple of
`(message, ResponseInstruction)`.
2024-08-22 22:17:54 +00:00
Matt Corallo
2ce2fe9392 Disambiguate blinded path ForwardNodes between payment + message
We currently have two structs with identical names in our public
API - `blinded_path::message::ForwardNode` and
`blinded_path::payment::ForwardNode`. This makes the API somewhat
awkward to use - users have to try (and fail) to import
`ForwardNode` twice only to then have to change their imports.

More importantly, however, this makes the API very hard to use in
some bindings languages where rename-imports or module imports
aren't available.

Thus, here, we rename both to give them context.
2024-08-21 19:48:34 +00:00
Elias Rohrer
b3abb192cc
Rename ChannelDetails::is_public to is_announced
Referring to announced/unannounced channels as 'public'/'private'
regularly leads to confusion on what they are and when which should be
used. To avoid perpetuating this confusion, we should avoid referring to
announced channels as 'public' in our API.

Here we rename `ChannelDetails::is_public` (which breaks
previously-released API) to align it with the changes in
`OpenChannelRequest`.
2024-08-21 12:40:21 +02:00
Valentine Wallace
db94d930f0
Move BlindedPayInfo into blinded_path::payment module. 2024-08-19 16:42:22 -04:00
Valentine Wallace
7038906890
Move BlindedPayInfo into BlindedPaymentPath.
Also removes the implementation of Writeable for BlindedPaymentPath, to ensure
callsites are explicit about what they're writing.
2024-08-19 16:28:30 -04:00
Matt Corallo
fb4403f8ae
Merge pull request #3204 from valentinewallace/2024-07-rb-test-vectors
Implement route blinding test vectors
2024-08-19 19:57:04 +00:00
Valentine Wallace
6f6115f177
Avoid && in public API for onion peeling/decoding.
No reason to take a reference to a Deref.
2024-08-19 12:47:42 -04:00
Valentine Wallace
f68b1249a9
Support next_blinding_override in blinded payment paths.
This allow us to forward blinded payments where the blinded path that we are
forwarding within was concatenated to another blinded path that starts at the
next hop.

Also allows constructing blinded paths using this override.
2024-08-19 12:47:40 -04:00
Matt Corallo
43dcf2f3d8
Merge pull request #3239 from arik-so/bitcoin-0.32.2-upgrade
Bitcoin 0.32.2 upgrade
2024-08-16 20:13:26 +00:00
Arik Sosman
36b484a720
Fix fuzz warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
176d2ad599
Upgrade rust-bitcoin to 0.32.2. 2024-08-16 10:31:45 -07:00
Valentine Wallace
6f0190d144
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct private to the module.
2024-08-15 13:04:07 -04:00
Valentine Wallace
e741a9a8e7
Add BlindedMessagePath type to disambiguate from blinded payment paths. 2024-08-15 13:04:01 -04:00
Valentine Wallace
caa836e8e5
Add BlindedPaymentPath type, to disambiguate from message paths.
Next up, we'll add a BlindedMessagePath type so the API is clear which type of
path is expected in each context.
2024-08-15 13:03:56 -04:00
Matt Corallo
9c93bd56c2 Provide the signer with a full RawBolt11Invoice to sign
Now that the `lightning` crate depends on the `lightning-invoice`
crate, there's no reason to have the `sign_invoice` method take raw
base32 field elements as we can now give it a real
`RawBolt11Invoice`, which we do here.

This simplifies the interface and avoids a
serialization-deserialization roundtrip when signing invoices in a
validating signer.

FIxes #3227
2024-08-13 12:55:19 +00:00
Matt Corallo
4624caf5a2 Move Payment{Hash,Preimage,Secret} into a new crate
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This is the first step towards fixing that - moving the common
types we need into a new `lightning-types` crate which both can
depend on.

Since we're using a new crate and can't depend on the existing
`lightning` hex utility to implement `Display`, we also take this
opportunity to switch to the new `Display` impl macro in
`hex_conservative`.
2024-08-13 12:54:59 +00:00
Matt Corallo
bc1c026712
Merge pull request #3210 from tcharding/07-31-rm-hex-dep
Remove explicit dependency on hex-conservative
2024-08-12 17:11:56 +00:00
Matt Corallo
4950f3cfc8
Merge pull request #3214 from TheBlueMatt/2024-07-chan-by-val
Make `funding_transaction_generated` take a `ChannelId` by value
2024-08-12 00:40:16 +00:00
Tobin C. Harding
eac1b87e65
Use bitcoin::hex instead of bitcoin::hashes::hex
Use the `hex-conservative` crate directly from `bitcoin` instead of from
`hashes`. Although it makes no real difference it is slightly more clear
and more terse.
2024-08-09 08:20:15 +10:00
Tobin C. Harding
aeee8fe31e
Remove explicit dependency on hex-conservative
The `hex` crate is re-exported by `rust-bitcoin` so we can get it from
there instead of explicitly depending on it. Doing so reduces the
maintenance burden and helps reduce the likelyhood of getting two
versions in the dependency graph.
2024-08-09 08:20:09 +10:00
Tobin C. Harding
b02f3134d8
Run contrib/run-rustfmt.sh
No other changes other than those introduced by the script.
2024-08-08 07:17:18 +10:00
Tobin C. Harding
e9b20cee43
Do not use bitcoin::blockdata
The `rust-bitcoin` project is working towards making the public API
separate from the directory structure; eventually the
`bitcoin::blockdata` will go away, to make maintenance easier here stop
using the `blockdata` module.

Do not run the formatter, so as to make review easier. This patch was
created mechanically using:

search-and-replace bitcoin::blockdata bitcoin

and having defined

```bash
search-and-replace () {
        if (($# != 2))
        then
                echo "Usage: $0 <this> <that>"
                return
        fi
        local this="$1"
        local that="$2"
        for file in $(git grep -l "$this")
        do
                perl -pi -e "s/$this/$that/g" "$file"
        done
}
```
2024-08-08 07:13:26 +10:00
valentinewallace
3071bbb92e
Merge pull request #3224 from TheBlueMatt/2024-08-deprecate-send_payment
Mark ChannelManager::send_payment_with_route as deprecated and take `Route` by value
2024-08-05 12:12:42 -07:00
Matt Corallo
1ff249516d Make funding_transaction_generated take a ChannelId by value
`ChannelId` is just a 32-byte array, so there's not a lot of value
in passing it by reference to `funding_transaction_generated`,
which we fix here.

This is also nice for bindings as languages like Java can better
analyze whether the `ChannelManager` ends up with a reference to
the `ChannelId`.
2024-08-04 18:16:22 +00:00
Matt Corallo
753a7ac8f2 Make send_payment_with_route take Route by value
Now that `ChannelManager::send_payment_with_route` is deprecated,
we don't care too much about making it as effecient as possible, so
there's not much cost to making it take `Route` by value. This
avoids bindings being unsure if the by-reference `Route` passed
needs to outlive the `ChannelManager` itself or if it only needs to
outlive the method call, creating some call overhead by forcing a
`Route::clone`, but avoiding a memory leak.
2024-08-04 18:08:49 +00:00