rust-lightning
11 months agoMove next hop packet pubkey calculation to outside channel lock
Valentine Wallace [Tue, 20 Jun 2023 21:40:12 +0000 (17:40 -0400)]
Move next hop packet pubkey calculation to outside channel lock

11 months agoMove PendingHTLCStatus construction inside channel lock
Valentine Wallace [Tue, 16 May 2023 20:14:40 +0000 (16:14 -0400)]
Move PendingHTLCStatus construction inside channel lock

We need the channel lock for constructing a pending HTLC's status because we
need to know if the channel accepts underpaying HTLCs in upcoming commits.

11 months agoMerge pull request #2077 from dunxen/2023-02-splitchannelstate
Matt Corallo [Fri, 16 Jun 2023 06:01:10 +0000 (06:01 +0000)]
Merge pull request #2077 from dunxen/2023-02-splitchannelstate

Split prefunded `Channel` into `Inbound`/`Outbound` channels

11 months agoRename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`
Duncan Dean [Tue, 13 Jun 2023 15:17:59 +0000 (17:17 +0200)]
Rename `inbound_is_awaiting_accept()` to `is_awaiting_accept()`

11 months agoRename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`
Duncan Dean [Wed, 7 Jun 2023 18:49:26 +0000 (20:49 +0200)]
Rename `InboundV1Channel::new_from_req` to `InboundV1Channel::new`

11 months agoMove inbound channel methods into `InboundV1Channel`'s impl
Duncan Dean [Wed, 7 Jun 2023 16:14:59 +0000 (18:14 +0200)]
Move inbound channel methods into `InboundV1Channel`'s impl

11 months agoMove outbound channel methods into `OutboundV1Channel`'s impl
Duncan Dean [Wed, 7 Jun 2023 16:09:23 +0000 (18:09 +0200)]
Move outbound channel methods into `OutboundV1Channel`'s impl

11 months agoCreate and use methods for counting channels
Duncan Dean [Wed, 7 Jun 2023 17:52:21 +0000 (19:52 +0200)]
Create and use methods for counting channels

This commit also adds two new maps to `PeerState` for keeping track
of `OutboundV1Channel`s and `InboundV1Channel`s so that further
commits are a bit easier to review.

11 months agoRefactor channel map update macros for use with `ChannelContext`
Duncan Dean [Wed, 7 Jun 2023 17:22:59 +0000 (19:22 +0200)]
Refactor channel map update macros for use with `ChannelContext`

11 months agoMove `Channel::force_shutdown` to `ChannelContext` impl
Duncan Dean [Tue, 13 Jun 2023 15:31:28 +0000 (17:31 +0200)]
Move `Channel::force_shutdown` to `ChannelContext` impl

11 months agoMove inbound channel constructor into `InboundV1Channel` impl
Duncan Dean [Wed, 7 Jun 2023 14:17:18 +0000 (16:17 +0200)]
Move inbound channel constructor into `InboundV1Channel` impl

11 months agoMove outbound channel constructor into `OutboundV1Channel` impl
Duncan Dean [Wed, 7 Jun 2023 14:09:35 +0000 (16:09 +0200)]
Move outbound channel constructor into `OutboundV1Channel` impl

11 months agoIntroduce `InboundV1Channel` & `OutboundV1Channel`
Duncan Dean [Wed, 5 Apr 2023 11:43:02 +0000 (13:43 +0200)]
Introduce `InboundV1Channel` & `OutboundV1Channel`

11 months agoMove channel constants up
Duncan Dean [Thu, 30 Mar 2023 09:17:32 +0000 (11:17 +0200)]
Move channel constants up

11 months agoMake `ChannelManager::issue_channel_close_events` take a `ChannelContext`
Duncan Dean [Tue, 13 Jun 2023 14:43:43 +0000 (16:43 +0200)]
Make `ChannelManager::issue_channel_close_events` take a `ChannelContext`

11 months agoConvert `ChannelDetails::from_channel` to `ChannelDetails::from_channel_context`
Duncan Dean [Wed, 7 Jun 2023 09:03:46 +0000 (11:03 +0200)]
Convert `ChannelDetails::from_channel` to `ChannelDetails::from_channel_context`

This rename and refactor is so that we can get channel details from a
`ChannelContext` which is a common object to all channels.

11 months agoMove `Channel::get_available_balances` to `ChannelContext` impl
Duncan Dean [Tue, 13 Jun 2023 14:40:49 +0000 (16:40 +0200)]
Move `Channel::get_available_balances` to `ChannelContext` impl

11 months agoMove `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext` impl
Duncan Dean [Tue, 13 Jun 2023 11:54:40 +0000 (13:54 +0200)]
Move `Channel::next_*_commit_tx_fee_msat` methods to `ChannelContext` impl

11 months agoMove `Channel::commit_tx_fee_msat` to file-level utilities
Duncan Dean [Tue, 13 Jun 2023 11:26:50 +0000 (13:26 +0200)]
Move `Channel::commit_tx_fee_msat` to file-level utilities

11 months agoMove `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl
Duncan Dean [Tue, 13 Jun 2023 11:19:02 +0000 (13:19 +0200)]
Move `Channel::get_*_pending_htlc_stats` to `ChannelContext` impl

11 months agoPrepare some methods for upcoming moves to `ChannelContext`
Duncan Dean [Tue, 13 Jun 2023 10:34:36 +0000 (12:34 +0200)]
Prepare some methods for upcoming moves to `ChannelContext`

To reduce interleaving in commits, we introduce a `context` variable
in methods to be moved in upcoming commits so there is minimal change
with the moves.

11 months agoMove `Channel::get_feerate_sat_per_1000_weight` and other methods
Duncan Dean [Wed, 7 Jun 2023 10:33:41 +0000 (12:33 +0200)]
Move `Channel::get_feerate_sat_per_1000_weight` and other methods

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.

f s/tarcontext.get_/target_/

11 months agoMove `Channel::build_holder_transaction_keys` and some other methods
Duncan Dean [Wed, 7 Jun 2023 10:26:53 +0000 (12:26 +0200)]
Move `Channel::build_holder_transaction_keys` and some other methods

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.

11 months agoMove `Channel::build_commitment_transaction` to `ChannelContext` impl
Duncan Dean [Wed, 7 Jun 2023 10:20:25 +0000 (12:20 +0200)]
Move `Channel::build_commitment_transaction` to `ChannelContext` impl

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.

11 months agoMove `Channel::channel_id` and some other methods to `ChannelContext` impl
Duncan Dean [Wed, 7 Jun 2023 10:15:24 +0000 (12:15 +0200)]
Move `Channel::channel_id` and some other methods to `ChannelContext` impl

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.

11 months agoMove `Channel::get_update_time_counter` and some other methods
Duncan Dean [Wed, 7 Jun 2023 09:57:35 +0000 (11:57 +0200)]
Move `Channel::get_update_time_counter` and some other methods

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

This commit also uses these methods through the `context` field where
needed for compilation and tests to pass due to the above change.

11 months agoMove `Channel::opt_anchors` to `ChannelContext` impl & move some util fns
Duncan Dean [Wed, 7 Jun 2023 09:29:44 +0000 (11:29 +0200)]
Move `Channel::opt_anchors` to `ChannelContext` impl & move some util fns

This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

11 months agoMove `Channel` fields into `ChannelContext` struct
Duncan Dean [Tue, 7 Mar 2023 19:56:01 +0000 (21:56 +0200)]
Move `Channel` fields into `ChannelContext` struct

This is a first step for simplifying the channel state and introducing
new unfunded channel types that hold similar state before being promoted
to funded channels.

Essentially, we want the outer `Channel` type (and upcoming channel types)
to wrap the context so we can apply typestate patterns to the that wrapper
while also deduplicating code for common state and other internal fields.

11 months agoMerge pull request #2294 from jkczyz/2023-05-onion-message-replies
Matt Corallo [Tue, 13 Jun 2023 21:01:32 +0000 (21:01 +0000)]
Merge pull request #2294 from jkczyz/2023-05-onion-message-replies

BOLT 12 Offers message handling support

11 months agoReduce log level of potential noisy log statement
Jeffrey Czyz [Tue, 13 Jun 2023 17:35:41 +0000 (12:35 -0500)]
Reduce log level of potential noisy log statement

11 months agoFuzz test onion message replies
Jeffrey Czyz [Fri, 24 Feb 2023 23:27:18 +0000 (17:27 -0600)]
Fuzz test onion message replies

11 months agoUse different node secrets in onion message fuzzer
Jeffrey Czyz [Wed, 7 Jun 2023 15:55:00 +0000 (10:55 -0500)]
Use different node secrets in onion message fuzzer

When generating onion message fuzz data, the same public key was used
for each node. However, the code now advances the blinded path if the
sender is the introduction node. Use different node secrets for each
node to avoid this. Note that the exercised handling code is for the
sender's immediate peer.

11 months agoTest onion message replies
Jeffrey Czyz [Fri, 24 Feb 2023 00:06:25 +0000 (18:06 -0600)]
Test onion message replies

11 months agoSplit TestCustomMessage into Request and Response
Jeffrey Czyz [Thu, 23 Feb 2023 22:54:58 +0000 (16:54 -0600)]
Split TestCustomMessage into Request and Response

This will allow for testing onion message replies.

11 months agoRemove unnecessary Sized bound
Jeffrey Czyz [Thu, 8 Jun 2023 19:30:38 +0000 (14:30 -0500)]
Remove unnecessary Sized bound

11 months agoSupport onion message replies in OnionMessenger
Jeffrey Czyz [Sun, 19 Feb 2023 01:29:14 +0000 (19:29 -0600)]
Support onion message replies in OnionMessenger

Modify onion message handlers to return an optional response message for
OnionMessenger to reply with.

11 months agoMessageRouter trait for OnionMessenger
Jeffrey Czyz [Thu, 23 Feb 2023 04:22:42 +0000 (22:22 -0600)]
MessageRouter trait for OnionMessenger

Add a trait for finding routes for onion messages and parameterize
OnionMessenger with it. This allows OnionMessenger to reply to messages
that it handles via one of its handlers (e.g., OffersMessageHandler).

11 months agoAdd OnionMessagePath wrapper struct
Jeffrey Czyz [Thu, 25 May 2023 20:02:10 +0000 (15:02 -0500)]
Add OnionMessagePath wrapper struct

To avoid confusion in the upcoming MessageRouter trait, introduce an
OnionMessagePath struct that wraps the intermediate nodes and the
destination. Use this in OnionMessenger::send_onion_message.

11 months agoOffersMessageHandler trait for OnionMessenger
Jeffrey Czyz [Wed, 15 Feb 2023 22:10:59 +0000 (16:10 -0600)]
OffersMessageHandler trait for OnionMessenger

Add a trait for handling BOLT 12 Offers messages to OnionMessenger and a
skeleton implementation of it for ChannelManager. This allows users to
either provide their own custom handling Offers messages or rely on a
version provided by LDK using stateless verification.

11 months agoAvoid an unnecessary unwrap
Jeffrey Czyz [Thu, 18 May 2023 18:15:00 +0000 (13:15 -0500)]
Avoid an unnecessary unwrap

11 months agoOnion message payload for BOLT 12 Offers
Jeffrey Czyz [Tue, 14 Feb 2023 23:41:18 +0000 (17:41 -0600)]
Onion message payload for BOLT 12 Offers

BOLT 12 Offers makes use of onion messages to request and respond with
invoices. Add these types and an error type to OnionMessageContents
along with the necessary parsing and encoding.

11 months agoPass logger to onion payload decoder
Jeffrey Czyz [Fri, 2 Jun 2023 13:08:59 +0000 (08:08 -0500)]
Pass logger to onion payload decoder

In an upcoming commit, messages for BOLT 12 offers are read from the
onion payload. Passing a logger allows for logging semantic errors when
parsing the messages.

11 months agoAdd InvoiceError message
Jeffrey Czyz [Thu, 18 May 2023 22:08:46 +0000 (17:08 -0500)]
Add InvoiceError message

If an InvoiceRequest or an Invoice delivered via an onion message cannot
be handled, the recipient should reply with an InvoiceError if a reply
path was given. Define the message and conversion from SemanticError.

11 months agoSupport WithoutLength for UntrustedString
Jeffrey Czyz [Mon, 5 Jun 2023 20:55:13 +0000 (15:55 -0500)]
Support WithoutLength for UntrustedString

11 months agoMerge pull request #2353 from TheBlueMatt/2023-06-fix-msrv-build
Matt Corallo [Mon, 12 Jun 2023 20:50:53 +0000 (20:50 +0000)]
Merge pull request #2353 from TheBlueMatt/2023-06-fix-msrv-build

11 months agoFix build on supported platforms due to `log` breakage 2023-06-fix-msrv-build
Matt Corallo [Mon, 12 Jun 2023 18:37:17 +0000 (18:37 +0000)]
Fix build on supported platforms due to `log` breakage

The `log` crate decided to break support for rustc 1.48 (Debian
bullseye) the day the next release of Debian comes out, obviously
before anyone has had a chance to upgrade to the new Debian
bookworm (at https://github.com/rust-lang/log/pull/543). Thus, we
have to manually pin it back to the previous release.

Sadly, the `log` crate is a transitive dependency of `tokio` until
0.20, which requires rustc 1.49. Luckily at least we won't have to
deal with this again, as `log` won't be a dependency of ours
anymore soon.

11 months agoMerge pull request #2156 from alecchendev/2023-04-mpp-keysend
Matt Corallo [Sat, 10 Jun 2023 19:48:54 +0000 (19:48 +0000)]
Merge pull request #2156 from alecchendev/2023-04-mpp-keysend

Support MPP Keysend

11 months agoAdd test for duplicate keysend payment
Alec Chen [Mon, 22 May 2023 20:20:02 +0000 (15:20 -0500)]
Add test for duplicate keysend payment

The logic has been changed around duplicate keysend payments such that
it's no longer explicitly clear that we reject duplicate keysend
payments now that we handle receiving multi-part keysends. This test
catches that. Note that this also tests that we reject MPP keysends when
our config states we should, and that we reject MPP keysends without
payemnt secrets when our config states we support MPP keysends.

11 months agoSupport receiving MPP keysend
Alec Chen [Wed, 5 Apr 2023 22:45:41 +0000 (17:45 -0500)]
Support receiving MPP keysend

This commit refactors a significant portion of the receive validation in
`ChannelManager::process_pending_htlc_forwards` now that we repurpose
previous MPP validation logic to accomodate keysends. This also removes
a previous restriction on claiming, as well as tests sending and
receiving MPP keysends.

11 months agoTrack MPP data while receiving keysends
Alec Chen [Tue, 2 May 2023 04:05:43 +0000 (23:05 -0500)]
Track MPP data while receiving keysends

This commit adds the field `payment_data: FinalOnionHopData` to
`ReceiveKeysend` which will allow us to check for payment secrets and
total amounts which is needed to support receiving MPP keysends. This
field is non-backwards compatible since we wouldn't be able to handle
an MPP keysend properly if we were to downgrade to a prior version.

We also no longer reject keysends with payment secrets if we support MPP
keysend.

11 months agoHelp users support sending MPP keysend
Alec Chen [Mon, 8 May 2023 22:51:19 +0000 (17:51 -0500)]
Help users support sending MPP keysend

When routing a keysend payment, the user may want to signal to the
router whether to find multi-path routes in the
`PaymentParameters::for_keysend` helper, without going through manual
construction. Since some implementations do not support MPP keysend, we
have the user make the choice here rather than making it the default.

Some implementations will reject keysend payments with payment secrets,
so this commit also adds docs to `RecipientOnionFields` to communicate
this to the user.

11 months agoMerge pull request #2334 from jkczyz/2023-06-bolt12-test-vectors
Matt Corallo [Thu, 8 Jun 2023 18:51:05 +0000 (18:51 +0000)]
Merge pull request #2334 from jkczyz/2023-06-bolt12-test-vectors

Update BOLT 12 test vectors

11 months agoMerge pull request #2333 from benthecarman/chan-mon-bal-helper
Wilmer Paulino [Thu, 8 Jun 2023 01:06:01 +0000 (18:06 -0700)]
Merge pull request #2333 from benthecarman/chan-mon-bal-helper

Add helper for getting claimable balance

11 months agoMerge pull request #2342 from vladimirfomene/2023-06-use-untrustedstring-in-error...
Matt Corallo [Wed, 7 Jun 2023 23:06:15 +0000 (23:06 +0000)]
Merge pull request #2342 from vladimirfomene/2023-06-use-untrustedstring-in-error-logs

Use PrintableString for displaying errors in PeerManager

11 months agoInclude signature check in BOLT 12 signature test
Jeffrey Czyz [Fri, 2 Jun 2023 19:46:00 +0000 (14:46 -0500)]
Include signature check in BOLT 12 signature test

The BOLT 12 test vectors had inadvertently left out a signature, but it
has since been added. Include a signature check in the corresponding
test for completeness.

11 months agoUpdate BOLT 12 test vectors
Jeffrey Czyz [Fri, 2 Jun 2023 19:36:38 +0000 (14:36 -0500)]
Update BOLT 12 test vectors

The previous test vectors contained recurrences and older TLV types, and
therefore couldn't be parsed. Update the tests with the latest test
vectors from the spec and stop ignoring the tests.

11 months agoRemove custom blinded path test vector
Jeffrey Czyz [Fri, 2 Jun 2023 19:21:35 +0000 (14:21 -0500)]
Remove custom blinded path test vector

These were added to help debug an encoding issue. However, the encoding
code was moved to the blinded_path module. Additionally, the test vector
used an old TLV encoding.

11 months agoAdd helper for getting claimable balance
benthecarman [Fri, 2 Jun 2023 19:39:16 +0000 (14:39 -0500)]
Add helper for getting claimable balance

It is annoying to have to match across all the enums of `Balance` to
just pull out the `claimable_amount_satoshis` value. This helper makes
it easier if you just want to amount.

11 months agoUse PrintableString for displaying errors in PeerManager
Vladimir Fomene [Wed, 7 Jun 2023 04:48:28 +0000 (07:48 +0300)]
Use PrintableString for displaying errors in PeerManager

We currently just print "with non-ASCII error message"
to log when we see non-ASCII chars, but should instead
use our fancy PrintableString type to display the
untrusted string and ignore control chars.

11 months agoMerge pull request #2312 from TheBlueMatt/2023-05-next-htlc-min-max
Matt Corallo [Wed, 7 Jun 2023 17:03:01 +0000 (17:03 +0000)]
Merge pull request #2312 from TheBlueMatt/2023-05-next-htlc-min-max

Avoid generating unpayable routes due to balance restrictions

11 months agoMerge pull request #2305 from valentinewallace/2023-05-respect-hint-maxhtlc
valentinewallace [Wed, 7 Jun 2023 13:02:26 +0000 (15:02 +0200)]
Merge pull request #2305 from valentinewallace/2023-05-respect-hint-maxhtlc

Respect route hint `max_htlc` in pathfinding

11 months agoMerge pull request #2330 from wvanlint/partial_config_updates
Matt Corallo [Wed, 7 Jun 2023 01:02:48 +0000 (01:02 +0000)]
Merge pull request #2330 from wvanlint/partial_config_updates

Support atomic partial updates to ChannelConfig

11 months agoSlightly improve docs on `next_*_commit_tx_fee_msat` 2023-05-next-htlc-min-max
Matt Corallo [Mon, 29 May 2023 18:50:35 +0000 (18:50 +0000)]
Slightly improve docs on `next_*_commit_tx_fee_msat`

11 months agoReplace `send_htlc` amount checking with available balances
Matt Corallo [Wed, 17 May 2023 01:33:42 +0000 (01:33 +0000)]
Replace `send_htlc` amount checking with available balances

Now that the `get_available_balances` min/max bounds are exact, we
can stop doing all the explicit checks in `send_htlc` entirely,
instead comparing against the `get_available_balances` bounds and
failing if the amount is out of those bounds.

This breaks support for sending amounts below the dust limit if
there is some amount of dust exposure remaining before we hit our
cap, however we will no longer generate such routes anyway.

11 months agoEnsure a 1:1 mapping of value sendable to send success in fuzzing
Matt Corallo [Wed, 17 May 2023 00:56:22 +0000 (00:56 +0000)]
Ensure a 1:1 mapping of value sendable to send success in fuzzing

Now that the value available to send is expected to match the
success or failure of sending exactly, we should assert this in the
`chanmon_consistency` fuzzer.

In the next commit we'll actually rip the checks out of `send_htlc`
which will make this a somewhat less useful test, however fuzzing
on this specific commit can help to reveal bugs.

11 months agoConsider dust exposure when assembling a route
Matt Corallo [Tue, 16 May 2023 05:00:01 +0000 (05:00 +0000)]
Consider dust exposure when assembling a route

When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we consider how much adding one additional (dust) HTLC would
impact our total dust exposure, setting the new next-HTLC-minimum
field to require HTLCs be non-dust if required or set our next-HTLC
maximum if we cannot send a dust HTLC but do have some additional
exposure remaining.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.

Fixes #2252.

11 months agoAdd a next-outbound-HTLC minimum field to chan details and use it
Matt Corallo [Tue, 16 May 2023 20:01:08 +0000 (20:01 +0000)]
Add a next-outbound-HTLC minimum field to chan details and use it

In the coming commits, in order to ensure all routes we generate
are usable, we'll start calculating the next-HTLC minimum for our
channels and using it in the router. Here we set this up by adding
an always-0 field for it in `ChannelDetails` and use it when
routing.

11 months agoConsider counterparty commitment tx fees when assembling a route
Matt Corallo [Tue, 16 May 2023 03:26:21 +0000 (03:26 +0000)]
Consider counterparty commitment tx fees when assembling a route

When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we consider whether one additional HTLC's commitment tx fees
would result in the counterparty's commitment tx fees being greater
than the reserve we've picked for them and, if so, limit our next
HTLC value to only include dust HTLCs.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.

This, and the previous few commits, fixes #1126.

11 months agoSupport atomic partial updates to ChannelConfig
Willem Van Lint [Thu, 1 Jun 2023 19:24:42 +0000 (15:24 -0400)]
Support atomic partial updates to ChannelConfig

11 months agoMerge pull request #2340 from TheBlueMatt/2023-06-fix-docs
valentinewallace [Tue, 6 Jun 2023 14:41:22 +0000 (16:41 +0200)]
Merge pull request #2340 from TheBlueMatt/2023-06-fix-docs

Remove spurious docs which imply you cannot retry a failed payment

11 months agoAccount for used liquidity in first hops when processing route hints
Valentine Wallace [Thu, 18 May 2023 22:49:00 +0000 (18:49 -0400)]
Account for used liquidity in first hops when processing route hints

.. in get_route.

11 months agoAbide by route hint max_htlc in pathfinding
Valentine Wallace [Wed, 17 May 2023 22:28:06 +0000 (18:28 -0400)]
Abide by route hint max_htlc in pathfinding

11 months agoRemove spurious double comma in documentation 2023-06-fix-docs
Matt Corallo [Tue, 6 Jun 2023 00:44:06 +0000 (00:44 +0000)]
Remove spurious double comma in documentation

11 months agoRemove spurious docs which imply you cannot retry a failed payment
Matt Corallo [Mon, 5 Jun 2023 18:21:19 +0000 (18:21 +0000)]
Remove spurious docs which imply you cannot retry a failed payment

If a payment (fully) fails, users are free to retry it, its only
once a payment succeeds that a user must never retry it.

11 months agoMerge pull request #2290 from upjohnc/2240_replace_vectors_with_iterators
Jeffrey Czyz [Mon, 5 Jun 2023 18:43:46 +0000 (13:43 -0500)]
Merge pull request #2290 from upjohnc/2240_replace_vectors_with_iterators

Set return type to Iterator for functions in file: `lightning-invoice/src/utils.rs` : issue #2240

11 months agoMerge pull request #2329 from dunxen/2023-05-initgenesischeck
Matt Corallo [Mon, 5 Jun 2023 18:14:17 +0000 (18:14 +0000)]
Merge pull request #2329 from dunxen/2023-05-initgenesischeck

Add support for `networks` field in `Init` message

11 months agoSend and handle `networks` field in `Init` messages
Duncan Dean [Thu, 1 Jun 2023 10:40:57 +0000 (12:40 +0200)]
Send and handle `networks` field in `Init` messages

If the `networks` field is present in a received `Init` message, then
we need to make sure our genesis chain hash matches one of those, otherwise
we should disconnect the peer.

We now also always send our genesis chain hash in `Init` messages to
our peers.

11 months agoAdd `networks` TLV to `Init`'s TLV stream
Duncan Dean [Thu, 1 Jun 2023 08:23:55 +0000 (10:23 +0200)]
Add `networks` TLV to `Init`'s TLV stream

This was a fairly old introduction to the spec to allow nodes to indicate
to their peers what chains they are interested in (i.e. will open channels
and gossip for).

We don't do any of the handling of this message in this commit and leave
that to the very next commit, so the behaviour is effectively the same
(ignore networks preference).

11 months agoMerge pull request #2332 from danielgranhao/fix/wrong-docs-link-channel-manager-send...
Jeffrey Czyz [Fri, 2 Jun 2023 20:47:51 +0000 (15:47 -0500)]
Merge pull request #2332 from danielgranhao/fix/wrong-docs-link-channel-manager-send-payment

Fix wrong link in `ChannelManager::send_payment()` docs

11 months agoRemove duplicate BOLT 12 test vector
Jeffrey Czyz [Fri, 2 Jun 2023 19:20:30 +0000 (14:20 -0500)]
Remove duplicate BOLT 12 test vector

11 months agoFix wrong link in `ChannelManager::send_payment()` docs
Daniel Granhão [Fri, 2 Jun 2023 16:29:52 +0000 (17:29 +0100)]
Fix wrong link in `ChannelManager::send_payment()` docs

11 months agoMerge pull request #2328 from benthecarman/partial-eq-in-mem-signer
Matt Corallo [Thu, 1 Jun 2023 19:51:24 +0000 (19:51 +0000)]
Merge pull request #2328 from benthecarman/partial-eq-in-mem-signer

Impl PartialEq and Debug for InMemorySigner

11 months agoRefactor lightning-invoice/src/utils.rs to yield iterators
Chad Upjohn [Tue, 30 May 2023 21:33:03 +0000 (16:33 -0500)]
Refactor lightning-invoice/src/utils.rs to yield iterators

- two functions refatored: `select_phantom_hints`, `sort_and_filter_channels`

11 months agoImpl PartialEq and Debug for InMemorySigner
benthecarman [Wed, 31 May 2023 22:47:54 +0000 (17:47 -0500)]
Impl PartialEq and Debug for InMemorySigner

These are needed for being able to compare a
ChannelMonitor<InMemorySigner> and are just nice to haves for
developers.

11 months agoMerge pull request #2167 from TheBlueMatt/2023-04-monitor-e-monitor-prep
Matt Corallo [Wed, 31 May 2023 22:48:34 +0000 (22:48 +0000)]
Merge pull request #2167 from TheBlueMatt/2023-04-monitor-e-monitor-prep

Add infra to block ChannelMonitorUpdates on forwarded claims

11 months agoMerge pull request #2324 from dunxen/2023-05-rgscheckgenesishash
Matt Corallo [Wed, 31 May 2023 19:21:10 +0000 (19:21 +0000)]
Merge pull request #2324 from dunxen/2023-05-rgscheckgenesishash

Fail RGS data processing early if there is a chain hash mismatch

11 months agoAdding rotate_through_iterators for select_phantom_hints refactor
Chad Upjohn [Tue, 30 May 2023 21:28:33 +0000 (16:28 -0500)]
Adding rotate_through_iterators for select_phantom_hints refactor

- adding function to allow for select_phantom_hints to yield an iterator

11 months agoAdd infra to block `ChannelMonitorUpdate`s on forwarded claims 2023-04-monitor-e-monitor-prep
Matt Corallo [Fri, 7 Apr 2023 00:31:39 +0000 (00:31 +0000)]
Add infra to block `ChannelMonitorUpdate`s on forwarded claims

When we forward a payment and receive an `update_fulfill_htlc`
message from the downstream channel, we immediately claim the HTLC
on the upstream channel, before even doing a `commitment_signed`
dance on the downstream channel. This implies that our
`ChannelMonitorUpdate`s "go out" in the right order - first we
ensure we'll get our money by writing the preimage down, then we
write the update that resolves giving money on the downstream node.

This is safe as long as `ChannelMonitorUpdate`s complete in the
order in which they are generated, but of course looking forward we
want to support asynchronous updates, which may complete in any
order.

Here we add infrastructure to handle downstream
`ChannelMonitorUpdate`s which are blocked on an upstream
preimage-containing one. We don't yet actually do the blocking which
will come in a future commit.

11 months agoReapply pending `ChannelMonitorUpdate`s on startup
Matt Corallo [Tue, 4 Apr 2023 21:45:37 +0000 (21:45 +0000)]
Reapply pending `ChannelMonitorUpdate`s on startup

If a `ChannelMonitorUpdate` was created and given to the user but
left uncompleted when the `ChannelManager` is persisted prior to a
restart, the user likely lost the `ChannelMonitorUpdate`(s). Thus,
we need to replay them for the user, which we do here using the
new `BackgroundEvent::MonitorUpdateRegeneratedOnStartup` variant.

11 months agoProcess background events when taking the total_consistency_lock
Matt Corallo [Thu, 6 Apr 2023 19:56:01 +0000 (19:56 +0000)]
Process background events when taking the total_consistency_lock

When we generated a `ChannelMonitorUpdate` during `ChannelManager`
deserialization, we must ensure that it gets processed before any
other `ChannelMonitorUpdate`s. The obvious hook for this is when
taking the `total_consistency_lock`, which makes it unlikely we'll
regress by forgetting this.

Here we add that call in the `PersistenceNotifierGuard`, with a
test-only atomic bool to test that this criteria is met.

11 months agoHandle `BackgroundEvent`s replaying non-closing monitor updates
Matt Corallo [Wed, 10 May 2023 05:39:26 +0000 (05:39 +0000)]
Handle `BackgroundEvent`s replaying non-closing monitor updates

`BackgroundEvent` was used to store `ChannelMonitorUpdate`s which
result in a channel force-close, avoiding relying on
`ChannelMonitor`s having been loaded while `ChannelManager`
block-connection methods are called during startup.

In the coming commit(s) we'll also generate non-channel-closing
`ChannelMonitorUpdate`s during startup, which will need to be
replayed prior to any other `ChannelMonitorUpdate`s generated from
normal operation.

In the next commit we'll handle that by handling `BackgroundEvent`s
immediately after locking the `total_consistency_lock`.

11 months agoMerge pull request #2293 from wpaulino/disconnect-peers-timer-tick
Matt Corallo [Tue, 30 May 2023 18:30:49 +0000 (18:30 +0000)]
Merge pull request #2293 from wpaulino/disconnect-peers-timer-tick

Disconnect peers on timer ticks to unblock channel state machine

11 months agoMake `AChannelManager` trait slightly more generic and always on
Matt Corallo [Wed, 10 May 2023 17:15:29 +0000 (17:15 +0000)]
Make `AChannelManager` trait slightly more generic and always on

Rather than letting `AChannelManager` be bounded by all traits
being `Sized` we make them explicitly `?Sized`. We also make the
trait no longer test-only as it will be used in a coming commit.

11 months agoReturn the counterparty node_id as a part of a force-shutdown res
Matt Corallo [Wed, 10 May 2023 00:45:08 +0000 (00:45 +0000)]
Return the counterparty node_id as a part of a force-shutdown res

In the coming commits we'll need the counterparty node_id when
handling a background monitor update as we may need to resume
normal channel operation as a result. Thus, we go ahead and pipe it
through from the shutdown end, as it makes the codepaths
consistent.

Sadly, the monitor-originated shutdown case doesn't allow for a
required counterparty node_id as some versions of LDK didn't have
it present in the ChannelMonitor.

11 months agoMove the `ShutdownResult` type alias to `channel.rs`
Matt Corallo [Wed, 24 May 2023 03:45:30 +0000 (03:45 +0000)]
Move the `ShutdownResult` type alias to `channel.rs`

This allows us to make the `force_shutdown` definition less verbose

11 months agoFix `held_by_thread` in `no-std` to return instead of panicing
Matt Corallo [Tue, 30 May 2023 18:11:47 +0000 (18:11 +0000)]
Fix `held_by_thread` in `no-std` to return instead of panicing

Our `no-std` locks simply panic if a lock cannot be taken as there
should be no lock contention in a single-threaded environment.
However, the `held_by_thread` debug methods were delegating to the
lock methods which resulted in a panic when asserting that a lock
*is* held by the current thread.

Instead, they are updated here to call the relevant `RefCell`
testing methods.

12 months agoMerge pull request #2323 from ariard/2023-05-remove-ariard-pgp-key
Matt Corallo [Mon, 29 May 2023 22:18:42 +0000 (22:18 +0000)]
Merge pull request #2323 from ariard/2023-05-remove-ariard-pgp-key

Remove ariard key from the security team

12 months agoFail RGS data processing early if there is a chain hash mismatch
Duncan Dean [Mon, 29 May 2023 12:43:05 +0000 (14:43 +0200)]
Fail RGS data processing early if there is a chain hash mismatch

No point in doing any extra processing if we don't even have a match
for the chain hash.

12 months agoRemove ariard key from the security team
Antoine Riard [Sun, 28 May 2023 19:58:06 +0000 (20:58 +0100)]
Remove ariard key from the security team

12 months agoAllow user to opt-in to accepting MPP keysend
Alec Chen [Thu, 20 Apr 2023 21:00:47 +0000 (16:00 -0500)]
Allow user to opt-in to accepting MPP keysend

To support receiving MPP keysends, we will add a new non-backward
compatible field to `PendingHTLCRouting::ReceiveKeysend`, which will
break deserialization of `ChannelManager` on downgrades, so we allow the
user choose whether they want to do this. Note that this commit only
adds the config flag, while full MPP support is added in later commits.