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

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

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 #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`

23 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

23 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

23 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

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

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

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

23 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

23 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

23 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

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

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

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

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

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

23 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

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

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

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

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

23 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

23 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

23 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

23 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

23 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

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

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

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

23 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

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

23 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

23 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

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

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

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

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

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

23 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

23 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}'

23 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

23 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

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

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

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

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

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

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

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

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

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

2 years agoLock pending inbound and outbound payments to before `channel_state`
Viktor Tigerström [Wed, 12 Oct 2022 19:26:28 +0000 (21:26 +0200)]
Lock pending inbound and outbound payments to before `channel_state`

As the `channel_state` lock will be removed, we prepare for that by
flipping the lock order for `pending_inbound_payments` and
`pending_outbound_payments` locks to before the `channel_state` lock.

2 years agoMove `claimable_htlcs` to separate lock
Viktor Tigerström [Tue, 11 Oct 2022 23:07:23 +0000 (01:07 +0200)]
Move `claimable_htlcs` to separate lock

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

2 years agoRemove the `post_handle_chan_restoration` macro 2022-11-rm-redundant-holding-cell-wipe
Matt Corallo [Mon, 21 Nov 2022 18:43:48 +0000 (18:43 +0000)]
Remove the `post_handle_chan_restoration` macro

Now that `handle_channel_resumption` can't fail, the error handling
in `post_handle_chan_restoration` is now dead code. Removing it
makes `post_handle_chan_restoration` only a single block, so here
we simply remove the macro and inline the single block into the two
places the macro was used.

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

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

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

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

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

2 years agoExplicitly track the set of spendable transactions which confirm
Matt Corallo [Fri, 18 Nov 2022 22:51:17 +0000 (22:51 +0000)]
Explicitly track the set of spendable transactions which confirm

In `ChannelMonitor`s, when a transaction containing a spend of a
revoked remote output reaches 6 confs, we may have no other
tracking of that txid remaining. Thus, if we see that transaction
again (because a user duplicatively confirms it), we'll generate a
redundant spendable output event for it.

Here we simply explicitly track all txids of transactions which
confirm with a spendable output, allowing us to check this
condition in the next commit.

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

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

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

2 years agoFix one test still connecting invalid blocks
Matt Corallo [Fri, 18 Nov 2022 18:49:16 +0000 (18:49 +0000)]
Fix one test still connecting invalid blocks

In the next commit we'll add some checks that redundant
transactions aren't confirmed in different blocks, which would
cause test_htlc_ignore_latest_remote_commitment to fail. Here we
fix it to avoid the issue.

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

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

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

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

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

2 years agoConvert the `handle_chan_restoration_locked` macro to a function
Matt Corallo [Thu, 17 Nov 2022 17:52:31 +0000 (17:52 +0000)]
Convert the `handle_chan_restoration_locked` macro to a function

There is no reason anymore for `handle_chan_restoration_locked` to
be a macro, and our long-term desire is to move away from macros as
they substantially bloat our compilation time (and binary size).
Thus, we simply remove `handle_chan_restoration_locked` here and
turn it into a function.

2 years agoWait to free the holding cell during channel_reestablish handling
Matt Corallo [Thu, 17 Nov 2022 05:48:21 +0000 (05:48 +0000)]
Wait to free the holding cell during channel_reestablish handling

When we process a `channel_reestablish` message we free the HTLC
update holding cell as things may have changed while we were
disconnected. However, some time ago, to handle freeing from the
holding cell when a monitor update completes, we added a holding
cell freeing check in `get_and_clear_pending_msg_events`. This
leaves the in-`channel_reestablish` holding cell clear redundant,
as doing it immediately or is `get_and_clear_pending_msg_events` is
not a user-visible difference.

Thus, we remove the redundant code here, substantially simplifying
`handle_chan_restoration_locked` while we're at it.

2 years agoRemove log assertions in `chanmon_update_fail_tests`
Matt Corallo [Thu, 17 Nov 2022 04:30:36 +0000 (04:30 +0000)]
Remove log assertions in `chanmon_update_fail_tests`

Asserting that specific log entries were printed isn't all that
useful, we should really be focusing on the expected messages (or,
when a monitor udpate fails, the lack thereof). In the next commit
one of these log checks would otherwise break due to the particular
time a monitor update fails changing, but I also plan on reworking
the montior update flows substantially soon, breaking lots of them.

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