rust-lightning
17 months agoAwait `Future::poll` `Complete`d before unsetting notify-required 2022-11-fix-broken-futures-----again
Matt Corallo [Tue, 15 Nov 2022 00:29:10 +0000 (00:29 +0000)]
Await `Future::poll` `Complete`d before unsetting notify-required

When we mark a future as complete, if the user is using the
`std::future::Future` impl to get notified, we shouldn't just
assume we have completed the `Future` when we call the `Waker`. A
`Future` may have been `drop`'d at that point (or may not be
`poll`'d again) even though we wake the `Waker`.

Because we now have a `callbacks_made` flag, we can fix this rather
trivially, simply not setting the flag until the `Future` is
`poll`'d `Complete`.

17 months agoWipe `Notifier` `FutureState` when returning from a waiter.
Matt Corallo [Tue, 15 Nov 2022 00:24:25 +0000 (00:24 +0000)]
Wipe `Notifier` `FutureState` when returning from a waiter.

When we return from one of the wait functions in `Notifier`, we
should also ensure that the next `Future` doesn't start in the
`complete` state, as we have already notified the user, as far as
we're concerned.

This is technically a regression from the previous commit, but as
it is a logically separate change it is in its own commit.

17 months agoUnset the needs-notify bit in a Notifier when a Future is fetched
Matt Corallo [Mon, 14 Nov 2022 23:49:27 +0000 (23:49 +0000)]
Unset the needs-notify bit in a Notifier when a Future is fetched

If a `Notifier` gets `notify()`ed and the a `Future` is fetched,
even though the `Future` is marked completed from the start and
the user may pass callbacks which are called, we'll never wipe the
needs-notify bit in the `Notifier`.

The solution is to keep track of the `FutureState` in the returned
`Future` even though its `complete` from the start, adding a new
flag in the `FutureState` which indicates callbacks have been made
and checking that flag when waiting or returning a second `Future`.

17 months agoRemove excess module
Matt Corallo [Mon, 14 Nov 2022 23:53:13 +0000 (23:53 +0000)]
Remove excess module

This appears to have been added with the intent of having a sealed
trait, which was never committed.

17 months agoMerge pull request #1845 from TheBlueMatt/2022-11-future-wake-fix
Matt Corallo [Fri, 11 Nov 2022 06:09:03 +0000 (06:09 +0000)]
Merge pull request #1845 from TheBlueMatt/2022-11-future-wake-fix

Fix persistence-required futures always completing instantly

17 months agoMerge pull request #1806 from arik-so/2022-10-background-processor-deparametrization
Matt Corallo [Fri, 11 Nov 2022 06:08:51 +0000 (06:08 +0000)]
Merge pull request #1806 from arik-so/2022-10-background-processor-deparametrization

Remove generic `Signer` parameter where it can be inferred from `KeysInterface`

17 months agoFix persistence-required futures always completing instantly 2022-11-future-wake-fix
Matt Corallo [Thu, 10 Nov 2022 00:37:01 +0000 (00:37 +0000)]
Fix persistence-required futures always completing instantly

After the first persistence-required `Future` wakeup, we'll always
complete additional futures instantly as we don't clear the
"need wake" bit. Instead, we need to just assume that if a future
was generated (and not immediately drop'd) that its sufficient to
notify the user.

17 months agoMerge pull request #1413 from ViktorTigerstrom/2022-04-default-to-bolt4-tlv-onions
Matt Corallo [Fri, 11 Nov 2022 00:49:45 +0000 (00:49 +0000)]
Merge pull request #1413 from ViktorTigerstrom/2022-04-default-to-bolt4-tlv-onions

Drop support for creating BOLT 4 Legacy onion format payloads

17 months agoAdd test for only creating tlv format onions
Viktor Tigerström [Tue, 5 Apr 2022 22:51:30 +0000 (00:51 +0200)]
Add test for only creating tlv format onions

17 months agoRemove `OnionHopDataFormat::Legacy`
Viktor Tigerström [Thu, 20 Oct 2022 08:44:12 +0000 (10:44 +0200)]
Remove `OnionHopDataFormat::Legacy`

17 months agoUpdate BOLT4 onion test vectors
Viktor Tigerström [Thu, 29 Sep 2022 23:29:02 +0000 (01:29 +0200)]
Update BOLT4 onion test vectors

17 months agoMerge pull request #1787 from wpaulino/async-event-handler
Matt Corallo [Thu, 10 Nov 2022 21:51:16 +0000 (21:51 +0000)]
Merge pull request #1787 from wpaulino/async-event-handler

Handle events asynchronously in the BackgroundProcessor's async variant

17 months agoNote async versions of event handling within EventsProvider
Wilmer Paulino [Wed, 2 Nov 2022 23:29:17 +0000 (16:29 -0700)]
Note async versions of event handling within EventsProvider

17 months agoDrop DecoratingEventHandler in favor of inline closure
Wilmer Paulino [Wed, 2 Nov 2022 23:29:00 +0000 (16:29 -0700)]
Drop DecoratingEventHandler in favor of inline closure

17 months agoHandle events asynchronously in the BackgroundProcessor's async variant
Wilmer Paulino [Thu, 20 Oct 2022 22:51:37 +0000 (15:51 -0700)]
Handle events asynchronously in the BackgroundProcessor's async variant

17 months agoImplement async versions of process_pending_events
Wilmer Paulino [Wed, 2 Nov 2022 19:39:07 +0000 (12:39 -0700)]
Implement async versions of process_pending_events

17 months agoConsume events by value in EventHandler's handle_event
Wilmer Paulino [Mon, 31 Oct 2022 17:36:12 +0000 (10:36 -0700)]
Consume events by value in EventHandler's handle_event

17 months agoUse BaseEventHandler to expose async event handling on InvoicePayer
Wilmer Paulino [Tue, 8 Nov 2022 02:09:16 +0000 (18:09 -0800)]
Use BaseEventHandler to expose async event handling on InvoicePayer

We introduce a new sealed trait BaseEventHandler that has a blanket
implementation for any T. Since the trait cannot be implemented outside
of the crate, this allow us to expose specific implementations of
InvoicePayer that allow for synchronous and asynchronous event handling.

17 months agoApply network graph updates through NetworkUpdate's instead of Event's
Wilmer Paulino [Mon, 31 Oct 2022 23:07:41 +0000 (16:07 -0700)]
Apply network graph updates through NetworkUpdate's instead of Event's

17 months agoMerge pull request #1844 from valentinewallace/2022-11-htlc-interception-refactor...
valentinewallace [Thu, 10 Nov 2022 16:36:28 +0000 (11:36 -0500)]
Merge pull request #1844 from valentinewallace/2022-11-htlc-interception-refactor-followup

Rename `PendingHTLCInfo` fields to include msat suffix

17 months agoMerge pull request #1843 from TheBlueMatt/2022-11-fix-bp-exit-docs
Matt Corallo [Thu, 10 Nov 2022 00:42:20 +0000 (00:42 +0000)]
Merge pull request #1843 from TheBlueMatt/2022-11-fix-bp-exit-docs

Correct async `lightning-background-processor` exit check docs

17 months agoRemove generic `Signer` parameter where it can be inferred from `KeysInterface`
Arik Sosman [Wed, 26 Oct 2022 20:57:11 +0000 (13:57 -0700)]
Remove generic `Signer` parameter where it can be inferred from `KeysInterface`

17 months agoMerge pull request #1796 from tnull/2022-10-track-confirmation-block-hash
Matt Corallo [Wed, 9 Nov 2022 20:24:10 +0000 (20:24 +0000)]
Merge pull request #1796 from tnull/2022-10-track-confirmation-block-hash

Track confirmation block hash and return via `Confirm::get_relevant_txids`

17 months agoRename PendingHTLCInfo fields to include msat suffix
Valentine Wallace [Wed, 9 Nov 2022 19:19:56 +0000 (14:19 -0500)]
Rename PendingHTLCInfo fields to include msat suffix

17 months agoMerge pull request #1842 from jkczyz/2022-11-channel-monitor-docs
Matt Corallo [Wed, 9 Nov 2022 19:16:00 +0000 (19:16 +0000)]
Merge pull request #1842 from jkczyz/2022-11-channel-monitor-docs

Fix outdated `ChannelMonitor` docs

17 months agoCorrect async `lightning-background-processor` exit check docs 2022-11-fix-bp-exit-docs
Matt Corallo [Wed, 9 Nov 2022 17:35:26 +0000 (17:35 +0000)]
Correct async `lightning-background-processor` exit check docs

The check to stop the background processor is true -> break, not
false -> break. This simply updates the docs and leaves the code
as-is.

17 months agoMerge pull request #1840 from valentinewallace/2022-11-htlc-intercept-prefactor
Matt Corallo [Wed, 9 Nov 2022 17:48:55 +0000 (17:48 +0000)]
Merge pull request #1840 from valentinewallace/2022-11-htlc-intercept-prefactor

Pre-refactor for HTLC Interception

17 months agoFix outdated ChannelMonitor docs
Jeffrey Czyz [Wed, 9 Nov 2022 17:11:08 +0000 (11:11 -0600)]
Fix outdated ChannelMonitor docs

ChannelMonitor::get_and_clear_pending_events docs references a method
that had been refactored and is no longer accurate.

17 months agoMerge pull request #1834 from dunxen/2022-11-expose-pending-monitor-updates
valentinewallace [Wed, 9 Nov 2022 16:15:06 +0000 (11:15 -0500)]
Merge pull request #1834 from dunxen/2022-11-expose-pending-monitor-updates

Add public method to list pending monitor updates from `ChainMonitor`

17 months agoTrack block hash, return via `get_relevant_txids`
Elias Rohrer [Tue, 8 Nov 2022 20:45:28 +0000 (21:45 +0100)]
Track block hash, return via `get_relevant_txids`

Previously, `Confirm::get_relevant_txids()` only returned a list of
transactions that have to be monitored for reorganization out of the
chain. This interface however required double bookkeeping: while we
internally keep track of the best block, height, etc, it would also
require the user to keep track which transaction was previously
confirmed in which block and to take actions based on any change, e.g,
to reconfirm them when the block would be reorged-out and the
transactions had been reconfirmed in another block.

Here, we track the confirmation block hash internally and return it via
`Confirm::get_relevant_txids()` to the user, which alleviates the
requirement for double bookkeeping: the user can now simply check
whether the given transaction is still confirmed and in the given block,
and take action if not.

We also split `update_claims_view`: Previously it was one, now it's two
methods: `update_claims_view_from_matched_txn` and
`update_claims_view_from_requests`.

17 months agoAdd public method to list pending monitor updates from `ChainMonitor`
Duncan Dean [Mon, 7 Nov 2022 11:52:05 +0000 (13:52 +0200)]
Add public method to list pending monitor updates from `ChainMonitor`

Users have requested the feature to list pending monitor updates from
`ChainMonitor` so this adds that.

17 months agoMerge pull request #1719 from jkczyz/2022-09-offer-encoding
Matt Corallo [Tue, 8 Nov 2022 23:54:55 +0000 (23:54 +0000)]
Merge pull request #1719 from jkczyz/2022-09-offer-encoding

BOLT 12 `offer` encoding and building

17 months agoFix scid_utils::is_valid* false positive
Valentine Wallace [Mon, 7 Nov 2022 22:29:23 +0000 (17:29 -0500)]
Fix scid_utils::is_valid* false positive

cargo bench was able to find an scid of 0 as a valid fake scid

17 months agoTrack incoming amount in PendingHTLCInfo
Valentine Wallace [Fri, 4 Nov 2022 16:42:48 +0000 (12:42 -0400)]
Track incoming amount in PendingHTLCInfo

Used in upcoming commit(s) when we generate the PaymentIntercepted event for
intercepted payments.

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoDelete unnecessary whitespace in process_pending_forwards
Valentine Wallace [Fri, 4 Nov 2022 18:16:20 +0000 (14:16 -0400)]
Delete unnecessary whitespace in process_pending_forwards

Only whitespace diff

17 months agoRefactor HTLCForwardInfo::AddHTLC for intercept forwards
Valentine Wallace [Fri, 4 Nov 2022 16:28:36 +0000 (12:28 -0400)]
Refactor HTLCForwardInfo::AddHTLC for intercept forwards

In upcoming commit(s), we'll want to store intercepted HTLC forwards in
ChannelManager before the user signals that they should be forwarded.  It
wouldn't make sense to store a HTLCForwardInfo as-is because the FailHTLC
variant doesn't make sense, so we refactor out the ::AddHTLC contents into its
own struct for storage.

Co-authored-by: John Cantrell <johncantrell97@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
17 months agoMerge pull request #1833 from johncantrell97/2022-11-rgs-handle-removed-channel
Arik [Tue, 8 Nov 2022 19:55:48 +0000 (11:55 -0800)]
Merge pull request #1833 from johncantrell97/2022-11-rgs-handle-removed-channel

Ignore RGS channel updates for unknown channels

17 months agoBuilder for creating offers
Jeffrey Czyz [Tue, 9 Aug 2022 22:40:26 +0000 (17:40 -0500)]
Builder for creating offers

Add a builder for creating offers given a required description and
node_id. Other settings are optional and duplicative settings will
override previous settings for non-Vec fields.

17 months agoMerge pull request #1837 from tnull/2022-10-fix-meeting-time
Matt Corallo [Tue, 8 Nov 2022 18:07:26 +0000 (18:07 +0000)]
Merge pull request #1837 from tnull/2022-10-fix-meeting-time

Fix LDK Dev Meeting time

17 months agoFix LDK Dev Meeting time and typo
Elias Rohrer [Tue, 8 Nov 2022 09:42:25 +0000 (10:42 +0100)]
Fix LDK Dev Meeting time and typo

18 months agoignore updates for unknown channels
John Cantrell [Fri, 4 Nov 2022 19:42:19 +0000 (15:42 -0400)]
ignore updates for unknown channels

18 months agoMerge pull request #1639 from ViktorTigerstrom/2022-07-move-short-to-chan-info
Matt Corallo [Fri, 4 Nov 2022 20:57:27 +0000 (20:57 +0000)]
Merge pull request #1639 from ViktorTigerstrom/2022-07-move-short-to-chan-info

Move `short_to_chan_info` into standalone lock

18 months agoSerialization macro for TLV streams
Jeffrey Czyz [Fri, 24 Jun 2022 21:27:42 +0000 (16:27 -0500)]
Serialization macro for TLV streams

BOLT 12's offer message is encoded as a TLV stream (i.e., a sequence of
TLV records). impl_writeable_tlv_based can't be used because it writes
the overall length of the struct, whereas TLV streams only include the
length of each TLV record. Add a `tlv_stream` macro for defining structs
used in encoding.

TLV records containing a single variable-length type should not encode
the types length in the value since it is redundant. Add a wrapper type
that can be used within a TLV stream to support the correct behavior
during serialization and de-serialization.

18 months agoAdd WithoutLength wrapper
Jeffrey Czyz [Fri, 7 Oct 2022 04:12:48 +0000 (23:12 -0500)]
Add WithoutLength wrapper

When serializing variable-length types as part of a TLV stream, the
length does not need to be serialized as it is already encoded in TLV
records. Add a WithoutLength wrapper for this encoding. Replace
VecReadWrapper and VecWriteWrapper with this single type to avoid
redundant encoders.

18 months agoOffer message interface and data format
Jeffrey Czyz [Tue, 9 Aug 2022 22:24:10 +0000 (17:24 -0500)]
Offer message interface and data format

Define an interface for BOLT 12 `offer` messages. The underlying format
consists of the original bytes and the parsed contents.

The bytes are later needed when constructing an `invoice_request`
message. This is because it must mirror all the `offer` TLV records,
including unknown ones, which aren't represented in the contents.

The contents will be used in `invoice_request` messages to avoid
duplication. Some fields while required in a typical user-pays-merchant
flow may not be necessary in the merchant-pays-user flow (i.e., refund).

18 months agoAdd PrintableString utility
Jeffrey Czyz [Thu, 6 Oct 2022 18:44:35 +0000 (13:44 -0500)]
Add PrintableString utility

Strings defined by third parties may contain control characters. Provide
a wrapper such that these are replaced when displayed. Useful in node
aliases and offer fields.

18 months agoOffer features for BOLT 12
Jeffrey Czyz [Fri, 24 Jun 2022 21:40:49 +0000 (16:40 -0500)]
Offer features for BOLT 12

The offer message in BOLT 12 contains a features TLV record. Add a
corresponding OfferFeatures type where the length is not included in the
serialization as it would be redundant with the record length.
Otherwise, define the features to be the same as InvoiceFeatures.

18 months agoMake `process_pending_htlc_forwards` more readable
Viktor Tigerström [Thu, 18 Aug 2022 23:07:15 +0000 (01:07 +0200)]
Make `process_pending_htlc_forwards` more readable

Refactor `process_pending_htlc_forwards` to ensure that both branches
that fails `pending_forwards` are placed next to eachother for improved
readability.

18 months agoConsider `channel_id`s in `short_to_chan_info` as unguaranteed
Viktor Tigerström [Thu, 18 Aug 2022 22:54:47 +0000 (00:54 +0200)]
Consider `channel_id`s in `short_to_chan_info` as unguaranteed

As the `short_to_chan_info` map has been removed from the
`channel_state`, there is no longer any consistency guarantees between
the `by_id` and `short_to_chan_info` maps. This commit ensures that we
don't force unwrap channels where the channel_id has been queried from
the `short_to_chan_info` map.

18 months agoRemove excess `channel_state` passing to macros
Viktor Tigerström [Tue, 26 Jul 2022 22:45:20 +0000 (00:45 +0200)]
Remove excess `channel_state` passing to macros

As the `short_to_chan_info` has been moved out of the `channel_state` to
a standalone lock, several macros no longer need the `channel_state`
passed into the macro.

18 months agoMove `short_to_chan_info` into standalone lock
Viktor Tigerström [Tue, 26 Jul 2022 20:59:24 +0000 (22:59 +0200)]
Move `short_to_chan_info` into standalone lock

As the `channel_state` (`ChannelHolder`) struct will be removed, this
commit moves the `short_to_chan_info` map from that lock into a seperate
lock.

18 months agoRemove empty match arm during prefix check
John Cantrell [Fri, 4 Nov 2022 18:15:02 +0000 (14:15 -0400)]
Remove empty match arm during prefix check

18 months agoMerge pull request #1831 from benthecarman/hash-ConfirmationTarget
Matt Corallo [Fri, 4 Nov 2022 16:31:54 +0000 (16:31 +0000)]
Merge pull request #1831 from benthecarman/hash-ConfirmationTarget

Implement Hash for ConfirmationTarget

18 months agoImplement Hash for ConfirmationTarget
benthecarman [Fri, 4 Nov 2022 07:32:45 +0000 (02:32 -0500)]
Implement Hash for ConfirmationTarget

18 months agoMerge pull request #1811 from valentinewallace/2022-10-chanman-router
Matt Corallo [Thu, 3 Nov 2022 23:43:03 +0000 (23:43 +0000)]
Merge pull request #1811 from valentinewallace/2022-10-chanman-router

Move `InflightHtlcs` and `Router` trait into `ChannelManager`

18 months agoMerge pull request #1761 from TheBlueMatt/2022-10-user-idempotency-token
Matt Corallo [Thu, 3 Nov 2022 22:38:49 +0000 (22:38 +0000)]
Merge pull request #1761 from TheBlueMatt/2022-10-user-idempotency-token

Provide `send_payment` idempotency guarantees

18 months agoMove InvoicePayer's Router into ChannelManager
Valentine Wallace [Thu, 27 Oct 2022 22:00:23 +0000 (18:00 -0400)]
Move InvoicePayer's Router into ChannelManager

This helps prepare to parameterize ChannelManager with a Router, to eventually
use in trampoline payments.

18 months agoMove InFlightHtlcs into ChannelManager
Valentine Wallace [Tue, 25 Oct 2022 00:38:48 +0000 (20:38 -0400)]
Move InFlightHtlcs into ChannelManager

This is part of moving the Router trait into ChannelManager, which will help
allow ChannelManager to fetch routes on-the-fly as part of supporting
trampoline payments.

18 months agoMerge pull request #1817 from TheBlueMatt/2022-10-removed-no-score-after
Matt Corallo [Thu, 3 Nov 2022 17:22:34 +0000 (17:22 +0000)]
Merge pull request #1817 from TheBlueMatt/2022-10-removed-no-score-after

18 months agoMerge pull request #1743 from tnull/2022-09-channel-events
Matt Corallo [Thu, 3 Nov 2022 16:25:55 +0000 (16:25 +0000)]
Merge pull request #1743 from tnull/2022-09-channel-events

Add `ChannelReady` event

18 months agoFix warnings for ununsed anchor imports
Elias Rohrer [Wed, 26 Oct 2022 09:26:23 +0000 (11:26 +0200)]
Fix warnings for ununsed anchor imports

Previously introduced during release commit.

18 months agoRename chan state `ChannelFunded` to `ChannelReady`
Elias Rohrer [Wed, 26 Oct 2022 09:24:28 +0000 (11:24 +0200)]
Rename chan state `ChannelFunded` to `ChannelReady`

We rename `ChannelState::ChannelFunded` to `ChannelState::ChannelReady`
as we'll be in this state when both sides sent the `ChannelReady`
messages, which may also be before funding in the 0conf case.

18 months agoAdd `ChannelReady` event
Elias Rohrer [Tue, 1 Nov 2022 08:57:37 +0000 (09:57 +0100)]
Add `ChannelReady` event

This adds a `ChannelReady` event that is emitted as soon as a new
channel becomes usable, i.e., after both sides have sent
`channel_ready`.

18 months agoAdd missing break when scoring a path with a missing channel 2022-10-removed-no-score-after
Matt Corallo [Mon, 31 Oct 2022 03:23:02 +0000 (03:23 +0000)]
Add missing break when scoring a path with a missing channel

If we send payments over a path where a channel ended up being
closed, we'll remove it before we call
`ProbabilisticPaymentScorer::payment_path_failed`. This should be
fine, except that `payment_path_failed` does not break out of its
scoring loop if a channel is missing, causing it to assign a
minimum available-liquidity of the payment amount even to channels
which our attempt never arrived at.

The fix is simple - add the missing check and break.

18 months agoMerge pull request #1735 from naumenkogs/2022-09-prune-channels-if-either-not-upd
Matt Corallo [Wed, 2 Nov 2022 19:23:27 +0000 (19:23 +0000)]
Merge pull request #1735 from naumenkogs/2022-09-prune-channels-if-either-not-upd

Prune channels if either not updated + track pruning time

18 months agoMerge pull request #1753 from wpaulino/avoid-redundant-claims-after-initial-conf
Matt Corallo [Wed, 2 Nov 2022 19:23:15 +0000 (19:23 +0000)]
Merge pull request #1753 from wpaulino/avoid-redundant-claims-after-initial-conf

Avoid generating redundant claims after initial confirmation

18 months agoAvoid generating redundant claims after initial confirmation
Wilmer Paulino [Wed, 21 Sep 2022 19:54:28 +0000 (12:54 -0700)]
Avoid generating redundant claims after initial confirmation

These claims will never be valid as a previous claim has already
confirmed. If a previous claim is reorged out of the chain, a new claim
will be generated bypassing the new behavior.

While this doesn't change much for our existing transaction-based
claims, as broadcasting an already confirmed transaction acts as a NOP,
it prevents us from yielding redundant event-based claims, which will be
introduced as part of the anchors patchset.

18 months agoTrack the time a stale channel was pruned
Gleb Naumenko [Thu, 27 Oct 2022 09:52:34 +0000 (12:52 +0300)]
Track the time a stale channel was pruned

18 months agoAdd a pending changelog entry for the past few commits 2022-10-user-idempotency-token
Matt Corallo [Sat, 8 Oct 2022 21:25:44 +0000 (21:25 +0000)]
Add a pending changelog entry for the past few commits

18 months agoAllow users to specify the `PaymentId` used in `InvoicePayer`
Matt Corallo [Wed, 2 Nov 2022 01:06:39 +0000 (01:06 +0000)]
Allow users to specify the `PaymentId` used in `InvoicePayer`

In order to allow users to pass a custom idempotency key to the
`send*` methods in `InvoicePayer`, we have to pipe the `PaymentId`
through to the `Payer` methods, which we do here.

By default, existing `InvoicePayer` methods use the `PaymentHash`
as the `PaymentId`, however we also add duplicate `send*_with_id`
methods which allow users to pass a custom `PaymentId`.

Finally, appropriate documentation updates are made to clarify
idempotency guarantees.

18 months agoTest that PaymentIds are idempotency keys until `abandon_payment`
Matt Corallo [Sun, 30 Oct 2022 00:20:52 +0000 (00:20 +0000)]
Test that PaymentIds are idempotency keys until `abandon_payment`

18 months agoStop timing out payments automatically, requiring abandon_payment
Matt Corallo [Sat, 8 Oct 2022 19:54:43 +0000 (19:54 +0000)]
Stop timing out payments automatically, requiring abandon_payment

When the `abandon_payment` flow was added there was some concern
that upgrading users may not migrate to the new flow, causing
memory leaks in the pending-payment tracking.

While this is true, now that we're relying on the
pending_outbound_payments map for `send_payment` idempotency, the
risk of removing a payment prematurely goes up from "spurious
retry failure" to "sending a duplicative payment", which is much
worse.

Thus, we simply remove the automated payment timeout here,
explicitly requiring that users call `abandon_payment` when they
give up retrying a payment.

18 months agoDelay removal of fulfilled outbound payments for a few timer ticks
Matt Corallo [Sat, 8 Oct 2022 23:26:18 +0000 (23:26 +0000)]
Delay removal of fulfilled outbound payments for a few timer ticks

Previously, once a fulfilled outbound payment completed and all
associated HTLCs were resolved, we'd immediately remove the payment
entry from the `pending_outbound_payments` map.

Now that we're using the `pending_outbound_payments` map for send
idempotency, this presents a race condition - if the user makes a
redundant `send_payment` call at the same time that the original
payment's last HTLC is resolved, the user would reasonably expect
the `send_payment` call to fail due to our idempotency guarantees.

However, because the `pending_outbound_payments` entry is being
removed, if it completes first the `send_payment` call will
succeed even though the user has not had a chance to see the
corresponding `Event::PaymentSent`.

Instead, here, we delay removal of `Fulfilled`
`pending_outbound_payments` entries until several timer ticks have
passed without any corresponding event or HTLC pending.

18 months agoAllow users to specify the `PaymentId` for new outbound payments
Matt Corallo [Thu, 6 Oct 2022 21:31:02 +0000 (21:31 +0000)]
Allow users to specify the `PaymentId` for new outbound payments

In c986e52ce83e9aeaa9447abebc5f6600470337cf, an `MppId` was added
to `HTLCSource` objects as a way of correlating HTLCs which belong
to the same payment when the `ChannelManager` sees an HTLC
succeed/fail. This allows it to have awareness of the state of all
HTLCs in a payment when it generates the ultimate user-facing
payment success/failure events. This was used in the same PR to
avoid generating duplicative success/failure events for a single
payment.

Because the field was only used as an internal token to correlate
HTLCs, and retries were not supported, it was generated randomly by
calling the `KeysInterface`'s 32-byte random-fetching function.
This also provided a backwards-compatibility story as the existing
HTLC randomization key was re-used for older clients.

In 28eea12bbe0d78d256f79ec725cf02366dce4e36 `MppId` was renamed to
the current `PaymentId` which was then used expose the
`retry_payment` interface, allowing users to send new HTLCs which
are considered a part of an existing payment.

At no point has the payment-sending API seriously considered
idempotency, a major drawback which leaves the API unsafe in most
deployments. Luckily, there is a simple solution - because the
`PaymentId` must be unique, and because payment information for a
given payment is held for several blocks after a payment
completes/fails, it represents an obvious idempotency token.

Here we simply require the user provide the `PaymentId` directly in
`send_payment`, allowing them to use whatever token they may
already have for a payment's idempotency token.

18 months agoMerge pull request #1791 from valentinewallace/2022-10-we-are-intro-node
Matt Corallo [Tue, 1 Nov 2022 21:12:30 +0000 (21:12 +0000)]
Merge pull request #1791 from valentinewallace/2022-10-we-are-intro-node

Onion messages: fix edge case where we are the intro node

18 months agoPrune channels if *either* not updated
Gleb Naumenko [Thu, 27 Oct 2022 09:30:44 +0000 (12:30 +0300)]
Prune channels if *either* not updated

18 months agoNon-mandatory "fix" enabling future tests
Gleb Naumenko [Tue, 1 Nov 2022 08:10:49 +0000 (10:10 +0200)]
Non-mandatory "fix" enabling future tests

18 months agoMerge pull request #1815 from TheBlueMatt/2022-10-dead-gossip-code
valentinewallace [Tue, 1 Nov 2022 00:02:52 +0000 (20:02 -0400)]
Merge pull request #1815 from TheBlueMatt/2022-10-dead-gossip-code

Require directional updates for a DirectionalChannelInfo

18 months agoMerge pull request #1818 from TheBlueMatt/2022-10-stable-bench
Matt Corallo [Mon, 31 Oct 2022 21:28:53 +0000 (21:28 +0000)]
Merge pull request #1818 from TheBlueMatt/2022-10-stable-bench

Use rustc stable for benchmark CI run to fix current breakage

18 months agoUse rustc stable for benchmark CI run to fix current breakage 2022-10-stable-bench
Matt Corallo [Mon, 31 Oct 2022 18:46:31 +0000 (18:46 +0000)]
Use rustc stable for benchmark CI run to fix current breakage

18 months agoOMs: fix panic sending to a two-hop blinded route where we are the intro node
Valentine Wallace [Mon, 31 Oct 2022 16:40:06 +0000 (12:40 -0400)]
OMs: fix panic sending to a two-hop blinded route where we are the intro node

18 months agoOnion messages: fix edge case where we are the introduction node
Valentine Wallace [Fri, 21 Oct 2022 19:09:03 +0000 (15:09 -0400)]
Onion messages: fix edge case where we are the introduction node

If we're sending straight to a blinded route with no unblinded intermediate
hops, and we are the introduction node, we need to advance the blinded route by
one hop so that the second hop is the new introduction node.

18 months agoMake `htlc_maximum_msat` in `EffectiveCapacity` non-`Option`al 2022-10-dead-gossip-code
Matt Corallo [Sat, 29 Oct 2022 18:30:37 +0000 (18:30 +0000)]
Make `htlc_maximum_msat` in `EffectiveCapacity` non-`Option`al

Because we now never generate an `EffectiveCapacity` with an
`htlc_maximum_msat` set to `None`, making it non-`Option`al
effectively removes dead code, which we do here.

18 months agoRequire directional updates for a `DirectionalChannelInfo`
Matt Corallo [Sat, 29 Oct 2022 18:24:36 +0000 (18:24 +0000)]
Require directional updates for a `DirectionalChannelInfo`

We currently construct `DirectedChannelInfo`s for routing before
checking if the given direction has its directional info filled in.
We then always check for directional info before actually deciding
to route over a channel, as otherwise we assume the channel is not
online.

This makes for somewhat redundant checks, and `DirectedCHannelInfo`
isn't, by itself, a very useful API. Because fetching the HTLC-max
or effective channel capacity gives spurious data if no directional
info is available, there's little reason to have that data
available, and so we here check for directional info first. This
effectively merges `DirectionalChannelInfo` and
`DirectionalChannelInfoWithUpdate`.

18 months agoRemove unused payment_hash param from Router::find_route
Valentine Wallace [Tue, 25 Oct 2022 00:17:03 +0000 (20:17 -0400)]
Remove unused payment_hash param from Router::find_route

This helps prepare for moving the Router trait into ChannelManager, which will
help allow ChannelManager to retrieve routes for trampoline

18 months agoFix inaccurate comment in InvoicePayer
Valentine Wallace [Thu, 27 Oct 2022 20:58:30 +0000 (16:58 -0400)]
Fix inaccurate comment in InvoicePayer

18 months agoMerge pull request #1809 from valentinewallace/2022-10-custom-om-self
Matt Corallo [Thu, 27 Oct 2022 21:34:45 +0000 (21:34 +0000)]
Merge pull request #1809 from valentinewallace/2022-10-custom-om-self

Give us a self when reading a custom onion message

18 months agoGive us a self when reading a custom onion message
Matt Corallo [Wed, 26 Oct 2022 19:23:10 +0000 (19:23 +0000)]
Give us a self when reading a custom onion message

+ remove MaybeReadableArgs trait as it is now unused
+ remove onion_utils::DecodeInput as it would've now needed to be parameterized
by the CustomOnionMessageHandler trait, and we'd like to avoid either
implementing DecodeInput in messenger or having onion_utils depend on
onion_message::*

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
18 months agoMerge pull request #1805 from TheBlueMatt/2022-10-remote-useless-mut
Matt Corallo [Thu, 27 Oct 2022 16:11:28 +0000 (16:11 +0000)]
Merge pull request #1805 from TheBlueMatt/2022-10-remote-useless-mut

Drop useless `mut` in `KeysInterface::sign_holder_anchor_input`

18 months agoMerge pull request #1807 from TheBlueMatt/2022-10-errorkind-bindings
Matt Corallo [Thu, 27 Oct 2022 16:11:14 +0000 (16:11 +0000)]
Merge pull request #1807 from TheBlueMatt/2022-10-errorkind-bindings

Export io::ErrorKind in bindings

18 months agoExport io::ErrorKind in bindings 2022-10-errorkind-bindings
Matt Corallo [Wed, 26 Oct 2022 21:55:23 +0000 (21:55 +0000)]
Export io::ErrorKind in bindings

The bindings have exported `io::Error` as, basically,
`io::ErrorKind`, for quite some time, so there's little reason to
not just export `io::ErrorKind` as well.

18 months agoDrop useless `mut` in `KeysInterface::sign_holder_anchor_input` 2022-10-remote-useless-mut
Matt Corallo [Wed, 26 Oct 2022 20:46:34 +0000 (20:46 +0000)]
Drop useless `mut` in `KeysInterface::sign_holder_anchor_input`

The `Transaction` is not modified so there's no reason to make the
reference `mut`

18 months agoMerge pull request #1797 from arik-so/2022-10-channel-manager-deparameterization
valentinewallace [Wed, 26 Oct 2022 17:32:09 +0000 (13:32 -0400)]
Merge pull request #1797 from arik-so/2022-10-channel-manager-deparameterization

Deparametrize `ChannelManager` to infer `Signer` from its `KeysInterface`.

18 months agoMerge pull request #1802 from TheBlueMatt/2022-10-112 v0.0.112
Matt Corallo [Tue, 25 Oct 2022 21:33:34 +0000 (21:33 +0000)]
Merge pull request #1802 from TheBlueMatt/2022-10-112

Add release date and release name to CHANGELOG for 0.0.112

18 months agoRefer to `lnd` as `LND` in CHANGELOG 2022-10-112
Matt Corallo [Tue, 25 Oct 2022 18:59:41 +0000 (18:59 +0000)]
Refer to `lnd` as `LND` in CHANGELOG

for consistency since its an abbreviation for "lightning network
daemon".

18 months agoAdd release date and release name to CHANGELOG for 0.0.112
Matt Corallo [Tue, 25 Oct 2022 18:58:54 +0000 (18:58 +0000)]
Add release date and release name to CHANGELOG for 0.0.112

18 months agoMerge pull request #1798 from TheBlueMatt/2022-10-112
Matt Corallo [Tue, 25 Oct 2022 18:57:01 +0000 (18:57 +0000)]
Merge pull request #1798 from TheBlueMatt/2022-10-112

Cut 0.0.112

18 months agoDeparametrize `ChannelManager` to infer `Signer` from its `KeysInterface`.
Arik Sosman [Mon, 24 Oct 2022 19:11:12 +0000 (12:11 -0700)]
Deparametrize `ChannelManager` to infer `Signer` from its `KeysInterface`.

18 months agoOnly create BOLT4 tlv payload format onions
Viktor Tigerström [Tue, 5 Apr 2022 22:49:08 +0000 (00:49 +0200)]
Only create BOLT4 tlv payload format onions

18 months agoAdd release notes for 0.0.112
Matt Corallo [Mon, 24 Oct 2022 18:50:47 +0000 (18:50 +0000)]
Add release notes for 0.0.112