rust-lightning
16 months agoNote that abandon_payment does not persist the state update in docs 2022-12-abandon-crash-reset
Matt Corallo [Thu, 8 Dec 2022 00:33:15 +0000 (00:33 +0000)]
Note that abandon_payment does not persist the state update in docs

If a user calls `abandon_payment`, then restarts without freshly
persisting the `ChannelManager`, the payment will still be pending
on restart. This was unclear from the docs (and the docs seemed to
imply otherwise). Because this doesn't materially impact the
usability of `abandon_payment` (users shouldn't be called
`retry_payment` on an abandoned one anyway), we simply document it.

Fixes #1804.

16 months agoMerge pull request #1863 from TheBlueMatt/2022-11-holding-cell-batch-update
Matt Corallo [Wed, 7 Dec 2022 17:52:04 +0000 (17:52 +0000)]
Merge pull request #1863 from TheBlueMatt/2022-11-holding-cell-batch-update

Lean on the holding cell when batch-forwarding/failing HTLCs

16 months agoMerge pull request #1825 from wpaulino/anchors-bump-htlc-resolution-event
Matt Corallo [Wed, 7 Dec 2022 05:51:27 +0000 (05:51 +0000)]
Merge pull request #1825 from wpaulino/anchors-bump-htlc-resolution-event

Introduce new BumpTransactionEvent variant HTLCResolution

16 months agoExtend BaseSign with HTLC output signing support for external claims
Wilmer Paulino [Wed, 30 Nov 2022 22:05:02 +0000 (14:05 -0800)]
Extend BaseSign with HTLC output signing support for external claims

16 months agoYield BumpHTLCResolution events
Wilmer Paulino [Wed, 31 Aug 2022 19:03:35 +0000 (12:03 -0700)]
Yield BumpHTLCResolution events

16 months agoExpose HTLC transaction construction helpers
Wilmer Paulino [Wed, 30 Nov 2022 22:03:45 +0000 (14:03 -0800)]
Expose HTLC transaction construction helpers

16 months agoRename set_equality within update_claims_view_from_matched_txn
Wilmer Paulino [Tue, 22 Nov 2022 01:22:06 +0000 (17:22 -0800)]
Rename set_equality within update_claims_view_from_matched_txn

16 months agoGenerate ClaimEvent for HolderHTLCOutput inputs from anchor channels
Wilmer Paulino [Wed, 30 Nov 2022 22:03:26 +0000 (14:03 -0800)]
Generate ClaimEvent for HolderHTLCOutput inputs from anchor channels

16 months agoIntroduce internal package ID to track pending claims
Wilmer Paulino [Mon, 28 Nov 2022 15:47:44 +0000 (07:47 -0800)]
Introduce internal package ID to track pending claims

Now that our txids will no longer be stable for package claims that
require external funds to be allocated, we transition to a 32-byte array
identifier to remain compatible with them.

16 months agoSupport HolderHTLCOutput inputs from anchor channels
Wilmer Paulino [Wed, 31 Aug 2022 18:56:59 +0000 (11:56 -0700)]
Support HolderHTLCOutput inputs from anchor channels

16 months agoSpecify amount units in HolderHTLCOutput
Wilmer Paulino [Wed, 13 Jul 2022 17:27:45 +0000 (10:27 -0700)]
Specify amount units in HolderHTLCOutput

This is only a name change, there is no change in behavior.

16 months agoUpdate HTLC transaction detection from revoked counterparty commitments
Wilmer Paulino [Tue, 22 Nov 2022 01:11:09 +0000 (17:11 -0800)]
Update HTLC transaction detection from revoked counterparty commitments

Previously, this method assumed that all HTLC transactions have 1 input
and 1 output, with the sole input having a witness of 5 elements. This
will no longer be the case for HTLC transactions on channels with
anchors outputs since additional inputs and outputs can be attached to
them to allow fee bumping.

16 months agoTrack HTLC resolving transaction to determine input index
Wilmer Paulino [Thu, 25 Aug 2022 20:09:29 +0000 (13:09 -0700)]
Track HTLC resolving transaction to determine input index

16 months agoMerge pull request #1895 from TheBlueMatt/2022-12-fix-missing-data
Matt Corallo [Tue, 6 Dec 2022 22:46:04 +0000 (22:46 +0000)]
Merge pull request #1895 from TheBlueMatt/2022-12-fix-missing-data

Fix some onion errors and assert their length is correct

16 months agoCorrectly handle any `UPDATE` errors to phandom invoices 2022-12-fix-missing-data
Matt Corallo [Fri, 2 Dec 2022 21:12:47 +0000 (21:12 +0000)]
Correctly handle any `UPDATE` errors to phandom invoices

If we try to send any onion error with the `UPDATE` flag in
response to a phantom receipt, we should always swap it for
something generic that doesn't require a `channel_update` in it.
Here we use `temporary_node_failure`.

Test provided by Valentine Wallace <vwallace@protonmail.com>

16 months agoReplace `build_first_hop_failure_packet` with `HTLCFailReason`
Matt Corallo [Thu, 1 Dec 2022 23:30:04 +0000 (23:30 +0000)]
Replace `build_first_hop_failure_packet` with `HTLCFailReason`

This ensures we always hit our new debug assertions while building
failure packets in the immediately-fail pipeline while processing
an inbound HTLC.

16 months agoUse `temporary_node_failure` for a phantom HTLC with bogus CLTV
Matt Corallo [Thu, 1 Dec 2022 23:39:28 +0000 (23:39 +0000)]
Use `temporary_node_failure` for a phantom HTLC with bogus CLTV

When we receive a phantom HTLC with a bogus/modified CLTV, we
should fail back with `incorrect_cltv_expiry`, but that requires a
`channel_update`, which we cannot generate for a phantom HTLC which
has no corresponding channel. Thus, instead, we have to fall back
to `incorrect_cltv_expiry`.

Fixes #1879

16 months agoAssert that all onion error messages are correct len in tests
Matt Corallo [Thu, 1 Dec 2022 20:31:52 +0000 (20:31 +0000)]
Assert that all onion error messages are correct len in tests

When we're constructing an HTLCFailReason, we should check that we
set the data to at least the correct length for the given failure
code, which we do here.

16 months agoCorrectly include the `sha256_hash_of_onion` field in BADONION errs
Matt Corallo [Thu, 1 Dec 2022 20:30:45 +0000 (20:30 +0000)]
Correctly include the `sha256_hash_of_onion` field in BADONION errs

The spec mandates that we copy the `sha256_hash_of_onion` field
from the `UpdateFailMalformedHTLC` message into the error message
we send back to the sender, however we simply ignored it. Here we
copy it into the message correctly.

16 months agoDrop the stale `final_expiry_too_soon` error code
Matt Corallo [Thu, 1 Dec 2022 20:25:33 +0000 (20:25 +0000)]
Drop the stale `final_expiry_too_soon` error code

This replaces `final_expiry_too_soon` with
`incorrect_or_unknown_payment` as was done in
https://github.com/lightning/bolts/pull/608. Note that the
rationale for this (that it may expose whether you are the final
recipient for the payment or not) does not currently apply to us -
we don't apply different final CLTV values to different payments.
However, we might in the future, and this will make us slightly
more consistent with other nodes.

16 months agoEncapsulate `HTLCFailReason` to not expose struct variants
Matt Corallo [Thu, 1 Dec 2022 19:28:32 +0000 (19:28 +0000)]
Encapsulate `HTLCFailReason` to not expose struct variants

Now that `HTLCFailReason` is opaque and in `onion_utils`, we should
encapsulate it so that `ChannelManager` can no longer directly
access its inner fields.

16 months agoMove `HTLCFailReason` to `onion_utils`
Matt Corallo [Thu, 1 Dec 2022 19:20:19 +0000 (19:20 +0000)]
Move `HTLCFailReason` to `onion_utils`

Now that it's entirely abstracted, there's no reason for
`HTLCFailReason` to be in `channelmanager`, it's really an
onion-level abstraction.

16 months agoMerge pull request #1902 from tnull/2022-12-payment-received-renaming-follow-up
Matt Corallo [Tue, 6 Dec 2022 19:07:09 +0000 (19:07 +0000)]
Merge pull request #1902 from tnull/2022-12-payment-received-renaming-follow-up

Also rename variables referring to `PaymentClaimable`

16 months agoCorrect confusing docs on `Channel` methods 2022-11-holding-cell-batch-update
Matt Corallo [Mon, 28 Nov 2022 23:51:55 +0000 (23:51 +0000)]
Correct confusing docs on `Channel` methods

The methods return `Ok(())` always, they just happen to never
return in the case of a duplicate claim if debug assertions are
enabled.

16 months agoLean on the holding cell for commitments when updating fees
Matt Corallo [Mon, 21 Nov 2022 01:13:52 +0000 (01:13 +0000)]
Lean on the holding cell for commitments when updating fees

Like the previous commit, here we update the update_fee+commit
logic to simply push the fee update into the holding cell and then
use the standard holding-cell-freeing codepaths to actually send
the commitment update. This removes a substantial amount of code,
reducing redundant codepaths and keeping channel state machine
logic in channel.rs.

16 months agoFree the holding cells during background timer ticks
Matt Corallo [Mon, 21 Nov 2022 01:22:51 +0000 (01:22 +0000)]
Free the holding cells during background timer ticks

We currently free the channel holding cells in
`get_and_clear_pending_msg_events`, blocking outbound messages
while we do so. This is fine, but may block the message pipeline
longer than we need to. In the next commit we'll push
timer-originating channel fee updates out through the holding cell
pipeline, leaning more on that freeing in the future.

Thus, to avoid a regression in message time, here we clear the
holding cell after processing all timer events. This also avoids
needing to change tests in the next commit.

16 months agoLean on the holding cell when batch-forwarding/failing HTLCs
Matt Corallo [Sat, 19 Nov 2022 00:00:28 +0000 (00:00 +0000)]
Lean on the holding cell when batch-forwarding/failing HTLCs

When we batch HTLC updates, we currently do the explicit queueing
plus the commitment generation in the `ChannelManager`. This is a
bit strange as its ultimately really a `Channel` responsibility to
generate commitments at the correct time, with the abstraction
leaking into `ChannelManager` with the `send_htlc` and
`get_update_fail_htlc` method docs having clear comments about
how `send_commitment` MUST be called prior to calling other
`Channel` methods.

Luckily `Channel` already has an update queue - the holding cell.
Thus, we can trivially rewrite the batch update logic as inserting
the desired updates into the holding cell and then asking all
channels to clear their holding cells.

16 months agoMerge pull request #1867 from wpaulino/remove-signer-persistence
Matt Corallo [Tue, 6 Dec 2022 18:13:49 +0000 (18:13 +0000)]
Merge pull request #1867 from wpaulino/remove-signer-persistence

Re-derive signers instead of persisting them

16 months agoRename variables referring to `PaymentClaimable`
Elias Rohrer [Tue, 6 Dec 2022 09:47:07 +0000 (10:47 +0100)]
Rename variables referring to `PaymentClaimable`

17 months agoMerge pull request #1857 from TheBlueMatt/2022-11-reload-htlc
Matt Corallo [Mon, 5 Dec 2022 22:54:08 +0000 (22:54 +0000)]
Merge pull request #1857 from TheBlueMatt/2022-11-reload-htlc

Fail HTLCs which were removed from a channel but not persisted

17 months agoFail HTLCs which were removed from a channel but not persisted 2022-11-reload-htlc
Matt Corallo [Wed, 16 Nov 2022 02:20:03 +0000 (02:20 +0000)]
Fail HTLCs which were removed from a channel but not persisted

When a channel is force-closed, if a `ChannelMonitor` update is
completed but a `ChannelManager` persist has not yet happened,
HTLCs which were removed in the latest (persisted) `ChannelMonitor`
update will not be failed even though they do not appear in the
commitment transaction which went on chain. This is because the
`ChannelManager` thinks the `ChannelMonitor` is responsible for
them (as it is stale), but the `ChannelMonitor` has no knowledge of
the HTLC at all (as it is not stale).

The fix for this is relatively simple - we need to check for this
specific case and fail back such HTLCs when deserializing a
`ChannelManager`

17 months agoAvoid attempting to forward to a closed chan on stale-data reload
Matt Corallo [Thu, 17 Nov 2022 05:55:45 +0000 (05:55 +0000)]
Avoid attempting to forward to a closed chan on stale-data reload

If, after forwarding a payment to our counterparty, we restart with
a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update was not persisted, we'll still
have the forwarded HTLC in the `forward_htlcs` map on start. This
will cause us to generate a (spurious) `PendingHTLCsForwardable`
event. However, when we go to forward said HTLC, we'll notice the
channel has been closed and leave it up to the `ChannelMontior` to
finalize the HTLC.

This is all fine today - we won't lose any funds, we'll just
generate an excess forwardable event and then fail to forward.
However, in the future when we allow for forward-time channel
changes this could break. Thus, its worth adding tests for this
behavior today, and, while we're at it, removing the spurious
forwardable HTLCs event.

17 months agoExpose the full set of outbound HTLCs from a `ChannelMonitor`
Matt Corallo [Tue, 15 Nov 2022 23:35:31 +0000 (23:35 +0000)]
Expose the full set of outbound HTLCs from a `ChannelMonitor`

This expands the outbound-HTLC-listing support in `ChannelMonitor`
to include not only the set of outbound HTLCs which have not yet
been resolved but to also include the full set of HTLCs which the
`ChannelMonitor` is currently able to to or has already finalized.

This will be used in the next commit to fail-back HTLCs which were
removed from a channel in the ChannelMonitor but not in a Channel.
Using the existing `get_pending_outbound_htlcs` for this purpose is
subtly broken - if the channel is already closed, an HTLC fail may
have completed on chain and is no longer "pending" to the monitor,
but the fail event is still in the monitor waiting to be handed
back to the `ChannelMonitor` when polled.

17 months agoRemove unnecessary byte_utils helpers
Wilmer Paulino [Thu, 1 Dec 2022 22:45:46 +0000 (14:45 -0800)]
Remove unnecessary byte_utils helpers

Now that to_be_bytes is available under our current MSRV of 1.41, we
can use it instead of our own version.

17 months agoDrop Clone requirement from Sign
Wilmer Paulino [Tue, 29 Nov 2022 17:06:31 +0000 (09:06 -0800)]
Drop Clone requirement from Sign

Now that we opt to always re-derive channel secrets whenever required,
we can drop the Clone requirement from Sign.

17 months agoAvoid use of OnlyReadsKeysInterface
Wilmer Paulino [Mon, 21 Nov 2022 21:34:22 +0000 (13:34 -0800)]
Avoid use of OnlyReadsKeysInterface

Since `ChannelMonitor`s will now re-derive signers rather than
persisting them, we can no longer use the OnlyReadsKeysInterface
concrete implementation.

17 months agoRe-derive signers upon deserializing OnchainTxHandler
Wilmer Paulino [Mon, 21 Nov 2022 20:49:05 +0000 (12:49 -0800)]
Re-derive signers upon deserializing OnchainTxHandler

Similar to the previous commit, we introduce a new serialization version
that doesn't store a monitor's signer. Since the monitor already knows
of a channel's `channel_keys_id`, there's no need to store any new data
to re-derive all private key material for said channel.

17 months agoRe-derive signers upon deserializing Channel
Wilmer Paulino [Mon, 21 Nov 2022 20:47:41 +0000 (12:47 -0800)]
Re-derive signers upon deserializing Channel

To do so, we introduce a new serialization version that doesn't store a
channel's signer, and instead stores its signer's `channel_keys_id`.
This is a unique identifier that can be provided to our `KeysInterface`
to re-derive all private key material for said channel.

We choose to not upgrade the minimum compatible serialization version
until a later time, which will also remove any signer serialization
logic on implementations of `KeysInterface` and `Sign`.

17 months agoRename KeysInterface ready_channel to provide_channel_parameters
Wilmer Paulino [Tue, 29 Nov 2022 17:05:47 +0000 (09:05 -0800)]
Rename KeysInterface ready_channel to provide_channel_parameters

Now that ready_channel is also called on startup upon deserializing
channels, we opt to rename it to a more indicative name.

We also derive `PartialEq` on ChannelTransactionParameters to allow
implementations to determine whether `provide_channel_parameters` calls
are idempotent after the channel parameters have already been provided.

17 months agoSplit KeysInterface::get_channel_signer into two
Wilmer Paulino [Mon, 21 Nov 2022 20:45:30 +0000 (12:45 -0800)]
Split KeysInterface::get_channel_signer into two

`get_channel_signer` previously had two different responsibilites:
generating unique `channel_keys_id` and using said ID to derive channel
keys. We decide to split it into two methods `generate_channel_keys_id`
and `derive_channel_signer`, such that we can use the latter to fulfill
our goal of re-deriving signers instead of persisting them. There's no
point in storing data that can be easily re-derived.

17 months agoMerge pull request #1891 from tnull/2022-12-rename-payment-events
Matt Corallo [Sun, 4 Dec 2022 19:31:52 +0000 (19:31 +0000)]
Merge pull request #1891 from tnull/2022-12-rename-payment-events

Rename `PaymentReceived` to `PaymentClaimable`

17 months agoUpdate docs and add pending changelog
Elias Rohrer [Sat, 3 Dec 2022 06:06:22 +0000 (07:06 +0100)]
Update docs and add pending changelog

17 months agoMerge pull request #1887 from TheBlueMatt/2022-11-definitely-valid
Matt Corallo [Sat, 3 Dec 2022 19:01:15 +0000 (19:01 +0000)]
Merge pull request #1887 from TheBlueMatt/2022-11-definitely-valid

Remove cryptographically unreachable error conditions

17 months agoMerge pull request #1893 from valentinewallace/2022-12-jit-forwards-followup
Matt Corallo [Thu, 1 Dec 2022 21:51:39 +0000 (21:51 +0000)]
Merge pull request #1893 from valentinewallace/2022-12-jit-forwards-followup

HTLC JIT channel interception followup + minor cleanups

17 months agoConstruct from-message `HTLCFailReason` via a constructor method
Matt Corallo [Thu, 1 Dec 2022 19:18:16 +0000 (19:18 +0000)]
Construct from-message `HTLCFailReason` via a constructor method

17 months agoFix `impl_writeable_tlv_based_enum` to not require `DecodeError`
Matt Corallo [Thu, 1 Dec 2022 19:14:43 +0000 (19:14 +0000)]
Fix `impl_writeable_tlv_based_enum` to not require `DecodeError`

`impl_writeable_tlv_based_enum` shouldn't be assuming that
`DecodeError` is in scope, which we address here.

17 months agoDecode `HTLCFailReason`s in a util method on the enum
Matt Corallo [Thu, 1 Dec 2022 19:08:53 +0000 (19:08 +0000)]
Decode `HTLCFailReason`s in a util method on the enum

17 months agoEncode HTLC failure packets in a util method on `HTLCFailReason`
Matt Corallo [Thu, 1 Dec 2022 18:56:17 +0000 (18:56 +0000)]
Encode HTLC failure packets in a util method on `HTLCFailReason`

17 months agoMerge pull request #1880 from tcharding/11-29-move-lock-outside-loop
Matt Corallo [Thu, 1 Dec 2022 18:03:35 +0000 (18:03 +0000)]
Merge pull request #1880 from tcharding/11-29-move-lock-outside-loop

Do not lock while looping `htlcs_to_fail`

17 months agoRename `PaymentReceived` to `PaymentClaimable`
Elias Rohrer [Thu, 1 Dec 2022 08:34:34 +0000 (09:34 +0100)]
Rename `PaymentReceived` to `PaymentClaimable`

17 months agoRename APIError::RouteError to ::InvalidRoute
Valentine Wallace [Thu, 1 Dec 2022 06:08:55 +0000 (01:08 -0500)]
Rename APIError::RouteError to ::InvalidRoute

Soon we're going to need to return an error when ChannelManager is unable to
find a route, so we'll need a way to distinguish between that and the user
supplying an invalid route.

17 months agoFix weird import format in persist
Valentine Wallace [Fri, 28 Oct 2022 15:26:40 +0000 (11:26 -0400)]
Fix weird import format in persist

17 months agoHTLC intercept test: swap hardcoded value for const
Valentine Wallace [Thu, 1 Dec 2022 05:16:31 +0000 (00:16 -0500)]
HTLC intercept test: swap hardcoded value for const

17 months agoTest for unknown HTLC intercept id error
Valentine Wallace [Thu, 1 Dec 2022 05:13:53 +0000 (00:13 -0500)]
Test for unknown HTLC intercept id error

17 months agoClean up HTLC intercept errors
Valentine Wallace [Thu, 1 Dec 2022 05:12:29 +0000 (00:12 -0500)]
Clean up HTLC intercept errors

ChannelUnavailable is a better fit for errors regarding unavailable channels
than APIMisuseError.

Also log bytes in errors as hex instead of decimal.

17 months agoMerge pull request #1862 from valentinewallace/2022-11-chanman-retries-prep
Matt Corallo [Thu, 1 Dec 2022 04:24:10 +0000 (04:24 +0000)]
Merge pull request #1862 from valentinewallace/2022-11-chanman-retries-prep

Prepare for Payment Retries in `ChannelManager`

17 months agoDo not lock while looping htlcs_to_fail
Tobin C. Harding [Tue, 29 Nov 2022 01:24:12 +0000 (12:24 +1100)]
Do not lock while looping htlcs_to_fail

Currently we loop over `htlcs_to_fail` locking `channel_state` for each
element only to call `get_htlc_inbound_temp_fail_err_and_data` with the
same inputs on each iteration. This is unnecessary, we can refactor and
call `get_htlc_inbound_temp_fail_err_and_data` outside of the loop.

17 months agoMake fail_htlc_backwards_internal borrow parameters
Tobin C. Harding [Tue, 29 Nov 2022 00:59:59 +0000 (11:59 +1100)]
Make fail_htlc_backwards_internal borrow parameters

Currently `fail_htlc_backwards_internal` takes ownership of its source
and reason parameters however they are not consumed so we can borrow them.

Includes refactoring to use local variables before the function call.

17 months agoAdd constructors to HTLCFailReason
Tobin C. Harding [Tue, 29 Nov 2022 00:41:14 +0000 (11:41 +1100)]
Add constructors to HTLCFailReason

We create `HTLCFailReason` inline in function calls in a bunch of places
in the `channelmanager` module, we can make the code more terse with no
loss of clarity by implementing a couple of constructor methods.

17 months agoMerge pull request #1835 from valentinewallace/2022-11-jit-chan-htlc-intercept
Matt Corallo [Thu, 1 Dec 2022 00:04:14 +0000 (00:04 +0000)]
Merge pull request #1835 from valentinewallace/2022-11-jit-chan-htlc-intercept

Intercept HTLC forwards for JIT channels

17 months agoRemove unreachable `Err` cases when constructing `TxCreationKeys` 2022-11-definitely-valid
Matt Corallo [Wed, 30 Nov 2022 22:43:29 +0000 (22:43 +0000)]
Remove unreachable `Err` cases when constructing `TxCreationKeys`

17 months agoRemove unreachable `Err` cases on `derive_*_revocation_key`
Matt Corallo [Wed, 30 Nov 2022 22:34:11 +0000 (22:34 +0000)]
Remove unreachable `Err` cases on `derive_*_revocation_key`

The `derive_{public,private}_revocation_key` methods hash the two
input keys and then multiply the two input keys by hashed values
before adding them together. Because addition can fail if the tweak
is the inverse of the secret key this method currently returns a
`Result`.

However, it is not cryptographically possible to reach the error
case - in order to create an issue, the point-multiplied-by-hash
values must be the inverse of each other, however each point
commits the SHA-256 hash of both keys together. Thus, because
changing either key changes the hashes (and the ultimate points
added together) in an unpredictable way, there should be no way to
construct such points.

17 months agoRemove unreachable `Err` cases on `derive_{public,private}_key`
Matt Corallo [Wed, 30 Nov 2022 22:21:24 +0000 (22:21 +0000)]
Remove unreachable `Err` cases on `derive_{public,private}_key`

The `derive_{public,private}_key` methods hash the two input keys
and then add them to the input public key. Because addition can
fail if the tweak is the inverse of the secret key this method
currently returns a `Result`.

However, it is not cryptographically possible to reach the error
case - in order to create an issue, the SHA-256 hash of the
`base_point` (and other data) must be the inverse of the
`base_point`('s secret key). Because changing the `base_point`
changes the hash in an unpredictable way, there should be no way to
construct such a `base_point`.

17 months agoMove DefaultRouter to router module
Valentine Wallace [Mon, 21 Nov 2022 22:07:44 +0000 (17:07 -0500)]
Move DefaultRouter to router module

17 months agoMove ScorerAccountingForInFlightHtlcs to router + make public
Valentine Wallace [Mon, 21 Nov 2022 20:51:28 +0000 (15:51 -0500)]
Move ScorerAccountingForInFlightHtlcs to router + make public

We move it to router instead of scoring because it pairs with the InFlightHtlcs
struct in router and is useful for custom Router trait implementations

17 months agoMerge pull request #1839 from ariard/2022-11-increase-visibility-helpers
Matt Corallo [Wed, 30 Nov 2022 18:56:15 +0000 (18:56 +0000)]
Merge pull request #1839 from ariard/2022-11-increase-visibility-helpers

Chan_utils helpers visibility relaxation

17 months agoDon't forward HTLC intercepts over unestablished channels
Valentine Wallace [Wed, 23 Nov 2022 00:15:56 +0000 (19:15 -0500)]
Don't forward HTLC intercepts over unestablished channels

17 months agoAutomatically fail intercepts back on timeout
Valentine Wallace [Mon, 14 Nov 2022 20:05:37 +0000 (15:05 -0500)]
Automatically fail intercepts back on timeout

17 months agoAdd config knob for forwarding intercept payments
Valentine Wallace [Mon, 14 Nov 2022 18:36:52 +0000 (13:36 -0500)]
Add config knob for forwarding intercept payments

17 months agoAllow failing back intercepted HTLCs
Valentine Wallace [Mon, 7 Nov 2022 16:16:49 +0000 (11:16 -0500)]
Allow failing back intercepted HTLCs

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoUtils for forwarding intercepted htlcs + getting intercept scids
Valentine Wallace [Sun, 6 Nov 2022 21:06:44 +0000 (16:06 -0500)]
Utils for forwarding intercepted htlcs + getting intercept scids

See ChannelManager::forward_intercepted_htlc and
ChannelManager::get_intercept_scid for details

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoGenerate HTLCIntercepted event upon interceptable forward
Valentine Wallace [Fri, 4 Nov 2022 20:23:47 +0000 (16:23 -0400)]
Generate HTLCIntercepted event upon interceptable forward

And store the pending intercepted HTLC in pending_intercepted_htlcs

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoAdd HTLCIntercepted event
Valentine Wallace [Fri, 4 Nov 2022 18:25:41 +0000 (14:25 -0400)]
Add HTLCIntercepted event

Used in upcoming commit(s) so users can intercept forwarded HTLCs

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoAdd fake scid namespace for intercepted HTLCs
Valentine Wallace [Fri, 4 Nov 2022 15:54:57 +0000 (11:54 -0400)]
Add fake scid namespace for intercepted HTLCs

This is useful for LSPs who wish to create a just-in-time channel for end users
receiving a lightning payment. These fake scids will be encoded into route
hints in end user invoices, and signal to LDK to create an event triggering the
JIT channel, after which the payment will be received.

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoPersist pending intercepted htlcs in ChannelManager
Valentine Wallace [Fri, 4 Nov 2022 17:01:25 +0000 (13:01 -0400)]
Persist pending intercepted htlcs in ChannelManager

No htlcs are intercepted yet, that will be added in upcoming commit(s)

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoMerge pull request #1885 from TheBlueMatt/2022-11-dumb-lookup
Matt Corallo [Wed, 30 Nov 2022 17:25:17 +0000 (17:25 +0000)]
Merge pull request #1885 from TheBlueMatt/2022-11-dumb-lookup

Drop useless SCID lookup in `claim_funds_from_hop`

17 months agoDrop unnecessary clone 2022-11-dumb-lookup
Matt Corallo [Mon, 21 Nov 2022 23:27:44 +0000 (23:27 +0000)]
Drop unnecessary clone

17 months agoDrop useless SCID lookup in `claim_funds_from_hop`
Matt Corallo [Wed, 30 Nov 2022 03:02:27 +0000 (03:02 +0000)]
Drop useless SCID lookup in `claim_funds_from_hop`

We have the channel_id available in `prev_hop` so there's no reason
to look it up by SCID.

17 months agoRemove get_p2wpkh_redeemscript in favor of lib helper
Antoine Riard [Fri, 11 Nov 2022 00:56:53 +0000 (19:56 -0500)]
Remove get_p2wpkh_redeemscript in favor of lib helper

17 months agoIncrease visibility of script helper
Antoine Riard [Thu, 10 Nov 2022 16:04:58 +0000 (11:04 -0500)]
Increase visibility of script helper

17 months agoIncrease visibility of protocol-level consts
Antoine Riard [Thu, 10 Nov 2022 16:01:20 +0000 (11:01 -0500)]
Increase visibility of protocol-level consts

17 months agoMerge pull request #1856 from tnull/2022-10-expose-channel-id
Matt Corallo [Tue, 29 Nov 2022 19:22:09 +0000 (19:22 +0000)]
Merge pull request #1856 from tnull/2022-10-expose-channel-id

Expose the channel via which we received a payment

17 months agoFix typo in ScorerAccountingForInFlightHtlcs
Valentine Wallace [Thu, 17 Nov 2022 02:29:10 +0000 (21:29 -0500)]
Fix typo in ScorerAccountingForInFlightHtlcs

17 months agoMove ScoringRouter methods to Router
Valentine Wallace [Wed, 16 Nov 2022 19:38:42 +0000 (14:38 -0500)]
Move ScoringRouter methods to Router

This helps us prepare to move all payment retries into ChannelManager, which is
needed for trampoline payments.

17 months agoExpose `confirmations` via `ChannelDetails`
Elias Rohrer [Thu, 17 Nov 2022 10:31:35 +0000 (11:31 +0100)]
Expose `confirmations` via `ChannelDetails`

We expose the current number of confirmations in `ChannelDetails`.

17 months agoExpose the channel via which we received a payment
Elias Rohrer [Tue, 25 Oct 2022 16:48:34 +0000 (18:48 +0200)]
Expose the channel via which we received a payment

We expose the `channel_id` and `user_channel_id` via which we received a
payment in the `PaymentReceived` event.

17 months agoMerge pull request #1766 from tee8z/event-node-received
Matt Corallo [Mon, 28 Nov 2022 17:32:23 +0000 (17:32 +0000)]
Merge pull request #1766 from tee8z/event-node-received

adds node_id to Event::Payment{Received, Claimed}

17 months agoMerge pull request #1874 from LeoDog896/patch-1
valentinewallace [Mon, 28 Nov 2022 15:39:17 +0000 (10:39 -0500)]
Merge pull request #1874 from LeoDog896/patch-1

Small grammar fixes to README.md

17 months agoadds 'receiver_node_id' to 'Event::Payment{Received,Claimed}'
Tee8z [Wed, 12 Oct 2022 18:11:21 +0000 (14:11 -0400)]
adds 'receiver_node_id' to 'Event::Payment{Received,Claimed}'

17 months agoSmall grammar fixes to README.md
Tristan F [Sat, 26 Nov 2022 20:32:57 +0000 (15:32 -0500)]
Small grammar fixes to README.md

17 months agoMerge pull request #1861 from TheBlueMatt/2022-11-tx-connection-idempotency
Matt Corallo [Fri, 25 Nov 2022 19:39:17 +0000 (19:39 +0000)]
Merge pull request #1861 from TheBlueMatt/2022-11-tx-connection-idempotency

Ensure transactions_confirmed is idempotent

17 months agoAdd additional testing in `montior_tests` for chain idempotency 2022-11-tx-connection-idempotency
Matt Corallo [Fri, 18 Nov 2022 19:02:02 +0000 (19:02 +0000)]
Add additional testing in `montior_tests` for chain idempotency

At the end of our `monitor_tests`, which test `ChannelMonitor`
`SpendableOutputs` and claimable `Balance`s, add new checks that
ensure that, if we're using the new
`ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we
can replay the full chain without getting redundant events or
`Balance`s.

17 months agoEnsure `transactions_confirmed` is idempotent
Matt Corallo [Fri, 18 Nov 2022 18:54:16 +0000 (18:54 +0000)]
Ensure `transactions_confirmed` is idempotent

In many complexity-reduced implementations of chain syncing using
esplora `transactions_confirmed` may be called redundantly for
transactions which were already confirmed. To ensure this is
idempotent we add two new `ConnectionStyle`s in our tests which
(a) call `transactions_confirmed` twice for each call, ensuring
simple idempotency is ensured and (b) call `transactions_confirmed`
once for each historical block every time we're connecting a new
block, ensuring we're fully idempotent even if every call is
repeated constantly.

In order to actually behave correctly this requires a simple
already-confirmed check in `ChannelMonitor`, which is included.

17 months agoMerge pull request #1828 from lightning-signer/2022-11-non-zero-fee-anchors
Matt Corallo [Tue, 22 Nov 2022 20:07:20 +0000 (20:07 +0000)]
Merge pull request #1828 from lightning-signer/2022-11-non-zero-fee-anchors

Re-add support for non-zero-fee-anchors to chan_utils

17 months agoMerge pull request #1866 from TheBlueMatt/2022-11-noisy-no-graph
valentinewallace [Tue, 22 Nov 2022 19:55:05 +0000 (14:55 -0500)]
Merge pull request #1866 from TheBlueMatt/2022-11-noisy-no-graph

Drop verbose log entries in BP when no network graph is provided

17 months agoDrop verbose log entries in BP when no network graph is provided 2022-11-noisy-no-graph
Matt Corallo [Mon, 21 Nov 2022 20:37:25 +0000 (20:37 +0000)]
Drop verbose log entries in BP when no network graph is provided

If no network graph is provided to the `BackgroundProcessor`, we
log every time the processor loop goes around (at least every
100ms, if not more) which fille up logs with useless indications
that we have no network graph.

17 months agoRe-add support for non-zero-fee-anchors to chan_utils and InMemorySigner
Devrandom [Thu, 3 Nov 2022 10:52:25 +0000 (11:52 +0100)]
Re-add support for non-zero-fee-anchors to chan_utils and InMemorySigner

17 months agoMerge pull request #1859 from TheBlueMatt/2022-11-rm-redundant-holding-cell-wipe
Matt Corallo [Tue, 22 Nov 2022 01:07:03 +0000 (01:07 +0000)]
Merge pull request #1859 from TheBlueMatt/2022-11-rm-redundant-holding-cell-wipe

Wait to free the holding cell during channel_reestablish handling

17 months agoMerge pull request #1772 from ViktorTigerstrom/2022-10-move-claimable-htlcs-to-sepera...
Matt Corallo [Tue, 22 Nov 2022 01:06:29 +0000 (01:06 +0000)]
Merge pull request #1772 from ViktorTigerstrom/2022-10-move-claimable-htlcs-to-seperate-lock

Move `claimable_htlcs` to separate lock

17 months agoDon't hold `per_peer_state` lock during chain monitor update
Viktor Tigerström [Mon, 7 Nov 2022 00:11:44 +0000 (01:11 +0100)]
Don't hold `per_peer_state` lock during chain monitor update

For Windows build only, the
`TestPersister::chain_sync_monitor_persistences` lock has a lock order
before the `ChannelManager::per_peer_state` lock. This fix ensures that
the `per_peer_state` lock isn't held before the
`TestPersister::chain_sync_monitor_persistences` lock is acquired.