rust-lightning
10 days agoDon't attempt to resume channels if we already exchanged funding 2024-04-2982-123-fix
Matt Corallo [Wed, 1 May 2024 14:32:47 +0000 (14:32 +0000)]
Don't attempt to resume channels if we already exchanged funding

ddf75afd16 introduced the ability to re-exchange our `ChannelOpen`
after a peer disconnects if we didn't complete funding on our end.
It did not implement nor consider what would happen if we
re-connected after we created our own funding transactions, and
currently it panics (and even if it did not it would replay the
`FundingTransactionGenerated` event to users).

While we'd very much like to replay the `open_channel` flow even
if we have already received an `accept_channel` and funded the
channel, we cannot as the peer will likely provide different key
material in their `accept_channel`, causing us to need a different
funding transaction.

Thus, here, we simply close channels which have been funded but not
yet signed when our peer disconnects.

10 days agoMerge pull request #3045 from TheBlueMatt/2024-03-fees-are-dust
Matt Corallo [Tue, 7 May 2024 15:50:46 +0000 (08:50 -0700)]
Merge pull request #3045 from TheBlueMatt/2024-03-fees-are-dust

Include excess counterparty commitment transaction fees in dust exposure

10 days agoAdd a simple test of the new excess-fees-are-dust behavior
Matt Corallo [Sun, 5 May 2024 02:00:42 +0000 (02:00 +0000)]
Add a simple test of the new excess-fees-are-dust behavior

10 days agoUpdate default dust exposure limit and the documentation thereof
Matt Corallo [Sun, 5 May 2024 00:44:07 +0000 (00:44 +0000)]
Update default dust exposure limit and the documentation thereof

Now that we're including excess counterparty commitment transaction
fees in our dust calculation, we need to update the docs
accordingly. We do so here, describing some of the considerations
and risks that come with the new changes.

We also take this opportunity to double the default value, as users
have regularly complained that non-anchor channels fail to send
HTLCs with the default settings with some feerates.

Fixes #2922

10 days agoInclude excess commitment transaction fees in dust exposure
Matt Corallo [Tue, 30 Apr 2024 20:42:36 +0000 (20:42 +0000)]
Include excess commitment transaction fees in dust exposure

Transaction fees on counterparty commitment transactions are
ultimately not our money and thus are really "dust" from our PoV -
they're funds that may be ours during off-chain updates but are not
ours once we go on-chain.

Thus, here, we count any such fees in excess of our own fee
estimates towards dust exposure. We don't bother to make an
inbound/outbound channel distinction here as in most cases users
will use `MaxDustExposure::FeeRateMultiplier` which will scale
with the fee we set on outbound channels anyway.

Note that this also enables the dust exposure checks on anchor
channels during feerate updates. We'd previously elided these as
increases in the channel feerates do not change the HTLC dust
exposure, but now do for the fee dust exposure.

11 days agoMerge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow
Matt Corallo [Mon, 6 May 2024 19:20:37 +0000 (12:20 -0700)]
Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow

Fix overflow in invoice amount setter.

11 days agoMerge pull request #2957 from G8XSU/pause-events
Matt Corallo [Mon, 6 May 2024 19:08:10 +0000 (12:08 -0700)]
Merge pull request #2957 from G8XSU/pause-events

Don't pause events for chainsync persistence

11 days agoFix overflow in invoice amount setter.
Valentine Wallace [Tue, 30 Apr 2024 17:01:03 +0000 (13:01 -0400)]
Fix overflow in invoice amount setter.

13 days agoMerge pull request #3035 from TheBlueMatt/2024-04-upstream-123-bindings
Matt Corallo [Sat, 4 May 2024 00:55:25 +0000 (17:55 -0700)]
Merge pull request #3035 from TheBlueMatt/2024-04-upstream-123-bindings

2 weeks agoMerge pull request #3018 from jkczyz/2024-04-optional-description
Matt Corallo [Fri, 3 May 2024 19:55:17 +0000 (12:55 -0700)]
Merge pull request #3018 from jkczyz/2024-04-optional-description

Optional description for `Offer` and `Refund`

2 weeks agoMerge pull request #3029 from TheBlueMatt/2024-04-fix-batch-funding-failures
Matt Corallo [Fri, 3 May 2024 19:17:58 +0000 (12:17 -0700)]
Merge pull request #3029 from TheBlueMatt/2024-04-fix-batch-funding-failures

Add error handling for channels which fail to be created in `funding_transaction_generated_intern`

2 weeks agoOnly require description when offer has an amount
Jeffrey Czyz [Thu, 2 May 2024 16:43:04 +0000 (11:43 -0500)]
Only require description when offer has an amount

The spec was changed to allow excluding an offer description if the
offer doesn't have an amount. However, it is still required when the
amount is set.

2 weeks agoSwap `UserConfig::default()` for `test_default_channel_config`
Matt Corallo [Wed, 1 May 2024 21:56:04 +0000 (21:56 +0000)]
Swap `UserConfig::default()` for `test_default_channel_config`

As LDK changes, `UserConfig::default()` may imply marginally
different behavior, whereas `test_default_channel_config` is
intended to tweak defaults to provide a stable behavior for test
contexts.

This commit changes a few uses of `UserConfig::default()` to
`test_default_channel_config` in cases that will fail over the
coming commits due to dust changes.

2 weeks agoCorrect indentation in `get_pending_htlc_stats`
Matt Corallo [Wed, 27 Mar 2024 02:21:40 +0000 (02:21 +0000)]
Correct indentation in `get_pending_htlc_stats`

The previous commit left indentation in `get_pending_htlc_stats`
deliberately wrong, to ease reviewability. This commit fixes the
indentation.

2 weeks agoUnify `get_{inbound,outbound}_pending_htlc_stats`
Matt Corallo [Wed, 27 Mar 2024 02:14:50 +0000 (02:14 +0000)]
Unify `get_{inbound,outbound}_pending_htlc_stats`

In most cases we already call both in a pair, and in fact always
consolidate some of the returned values across both accessors, so
there's not much reason to have them be separate methods.

Here we merge them.

2 weeks agoMerge pull request #3033 from TheBlueMatt/2024-04-notify-bp-on-blocks
Matt Corallo [Wed, 1 May 2024 21:21:28 +0000 (14:21 -0700)]
Merge pull request #3033 from TheBlueMatt/2024-04-notify-bp-on-blocks

Wake `background-processor` from `ChainMonitor` on new blocks

2 weeks agoWake `background-processor` from `ChainMonitor` on new blocks 2024-04-notify-bp-on-blocks
Matt Corallo [Tue, 30 Apr 2024 21:30:26 +0000 (21:30 +0000)]
Wake `background-processor` from `ChainMonitor` on new blocks

When we receive a new block we may generate
`Event::SpendableOutputs` in `ChannelMonitor`s which then need to
be processed by the background processor. While it will do so
eventually when its normal loop goes around, this may cause user
tests to be delayed in finding events, so we should notify the BP
immediately to wake it on new blocks.

We implement that here, unconditionally notifying the
`background-processor` whenever we receive a new block or confirmed
transactions.

2 weeks agoUpdate documentation on `[u8; 32]` wrappers for clarity 2024-04-upstream-123-bindings
Matt Corallo [Wed, 1 May 2024 16:04:13 +0000 (16:04 +0000)]
Update documentation on `[u8; 32]` wrappers for clarity

2 weeks agoMove `[u8; 32]` wrapper types to a common module
Matt Corallo [Wed, 1 May 2024 15:49:59 +0000 (15:49 +0000)]
Move `[u8; 32]` wrapper types to a common module

The `PaymentHash`, `PaymentSecret`, `PaymentPreimage`, and
`ChannelId` types are all small wrappers around `[u8; 32]` and are
used throughout the codebase but were defined in the top-level
`ln/mod.rs` file and the relatively sparsely-populated
`ln/channel_id.rs` file.

Here we move them to a common `types` module and go ahead and
update all our in-crate `use` statements to refer to the new
module for bindings. We do, however, leave a `pub use` alias for
the old paths to avoid upgrade hassle for users.

2 weeks agoAdd bindings no-export tags to doc test types
Matt Corallo [Wed, 1 May 2024 15:19:20 +0000 (15:19 +0000)]
Add bindings no-export tags to doc test types

We don't actually intend these to be public as they're just for
docs but the bindings don't currently parse `#[doc(hidden)]` as
"no-export" so we add manual no-export tags as well.

2 weeks agoAdd derives where they make sense and the bindings require them
Matt Corallo [Wed, 1 May 2024 15:18:29 +0000 (15:18 +0000)]
Add derives where they make sense and the bindings require them

2 weeks agoRename and expose message-specific `NextHop`
Matt Corallo [Tue, 23 Apr 2024 15:56:13 +0000 (15:56 +0000)]
Rename and expose message-specific `NextHop`

`onion::message::messenger::PeeledOnion` is a public enum which
included the private enum `NextHop`, which is not acceptable. Thus,
we here expose `NextHop` but rename it `NextMessageHop` to make
clear that it is specific to messages.

2 weeks agoMerge pull request #3032 from valentinewallace/2024-04-pico-btc-overflow
Matt Corallo [Wed, 1 May 2024 13:08:45 +0000 (06:08 -0700)]
Merge pull request #3032 from valentinewallace/2024-04-pico-btc-overflow

Fix overflow in lightning-invoice `amount_pico_btc`

2 weeks agoMerge pull request #3031 from TheBlueMatt/2024-04-new-rustc-warning
valentinewallace [Tue, 30 Apr 2024 17:16:11 +0000 (13:16 -0400)]
Merge pull request #3031 from TheBlueMatt/2024-04-new-rustc-warning

Fix new rustc `#[macro_export]` warning in doctests

2 weeks agoFix new rustc `#[macro_export]` warning in doctests 2024-04-new-rustc-warning
Matt Corallo [Tue, 30 Apr 2024 13:45:45 +0000 (13:45 +0000)]
Fix new rustc `#[macro_export]` warning in doctests

rustc now warns any time a `#[macro_export]` is used inside a
function as it generates surprising results. Because doctests are
run inside implicit test functions this means any use of
`#[macro_export]` inside a doctest will now warn. We do this in
`lightning-custom-message` to demonstrated how to use the crate,
which now fails to compile.

Here we fix this by adding an `fn main() {}` to the doctest, which
causes doctests to be compiled as freestanding code rather than
inside a test function.

Note that while discussing this upstream it came up that rustc is
also planning on changing the way doctests are compiled to compile
an entire crate's doctests in one go rather than in separate
crates, causing doctests to have a shared namespace which may
generate future surprising outcomes.

2 weeks agoFix overflow in lightning-invoice amount_pico_btc.
Valentine Wallace [Tue, 30 Apr 2024 14:05:35 +0000 (10:05 -0400)]
Fix overflow in lightning-invoice amount_pico_btc.

2 weeks agoSend peers error messages for failures due to invalid batch funding 2024-04-fix-batch-funding-failures
Matt Corallo [Mon, 29 Apr 2024 21:05:52 +0000 (21:05 +0000)]
Send peers error messages for failures due to invalid batch funding

If we fail to fund a batch open we'll force-close all channels in
the batch, however would previously fail to send error messages to
our peers for any channels we were due to test after the one that
failed.

This commit fixes that issue, sending the required error messages
to allow our peers to clean up their state.

2 weeks agoClose channels when `find_funding_output` fails to find an output
Matt Corallo [Mon, 29 Apr 2024 18:12:59 +0000 (18:12 +0000)]
Close channels when `find_funding_output` fails to find an output

In `funding_transaction_generated_intern`, if `find_funding_output`
fails (e.g. due to the require output not being present in the
provided funding transaction) we'd previously not generated a
`ChannelClosed` event which leaves users possibly in a confused
state.

Here we fix this, also fixing the relevant tests to check for the
new event.

Fixes #2843.

2 weeks agoMerge pull request #3017 from jkczyz/2024-04-optional-pubkey
Matt Corallo [Mon, 29 Apr 2024 19:05:30 +0000 (12:05 -0700)]
Merge pull request #3017 from jkczyz/2024-04-optional-pubkey

Sending to `Offer` without `signing_pubkey`

2 weeks agoMerge pull request #3028 from jkczyz/2024-04-offer-id-followups
Matt Corallo [Mon, 29 Apr 2024 18:26:44 +0000 (11:26 -0700)]
Merge pull request #3028 from jkczyz/2024-04-offer-id-followups

Follow-ups to #2970

2 weeks agoRemove InvoiceRequestFields::features
Jeffrey Czyz [Fri, 26 Apr 2024 17:13:12 +0000 (12:13 -0500)]
Remove InvoiceRequestFields::features

InvoiceRequestFeatures may contain a large, odd bit. Including this in
InvoiceRequestFields, which is in each BlindedPath of a Bolt12Invoice,
could cause the invoice's onion message to exceed the maximum size. The
features are already checked before sending an invoice.

2 weeks agoRemove InvoiceRequestFields::amount_msats
Jeffrey Czyz [Fri, 26 Apr 2024 17:03:07 +0000 (12:03 -0500)]
Remove InvoiceRequestFields::amount_msats

Event::PaymentClaimable and Event::PaymentClaimed already contain the
paid amount, so there's no need to included the requested amount in
InvoiceRequestFields.

2 weeks agoRemove PaymentContext from OnionPayload
Jeffrey Czyz [Fri, 26 Apr 2024 16:37:24 +0000 (11:37 -0500)]
Remove PaymentContext from OnionPayload

PaymentContext is already stored in ClaimablePayment via PaymentPurpose,
so there is no need to repeat it in each ClaimableHTLC via OnionPayload.
This avoids cloning the PaymentContext each time an HTLC is received,
other than for the first HTLC for a payment.

2 weeks agoRemove ChainMonitor::sync_persistence_id
Gursharan Singh [Fri, 12 Apr 2024 06:35:54 +0000 (23:35 -0700)]
Remove ChainMonitor::sync_persistence_id

It was used earlier for generating unique MonitorUpdateId for
UpdateOrigin::ChainSync monitor updates.

2 weeks agoRemove MonitorUpdateId from persist trait
Gursharan Singh [Fri, 12 Apr 2024 06:31:30 +0000 (23:31 -0700)]
Remove MonitorUpdateId from persist trait

MonitorUpdateId was an opaque abstraction for id's generated by
UpdateOrigin:Offchain and UpdateOrigin::ChainSync monitor updates.
It was mainly needed to map calls made to
ChainMonitor::channel_monitor_updated. We no longer track
UpdateOrigin::ChainSync MonitorUpdates and can directly use
ChannelMonitor::get_latest_update_id() for tracking
UpdateOrigin::Offchain monitor updates.

3 weeks agoDon't require Refund::description in API
Jeffrey Czyz [Wed, 24 Apr 2024 18:59:01 +0000 (13:59 -0500)]
Don't require Refund::description in API

Refunds currently require a description, though this may change to be
optional. Remove the description requirement from the API, setting and
empty string by default.

3 weeks agoDon't require Offer::description in API
Jeffrey Czyz [Wed, 24 Apr 2024 17:40:22 +0000 (12:40 -0500)]
Don't require Offer::description in API

Offers currently require a description, though this may change to be
optional. Remove the description requirement from the API, setting and
empty string by default.

3 weeks agoBolt12Invoice for Offer without signing_pubkey
Jeffrey Czyz [Tue, 23 Apr 2024 23:35:05 +0000 (18:35 -0500)]
Bolt12Invoice for Offer without signing_pubkey

When parsing a Bolt12Invoice use both the Offer's signing_pubkey and
paths to determine if it is for an Offer or a Refund. Previously, an
Offer was required to have a signing_pubkey. But now that it is
optional, the Offers paths can be used to make the determination.
Additionally, check that the invoice matches one of the blinded node ids
from the paths' last hops.

3 weeks agoAdd InvoiceRequestTlvStream::paths
Jeffrey Czyz [Tue, 23 Apr 2024 23:30:59 +0000 (18:30 -0500)]
Add InvoiceRequestTlvStream::paths

Instead of reusing OfferTlvStream::paths, add a dedicated paths TLV to
InvoiceRequestTlvStream such that it can be used in Refund. This allows
for an Offer without a signing_pubkey and still be able to differentiate
whether an invoice is for an offer or a refund.

3 weeks agoAllow parsing Offer without signing_pubkey
Jeffrey Czyz [Wed, 24 Apr 2024 14:03:56 +0000 (09:03 -0500)]
Allow parsing Offer without signing_pubkey

If an offer has at least one path, it may omit the signing pubkey and
use the blinded node id of the last hop of a path to sign an invoice.
Allow parsing such offers but not yet creating them.

3 weeks agoOptional OfferContents::signing_pubkey
Jeffrey Czyz [Tue, 23 Apr 2024 22:38:13 +0000 (17:38 -0500)]
Optional OfferContents::signing_pubkey

If an Offer contains a path, the blinded_node_id of the path's final hop
can be used as the signing pubkey. Make Offer::signing_pubkey and
OfferContents::signing_pubkey return an Option to support this. Upcoming
commits will implement this behavior.

3 weeks agoStop tracking MonitorUpdates from ChainSync in pending_monitor_updates
Gursharan Singh [Wed, 27 Mar 2024 15:16:14 +0000 (16:16 +0100)]
Stop tracking MonitorUpdates from ChainSync in pending_monitor_updates

We no longer need to track them since we no longer hold events for
pending MonitorUpdates resulting from ChainSync.

3 weeks agoStop storing last_chain_persist_height
Gursharan Singh [Wed, 27 Mar 2024 11:18:31 +0000 (12:18 +0100)]
Stop storing last_chain_persist_height

We only used to store last_chain_persist_height to release
events held for more than LATENCY_GRACE_PERIOD_BLOCKS due to
pending monitor update with UpdateOrigin::ChainSync. Since we no
longer pause events for ChainSync persistence, we no longer need to
store last_chain_persist_height.

3 weeks agoDon't pause events for chainsync persistence
Gursharan Singh [Thu, 7 Mar 2024 19:00:41 +0000 (11:00 -0800)]
Don't pause events for chainsync persistence

We used to wait on ChannelMonitor persistence to avoid
duplicate payment events. But this can still happen in cases where
ChannelMonitor handed the event to ChannelManager and we did not persist
ChannelManager after event handling.
It is expected to receive payment duplicate events and clients should handle these
events in an idempotent manner. Removing this hold-up of events simplifies
the logic and makes it easier to not persist ChannelMonitors on every block connect.

3 weeks agoMerge pull request #3003 from TheBlueMatt/2024-04-2964-followups
Gursharan Singh [Thu, 25 Apr 2024 20:19:09 +0000 (13:19 -0700)]
Merge pull request #3003 from TheBlueMatt/2024-04-2964-followups

#2964 Followups

3 weeks agoMerge pull request #3021 from TheBlueMatt/2024-04-drop-blocked-completed-updates
Matt Corallo [Thu, 25 Apr 2024 18:33:18 +0000 (11:33 -0700)]
Merge pull request #3021 from TheBlueMatt/2024-04-drop-blocked-completed-updates

Drop completed blocked `ChannelMonitorUpdate`s on startup

3 weeks agoMerge pull request #3004 from TheBlueMatt/2024-04-2761-followups
Matt Corallo [Thu, 25 Apr 2024 17:52:12 +0000 (10:52 -0700)]
Merge pull request #3004 from TheBlueMatt/2024-04-2761-followups

#2761 Followups

3 weeks agoDrop completed blocked `ChannelMonitorUpdate`s on startup 2024-04-drop-blocked-completed-updates
Matt Corallo [Thu, 25 Apr 2024 14:30:05 +0000 (14:30 +0000)]
Drop completed blocked `ChannelMonitorUpdate`s on startup

If a user receives a payment preimage for an outbound payment, the
`PaymentSent` event will block any eventual RAA
`ChannelMonitorUpdate` from the same channel, assuming it comes in
before the event can be processed. If this blocking kicks in, but
the flow eventually completes with the RAA `ChannelMonitorUpdate`
being persisted, but the `ChannelManager` is only persisted prior
to the event being handled, on startup we'll have a fully
up-to-date `ChannelMonitor` but a pending, blocked
`ChannelMonitorUpdate`. When the `PaymentSent` event is replayed
we'll end up trying to apply a redundant `ChannelMonitorUpdate`
which will panic.

See the test added in this commit for an implementation of this
situation.

In this commit we fix this issue by simply dropping blocked
`ChannelMonitorUpdate`s the same as we do pending ones.

3 weeks agoMerge pull request #3015 from tnull/2024-04-sweeper-error-on-persistence-failure
Elias Rohrer [Wed, 24 Apr 2024 14:35:51 +0000 (16:35 +0200)]
Merge pull request #3015 from tnull/2024-04-sweeper-error-on-persistence-failure

Make `OutputSweeper::track_spendable_outputs` fallible

3 weeks agoMake `OutputSweeper::track_spendable_outputs` fallible
Elias Rohrer [Wed, 24 Apr 2024 07:30:16 +0000 (09:30 +0200)]
Make `OutputSweeper::track_spendable_outputs` fallible

.. as otherwise we might only log an error and continue if we fail to
persist the sweeper state.

3 weeks agoMerge pull request #2981 from dunxen/2024-03-PR2419fixups
Matt Corallo [Tue, 23 Apr 2024 13:48:40 +0000 (06:48 -0700)]
Merge pull request #2981 from dunxen/2024-03-PR2419fixups

Fixups for #2419

3 weeks agoAdd intermediate `ConstructedTransaction`
Duncan Dean [Fri, 12 Apr 2024 13:37:17 +0000 (15:37 +0200)]
Add intermediate `ConstructedTransaction`

3 weeks agoAdd lower bound segwit input weight estimates
Duncan Dean [Tue, 9 Apr 2024 17:07:45 +0000 (19:07 +0200)]
Add lower bound segwit input weight estimates

3 weeks agoAdd descriptions to test cases
Duncan Dean [Mon, 8 Apr 2024 15:44:10 +0000 (17:44 +0200)]
Add descriptions to test cases

3 weeks agoAbort if we add a duplicate input
Duncan Dean [Tue, 26 Mar 2024 10:15:37 +0000 (12:15 +0200)]
Abort if we add a duplicate input

3 weeks agoMake sent_tx_* fallible and handle errors & simplify counterparty_weight_contributed...
Duncan Dean [Tue, 26 Mar 2024 10:06:33 +0000 (12:06 +0200)]
Make sent_tx_* fallible and handle errors & simplify counterparty_weight_contributed calc

3 weeks agoCheck if msg.script.is_witness_program() before checking version
Duncan Dean [Tue, 26 Mar 2024 09:17:05 +0000 (11:17 +0200)]
Check if msg.script.is_witness_program() before checking version

3 weeks agoUse HashMaps as, well, HashMaps (don't iter for key match)
Duncan Dean [Tue, 26 Mar 2024 08:57:44 +0000 (10:57 +0200)]
Use HashMaps as, well, HashMaps (don't iter for key match)

3 weeks agoRemove unnecessary PaymentPreimage clone
Jeffrey Czyz [Mon, 22 Apr 2024 21:43:26 +0000 (16:43 -0500)]
Remove unnecessary PaymentPreimage clone

3 weeks agoMerge pull request #2990 from TheBlueMatt/2024-04-log-in-flights
Gursharan Singh [Mon, 22 Apr 2024 17:29:35 +0000 (10:29 -0700)]
Merge pull request #2990 from TheBlueMatt/2024-04-log-in-flights

Log pending in-flight updates when we are missing a monitor

3 weeks agoDrop the rustup-specific calling in `ci/rustfmt.sh` 2024-04-2761-followups
Matt Corallo [Mon, 22 Apr 2024 13:03:14 +0000 (13:03 +0000)]
Drop the rustup-specific calling in `ci/rustfmt.sh`

The +rustversion call semantics are specific to rustup and do not
work with standard rust toolchains. However, because rustfmt
formatting differs slightly between stable and our 1.63 target, we
need to keep the +1.63.0 for rustup users.

Thus, here, we check for the presence of a `rustup` command and
pass the "+1.63.0" argument if we find one.

3 weeks agoInclude `channel_keys.rs` in the rustfmt list
Matt Corallo [Mon, 22 Apr 2024 13:00:38 +0000 (13:00 +0000)]
Include `channel_keys.rs` in the rustfmt list

Since its already formatted and there's not much active work going
on in it.

3 weeks agoOnly include `derive_add_tweak` for base key types that use it
Matt Corallo [Mon, 22 Apr 2024 12:50:58 +0000 (12:50 +0000)]
Only include `derive_add_tweak` for base key types that use it

Specifically `RevocationBasepoint` has a different derivation, so
shouldn't have a `derive_add_tweak` at all. We also use this
opportunity to link to the `from_basepoint` function in the
`derive_add_tweak` docs.

3 weeks agoWord-wrap new doc comment in `DelayedPaymentOutputDescriptor`
Matt Corallo [Fri, 19 Apr 2024 00:42:55 +0000 (00:42 +0000)]
Word-wrap new doc comment in `DelayedPaymentOutputDescriptor`

3 weeks agoUse `Sha256`s for tweaks in `sign` to enforce randomness
Matt Corallo [Fri, 19 Apr 2024 00:36:52 +0000 (00:36 +0000)]
Use `Sha256`s for tweaks in `sign` to enforce randomness

We assume that tweaks are the output of a SHA-256 hash function
(and thus that failing to create a private key from the has
negligible probability) in `add_public_key_tweak` and elsewhere.

Thus, we really shouldn't be taking byte arrays in the public API
but rather `Sha256` objects, and communicating in the docs for
`add_public_key_tweak` that we can panic if its not the output of
a hash function, both of which we do here.

3 weeks agoSimplify and clarify `derive_add_tweak` documentation
Matt Corallo [Fri, 19 Apr 2024 00:28:09 +0000 (00:28 +0000)]
Simplify and clarify `derive_add_tweak` documentation

3 weeks agoLog when a ChannelMonitor's claimable balances set goes empty 2024-04-2964-followups
Matt Corallo [Thu, 18 Apr 2024 21:42:48 +0000 (21:42 +0000)]
Log when a ChannelMonitor's claimable balances set goes empty

3 weeks agoDebug-log monitor update starts and completions in `ChainMonitor` 2024-04-log-in-flights
Matt Corallo [Thu, 11 Apr 2024 21:53:44 +0000 (21:53 +0000)]
Debug-log monitor update starts and completions in `ChainMonitor`

When a `ChannelMonitor[Update]` persistence completes, we rely on
logging in `ChannelManager` to hear about it. However, this won't
happen at all if there's still pending updates as no `MonitorEvent`
will be generated.

Thus, here, we add logging directly in `ChainMonitor`, ensuring we
can deduce when individual updates completed from debug logs.

3 weeks agoMerge pull request #3009 from tnull/2024-04-fix-sweeper-typo
Matt Corallo [Mon, 22 Apr 2024 11:36:41 +0000 (04:36 -0700)]
Merge pull request #3009 from tnull/2024-04-fix-sweeper-typo

Fix typo in `OutputSweeper`

3 weeks agoFix typo in `OutputSweeper`
Elias Rohrer [Mon, 22 Apr 2024 09:29:42 +0000 (11:29 +0200)]
Fix typo in `OutputSweeper`

... as 'ouputs' isn't a thing.

4 weeks agoMerge pull request #3005 from TheBlueMatt/2024-04-0.0.123-beta v0.0.123-beta
Matt Corallo [Fri, 19 Apr 2024 14:51:06 +0000 (07:51 -0700)]
Merge pull request #3005 from TheBlueMatt/2024-04-0.0.123-beta

Cut 0.0.123-beta

4 weeks agoBump crate versions to 0.0.123-beta/invoice 0.31-beta 2024-04-0.0.123-beta
Matt Corallo [Fri, 19 Apr 2024 01:03:03 +0000 (01:03 +0000)]
Bump crate versions to 0.0.123-beta/invoice 0.31-beta

4 weeks agoMerge pull request #2761 from yellowred/self_sufficient_psbt
Wilmer Paulino [Fri, 19 Apr 2024 00:45:56 +0000 (17:45 -0700)]
Merge pull request #2761 from yellowred/self_sufficient_psbt

Implement PSBT fields that were missing for a Signer

4 weeks agoImplement Script for Witness and Add Tweak in PSBT.
olegkubrakov [Tue, 19 Dec 2023 00:54:59 +0000 (16:54 -0800)]
Implement Script for Witness and Add Tweak in PSBT.

Adding Witness Script and key tweaks makes
a Partially Signed Bitcoin Transaction the single data
source needed for a Signer to produce valid signatures.
A Signer is not required to be able to generate L2 keys,
e.g delayed payment basepoint.

4 weeks agoCorrect `ChannelMonitor::is_fully_resolved` docs
Matt Corallo [Thu, 18 Apr 2024 21:40:41 +0000 (21:40 +0000)]
Correct `ChannelMonitor::is_fully_resolved` docs

The block count at which the monitor will become prunable was
changed by an update while the PR was pending but not propagated
to the docs.

4 weeks agoMerge pull request #2964 from jbesraa/prune-stale-chanmonitor
Matt Corallo [Thu, 18 Apr 2024 21:39:43 +0000 (14:39 -0700)]
Merge pull request #2964 from jbesraa/prune-stale-chanmonitor

Add `archive_fully_resolved_monitors` to `ChainMonitor`

4 weeks agoMerge pull request #2998 from tnull/2024-04-fix-potential-lock-race-in-CM-write
Gursharan Singh [Thu, 18 Apr 2024 20:21:08 +0000 (13:21 -0700)]
Merge pull request #2998 from tnull/2024-04-fix-potential-lock-race-in-CM-write

4 weeks agoMerge pull request #3001 from optout21/splicing-feature-bit-with-any
Jeffrey Czyz [Thu, 18 Apr 2024 19:24:00 +0000 (14:24 -0500)]
Merge pull request #3001 from optout21/splicing-feature-bit-with-any

Add splicing feature flag

4 weeks agoMerge pull request #2999 from keyuebao/keyue/update-ldk-docs
Gursharan Singh [Thu, 18 Apr 2024 17:26:07 +0000 (10:26 -0700)]
Merge pull request #2999 from keyuebao/keyue/update-ldk-docs

Update docs for ChannelClosed Event

4 weeks agoAdd `ChainMonitor::archive_fully_resolved_monitor_channels`
jbesraa [Wed, 27 Mar 2024 16:19:14 +0000 (18:19 +0200)]
Add `ChainMonitor::archive_fully_resolved_monitor_channels`

  Archives fully resolved channel monitors by adding them to a backup
  location and removing them from the primary storage & the monitor set.

  This is useful for pruning fully resolved monitors from the monitor
  set and primary storage so they are not reloaded on every new new
  block connection.

  We also add a new function, `archive_persisted_channel` to the
  `Persist` trait that writes the monitor to an archive storage and
  removes it from the primary storage.

4 weeks agoAdd `ChannelMonitor::is_fully_resolved` function
jbesraa [Fri, 29 Mar 2024 05:56:23 +0000 (08:56 +0300)]
Add `ChannelMonitor::is_fully_resolved` function

  Checks if the monitor is fully resolved. Resolved monitor is one that has claimed all of
  its ouputs and balacnes.

  This function returns true only if `get_claimable_balances` has been empty for at least
  2016 blocks.

4 weeks agoMerge pull request #2825 from tnull/2024-01-upstream-output-sweeper
Matt Corallo [Thu, 18 Apr 2024 15:24:47 +0000 (08:24 -0700)]
Merge pull request #2825 from tnull/2024-01-upstream-output-sweeper

Add `OutputSweeper` utility persisting and sweeping spendable outputs

4 weeks agoMerge pull request #2970 from jkczyz/2024-03-offer-id
Matt Corallo [Thu, 18 Apr 2024 15:21:19 +0000 (08:21 -0700)]
Merge pull request #2970 from jkczyz/2024-03-offer-id

Include a `PaymentContext` in `PaymentPurpose`

4 weeks agoEdit `Event::SpendableOutputs` docs to mention `OutputSweeper`
Elias Rohrer [Tue, 16 Apr 2024 12:50:51 +0000 (14:50 +0200)]
Edit `Event::SpendableOutputs` docs to mention `OutputSweeper`

4 weeks agoAdd basic `OutputSweeper` test in BP
Elias Rohrer [Fri, 12 Jan 2024 16:46:37 +0000 (17:46 +0100)]
Add basic `OutputSweeper` test in BP

.. we simply check that the `OutputSweeper` generates a spending tx and
that the `TrackedSpendableOutput` is pruned once it reaches
`ANTI_REORG_DELAY`.

4 weeks agoAllow delaying generation and broadcasting of spending txs
Elias Rohrer [Tue, 16 Apr 2024 12:19:54 +0000 (14:19 +0200)]
Allow delaying generation and broadcasting of spending txs

.. which enables users to batch output spends.

4 weeks agoAdd `OutputSweeper` utility persisting and sweeping spendable outputs
Elias Rohrer [Fri, 12 Jan 2024 10:36:08 +0000 (11:36 +0100)]
Add `OutputSweeper` utility persisting and sweeping spendable outputs

We add a `OutputSweeper` utility that allows to track the state of
spendable output descriptors as emitted by `Event::SpendableOutputs`.

To this end, the `OutputSweeper` persists the necessary information in
our `KVStore` and regularly tries to sweep the spendable outputs,
removing them after reaching threshold confirmations, i.e.,
`ANTI_REORG_DELAY`.

4 weeks agoAdd `ConfirmationTarget::OutputSpendingFee`
Elias Rohrer [Tue, 16 Apr 2024 11:41:57 +0000 (13:41 +0200)]
Add `ConfirmationTarget::OutputSpendingFee`

4 weeks agoUpdate PaymentPurpose's payment_preimage docs
Jeffrey Czyz [Wed, 17 Apr 2024 21:45:45 +0000 (16:45 -0500)]
Update PaymentPurpose's payment_preimage docs

Clarify that payment_preimage should only be used to claim a payment
when handling Event::PaymentClaimable, not Event::PaymentClaimed.

4 weeks agoInclude InvoiceRequest fields in PaymentContext
Jeffrey Czyz [Fri, 29 Mar 2024 02:31:10 +0000 (21:31 -0500)]
Include InvoiceRequest fields in PaymentContext

When receiving a payment, it's useful to know information about the
InvoiceRequest. Include this data in PaymentContext::Bolt12Offer so
users can display information about an inbound payment (e.g., the payer
note).

4 weeks agoTest for PaymentContext in offers_tests.rs
Jeffrey Czyz [Wed, 27 Mar 2024 01:19:32 +0000 (20:19 -0500)]
Test for PaymentContext in offers_tests.rs

4 weeks agoUse BOLT 12 PaymentPurpose variants
Jeffrey Czyz [Sat, 13 Apr 2024 23:20:19 +0000 (18:20 -0500)]
Use BOLT 12 PaymentPurpose variants

When constructing a PaymentPurpose in ChannelManager, use the
PaymentContext from OnionPayload to determine which variant to
construct, including those for BOLT 12 payments.

4 weeks agoBOLT 12 variants of PaymentPurpose
Jeffrey Czyz [Sat, 13 Apr 2024 22:29:24 +0000 (17:29 -0500)]
BOLT 12 variants of PaymentPurpose

In order to provide more context in PaymentClaimable and PaymentClaimed
events, introduce new variants of PaymentPurpose for use with BOLT 12
payments. Separate variants are used for offers and refunds. An unknown
variant is used for backwards compatibility and ease of testing, but is
otherwise not publicly constructable.

4 weeks agoAdd PaymentPurpose::is_keysend utility method
Jeffrey Czyz [Sat, 13 Apr 2024 02:21:00 +0000 (21:21 -0500)]
Add PaymentPurpose::is_keysend utility method

4 weeks agoRename InvoicePayment to Bolt11InvoicePayment
Jeffrey Czyz [Sat, 13 Apr 2024 02:17:35 +0000 (21:17 -0500)]
Rename InvoicePayment to Bolt11InvoicePayment

PaymentPurpose will be expanded to include BOLT 12 payment context.
Rename the InvoicePayment variant accordinly before new variants are
added.

4 weeks agoInclude Refund context in blinded payment paths
Jeffrey Czyz [Tue, 26 Mar 2024 23:57:57 +0000 (18:57 -0500)]
Include Refund context in blinded payment paths

When requesting a payment for a refund, include a context in the
Bolt12Invoice's blinded payment paths indicated it is for such. When the
eventual payment is received, the user can use the payment hash to
correlate it with the corresponding Refund.

4 weeks agoInclude Offer context in blinded payment paths
Jeffrey Czyz [Tue, 26 Mar 2024 23:48:39 +0000 (18:48 -0500)]
Include Offer context in blinded payment paths

When constructing blinded payment paths for a Bolt12Invoice response,
include the OfferId so that the eventual payment can be correlated with
the Offer.

4 weeks agoInclude OfferId in VerifiedInvoiceRequest
Jeffrey Czyz [Tue, 26 Mar 2024 23:39:06 +0000 (18:39 -0500)]
Include OfferId in VerifiedInvoiceRequest

Extract the OfferId from the offer metadata sent back in the
InvoiceRequest and include it in VerifiedInvoiceRequest. This can be
used to correspond the eventual payment for the invoice response by
including it in the invoice's blinded payment paths.

4 weeks agoDefine an OfferId for BOLT 12 Offers
Jeffrey Czyz [Mon, 25 Mar 2024 21:10:36 +0000 (16:10 -0500)]
Define an OfferId for BOLT 12 Offers

Use a merkle root hash of the offer TLV records to define an offer id.
Will be included in a BOLT 12 invoice's blinded payment paths in order
for the recipient to identify which offer the payment is for.

4 weeks agoPass PaymentContext through HTLC processing
Jeffrey Czyz [Tue, 26 Mar 2024 18:10:04 +0000 (13:10 -0500)]
Pass PaymentContext through HTLC processing

PendingInboundPayment::BlindedReceive includes a PaymentContext, which
the recipient includes in each blinded path. Included this when
processing HTLCs in ChannelManager, first into PendingHTLCRouting and
then to OnionPayload. Later, this will be included in the PaymentPurpose
when surfaced to user in PaymentClaimable and PaymentClaimed events.