]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
23 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.

23 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.

23 months agoMerge pull request #1830 from jurvis/jurvis/2022-10-calculate-inflight-with-chanmanager
Matt Corallo [Mon, 21 Nov 2022 19:32:58 +0000 (19:32 +0000)]
Merge pull request #1830 from jurvis/jurvis/2022-10-calculate-inflight-with-chanmanager

Calculate `InFlightHtlcs` based on information in `ChannelManager`

23 months agoRemove pub visibility of InFlightHtlcs HashMap
jurvis [Thu, 17 Nov 2022 00:53:31 +0000 (16:53 -0800)]
Remove pub visibility of InFlightHtlcs HashMap

23 months agoAdd functional test for inflight HTLC tracking with ChanManager
jurvis [Sun, 13 Nov 2022 04:16:52 +0000 (20:16 -0800)]
Add functional test for inflight HTLC tracking with ChanManager

23 months agoRemove `paths` from `PaymentInfo` in `payment_cache`
jurvis [Thu, 17 Nov 2022 01:50:30 +0000 (17:50 -0800)]
Remove `paths` from `PaymentInfo` in `payment_cache`

In c70bd1f, we implemented tracking HTLCs by adding path information
for pending HTLCs to `InvoicePayer`’s `payment_cache` when receiving
specific events.

Since we can now track inflight HTLCs entirely within ChannelManager,
there is no longer a need for this to exist.

23 months agoCompute InflightHtlcs from available information in ChannelManager
jurvis [Sun, 13 Nov 2022 01:48:45 +0000 (17:48 -0800)]
Compute InflightHtlcs from available information in ChannelManager

23 months agoMerge pull request #1846 from TheBlueMatt/2022-11-more-robust-unconfirmed
Matt Corallo [Sat, 19 Nov 2022 00:06:32 +0000 (00:06 +0000)]
Merge pull request #1846 from TheBlueMatt/2022-11-more-robust-unconfirmed

Handle `transaction_unconfirmed` as a full reorg to the tx height

23 months agoMerge pull request #1852 from TheBlueMatt/2022-11-accept-bad-but-better-fee-updates
Matt Corallo [Fri, 18 Nov 2022 20:50:27 +0000 (20:50 +0000)]
Merge pull request #1852 from TheBlueMatt/2022-11-accept-bad-but-better-fee-updates

Accept feerate increases even if they aren't high enough for us

23 months agoHandle `transaction_unconfirmed` as a full reorg to the tx height 2022-11-more-robust-unconfirmed
Matt Corallo [Thu, 10 Nov 2022 01:01:31 +0000 (01:01 +0000)]
Handle `transaction_unconfirmed` as a full reorg to the tx height

In `ChannelMonitor`, if we see a `transaction_unconfirmed` for a
transaction we last saw in a block at height X, we shouldn't
*only* remove the `onchain_events_awaiting_threshold_conf` entry
for the given tx but rather for all transactions that we last saw
at height >= X.

This avoids any potential `onchain_events_awaiting_threshold_conf`
inconsistencies due to the order in whcih users mark transactions
unconfirmed (which the `chain::Confirm` docs do not currently set
any requirements on).

This also matches the `OnchainTxHandler` behavior, which does the
same lookup.

23 months agoMerge pull request #1726 from jkczyz/2022-09-offer-parsing
Matt Corallo [Fri, 18 Nov 2022 19:46:51 +0000 (19:46 +0000)]
Merge pull request #1726 from jkczyz/2022-09-offer-parsing

BOLT 12 offer parsing

23 months agoExpose the default Quantity::one as pub
Jeffrey Czyz [Fri, 11 Nov 2022 19:51:24 +0000 (13:51 -0600)]
Expose the default Quantity::one as pub

23 months agoLimit TLV stream decoding to type ranges
Jeffrey Czyz [Fri, 30 Sep 2022 20:50:12 +0000 (15:50 -0500)]
Limit TLV stream decoding to type ranges

BOLT 12 messages are limited to a range of TLV record types. Refactor
decode_tlv_stream into a decode_tlv_stream_range macro for limiting
which types are parsed. Requires a SeekReadable trait for rewinding when
a type outside of the range is seen. This allows for composing TLV
streams of different ranges.

Updates offer parsing accordingly and adds a test demonstrating failure
if a type outside of the range is included.

23 months agoOffer parsing tests
Jeffrey Czyz [Thu, 22 Sep 2022 03:38:11 +0000 (22:38 -0500)]
Offer parsing tests

Test semantic errors when parsing offer bytes.

23 months agoUse SemanticError in OfferBuilder::build
Jeffrey Czyz [Wed, 21 Sep 2022 18:09:06 +0000 (13:09 -0500)]
Use SemanticError in OfferBuilder::build

23 months agoOffer parsing from bech32 strings
Jeffrey Czyz [Thu, 11 Aug 2022 21:51:06 +0000 (16:51 -0500)]
Offer parsing from bech32 strings

Add common bech32 parsing for BOLT 12 messages. The encoding is similar
to bech32 only without a checksum and with support for continuing
messages across multiple parts.

Messages implementing Bech32Encode are parsed into a TLV stream, which
is converted to the desired message content while performing semantic
checks. Checking after conversion allows for more elaborate checks of
data composed of multiple TLV records and for more meaningful error
messages.

The parsed bytes are also saved to allow creating messages with mirrored
data, even if TLV records are unknown.

23 months agoUnparameterize HashMap from InFlightHtlcs initializer
jurvis [Fri, 4 Nov 2022 02:48:22 +0000 (19:48 -0700)]
Unparameterize HashMap from InFlightHtlcs initializer

2 years agoMerge pull request #1855 from tnull/2022-11-inbound-user-channel-id-randomization...
Matt Corallo [Wed, 16 Nov 2022 20:46:30 +0000 (20:46 +0000)]
Merge pull request #1855 from tnull/2022-11-inbound-user-channel-id-randomization-fixup

Inbound `user_channel_id` randomization follow-up

2 years agoRemove unused import
Elias Rohrer [Wed, 16 Nov 2022 15:00:48 +0000 (16:00 +0100)]
Remove unused import

2 years agoMention `user_channel_id` rand. version req.
Elias Rohrer [Wed, 16 Nov 2022 09:54:25 +0000 (10:54 +0100)]
Mention `user_channel_id` rand. version req.

As it was previously omitted, we clarify here starting from which version users can expect the `user_channel_id` to be randomized for inbound channels.

2 years agoAlso set `user_channel_id` when its overridden
Elias Rohrer [Wed, 16 Nov 2022 14:20:31 +0000 (15:20 +0100)]
Also set `user_channel_id` when its overridden

2 years agoMerge pull request #1826 from TheBlueMatt/2022-10-idempotency-err
Matt Corallo [Wed, 16 Nov 2022 17:42:23 +0000 (17:42 +0000)]
Merge pull request #1826 from TheBlueMatt/2022-10-idempotency-err

Add a separate PaymentSendFailure for idempotency violation

2 years agoMerge pull request #1853 from TheBlueMatt/2022-11-reload-macro
Matt Corallo [Wed, 16 Nov 2022 17:36:41 +0000 (17:36 +0000)]
Merge pull request #1853 from TheBlueMatt/2022-11-reload-macro

Replace manual node reloading with a macro/function in tests

2 years agoMerge pull request #1851 from TheBlueMatt/2022-11-fix-broken-futures-----again
Matt Corallo [Wed, 16 Nov 2022 17:34:37 +0000 (17:34 +0000)]
Merge pull request #1851 from TheBlueMatt/2022-11-fix-broken-futures-----again

Unset the needs-notify bit in a Notifier when a Future is fetched

2 years agoAccept feerate increases even if they aren't high enough for us 2022-11-accept-bad-but-better-fee-updates
Matt Corallo [Tue, 15 Nov 2022 00:46:22 +0000 (00:46 +0000)]
Accept feerate increases even if they aren't high enough for us

LND nodes have very broken fee estimators, causing them to suggest
feerates that don't even meet a current mempool minimum feerate
when fees go up over the course of hours. This can cause us to
reject their feerate estimates as they're not high enough, even
though their new feerate is higher than what we had already (which
is the feerate we'll use to broadcast a closing transaction). This
implies we force-close the channel and broadcast something with a
feerate lower than our counterparty was offering.

Here we simply accept such feerates as they are better than what we
had. We really should also close the channel, but only after we
get their signature on the new feerate. That should happen by
checking channel feerates every time we see a new block so is
orthogonal to this code.

Ultimately the fix is anchor outputs plus package-based relay in
Bitcoin Core, however we're still quite some ways from that, so
worth needlessly closing channels for now.

2 years 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`.

2 years 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.

2 years 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`.

2 years 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.

2 years agoMove restart-related tests to their own file 2022-11-reload-macro
Matt Corallo [Tue, 15 Nov 2022 03:45:17 +0000 (03:45 +0000)]
Move restart-related tests to their own file

2 years agoReplace manual node reloading with a macro/function in tests
Matt Corallo [Tue, 15 Nov 2022 02:43:51 +0000 (02:43 +0000)]
Replace manual node reloading with a macro/function in tests

Fixes #1696

2 years agoMerge pull request #1790 from tnull/2022-10-inbound-user-channel-id-randomization
Matt Corallo [Tue, 15 Nov 2022 22:35:17 +0000 (22:35 +0000)]
Merge pull request #1790 from tnull/2022-10-inbound-user-channel-id-randomization

Randomize `user_channel_id` for inbound channels

2 years agoMake `user_channel_id` a `u128`
Elias Rohrer [Mon, 24 Oct 2022 08:30:11 +0000 (10:30 +0200)]
Make `user_channel_id` a `u128`

We increase the `user_channel_id` type from `u64` to `u128`. In order to
maintain backwards compatibility, we have to de-/serialize it as two
separate `u64`s in `Event` as well as in the `Channel` itself.

2 years agoRandomize `user_channel_id` for inbound channels
Elias Rohrer [Fri, 21 Oct 2022 09:05:18 +0000 (11:05 +0200)]
Randomize `user_channel_id` for inbound channels

Previously, all inbound channels defaulted to a `user_channel_id` of 0,
which didn't allow for them being discerned on that basis. Here, we
simply randomize the identifier to fix this and enable the use of
`user_channel_id` as a true identifier for channels (assuming an equally
reasonable value is chosen for outbound channels and given upon
`create_channel()`).

2 years agoIntroduce `init_and_read_tlv_fields` macro
Elias Rohrer [Tue, 15 Nov 2022 13:57:47 +0000 (14:57 +0100)]
Introduce `init_and_read_tlv_fields` macro

We introduce a new macro that inits and reads tlv fields and DRY up
`impl_writeable_tlv_based` and other macros.

2 years 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

2 years 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`

2 years 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.

2 years 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

2 years 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

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

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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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.

2 years 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

2 years 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

2 years 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

2 years 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`

2 years 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`

2 years 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

2 years 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

2 years agoAdd a separate PaymentSendFailure for idempotency violation 2022-10-idempotency-err
Matt Corallo [Wed, 2 Nov 2022 23:25:34 +0000 (23:25 +0000)]
Add a separate PaymentSendFailure for idempotency violation

When a user attempts to send a payment but it fails due to
idempotency key violation, they need to know that this was the
reason as they need to handle the error programmatically
differently from other errors.

Here we simply add a new `PaymentSendFailure` enum variant for
`DuplicatePayment` to allow for that.

2 years agoRename `PaymentSendFailure::AllFailedRetrySafe` `...ResendSafe`
Matt Corallo [Wed, 2 Nov 2022 23:16:25 +0000 (23:16 +0000)]
Rename `PaymentSendFailure::AllFailedRetrySafe` `...ResendSafe`

It was pointed out that its quite confusing that
`AllFailedRetrySafe` does not allow you to call `retry_payment`,
though the documentation on it does specify this. Instead, we
simply rename it to `AllFailedResendSafe` to indicate that the
action that is safe to take is *resending*, not *retrying*.

2 years 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.

2 years 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

2 years 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.

2 years 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`

2 years 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`.

2 years 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.

2 years 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

2 years 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

2 years 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>
2 years 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

2 years 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>
2 years 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

2 years 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.

2 years 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

2 years 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

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

2 years 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

2 years 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.

2 years 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.

2 years 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).

2 years 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.

2 years 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.

2 years 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.

2 years 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.

2 years 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.

2 years 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.

2 years 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

2 years 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

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

2 years 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`

2 years 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

2 years 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.

2 years 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.

2 years 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

2 years 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

2 years 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.

2 years 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.

2 years 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`.

2 years 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.

2 years 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

2 years 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

2 years 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.