]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
19 months agoDRY up InvoiceFields construction
Jeffrey Czyz [Mon, 17 Apr 2023 23:31:52 +0000 (18:31 -0500)]
DRY up InvoiceFields construction

19 months agoSupport responding to refunds with transient keys
Jeffrey Czyz [Mon, 10 Apr 2023 16:58:14 +0000 (11:58 -0500)]
Support responding to refunds with transient keys

19 months agoExtract keys from Offer::metadata to sign Invoice
Jeffrey Czyz [Wed, 5 Apr 2023 05:04:41 +0000 (00:04 -0500)]
Extract keys from Offer::metadata to sign Invoice

For offers where the signing pubkey is derived, the keys need to be
extracted from the Offer::metadata in order to sign an invoice.
Parameterize InvoiceBuilder such that a build_and_sign method is
available for this situation.

19 months agoDRY up verification of invreq TLV records
Jeffrey Czyz [Tue, 4 Apr 2023 19:59:09 +0000 (14:59 -0500)]
DRY up verification of invreq TLV records

19 months agoStateless verification of Invoice for Refund
Jeffrey Czyz [Mon, 6 Feb 2023 21:30:44 +0000 (15:30 -0600)]
Stateless verification of Invoice for Refund

Stateless verification of Invoice for Offer

Verify that an Invoice was produced from a Refund constructed by the
payer using the payer metadata reflected in the Invoice. The payer
metadata consists of a 128-bit encrypted nonce and possibly a 256-bit
HMAC over the nonce and Refund TLV records (excluding the payer id)
using an ExpandedKey.

Thus, the HMAC can be reproduced from the refund bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the payer id.

19 months agoRefund metadata and payer id derivation
Jeffrey Czyz [Mon, 6 Feb 2023 21:10:07 +0000 (15:10 -0600)]
Refund metadata and payer id derivation

Add support for deriving a transient payer id for each Refund from an
ExpandedKey and a nonce. This facilitates payer privacy by not tying any
Refund to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.

19 months agoStateless verification of Invoice for Offer
Jeffrey Czyz [Mon, 30 Jan 2023 20:57:43 +0000 (14:57 -0600)]
Stateless verification of Invoice for Offer

Verify that an Invoice was produced from an InvoiceRequest constructed
by the payer using the payer metadata reflected in the Invoice. The
payer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and InvoiceRequest TLV records (excluding
the payer id) using an ExpandedKey.

Thus, the HMAC can be reproduced from the invoice request bytes using
the nonce and the original ExpandedKey, and then checked against the
metadata. If metadata does not contain an HMAC, then the reproduced HMAC
was used to form the signing keys, and thus can be checked against the
payer id.

19 months agoFix builder docs in offers module
Jeffrey Czyz [Tue, 21 Mar 2023 01:24:54 +0000 (20:24 -0500)]
Fix builder docs in offers module

19 months agoInvoiceRequest metadata and payer id derivation
Jeffrey Czyz [Mon, 30 Jan 2023 20:56:42 +0000 (14:56 -0600)]
InvoiceRequest metadata and payer id derivation

Add support for deriving a transient payer id for each InvoiceRequest
from an ExpandedKey and a nonce. This facilitates payer privacy by not
tying any InvoiceRequest to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.

19 months agoRefactor InvoiceRequestContents fields into a sub-struct
Jeffrey Czyz [Fri, 10 Mar 2023 23:12:12 +0000 (17:12 -0600)]
Refactor InvoiceRequestContents fields into a sub-struct

InvoiceRequestBuilder has a field containing InvoiceRequestContents.
When deriving the payer_id from the remaining fields, a struct is needed
without payer_id as it not optional. Refactor InvoiceRequestContents to
have an inner struct without the payer_id such that
InvoiceRequestBuilder can use it instead.

19 months agoStateless verification of InvoiceRequest
Jeffrey Czyz [Wed, 8 Feb 2023 01:15:44 +0000 (19:15 -0600)]
Stateless verification of InvoiceRequest

Verify that an InvoiceRequest was produced from an Offer constructed by
the recipient using the Offer metadata reflected in the InvoiceRequest.
The Offer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and Offer TLV records (excluding the signing
pubkey) using an ExpandedKey.

Thus, the HMAC can be reproduced from the offer bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the signing
pubkey.

19 months agoTlvStream range iterator
Jeffrey Czyz [Wed, 25 Jan 2023 17:34:43 +0000 (11:34 -0600)]
TlvStream range iterator

Add an iterator that yields TlvRecords over a range of a TlvStream.
Useful for verifying that, e.g., an InvoiceRequest was sent in response
to an Offer constructed by the intended recipient.

19 months agoOffer metadata and signing pubkey derivation
Jeffrey Czyz [Wed, 8 Feb 2023 01:13:08 +0000 (19:13 -0600)]
Offer metadata and signing pubkey derivation

Add support for deriving a transient signing pubkey for each Offer from
an ExpandedKey and a nonce. This facilitates recipient privacy by not
tying any Offer to any other nor to the recipient's node id.

Additionally, support stateless Offer verification by setting its
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an InvoiceRequest.

19 months agoAdd another ExpandedKey derivation for Offers
Jeffrey Czyz [Tue, 7 Feb 2023 21:25:36 +0000 (15:25 -0600)]
Add another ExpandedKey derivation for Offers

To support transient signing pubkeys and payer ids for Offers, add
another key derivation to ExpandedKey. Also useful for constructing
metadata for stateless message authentication.

19 months agoAdd missing UnknownRequiredFeatures tests
Jeffrey Czyz [Mon, 6 Feb 2023 18:55:54 +0000 (12:55 -0600)]
Add missing UnknownRequiredFeatures tests

19 months agoCommon offers test_utils module
Jeffrey Czyz [Thu, 2 Feb 2023 23:13:09 +0000 (17:13 -0600)]
Common offers test_utils module

Move utility functions used across all offers modules into a common
module. Avoids duplicating larger utilities such as payment_path across
more than one module.

19 months agoMerge pull request #2198 from TheBlueMatt/2023-04-fewer-disables
Matt Corallo [Tue, 18 Apr 2023 15:56:58 +0000 (15:56 +0000)]
Merge pull request #2198 from TheBlueMatt/2023-04-fewer-disables

Only disable channels ~10 min after disconnect, rather than one

19 months agoOnly disable channels ~10 min after disconnect, rather than one 2023-04-fewer-disables
Matt Corallo [Mon, 17 Apr 2023 23:09:11 +0000 (23:09 +0000)]
Only disable channels ~10 min after disconnect, rather than one

We correctly send out a gossip channel disable update after one
full time tick being down (1-2 minutes). This is pretty nice in
that it avoids nodes trying to route through our nodes too often
if they're down. Other nodes have a much longer time window,
causing them to have much less aggressive channel disables. Sadly,
at one minute it's not super uncommon for tor nodes to get disabled
(once a day or so on two nodes I looked at), and this causes the
lightning terminal scorer to consider the LDK node unstable (even
though it's the one doing the disabling - so is online). This
causes user frustration and makes LDK look bad (even though it's
probably failing fewer payments).

Given this, and future switches to block-based `channel_update`
timestamp fields, it makes sense to go ahead and switch to delaying
channel disable announcements for 10 minutes. This puts us more in
line with other implementations and reduces gossip spam, at the
cost of less reliable payments.

Fixes #2175, at least the currently visible parts.

19 months agoSet `channel_update` disable bit based on staged even for onions
Matt Corallo [Mon, 17 Apr 2023 22:59:18 +0000 (22:59 +0000)]
Set `channel_update` disable bit based on staged even for onions

When generating a `channel_update` either in response to a fee
configuration change or an HTLC failure, we currently poll the
channel to check if the peer's connected when setting the disabled
bit in the `channel_update`. This could cause cases where we set
the disable bit even though the peer *just* disconnected, and don't
generate a followup broadcast `channel_update` with the disabled
bit unset.

While a node generally shouldn't rebroadcast a `channel_update` it
received in an onion, there's nothing inherently stopping them from
doing so. Obviously in the fee-update case we expect the message to
propagate.

Luckily, since we already "stage" disable-changed updates, we can
check the staged state and use that to set the disabled bit in all
`channel_update` cases.

19 months agoMerge pull request #2138 from swilliamson5/replace-our-max-htlcs-constant
Matt Corallo [Mon, 17 Apr 2023 21:58:07 +0000 (21:58 +0000)]
Merge pull request #2138 from swilliamson5/replace-our-max-htlcs-constant

Replace `OUR_MAX_HTLCS` with config knob

19 months agoMerge pull request #2196 from wpaulino/ci-ignore-master-cancel-prev
Matt Corallo [Mon, 17 Apr 2023 21:54:55 +0000 (21:54 +0000)]
Merge pull request #2196 from wpaulino/ci-ignore-master-cancel-prev

Prevent unnecessary CI workflow runs

19 months agoMerge pull request #2195 from TheBlueMatt/2023-04-115-bindings-upstream
Matt Corallo [Mon, 17 Apr 2023 21:25:37 +0000 (21:25 +0000)]
Merge pull request #2195 from TheBlueMatt/2023-04-115-bindings-upstream

19 months agoCancel in-progress jobs on updated push
Wilmer Paulino [Mon, 17 Apr 2023 18:32:53 +0000 (11:32 -0700)]
Cancel in-progress jobs on updated push

At times, PRs can go through multiple pushes in a short amount of time,
spawning a workflow run for each. Most of the time, there's no need to
let the previous jobs running if the code itself has changed (e.g., via
a force push), and we'd benefit from having those slots be used by other
PRs/branches instead.

19 months agoIgnore workflow runs on master branch
Wilmer Paulino [Mon, 17 Apr 2023 17:25:30 +0000 (10:25 -0700)]
Ignore workflow runs on master branch

This master branch is just an alias to the main branch for legacy
reasons, so there's no need to run workflows on both branches.

19 months agoMark the invoice `Network` getter no-export 2023-04-115-bindings-upstream
Matt Corallo [Mon, 17 Apr 2023 17:35:50 +0000 (17:35 +0000)]
Mark the invoice `Network` getter no-export

...as it is redundant with the `currency` getter if we're not using
the rust-bitcoin types natively.

19 months agoMerge pull request #2177 from TheBlueMatt/2023-04-test-function-generics
Wilmer Paulino [Mon, 17 Apr 2023 16:56:18 +0000 (09:56 -0700)]
Merge pull request #2177 from TheBlueMatt/2023-04-test-function-generics

Genericize Test Functions

19 months agoMerge pull request #2191 from TheBlueMatt/2023-04-fix-bucket-deser
Matt Corallo [Mon, 17 Apr 2023 15:11:53 +0000 (15:11 +0000)]
Merge pull request #2191 from TheBlueMatt/2023-04-fix-bucket-deser

Fix deserialization of u16 arrays

19 months agoMerge pull request #2187 from benthecarman/invoice-serde-no-std
Matt Corallo [Mon, 17 Apr 2023 13:28:49 +0000 (13:28 +0000)]
Merge pull request #2187 from benthecarman/invoice-serde-no-std

19 months agoReplace OUR_MAX_HTLCS constant with config knob
Steven Williamson [Wed, 29 Mar 2023 23:45:09 +0000 (19:45 -0400)]
Replace OUR_MAX_HTLCS constant with config knob
holder_max_accepted_htlcs. Set upper bound of 483

Writes an even TLV if the value isn't 50

19 months agoFix deserialization of u16 arrays 2023-04-fix-bucket-deser
Matt Corallo [Sun, 16 Apr 2023 21:57:20 +0000 (21:57 +0000)]
Fix deserialization of u16 arrays

u16 arrays are used in the historical liquidity range tracker.
Previously, we read them without applying the stride multiple,
reading bytes repeatedly and at an offset, corrupting data as we
go.

This applies the correct stride multiplayer fixing the issue.

19 months agoAdd CI test for compile no-std serde lightning-invoice
benthecarman [Sun, 16 Apr 2023 18:17:22 +0000 (13:17 -0500)]
Add CI test for compile no-std serde lightning-invoice

19 months agoFix compiling lightning-invoice for no-std + serde
benthecarman [Sat, 15 Apr 2023 20:38:53 +0000 (15:38 -0500)]
Fix compiling lightning-invoice for no-std + serde

19 months agoMerge pull request #2172 from TheBlueMatt/2023-04-fix-panicy-debug-assert
Matt Corallo [Fri, 14 Apr 2023 15:00:12 +0000 (15:00 +0000)]
Merge pull request #2172 from TheBlueMatt/2023-04-fix-panicy-debug-assert

Remove a race-y debug assertion in new channel update handling

19 months agoMerge pull request #2180 from benthecarman/impl-pk-to-node-id
Matt Corallo [Fri, 14 Apr 2023 14:56:51 +0000 (14:56 +0000)]
Merge pull request #2180 from benthecarman/impl-pk-to-node-id

Implement to and from for PublicKey and NodeId

19 months agoImpl FromStr for NodeId
benthecarman [Thu, 13 Apr 2023 17:54:04 +0000 (12:54 -0500)]
Impl FromStr for NodeId

19 months agoMerge pull request #2179 from benthecarman/use-node-alias-type
Matt Corallo [Thu, 13 Apr 2023 19:46:30 +0000 (19:46 +0000)]
Merge pull request #2179 from benthecarman/use-node-alias-type

Use NodeAlias type in NodeAnnouncement

19 months agoMove some additional test macros into functions 2023-04-test-function-generics
Matt Corallo [Thu, 16 Mar 2023 18:27:52 +0000 (18:27 +0000)]
Move some additional test macros into functions

This marginally reduces the quantity of code compiled in tests
further.

19 months agoIntroduce traits to make test utils generic across the `CM` Holder
Matt Corallo [Fri, 17 Mar 2023 20:50:19 +0000 (20:50 +0000)]
Introduce traits to make test utils generic across the `CM` Holder

In our test utilities, we generally refer to a `Node` struct which
holds a `ChannelManager` and a number of other structs. However, we
use the same utilities in benchmarking, where we have a different
`Node`-like struct. This made moving from macros to functions
entirely impossible, as we end up needing multiple types in a given
context.

Thus, here, we take the pain and introduce some wrapper traits
which encapsulte what we need from `Node`, swapping some of our
macros to functions.

19 months agoUse NodeAlias type in NodeAnnouncement
benthecarman [Wed, 12 Apr 2023 21:09:28 +0000 (16:09 -0500)]
Use NodeAlias type in NodeAnnouncement

19 months agoImplement to and from for PublicKey and NodeId
benthecarman [Thu, 13 Apr 2023 00:14:03 +0000 (19:14 -0500)]
Implement to and from for PublicKey and NodeId

19 months agoDRY the event handling in `ChannelManager`
Matt Corallo [Thu, 30 Mar 2023 23:35:07 +0000 (23:35 +0000)]
DRY the event handling in `ChannelManager`

In the coming commits we'll add some additional complexity to the
event handling flows, so best to DRY them up before we get there.

19 months agoMerge pull request #2142 from alecchendev/2023-03-expose-fail-reason-in-payment-failure
valentinewallace [Tue, 11 Apr 2023 21:26:16 +0000 (17:26 -0400)]
Merge pull request #2142 from alecchendev/2023-03-expose-fail-reason-in-payment-failure

Expose a failure reason in `PaymentFailed`

19 months agoAdd reason to `Event::PaymentFailed`
Alec Chen [Sat, 1 Apr 2023 00:07:57 +0000 (19:07 -0500)]
Add reason to `Event::PaymentFailed`

This includes adding a reason to `PendingOutboundPayment::Abandoned` and
using that reason when pushing an `Event::PaymentFailed`.

19 months agoMerge pull request #2173 from benthecarman/convert-currency-to-netowkr
valentinewallace [Mon, 10 Apr 2023 16:21:16 +0000 (12:21 -0400)]
Merge pull request #2173 from benthecarman/convert-currency-to-netowkr

Convert Network to and from Currency

19 months agoConvert Network to and from Currency
benthecarman [Sun, 9 Apr 2023 02:24:17 +0000 (21:24 -0500)]
Convert Network to and from Currency

19 months agoRemove a race-y debug assertion in new channel update handling 2023-04-fix-panicy-debug-assert
Matt Corallo [Sun, 9 Apr 2023 01:43:39 +0000 (01:43 +0000)]
Remove a race-y debug assertion in new channel update handling

In 6090d9e6a862a2010eb80be56b7449947bc08374 we swapped out old
debug assertions that checked that a lock was `try_lock`able to
test that certain locks weren't held when we needed to be able to
take them in some near branch. However, another slipped in after in
the `ChannelMonitorUpdate` handling rework, which is replaced with
the new debug assertions here.

19 months agoMerge pull request #2161 from benthecarman/prune-stale-channels-rgs
Arik [Sat, 8 Apr 2023 06:26:19 +0000 (23:26 -0700)]
Merge pull request #2161 from benthecarman/prune-stale-channels-rgs

Prune stale channels from network graph after RGS sync.

19 months agoMerge pull request #2158 from TheBlueMatt/2023-04-handle_err_more-check
valentinewallace [Fri, 7 Apr 2023 20:19:27 +0000 (16:19 -0400)]
Merge pull request #2158 from TheBlueMatt/2023-04-handle_err_more-check

Test for extra locks held in `handle_error` unconditionally

19 months agoMerge pull request #2023 from futurepaul/fallback-to-address
Jeffrey Czyz [Fri, 7 Apr 2023 19:39:32 +0000 (14:39 -0500)]
Merge pull request #2023 from futurepaul/fallback-to-address

add `Fallback` getter that returns `Address`

19 months agoCreate `PaymentFailureReason` enum
Alec Chen [Thu, 30 Mar 2023 03:30:08 +0000 (22:30 -0500)]
Create `PaymentFailureReason` enum

19 months agoMerge pull request #2170 from TheBlueMatt/2023-04-silent-merge-conflict
Matt Corallo [Fri, 7 Apr 2023 18:27:33 +0000 (18:27 +0000)]
Merge pull request #2170 from TheBlueMatt/2023-04-silent-merge-conflict

Fix silent merge conflict between new test and payment refactor

19 months agoMerge pull request #2162 from jkczyz/2023-04-invoice-hash
Wilmer Paulino [Fri, 7 Apr 2023 17:11:36 +0000 (10:11 -0700)]
Merge pull request #2162 from jkczyz/2023-04-invoice-hash

19 months agoFix silent merge conflict between new test and payment refactor 2023-04-silent-merge-conflict
Matt Corallo [Fri, 7 Apr 2023 16:29:19 +0000 (16:29 +0000)]
Fix silent merge conflict between new test and payment refactor

19 months agoMerge pull request #2148 from TheBlueMatt/2023-04-claim-from-closed
Matt Corallo [Fri, 7 Apr 2023 16:17:25 +0000 (16:17 +0000)]
Merge pull request #2148 from TheBlueMatt/2023-04-claim-from-closed

Allow claiming a payment if a channel with an HTLC has closed

19 months agoMerge pull request #2139 from TheBlueMatt/2023-03-metadata-prefactors
Matt Corallo [Fri, 7 Apr 2023 16:14:30 +0000 (16:14 +0000)]
Merge pull request #2139 from TheBlueMatt/2023-03-metadata-prefactors

Add a new `RecipientOnionFields` and replace `PaymentSecret` with it

19 months agoMerge pull request #2165 from wpaulino/fix-bp-channel-pending-panic-flake
Matt Corallo [Fri, 7 Apr 2023 16:08:34 +0000 (16:08 +0000)]
Merge pull request #2165 from wpaulino/fix-bp-channel-pending-panic-flake

Use signal for handling ChannelPending in test_background_event_handling

19 months agoSplit up comically long error return 2023-04-handle_err_more-check
Matt Corallo [Fri, 7 Apr 2023 04:54:07 +0000 (04:54 +0000)]
Split up comically long error return

19 months agoExpose a BOLT 12 Invoice's signable_hash
Jeffrey Czyz [Thu, 6 Apr 2023 15:30:57 +0000 (10:30 -0500)]
Expose a BOLT 12 Invoice's signable_hash

This is useful as an identifier for downstream clients like VLS.

19 months agoExpose a BOLT 11 Invoice's signable_hash
Jeffrey Czyz [Thu, 6 Apr 2023 14:47:45 +0000 (09:47 -0500)]
Expose a BOLT 11 Invoice's signable_hash

Otherwise, an Invoice must first be converted to a SignedRawInvoice to
obtain the hash.

19 months agoLinkify lightning-invoice docs
Jeffrey Czyz [Fri, 7 Apr 2023 04:13:05 +0000 (23:13 -0500)]
Linkify lightning-invoice docs

19 months agoLift std check to function definition
benthecarman [Thu, 6 Apr 2023 23:10:57 +0000 (18:10 -0500)]
Lift std check to function definition

19 months agoUse signal for handling ChannelPending in test_background_event_handling
Wilmer Paulino [Thu, 6 Apr 2023 21:59:04 +0000 (14:59 -0700)]
Use signal for handling ChannelPending in test_background_event_handling

This fixes two potential panics within the test if the
`BackgroundProcessor` for `nodes[0]` consumed the `ChannelPending` event
prior to us consuming it manually in `end_open_channel`. The first panic
would happen within the event handler, since `ChannelPending` was not
being handled. The second panic would happen upon expecting the
`ChannelPending` event after handling `nodes[1]`'s `funding_signed` if
the `BackgroundProcessor` handled the event first. To ensure we still
reliably receive a `ChannelPending` event once possible, we let the
`BackgroundProcessor` consume the event and notify it.

19 months agoMerge pull request #2163 from TheBlueMatt/2023-04-less-lock
Matt Corallo [Thu, 6 Apr 2023 21:53:49 +0000 (21:53 +0000)]
Merge pull request #2163 from TheBlueMatt/2023-04-less-lock

Avoid holding a `per_peer_state` lock while claiming from a monitor

19 months agoPrune stale channels from network graph after RGS sync
benthecarman [Thu, 6 Apr 2023 15:10:14 +0000 (10:10 -0500)]
Prune stale channels from network graph after RGS sync

19 months agoAdd a `claim_deadline` field to `PaymentClaimable` with guarantees 2023-04-claim-from-closed
Matt Corallo [Tue, 4 Apr 2023 04:21:45 +0000 (04:21 +0000)]
Add a `claim_deadline` field to `PaymentClaimable` with guarantees

Now that we guarantee `claim_payment` will always succeed we have
to let the user know what the deadline is. We still fail payments
if they haven't been claimed in time, which we now expose in
`PaymentClaimable`.

19 months agoAvoid holding a `per_peer_state` lock while claiming from a monitor 2023-04-less-lock
Matt Corallo [Sat, 1 Apr 2023 19:22:22 +0000 (19:22 +0000)]
Avoid holding a `per_peer_state` lock while claiming from a monitor

There's no reason to hold a lock on `per_peer_state` while we're
claiming from a since-closed channel via a `ChannelMonitorUpdate`,
which we stop doing here.

19 months agoMerge pull request #2101 from TheBlueMatt/2023-03-one-less-sig
Matt Corallo [Thu, 6 Apr 2023 18:07:55 +0000 (18:07 +0000)]
Merge pull request #2101 from TheBlueMatt/2023-03-one-less-sig

Support future removal of redundant per-HTLC signatures in `CMU`s

19 months ago`Fallback`: add `Address` getter and use bitcoin types
Paul Miller [Wed, 8 Feb 2023 15:09:44 +0000 (09:09 -0600)]
`Fallback`: add `Address` getter and use bitcoin types

19 months agoTest for extra locks held in `handle_error` unconditionally
Matt Corallo [Thu, 6 Apr 2023 02:35:37 +0000 (02:35 +0000)]
Test for extra locks held in `handle_error` unconditionally

`handle_error` must be called without `per_peer_state` mutex or
`pending_events` mutex locks held or we may risk deadlocks.
Previously we checked this in debug builds in the error path, but
not in the success path.

As it turns out, `funding_transaction_generated`'s error path does
hold a `per_peer_state` lock, which we fix here as well as move the
tests to happen unconditionally.

19 months agoMerge pull request #2145 from TheBlueMatt/2023-04-async-bp-cleanups
Matt Corallo [Wed, 5 Apr 2023 16:55:51 +0000 (16:55 +0000)]
Merge pull request #2145 from TheBlueMatt/2023-04-async-bp-cleanups

Add test coverage of async BP and fix minor bug

19 months agoCorrect documentation of `payment_id` in events 2023-03-metadata-prefactors
Matt Corallo [Wed, 5 Apr 2023 16:31:50 +0000 (16:31 +0000)]
Correct documentation of `payment_id` in events

19 months agoPipe the new `RecipientOnionFields` through send pipeline
Matt Corallo [Fri, 24 Mar 2023 05:32:56 +0000 (05:32 +0000)]
Pipe the new `RecipientOnionFields` through send pipeline

This passes the new `RecipientOnionFields` through the internal
sending APIs, ensuring we have access to the full struct when we
go to construct the sending onion so that we can include any new
fields added there.

19 months agoAdd a `RecipientOnionFields` argument to spontaneous payment sends
Matt Corallo [Fri, 24 Mar 2023 01:19:20 +0000 (01:19 +0000)]
Add a `RecipientOnionFields` argument to spontaneous payment sends

While most lightning nodes don't (currently) support providing a
payment secret or payment metadata for spontaneous payments,
there's no specific technical reason why we shouldn't support
sending those fields to a recipient.

Further, when we eventually move to allowing custom TLV entries in
the recipient's onion TLV stream, we'll want to support it for
spontaneous payments as well.

Here we simply add the new `RecipientOnionFields` struct as an
argument to the spontaneous payment send methods. We don't yet
plumb it through the payment sending logic, which will come when we
plumb the new struct through the sending logic to replace the
existing payment secret arguments.

19 months agoReplace `PaymentSecret` with `RecipientOnionFields` in the pub API
Matt Corallo [Wed, 22 Mar 2023 21:48:22 +0000 (21:48 +0000)]
Replace `PaymentSecret` with `RecipientOnionFields` in the pub API

This moves the public payment sending API from passing an explicit
`PaymentSecret` to a new `RecipientOnionFields` struct (which
currently only contains the `PaymentSecret`). This gives us
substantial additional flexibility as we look at add both
`PaymentMetadata`, a new (well, year-or-two-old) BOLT11 invoice
extension to provide additional data sent to the recipient.

In the future, we should also add the ability to add custom TLV
entries in the `RecipientOnionFields` struct.

19 months agoRemove the `PaymentSecret` field from `HTLCSource::OutboundRoute`
Matt Corallo [Wed, 22 Mar 2023 19:15:52 +0000 (19:15 +0000)]
Remove the `PaymentSecret` field from `HTLCSource::OutboundRoute`

Many of the fields in `HTLCSource::OutboundRoute` are used to
rebuild the pending-outbound-payment map on reload if the
`ChannelManager` was not serialized though `ChannelMonitor`(s)
were after an HTLC was sent. As of 0.0.114, however, such payments
are not retryable without allowing them to fail and doing a full,
fresh, send.

Thus, some of the fields can be safely removed - we only really
care about having enough information to provide the user a failure
event, not being able to retry.

Here we drop one such field - the `payment_secret`, making our
`ChannelMonitorUpdate`s another handful of bytes smaller.

19 months agoAllow claiming a payment if a channel with an HTLC has closed
Matt Corallo [Tue, 4 Apr 2023 04:12:55 +0000 (04:12 +0000)]
Allow claiming a payment if a channel with an HTLC has closed

Previously, LDK would refuse to claim a payment if a channel on
which the payment was received had been closed between when the
HTLC was received and when we went to claim it. This makes sense in
the payment case - why pay an on-chain fee to claim the HTLC when
presumably the sender may retry later. Long ago it also reduced
total code in the claim pipeline.

However, this doesn't make sense if you're trying to do an atomic
swap or some other protocol that requires atomicity with some other
action - if your money got claimed elsewhere you need to be able to
claim the HTLC in lightning no matter what. Further, this is an
over-optimization - there should be a very, very low likelihood
that a channel closes between when we receive the last HTLC for a
payment and the user goes to claim the payment. Since we now have
code to handle this anyway we should allow it.

Fixes #2017.

19 months agoAdd an async version of BP's test_channel_manager_persist_error 2023-04-async-bp-cleanups
Matt Corallo [Mon, 3 Apr 2023 20:47:02 +0000 (20:47 +0000)]
Add an async version of BP's test_channel_manager_persist_error

This gives us coverage of an async BP returning an error.

19 months agoMake BP's `not_pruning_network_graph_until...` test dual async-sync
Matt Corallo [Mon, 3 Apr 2023 20:34:13 +0000 (20:34 +0000)]
Make BP's `not_pruning_network_graph_until...` test dual async-sync

19 months agoMake BP's `test_payment_path_scoring` dual sync/async.
Matt Corallo [Mon, 3 Apr 2023 20:19:49 +0000 (20:19 +0000)]
Make BP's `test_payment_path_scoring` dual sync/async.

This finally gives us a bit of test coverage of the async BP, which
was embarrassingly missing until now.

19 months agoEnsure `background-processor` exits after any sleep future says to
Matt Corallo [Mon, 3 Apr 2023 20:15:04 +0000 (20:15 +0000)]
Ensure `background-processor` exits after any sleep future says to

If the user's sleep future passed to an async background processor
only returns true for exiting once and then reverts back to false,
we should exit anyway when we get a chance to. We do to this here
by always ensuring we check the exit flag even when only polling
sleep futures with no intent to (yet) exit. This is utilized in the
tests added in the coming commit(s).

19 months agoDon't immediately exit BP if `ChannelManager` is persistable
Matt Corallo [Mon, 3 Apr 2023 20:11:30 +0000 (20:11 +0000)]
Don't immediately exit BP if `ChannelManager` is persistable

If `ChannelManager` is persistable before the async background
processor even starts, it may not even get around to overwriting
the `should_exit` flag before testing it, and the default value is
(incorrectly) true, causing an immediate unconditional exit.

The default value should simply be false.

Fixes #2140

19 months agoMake `lightning-background-processor` test failures more debugable
Matt Corallo [Mon, 3 Apr 2023 18:38:26 +0000 (18:38 +0000)]
Make `lightning-background-processor` test failures more debugable

Instead of asserting a `Result` `is_ok`, we should always simply
`unwrap` to get a backgrace, and we should avoid doing so if the
thread is already panicking.

19 months agoMerge pull request #2150 from TonyGiorgio/esplora-0.4
valentinewallace [Tue, 4 Apr 2023 19:49:44 +0000 (15:49 -0400)]
Merge pull request #2150 from TonyGiorgio/esplora-0.4

lightning-transaction-sync: Bump esplora to 0.4

19 months agoMerge pull request #2147 from TheBlueMatt/2023-04-rgs-log-some
Matt Corallo [Tue, 4 Apr 2023 19:07:24 +0000 (19:07 +0000)]
Merge pull request #2147 from TheBlueMatt/2023-04-rgs-log-some

Add some trivial logging during RGS update processing.

19 months agolightning-transaction-sync: Bump esplora to 0.4
Tony Giorgio [Tue, 4 Apr 2023 17:28:15 +0000 (12:28 -0500)]
lightning-transaction-sync: Bump esplora to 0.4

19 months agoMerge pull request #2005 from arik-so/2023-01-taproot-message-types
Matt Corallo [Tue, 4 Apr 2023 16:38:04 +0000 (16:38 +0000)]
Merge pull request #2005 from arik-so/2023-01-taproot-message-types

Update messages for Taproot types.

19 months agoAdd some trivial logging during RGS update processing. 2023-04-rgs-log-some
Matt Corallo [Mon, 3 Apr 2023 22:29:41 +0000 (22:29 +0000)]
Add some trivial logging during RGS update processing.

Rather than being totally silent, we need to at least note that we
are processing an RGS update when doing so in the logs, which we do
here.

Fixes #1981.

19 months agoAdd Taproot CI test.
Arik Sosman [Fri, 31 Mar 2023 05:59:21 +0000 (22:59 -0700)]
Add Taproot CI test.

19 months agoUpdate the `RevokeAndACK` message for Taproot support.
Arik Sosman [Wed, 29 Mar 2023 23:35:05 +0000 (16:35 -0700)]
Update the `RevokeAndACK` message for Taproot support.

19 months agoUpdate the `CommitmentSigned` message for Taproot support.
Arik Sosman [Wed, 29 Mar 2023 22:21:30 +0000 (15:21 -0700)]
Update the `CommitmentSigned` message for Taproot support.

19 months agoUpdate the `FundingSigned` message for Taproot support.
Arik Sosman [Wed, 29 Mar 2023 22:02:34 +0000 (15:02 -0700)]
Update the `FundingSigned` message for Taproot support.

19 months agoUpdate the `FundingCreated` message for Taproot support.
Arik Sosman [Wed, 29 Mar 2023 00:33:45 +0000 (17:33 -0700)]
Update the `FundingCreated` message for Taproot support.

19 months agoUpdate the `AcceptChannel` message for Taproot support.
Arik Sosman [Tue, 28 Mar 2023 21:59:20 +0000 (14:59 -0700)]
Update the `AcceptChannel` message for Taproot support.

19 months agoIntroduce MuSig2-related types for Taproot channels.
Arik Sosman [Tue, 28 Mar 2023 21:37:01 +0000 (14:37 -0700)]
Introduce MuSig2-related types for Taproot channels.

19 months agoMerge pull request #2090 from TheBlueMatt/2023-03-mon-wake-bp
Matt Corallo [Mon, 3 Apr 2023 20:12:46 +0000 (20:12 +0000)]
Merge pull request #2090 from TheBlueMatt/2023-03-mon-wake-bp

Wake background-processor on async monitor update completion

19 months agoMerge pull request #2098 from tnull/2023-03-add-channel-pending-event
Matt Corallo [Mon, 3 Apr 2023 18:26:18 +0000 (18:26 +0000)]
Merge pull request #2098 from tnull/2023-03-add-channel-pending-event

Add `ChannelPending` event emitted upon `funding_signed`

19 months agoMerge pull request #2143 from get10101/chore/convenient-confirm
Matt Corallo [Mon, 3 Apr 2023 17:58:54 +0000 (17:58 +0000)]
Merge pull request #2143 from get10101/chore/convenient-confirm

Implement `chain::Confirm` without mandating any owned values

19 months agoAdd `ChannelPending` event emitted upon `funding_signed`
Elias Rohrer [Fri, 10 Mar 2023 15:30:37 +0000 (16:30 +0100)]
Add `ChannelPending` event emitted upon `funding_signed`

Currently, users don't have good way of being notified when channel open
negotiations have succeeded and new channels are pending confirmation on
chain. To this end, we add a new `ChannelPending` event that is emitted
when send or receive a `funding_signed` message, i.e., at the last
moment before waiting for the confirmation period.

We track whether the event had previously been emitted in `Channel` and
remove it from `internal_funding_created` entirely. Hence, we now
only emit the event after ChannelMonitorUpdate completion, or upon
channel reestablish. This mitigates a race condition where where we
wouldn't persist the event *and* wouldn't regenerate it on restart,
therefore potentially losing it, if async CMU wouldn't complete before
ChannelManager persistence.

19 months agoExpose an option to substantially reduce sleep time in futures BP 2023-03-mon-wake-bp
Matt Corallo [Tue, 14 Mar 2023 21:23:21 +0000 (21:23 +0000)]
Expose an option to substantially reduce sleep time in futures BP

Some users have suggested that waking every 100ms can be
CPU-intensive in deployments with hundreds or thousands of nodes
all running on the same machine. Thus, we add an option to the
futures-based `background-processor` to avoid waking every 100ms to
check for iOS having backgrounded our app and cut our TCP sockets.

This cuts the normal sleep time down from 100ms to 10s, for those
who turn it on.

19 months agoWake the background processor if an async monitor update completes
Matt Corallo [Thu, 9 Mar 2023 03:11:13 +0000 (03:11 +0000)]
Wake the background processor if an async monitor update completes

If the `ChainMonitor` gets an async monitor update completion, this
means the `ChannelManager` needs to be polled for event processing.
Here we wake it using the new multi-`Future`-await `Sleeper`, or
the existing `select` block in the async BP.

Fixes #2052.