]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
21 months agoMake the `offers` module non-public 2023-02-0.0.114-bindings
Matt Corallo [Wed, 1 Mar 2023 00:21:51 +0000 (00:21 +0000)]
Make the `offers` module non-public

As the `offers` types in LDK are currently only practically useful
for VLS users, there's no need to rush to get them included in
bindings, and sadly some tweaks to the bindings generator are
required for them.

For now, its simpler to just make them non-public.

21 months agoMark `InFlightHtlcs::process_path` not exported due to object slice
Matt Corallo [Mon, 6 Mar 2023 02:46:45 +0000 (02:46 +0000)]
Mark `InFlightHtlcs::process_path` not exported due to object slice

21 months agoAvoid enums containing references with lifetimes
Matt Corallo [Sun, 5 Mar 2023 20:38:42 +0000 (20:38 +0000)]
Avoid enums containing references with lifetimes

Having struct fields with references to other structs is tough in
our bindings logic, but even worse if the fields are in an enum.
Its simplest to just take the clone penalty here.

21 months agoExport `outbound_payment` structs in their respective modules
Matt Corallo [Tue, 28 Feb 2023 21:45:14 +0000 (21:45 +0000)]
Export `outbound_payment` structs in their respective modules

Re-exports in Rust make `use` statements a little shorter, but for
otherwise don't materially change a crate's API. Sadly, the C
bindings generator currently can't figure out re-exports, but it
also exports everything into one global namespace, so it doesn't
matter much anyway.

21 months agoUse an explicit `Sign` type on the `ChannelMonitor` read tuple
Matt Corallo [Sat, 24 Dec 2022 04:16:48 +0000 (04:16 +0000)]
Use an explicit `Sign` type on the `ChannelMonitor` read tuple

The bindings currently get confused by the implicit `Sign` type, so
we temporarily remove it on the `impl` here.

21 months agoExport Onion Message structs in their respective modules
Matt Corallo [Mon, 19 Dec 2022 21:38:45 +0000 (21:38 +0000)]
Export Onion Message structs in their respective modules

Re-exports in Rust make `use` statements a little shorter, but for
otherwise don't materially change a crate's API. Sadly, the C
bindings generator currently can't figure out re-exports, but it
also exports everything into one global namespace, so it doesn't
matter much anyway.

21 months agoTag `KVStore` `(C-not exported)` as `Writeable` isn't mapped
Matt Corallo [Sun, 26 Jun 2022 18:14:30 +0000 (18:14 +0000)]
Tag `KVStore` `(C-not exported)` as `Writeable` isn't mapped

Currently `Writeable` is mapped manually, making it impossible to
automatically map a trait method that is parameterized by
`Writeable` (as is true for the `write` method on `KVStore`).

Ultimately we'll want to move to automatically mapping `Writeable`
like any other trait (only manually mapping the std `Write` and
`Read` traits), so this is only a candidate for the bindings branch,
not upstream. That may take a few releases, however.

21 months agoRestrict ChannelInfo::as_directed_from visibility
Jeffrey Czyz [Tue, 29 Mar 2022 15:20:39 +0000 (10:20 -0500)]
Restrict ChannelInfo::as_directed_from visibility

Bindings can't handle references in return types, so reduce the
visibility to pub(crate).

21 months agoSimplify type aliasing somewhat around times
Matt Corallo [Tue, 1 Mar 2022 03:47:28 +0000 (03:47 +0000)]
Simplify type aliasing somewhat around times

.. as the current C bindings generator isn't capable of handling
type aliases in generics in type alias definition currently.

21 months agoMake `as_directed_to` non-public
Matt Corallo [Tue, 1 Mar 2022 03:46:52 +0000 (03:46 +0000)]
Make `as_directed_to` non-public

...as the bindings generation does not currently have the ability
to map a reference to a `NodeId` inside a tuple.

21 months agoMerge pull request #2065 from TheBlueMatt/2023-02-0.0.114 0.0.114-bindings v0.0.114
Matt Corallo [Sat, 4 Mar 2023 01:00:06 +0000 (01:00 +0000)]
Merge pull request #2065 from TheBlueMatt/2023-02-0.0.114

Cut 0.0.114

21 months agoUpdate crate versions to 0.0.114/invoice 0.22 2023-02-0.0.114
Matt Corallo [Wed, 1 Mar 2023 05:06:03 +0000 (05:06 +0000)]
Update crate versions to 0.0.114/invoice 0.22

21 months agoAdd release notes for 0.0.114
Matt Corallo [Wed, 1 Mar 2023 05:03:21 +0000 (05:03 +0000)]
Add release notes for 0.0.114

21 months agoMerge pull request #2072 from jkczyz/2023-01-fix-scoring-div-by-zero
Matt Corallo [Sat, 4 Mar 2023 00:06:29 +0000 (00:06 +0000)]
Merge pull request #2072 from jkczyz/2023-01-fix-scoring-div-by-zero

Fix division by zero in `ProbabilisticScorer`

21 months agoMerge pull request #2071 from TheBlueMatt/2023-01-fix-fast-extra-ready-panic
Matt Corallo [Fri, 3 Mar 2023 23:32:42 +0000 (23:32 +0000)]
Merge pull request #2071 from TheBlueMatt/2023-01-fix-fast-extra-ready-panic

Fix panic on receiving `channel_ready` after 1st commitment update

21 months agoUse ProbabilisticScorer in router fuzzing, to cover overflows there
Matt Corallo [Wed, 18 Jan 2023 00:01:15 +0000 (18:01 -0600)]
Use ProbabilisticScorer in router fuzzing, to cover overflows there

21 months agoGuard against division by zero in scorer
Jeffrey Czyz [Fri, 6 Jan 2023 04:00:31 +0000 (22:00 -0600)]
Guard against division by zero in scorer

Since a node may announce that the htlc_maximum_msat of a channel is
zero, adding one to the denominator in the bucket formulas will prevent
the panic from ever happening. While the routing algorithm may never
select such a channel to score, this precaution may still be useful in
case the algorithm changes or if the scorer is used with a different
routing algorithm.

21 months agoUpdate scoring history buckets when no change
Jeffrey Czyz [Tue, 17 Jan 2023 23:36:03 +0000 (17:36 -0600)]
Update scoring history buckets when no change

Even when there is no change in min/max liquidity knowledge, tracking
should still be updated to include the additional data point.

21 months agoMerge pull request #2068 from jkczyz/2023-03-doc-fixes
Matt Corallo [Fri, 3 Mar 2023 22:19:59 +0000 (22:19 +0000)]
Merge pull request #2068 from jkczyz/2023-03-doc-fixes

Doc and build warning fixes

21 months agoMerge pull request #2069 from TheBlueMatt/2023-03-no-tx-sync-auto-std
Matt Corallo [Fri, 3 Mar 2023 22:19:46 +0000 (22:19 +0000)]
Merge pull request #2069 from TheBlueMatt/2023-03-no-tx-sync-auto-std

Do not auto-select the lightning `std` feature from tx-sync crate

21 months agoMerge pull request #2070 from TheBlueMatt/2023-03-get-key
Matt Corallo [Fri, 3 Mar 2023 22:19:37 +0000 (22:19 +0000)]
Merge pull request #2070 from TheBlueMatt/2023-03-get-key

Expose the node secret key in `{Phantom,}KeysManager`

21 months agoFix build warnings
Jeffrey Czyz [Fri, 3 Mar 2023 16:54:42 +0000 (10:54 -0600)]
Fix build warnings

21 months agoAdd more documentation about BlockSourceError
Jeffrey Czyz [Fri, 3 Mar 2023 16:09:58 +0000 (10:09 -0600)]
Add more documentation about BlockSourceError

Some BlockSource implementations provide more error details. Document
this in case users want to examine it further.

21 months agoExpose the node secret key in `{Phantom,}KeysManager` 2023-03-get-key
Matt Corallo [Fri, 3 Mar 2023 20:03:57 +0000 (20:03 +0000)]
Expose the node secret key in `{Phantom,}KeysManager`

When we removed the private keys from the signing interface we
forgot to re-add them in the public interface of our own
implementations, which users may need.

21 months agoMerge pull request #2067 from benthecarman/fix-typos
Matt Corallo [Fri, 3 Mar 2023 20:00:12 +0000 (20:00 +0000)]
Merge pull request #2067 from benthecarman/fix-typos

Fix typos in lightning-transaction-sync

21 months agoMerge pull request #2066 from TheBlueMatt/2023-02-no-enum-refs
Matt Corallo [Fri, 3 Mar 2023 19:44:40 +0000 (19:44 +0000)]
Merge pull request #2066 from TheBlueMatt/2023-02-no-enum-refs

Pass `FailureCode` to `fail_htlc_backwards` by ownership

21 months agoMerge pull request #2048 from TheBlueMatt/2023-02-send-persist-order-a
Matt Corallo [Fri, 3 Mar 2023 19:37:31 +0000 (19:37 +0000)]
Merge pull request #2048 from TheBlueMatt/2023-02-send-persist-order-a

Track claimed outbound HTLCs in ChannelMonitors

21 months agoDo not auto-select the lightning `std` feature from tx-sync crate 2023-03-no-tx-sync-auto-std
Matt Corallo [Fri, 3 Mar 2023 05:14:04 +0000 (05:14 +0000)]
Do not auto-select the lightning `std` feature from tx-sync crate

We have some downstream folks who are using LDK in wasm compiled
via the normal rust wasm path. To ensure nothing breaks they want
to use `no-std` on the lightning crate, disabling time calls as
those panic. However, the HTTP logic in
`lightning-transaction-sync` gets automatically stubbed out by the
HTTP client crates when targeting wasm via `wasm_bindgen`, so it
works fine despite the std restrictions.

In order to make both work, `lightning-transaction-sync` can remain
`std`, but needs to not automatically enable the `std` flag on the
`lightning` crate, ie by setting `default-features = false`. We do
so here.

21 months agoPass `FailureCode` to `fail_htlc_backwards` by ownership 2023-02-no-enum-refs
Matt Corallo [Fri, 3 Mar 2023 01:24:24 +0000 (01:24 +0000)]
Pass `FailureCode` to `fail_htlc_backwards` by ownership

`FaliureCode` is a trivial enum with no body, so we shouldn't be
passing it by reference. Its sufficiently strange that the Java
bindings aren't happy with it, which is fine, we should just fix it
here.

21 months agoRemove unused compat block in `provide_latest_holder_commitment_tx` 2023-02-send-persist-order-a
Matt Corallo [Wed, 1 Mar 2023 01:31:55 +0000 (01:31 +0000)]
Remove unused compat block in `provide_latest_holder_commitment_tx`

21 months agoTrack claimed outbound HTLCs in ChannelMonitors
Matt Corallo [Wed, 22 Feb 2023 02:40:59 +0000 (02:40 +0000)]
Track claimed outbound HTLCs in ChannelMonitors

When we receive an update_fulfill_htlc message, we immediately try
to "claim" the HTLC against the HTLCSource. If there is one, this
works great, we immediately generate a `ChannelMonitorUpdate` for
the corresponding inbound HTLC and persist that before we ever get
to processing our counterparty's `commitment_signed` and persisting
the corresponding `ChannelMonitorUpdate`.

However, if there isn't one (and this is the first successful HTLC
for a payment we sent), we immediately generate a `PaymentSent`
event and queue it up for the user. Then, a millisecond later, we
receive the `commitment_signed` from our peer, removing the HTLC
from the latest local commitment transaction as a side-effect of
the `ChannelMonitorUpdate` applied.

If the user has processed the `PaymentSent` event by that point,
great, we're done. However, if they have not, and we crash prior to
persisting the `ChannelManager`, on startup we get confused about
the state of the payment. We'll force-close the channel for being
stale, and see an HTLC which was removed and is no longer present
in the latest commitment transaction (which we're broadcasting).
Because we claim corresponding inbound HTLCs before updating a
`ChannelMonitor`, we assume such HTLCs have failed - attempting to
fail after having claimed should be a noop. However, in the
sent-payment case we now generate a `PaymentFailed` event for the
user, allowing an HTLC to complete without giving the user a
preimage.

Here we address this issue by storing the payment preimages for
claimed outbound HTLCs in the `ChannelMonitor`, in addition to the
existing inbound HTLC preimages already stored there. This allows
us to fix the specific issue described by checking for a preimage
and switching the type of event generated in response. In addition,
it reduces the risk of future confusion by ensuring we don't fail
HTLCs which were claimed but not fully committed to before a crash.

It does not, however, full fix the issue here - because the
preimages are removed after the HTLC has been fully removed from
available commitment transactions if we are substantially delayed
in persisting the `ChannelManager` from the time we receive the
`update_fulfill_htlc` until after a full commitment signed dance
completes we may still hit this issue. The full fix for this issue
is to delay the persistence of the `ChannelMonitorUpdate` until
after the `PaymentSent` event has been processed. This avoids the
issue entirely, ensuring we process the event before updating the
`ChannelMonitor`, the same as we ensure the upstream HTLC has been
claimed before updating the `ChannelMonitor` for forwarded
payments.

The full solution will be implemented in a later work, however this
change still makes sense at that point as well - if we were to
delay the initial `commitment_signed` `ChannelMonitorUpdate` util
after the `PaymentSent` event has been processed (which likely
requires a database update on the users' end), we'd hold our
`commitment_signed` + `revoke_and_ack` response for two DB writes
(i.e. `fsync()` calls), making our commitment transaction
processing a full `fsync` slower. By making this change first, we
can instead delay the `ChannelMonitorUpdate` from the
counterparty's final `revoke_and_ack` message until the event has
been processed, giving us a full network roundtrip to do so and
avoiding delaying our response as long as an `fsync` is faster than
a network roundtrip.

21 months agoReference `Router` in `ChannelManager` docs
Jeffrey Czyz [Fri, 3 Mar 2023 15:45:11 +0000 (09:45 -0600)]
Reference `Router` in `ChannelManager` docs

21 months agoDRY up historical bucket_idx calculation
Jeffrey Czyz [Fri, 6 Jan 2023 02:13:12 +0000 (20:13 -0600)]
DRY up historical bucket_idx calculation

21 months agoFix scorer panic when available capacity is zero
Jeffrey Czyz [Thu, 5 Jan 2023 17:50:24 +0000 (11:50 -0600)]
Fix scorer panic when available capacity is zero

ProbabilisticScorer takes a ChannelUsage when computing a penalty for a
channel. The formula for calculating the liquidity penalty reduces the
maximum capacity by the amount of in-flight HTLCs (available capacity)
and adds one to prevent division by zero.

However, since the available capacity is passed to
DirectedChannelLiquidity as the capacity, other penalty formulas may use
the available (i.e., reduced) capacity inadvertently. In practice, this
has two ramifications for the historical liquidity penalty computation:

1. The bucket formula doesn't have a consistent denominator for a given
   channel.
2. The bucket formula may divide by zero when the in-flight HTLC amount
   equals or exceeds the effective capacity.

Fixing this involves only using the available capacity when appropriate.

21 months agoFix typos in lightning-transaction-sync
benthecarman [Fri, 3 Mar 2023 05:36:54 +0000 (23:36 -0600)]
Fix typos in lightning-transaction-sync

21 months agoMerge pull request #2060 from TheBlueMatt/2023-02-peers-disconnect-consistency
Matt Corallo [Thu, 2 Mar 2023 23:44:23 +0000 (23:44 +0000)]
Merge pull request #2060 from TheBlueMatt/2023-02-peers-disconnect-consistency

Remove peers from the node_id_to_descriptor even without init

21 months agoAvoid removing stale preimages when hashes collide in fuzzing
Matt Corallo [Thu, 2 Mar 2023 04:48:14 +0000 (04:48 +0000)]
Avoid removing stale preimages when hashes collide in fuzzing

21 months agoFuzz rapid peer connection/disconnections in threads 2023-02-peers-disconnect-consistency
Matt Corallo [Thu, 2 Mar 2023 06:27:08 +0000 (06:27 +0000)]
Fuzz rapid peer connection/disconnections in threads

This test fails on the bug fixed two commits ago with the
additional assertions in the previous commit.

21 months agoImprove `PeerHandler` debug_assertions and checks
Matt Corallo [Tue, 28 Feb 2023 21:38:29 +0000 (21:38 +0000)]
Improve `PeerHandler` debug_assertions and checks

This removes two panics from `PeerHandler` which can trivially be
`debug_assert!(false); return Err;`s, and adds another
`debug_assertion` on internal state consistency during disconnect.

21 months agoMerge pull request #2064 from TheBlueMatt/2023-03-debug-futures
Wilmer Paulino [Thu, 2 Mar 2023 19:49:54 +0000 (11:49 -0800)]
Merge pull request #2064 from TheBlueMatt/2023-03-debug-futures

Make waking after a future completes propagates to the next future

21 months agoMerge pull request #2057 from johncantrell97/rpc-error-code
Jeffrey Czyz [Thu, 2 Mar 2023 14:26:29 +0000 (08:26 -0600)]
Merge pull request #2057 from johncantrell97/rpc-error-code

Surface bitcoind rpc error information

21 months agoMake waking after a future completes propagates to the next future 2023-03-debug-futures
Matt Corallo [Thu, 2 Mar 2023 07:50:16 +0000 (07:50 +0000)]
Make waking after a future completes propagates to the next future

In our `wakers`, if we first `notify` a future, which is then
`poll`ed complete, and then `notify` the same waker again before a
new future is fetched, that new future will be marked as
non-complete initially and wait for a third `notify`.

The fix is luckily rather trivial, when we `notify` a future, if it
is completed immediately, simply wipe the future state so that we
look at the pending-notify flag when we generate the next future.

21 months agoMerge pull request #2061 from TheBlueMatt/2023-02-114-upstream-bindings
Matt Corallo [Wed, 1 Mar 2023 18:57:12 +0000 (18:57 +0000)]
Merge pull request #2061 from TheBlueMatt/2023-02-114-upstream-bindings

`C-not exported` tags for 0.0.114

21 months agoTag types used for the TLV macros with `(C-not exported)` 2023-02-114-upstream-bindings
Matt Corallo [Tue, 28 Feb 2023 19:59:34 +0000 (19:59 +0000)]
Tag types used for the TLV macros with `(C-not exported)`

Obviously bindings users can't use the Rust TLV-implementation
macros, so there's no reason to export typsed used exclusively by
them.

21 months agoMark `IndexedMap` types as `(C-not exported)`
Matt Corallo [Tue, 28 Feb 2023 19:42:31 +0000 (19:42 +0000)]
Mark `IndexedMap` types as `(C-not exported)`

While we could try to expose the type explicitly, we already have
alternative accessors for bindings, and mapping `Hash`, `Ord` and
the other requirements for `IndexedMap` would be a good chunk of
additional work.

21 months agoRemove peers from the `node_id_to_descriptor` even without init
Matt Corallo [Tue, 28 Feb 2023 21:28:13 +0000 (21:28 +0000)]
Remove peers from the `node_id_to_descriptor` even without init

When a peer has finished the noise handshake, but has not yet
completed the lightning `Init`-based handshake, they will be
present in the `node_id_to_descriptor` set, even though
`Peer::handshake_complete()` returns false. Thus, when we go to
disconnect such a peer, we must ensure that we remove it from the
descriptor set as well.

Failing to do so caused an `Inconsistent peers set state!` panic in
the C bindings network handler.

21 months agoMerge pull request #2046 from TheBlueMatt/2023-02-rgs-robust-and-log
Wilmer Paulino [Tue, 28 Feb 2023 19:36:04 +0000 (11:36 -0800)]
Merge pull request #2046 from TheBlueMatt/2023-02-rgs-robust-and-log

Do not fail to apply RGS updates for removed channels

21 months agoSurface bitcoind rpc error code
John Cantrell [Tue, 28 Feb 2023 16:39:29 +0000 (11:39 -0500)]
Surface bitcoind rpc error code

Users of the RpcClient had no way to access the error code
returned by bitcoind's rpc.  We embed a new RpcError struct
as the inner error for the returned io::Error. Users can access
both the code and the message using this inner struct.

21 months agoAdd some basic logging to Rapid Gossip Sync processing 2023-02-rgs-robust-and-log
Matt Corallo [Thu, 23 Feb 2023 19:20:41 +0000 (19:20 +0000)]
Add some basic logging to Rapid Gossip Sync processing

21 months agoMake log macros more usable outside of the `lightning` crate
Matt Corallo [Thu, 23 Feb 2023 19:20:09 +0000 (19:20 +0000)]
Make log macros more usable outside of the `lightning` crate

... by using explicit paths rather than requiring imports.

21 months agoDo not fail to apply RGS updates for removed channels
Matt Corallo [Thu, 23 Feb 2023 19:06:21 +0000 (19:06 +0000)]
Do not fail to apply RGS updates for removed channels

If we receive a Rapid Gossip Sync update for channels where we are
missing the existing channel data, we should ignore the missing
channel. This can happen in a number of cases, whether because we
received updated channel information via an onion error from an
HTLC failure or because we've partially synced the graph from a
peer over the standard lightning P2P protocol.

21 months agoMerge pull request #2006 from TheBlueMatt/2023-02-no-recursive-read-locks v0.0.114-beta
Wilmer Paulino [Tue, 28 Feb 2023 08:24:16 +0000 (00:24 -0800)]
Merge pull request #2006 from TheBlueMatt/2023-02-no-recursive-read-locks

Refuse recursive read locks

21 months agoMerge pull request #2015 from TheBlueMatt/2023-02-no-dumb-redundant-fields
Matt Corallo [Tue, 28 Feb 2023 07:55:56 +0000 (07:55 +0000)]
Merge pull request #2015 from TheBlueMatt/2023-02-no-dumb-redundant-fields

21 months agoMake sure individual mutexes are constructed on different lines 2023-02-no-recursive-read-locks
Matt Corallo [Sun, 26 Feb 2023 20:22:28 +0000 (20:22 +0000)]
Make sure individual mutexes are constructed on different lines

Our lockdep logic (on Windows) identifies a mutex based on which
line it was constructed on. Thus, if we have two mutexes
constructed on the same line it will generate false positives.

21 months agoExport RUST_BACKTRACE=1 in `--feature backtrace` CI test
Matt Corallo [Fri, 24 Feb 2023 20:29:45 +0000 (20:29 +0000)]
Export RUST_BACKTRACE=1 in `--feature backtrace` CI test

as this test often fails on windows which is hard to debug locally
for most contributors.

21 months agoDisallow taking two instances of the same mutex at the same time
Matt Corallo [Wed, 22 Feb 2023 22:54:38 +0000 (22:54 +0000)]
Disallow taking two instances of the same mutex at the same time

Taking two instances of the same mutex may be totally fine, but it
requires a total lockorder that we cannot (trivially) check. Thus,
its generally unsafe to do if we can avoid it.

To discourage doing this, here we default to panicing on such locks
in our lockorder tests, with a separate lock function added that is
clearly labeled "unsafe" to allow doing so when we can guarantee a
total lockorder.

This requires adapting a number of sites to the new API, including
fixing a bug this turned up in `ChannelMonitor`'s `PartialEq` where
no lockorder was guaranteed.

21 months agoRefuse recursive read locks in lockorder testing
Matt Corallo [Thu, 2 Feb 2023 22:38:54 +0000 (22:38 +0000)]
Refuse recursive read locks in lockorder testing

Our existing lockorder tests assume that a read lock on a thread
that is already holding the same read lock is totally fine. This
isn't at all true. The `std` `RwLock` behavior is
platform-dependent - on most platforms readers can starve writers
as readers will never block for a pending writer. However, on
platforms where this is not the case, one thread trying to take a
write lock may deadlock with another thread that both already has,
and is attempting to take again, a read lock.

Worse, our in-tree `FairRwLock` exhibits this behavior explicitly
on all platforms to avoid the starvation issue.

Thus, we shouldn't have any special handling for allowing recursive
read locks, so we simply remove it here.

21 months agoDon't `per_peer_state` read locks recursively in monitor updating
Matt Corallo [Wed, 22 Feb 2023 22:10:46 +0000 (22:10 +0000)]
Don't `per_peer_state` read locks recursively in monitor updating

When handling a `ChannelMonitor` update via the new
`handle_new_monitor_update` macro, we always call the macro with
the `per_peer_state` read lock held and have the macro drop the
per-peer state lock. Then, when handling the resulting updates, we
may take the `per_peer_state` read lock again in another function.

In a coming commit, recursive read locks will be disallowed, so we
have to drop the `per_peer_state` read lock before calling
additional functions in `handle_new_monitor_update`, which we do
here.

21 months agoExpect callers to hold read locks before `channel_monitor_updated`
Matt Corallo [Fri, 3 Feb 2023 00:46:50 +0000 (00:46 +0000)]
Expect callers to hold read locks before `channel_monitor_updated`

Our existing lockorder tests assume that a read lock on a thread
that is already holding the same read lock is totally fine. This
isn't at all true. The `std` `RwLock` behavior is
platform-dependent - on most platforms readers can starve writers
as readers will never block for a pending writer. However, on
platforms where this is not the case, one thread trying to take a
write lock may deadlock with another thread that both already has,
and is attempting to take again, a read lock.

Worse, our in-tree `FairRwLock` exhibits this behavior explicitly
on all platforms to avoid the starvation issue.

Sadly, a user ended up hitting this deadlock in production in the
form of a call to `get_and_clear_pending_msg_events` which holds
the `ChannelManager::total_consistency_lock` before calling
`process_pending_monitor_events` and eventually
`channel_monitor_updated`, which tries to take the same read lock
again.

Luckily, the fix is trivial, simply remove the redundand read lock
in `channel_monitor_updated`.

Fixes #2000

21 months agoHold the `total_consistency_lock` while in `outbound_payment` fns
Matt Corallo [Fri, 3 Feb 2023 00:33:27 +0000 (00:33 +0000)]
Hold the `total_consistency_lock` while in `outbound_payment` fns

We previously avoided holding the `total_consistency_lock` while
doing crypto operations to build onions. However, now that we've
abstracted out the outbound payment logic into a utility module,
ensuring the state is consistent at all times is now abstracted
away from code authors and reviewers, making it likely to break.

Further, because we now call `send_payment_along_path` both with,
and without, the `total_consistency_lock`, and because recursive
read locks may deadlock, it would now be quite difficult to figure
out which paths through `outbound_payment` need the lock and which
don't.

While it may slow writes somewhat, it's not really worth trying to
figure out this mess, instead we just hold the
`total_consistency_lock` before going into `outbound_payment`
functions.

21 months agoRemove the `final_cltv_expiry_delta` in `RouteParameters` entirely 2023-02-no-dumb-redundant-fields
Matt Corallo [Mon, 6 Feb 2023 22:12:09 +0000 (22:12 +0000)]
Remove the `final_cltv_expiry_delta` in `RouteParameters` entirely

fbc08477e8dcdd8f3f2ada8ca77388b6185febe2 purported to "move" the
`final_cltv_expiry_delta` field to `PaymentParamters` from
`RouteParameters`. However, for naive backwards-compatibility
reasons it left the existing on in place and only added a new,
redundant field in `PaymentParameters`.

It turns out there's really no reason for this - if we take a more
critical eye towards backwards compatibility we can figure out the
correct value in every `PaymentParameters` while deserializing.

We do this here - making `PaymentParameters` a `ReadableArgs`
taking a "default" `cltv_expiry_delta` when it goes to read. This
allows existing `RouteParameters` objects to pass the read
`final_cltv_expiry_delta` field in to be used if the new field
wasn't present.

21 months agoSupport `ReadableArgs` types across in the TLV struct serialization
Matt Corallo [Mon, 6 Feb 2023 21:56:39 +0000 (21:56 +0000)]
Support `ReadableArgs` types across in the TLV struct serialization

This adds `required` support for trait-wrapped reading (e.g. for
objects read via `ReadableArgs`) as well as support for the
trait-wrapped reading syntax across the TLV struct/enum
serialization macros.

21 months agoRequire a non-0 number of non-empty paths when deserializing routes
Matt Corallo [Mon, 6 Feb 2023 21:43:10 +0000 (21:43 +0000)]
Require a non-0 number of non-empty paths when deserializing routes

When we read a `Route` (or a list of `RouteHop`s), we should never
have zero paths or zero `RouteHop`s in a path. As such, its fine to
simply reject these at deserialization-time. Technically this could
lead to something which we can generate not round-trip'ing
serialization, but that seems okay here.

21 months agoMerge pull request #2055 from TheBlueMatt/2023-02-fning-msrv
Matt Corallo [Mon, 27 Feb 2023 22:30:14 +0000 (22:30 +0000)]
Merge pull request #2055 from TheBlueMatt/2023-02-fning-msrv

Remove the lightning-transaction-sync MSRV

21 months agoMove `lightning-transaction-sync` out of the main workspace 2023-02-fning-msrv
Matt Corallo [Mon, 27 Feb 2023 17:32:07 +0000 (17:32 +0000)]
Move `lightning-transaction-sync` out of the main workspace

Because `lightning-transaction-sync` does not have an MSRV (and
because its dev-dependencies are huge), we can't build it by
default when devs run `cargo test`, so it is moved out of the
top-level workspace.

21 months agoRemove the `lightning-transaction-sync` MSRV
Matt Corallo [Mon, 27 Feb 2023 17:31:15 +0000 (17:31 +0000)]
Remove the `lightning-transaction-sync` MSRV

Apparently it has dependencies that don't track an MSRV at all, so
we can't practically enforce one in CI.

21 months agoFix silent rebase conflict in previous PR
Matt Corallo [Mon, 27 Feb 2023 18:28:26 +0000 (18:28 +0000)]
Fix silent rebase conflict in previous PR

21 months agoMerge pull request #2043 from valentinewallace/2023-02-initial-send-path-fails
Matt Corallo [Mon, 27 Feb 2023 18:10:27 +0000 (18:10 +0000)]
Merge pull request #2043 from valentinewallace/2023-02-initial-send-path-fails

`PaymentPathFailed`: add initial send error details

21 months agoMerge pull request #2033 from tnull/2023-02-make-esplora-sync-test-more-robust
Matt Corallo [Mon, 27 Feb 2023 17:55:43 +0000 (17:55 +0000)]
Merge pull request #2033 from tnull/2023-02-make-esplora-sync-test-more-robust

Make `test_esplora_syncs` more robust

21 months agoMerge pull request #2025 from TheBlueMatt/2023-02-no-pub-genesis-hashes
Matt Corallo [Mon, 27 Feb 2023 17:50:22 +0000 (17:50 +0000)]
Merge pull request #2025 from TheBlueMatt/2023-02-no-pub-genesis-hashes

Remove genesis block hash from public API

21 months agoFix PaymentPathFailed generation and scid on initial send
Valentine Wallace [Fri, 24 Feb 2023 03:46:45 +0000 (22:46 -0500)]
Fix PaymentPathFailed generation and scid on initial send

21 months agoChange PaymentPathFailed's optional network update to a Failure enum
Valentine Wallace [Mon, 13 Feb 2023 22:55:42 +0000 (17:55 -0500)]
Change PaymentPathFailed's optional network update to a Failure enum

This let us capture the errors when we fail without committing to an HTLC vs
failing via update_fail.

21 months agoImplement writeable for APIError
Valentine Wallace [Sun, 19 Feb 2023 23:32:29 +0000 (18:32 -0500)]
Implement writeable for APIError

21 months agoser_macros: Document behavior of upgradable_* variants
Valentine Wallace [Sat, 25 Feb 2023 21:03:43 +0000 (16:03 -0500)]
ser_macros: Document behavior of upgradable_* variants

21 months agoFix upgradable_required fields to actually be required in lower level macros
Valentine Wallace [Sun, 19 Feb 2023 21:52:22 +0000 (16:52 -0500)]
Fix upgradable_required fields to actually be required in lower level macros

When using lower level macros such as read_tlv_stream, upgradable_required
fields have been treated as regular options. This is incorrect, they should
either be upgradable_options or treated as required fields.

21 months agoMerge pull request #1977 from jkczyz/2023-01-offers-fuzz
Matt Corallo [Sat, 25 Feb 2023 18:03:51 +0000 (18:03 +0000)]
Merge pull request #1977 from jkczyz/2023-01-offers-fuzz

BOLT 12 deserialization fuzzers

21 months agoRename OptionDeserWrapper->RequiredWrapper
Valentine Wallace [Sat, 25 Feb 2023 00:50:24 +0000 (19:50 -0500)]
Rename OptionDeserWrapper->RequiredWrapper

Makes more sense and sets us up for the UpgradableRequired version of it

21 months agoDisambiguate ignorable and ignorable_option
Valentine Wallace [Mon, 20 Feb 2023 17:42:45 +0000 (12:42 -0500)]
Disambiguate ignorable and ignorable_option

Would rather not rename ignorable to ignorable_required, so rename both of them
to upgradable_*

21 months agoSupport deserializing an Option-al MaybeReadable
Valentine Wallace [Mon, 13 Feb 2023 21:49:22 +0000 (16:49 -0500)]
Support deserializing an Option-al MaybeReadable

Prior to this change, our impl_writeable_tlv_based macros only supported
deserializing a MaybeReadable if it's non-Optional.

21 months agoRemove all_paths_failed from PaymentPathFailed
Valentine Wallace [Sun, 12 Feb 2023 00:38:48 +0000 (19:38 -0500)]
Remove all_paths_failed from PaymentPathFailed

This field was previous useful in manual retries for users to know when all
paths of a payment have failed and it is safe to retry. Now that we support
automatic retries in ChannelManager and no longer support manual retries, the
field is no longer useful.

For backwards compat, we now always write false for this field. If we didn't do
this, previous versions would default this field's value to true, which can be
problematic because some clients have relied on the field to indicate when a
full payment retry is safe.

21 months agoMerge pull request #2050 from douglaz/import-lightning-io-futures
wpaulino [Fri, 24 Feb 2023 19:03:32 +0000 (11:03 -0800)]
Merge pull request #2050 from douglaz/import-lightning-io-futures

Only import lightning::io if futures are enabled

21 months agoOnly import lightning::io if futures are enabled
Allan Douglas R. de Oliveira [Fri, 24 Feb 2023 02:56:11 +0000 (02:56 +0000)]
Only import lightning::io if futures are enabled

21 months agoMake `test_esplora_syncs` more robust
Elias Rohrer [Wed, 15 Feb 2023 00:16:23 +0000 (18:16 -0600)]
Make `test_esplora_syncs` more robust

The test generally works and the parts in question *should* never fail.
However, they did, so we give the test server instances some leeway.

21 months agoFix amount overflow in Invoice building
Jeffrey Czyz [Thu, 16 Feb 2023 02:17:18 +0000 (20:17 -0600)]
Fix amount overflow in Invoice building

An overflow can occur when multiplying the offer amount by the requested
quantity when no amount is given in the request. Return an error instead
of overflowing.

21 months agoFix amount overflow in Offer parsing and building
Jeffrey Czyz [Wed, 15 Feb 2023 22:43:41 +0000 (16:43 -0600)]
Fix amount overflow in Offer parsing and building

An overflow can occur when multiplying the offer amount by the requested
quantity when checking if the given amount is enough. Return an error
instead of overflowing.

21 months agoFuzz test for bech32 decoding
Jeffrey Czyz [Thu, 9 Feb 2023 17:09:23 +0000 (11:09 -0600)]
Fuzz test for bech32 decoding

Fuzz testing bech32 decoding along with deserializing the underlying
message can result in overly exhaustive searches. Instead, the message
deserializations are now fuzzed separately. Add fuzzing for bech32
decoding.

21 months agoExpose Bech32Encode trait for fuzzing
Jeffrey Czyz [Thu, 9 Feb 2023 16:59:11 +0000 (10:59 -0600)]
Expose Bech32Encode trait for fuzzing

In order to fuzz test Bech32Encode parsing independent of the underlying
message deserialization, the trait needs to be exposed. Conditionally
expose it only for fuzzing.

21 months agoFuzz test for parsing Invoice
Jeffrey Czyz [Fri, 20 Jan 2023 22:30:45 +0000 (16:30 -0600)]
Fuzz test for parsing Invoice

An invoice is serialized as a TLV stream and encoded as bytes. Add a
fuzz test that parses the TLV stream and deserializes the underlying
Invoice. Then compare the original bytes with those obtained by
re-serializing the Invoice.

21 months agoFuzz test for parsing InvoiceRequest
Jeffrey Czyz [Fri, 20 Jan 2023 19:34:34 +0000 (13:34 -0600)]
Fuzz test for parsing InvoiceRequest

An invoice request is serialized as a TLV stream and encoded as bytes.
Add a fuzz test that parses the TLV stream and deserializes the
underlying InvoiceRequest. Then compare the original bytes with those
obtained by re-serializing the InvoiceRequest.

21 months agoRename `BestBlock::from_genesis` to `from_network` for clarity 2023-02-no-pub-genesis-hashes
Matt Corallo [Wed, 15 Feb 2023 06:09:00 +0000 (06:09 +0000)]
Rename `BestBlock::from_genesis` to `from_network` for clarity

21 months agoRemove genesis block hash from public API
Matt Corallo [Thu, 9 Feb 2023 19:20:22 +0000 (19:20 +0000)]
Remove genesis block hash from public API

Forcing users to pass a genesis block hash has ended up being
error-prone largely due to byte-swapping questions for bindings
users. Further, our API is currently inconsistent - in
`ChannelManager` we take a `Bitcoin::Network` but in `NetworkGraph`
we take the genesis block hash.

Luckily `NetworkGraph` is the only remaining place where we require
users pass the genesis block hash, so swapping it for a `Network`
is a simple change.

21 months agoAdd missing import path in ser macro
Valentine Wallace [Sun, 19 Feb 2023 23:32:06 +0000 (18:32 -0500)]
Add missing import path in ser macro

21 months agoMerge pull request #2014 from valentinewallace/2023-02-rework-partial-pmt-fail
Matt Corallo [Thu, 23 Feb 2023 21:54:16 +0000 (21:54 +0000)]
Merge pull request #2014 from valentinewallace/2023-02-rework-partial-pmt-fail

Rework auto-retry send errors

21 months agoClarify Retry::Timeout vs PaymentParams::expiry_time in docs
Valentine Wallace [Thu, 23 Feb 2023 20:49:44 +0000 (15:49 -0500)]
Clarify Retry::Timeout vs PaymentParams::expiry_time in docs

21 months agoFix outdated PendingOutboundPayment::Abandoned docs
Valentine Wallace [Sun, 12 Feb 2023 00:35:48 +0000 (19:35 -0500)]
Fix outdated PendingOutboundPayment::Abandoned docs

21 months agoOn initial send retries, avoid previously failed scids
Valentine Wallace [Thu, 16 Feb 2023 21:40:51 +0000 (16:40 -0500)]
On initial send retries, avoid previously failed scids

Previously, we could have tried the same failed channels over and over until
retries are exhausted.

21 months agoIn-line retry_with_route method
Valentine Wallace [Sun, 19 Feb 2023 21:12:24 +0000 (16:12 -0500)]
In-line retry_with_route method

Since it's only used one place now

21 months agoRework auto retry send errors
Valentine Wallace [Fri, 10 Feb 2023 21:09:01 +0000 (15:09 -0600)]
Rework auto retry send errors

Prior to this, we returned PaymentSendFailure from auto retry send payment
methods. This implied that we might return a PartialFailure from them, which
has never been the case. So it makes sense to rework the errors to be a better
fit for the methods.

We're taking error handling in a totally different direction now to make it
more asynchronous, see send_payment_internal for more information.

21 months agoFix InvalidRoute error to be ChannelUnavailable
Valentine Wallace [Wed, 22 Feb 2023 19:09:58 +0000 (14:09 -0500)]
Fix InvalidRoute error to be ChannelUnavailable

InvalidRoute is reserved for malformed routes, not routes where a channel or
its peer is unavailable

21 months agoMerge pull request #1897 from TheBlueMatt/2022-11-monitor-updates-always-async
Matt Corallo [Wed, 22 Feb 2023 19:12:31 +0000 (19:12 +0000)]
Merge pull request #1897 from TheBlueMatt/2022-11-monitor-updates-always-async

Always process `ChannelMonitorUpdate`s asynchronously