rust-lightning
18 months agoInclude all channel route hints if no connected channels exist 2022-10-disconnected-hints
Matt Corallo [Thu, 13 Oct 2022 21:57:09 +0000 (21:57 +0000)]
Include all channel route hints if no connected channels exist

Mobile clients often take a second or two before they reconnect to
their peers as its not always clear immediately that connections
have been killed (especially on iOS). This can cause us to
spuriously fail to include route hints in our invoices if we're on
mobile.

The fix is simple, if we're selecting channels to include in route
hints and we're not not connected to the peer for any of our
channels, we should simply include the hints for all channels, even
though we're disconencted.

Fixes #1768.

18 months agoMerge pull request #1754 from TheBlueMatt/2022-10-better-liq-halflife-docs
Matt Corallo [Tue, 11 Oct 2022 21:54:48 +0000 (21:54 +0000)]
Merge pull request #1754 from TheBlueMatt/2022-10-better-liq-halflife-docs

Rewrite some documentation on `ProbabilisticScorer` and increase half-life to 6 hours.

18 months agoIncrease the default `liquidity_offset_half_life` to six hours 2022-10-better-liq-halflife-docs
Matt Corallo [Wed, 5 Oct 2022 19:23:56 +0000 (19:23 +0000)]
Increase the default `liquidity_offset_half_life` to six hours

Even at relatively high payment volumes, decaying knowledge of each
individual channel every hour causes aggressive retrying of
channels as we quickly forget the state of a channel. Even with the
historical tracker, this isn't fully remedied, as we'll track the
history bounds with the decayed value.

Instead, we decay every six hours here, reducing how often we'll
retry a channel due to decay.

In addition to this, the decay likely needs to be substantially
more linear, as tracked in #1752.

18 months agoRewrite documentation some on `ProbabilisticScorer`
Matt Corallo [Wed, 5 Oct 2022 19:10:06 +0000 (19:10 +0000)]
Rewrite documentation some on `ProbabilisticScorer`

We had some user confusion on how the probabilistic scorer works,
especially in reference to the half-life parameter. This attempts
to clarify how the bounds work, and how they are decayed.

18 months agoMerge pull request #1744 from tnull/2022-09-fix-bp-futures-doc
Matt Corallo [Mon, 10 Oct 2022 20:29:11 +0000 (20:29 +0000)]
Merge pull request #1744 from tnull/2022-09-fix-bp-futures-doc

Fix `background-processor` doc build for `futures`

18 months agoAdd `futures` CI check
Elias Rohrer [Mon, 10 Oct 2022 18:47:18 +0000 (14:47 -0400)]
Add `futures` CI check

This adds testing of the `futures` feature to CI. In order to avoid
introducing a dependency on `std`, we switch to using the `futures-util`
crate directly enabling only a subset of features. To this end, we also
switch to using the `select_biased!` macro, which is equivalent to
`select!` except that it doesn't choose ready futures pseudo-randomly
at runtime.

18 months agoFix `background-processor` doc build for `futures`
Elias Rohrer [Mon, 26 Sep 2022 12:41:59 +0000 (14:41 +0200)]
Fix `background-processor` doc build for `futures`

18 months agoMerge pull request #1756 from TheBlueMatt/2022-10-rgs-no-std
valentinewallace [Fri, 7 Oct 2022 21:01:10 +0000 (17:01 -0400)]
Merge pull request #1756 from TheBlueMatt/2022-10-rgs-no-std

Fix `rapid-gossip-sync` `no-std` and properly test no-std in CI

18 months agoMerge pull request #1649 from dunxen/2022-08-implementnodefailure
Matt Corallo [Fri, 7 Oct 2022 18:41:19 +0000 (18:41 +0000)]
Merge pull request #1649 from dunxen/2022-08-implementnodefailure

Implement permanent node failure handling

18 months agoMerge pull request #1693 from valentinewallace/2022-09-readme-updates
Jeffrey Czyz [Fri, 7 Oct 2022 17:44:52 +0000 (12:44 -0500)]
Merge pull request #1693 from valentinewallace/2022-09-readme-updates

Fix outdated README sections

18 months agoMerge pull request #1758 from TheBlueMatt/2022-10-fix-pre-notified-future
Matt Corallo [Fri, 7 Oct 2022 17:38:50 +0000 (17:38 +0000)]
Merge pull request #1758 from TheBlueMatt/2022-10-fix-pre-notified-future

Fix (and test) `Future` creation after a `Notifier` was notified

18 months agoTest a full `no-std` build in the `no-std-check` crate in CI 2022-10-rgs-no-std
Matt Corallo [Thu, 6 Oct 2022 15:44:03 +0000 (15:44 +0000)]
Test a full `no-std` build in the `no-std-check` crate in CI

Rust is incredibly forgiving in attempts to access `std`, making it
rather difficult to test `no-std` properly. In practice, the only
decent way to do so is to actually build for a platform that does
not have `std`, which we do here by building the `no-std-check`
crate for `arm-thumbv7m-none-eabi`.

18 months agoMerge pull request #1625 from TheBlueMatt/2022-07-history-tracking
Matt Corallo [Fri, 7 Oct 2022 16:32:10 +0000 (16:32 +0000)]
Merge pull request #1625 from TheBlueMatt/2022-07-history-tracking

18 months agoMerge pull request #1751 from TheBlueMatt/2022-10-fix-score-log-direction
valentinewallace [Fri, 7 Oct 2022 16:28:23 +0000 (12:28 -0400)]
Merge pull request #1751 from TheBlueMatt/2022-10-fix-score-log-direction

Correct the directionality of liquidity non-update messages

18 months agoMerge pull request #1760 from TheBlueMatt/2022-10-invoice-builder-round
Matt Corallo [Fri, 7 Oct 2022 16:25:25 +0000 (16:25 +0000)]
Merge pull request #1760 from TheBlueMatt/2022-10-invoice-builder-round

18 months agoFix outdated README sections
Valentine Wallace [Fri, 2 Sep 2022 21:55:53 +0000 (17:55 -0400)]
Fix outdated README sections

18 months agoRemove and track perm failed nodes & channels
Duncan Dean [Fri, 26 Aug 2022 10:54:16 +0000 (12:54 +0200)]
Remove and track perm failed nodes & channels

We never had the `NetworkGraph::node_failed` method implemented. The
scorer now handles non-permanent failures by downgrading nodes, so we
don't want that implemented.

The method is renamed to `node_failed_permanent` to explicitly indicate
that this is the only case it handles. We also add tracking in the form
of two maps as fields of `NetworkGraph`, namely, `removed_nodes` and
`removed_channels`. We track these removed graph entries to ensure we
don't just resync them right away from gossip soon after removing them.
We stop tracking these removed nodes whenever `remove_stale_channels_and_tracking()`
is called and the entries have been tracked for longer than
`REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS` which is currently set to one
week.

18 months agoDrop the subsecond part of timestamps when constructing invoices 2022-10-invoice-builder-round
Matt Corallo [Fri, 7 Oct 2022 01:38:56 +0000 (01:38 +0000)]
Drop the subsecond part of timestamps when constructing invoices

We had a user who was confused why an invoice failed to round-trip
(i.e. was not `PartialEq` with itself after write/read) when a
subsecond creation time was used (e.g. via the `from_system_time`
constructor).

This commit should address this confusion by dropping subsecond
parts in easily-accessible constructors when creating BOLT 11
invoices.

Fixes #1759.

18 months agoSupport platforms with only 32-bit atomics
Matt Corallo [Thu, 6 Oct 2022 16:48:14 +0000 (16:48 +0000)]
Support platforms with only 32-bit atomics

Given there is only one instance in our code of `AtomicU64` its
simplest to just remove it rather than try to add some kind of
wrapper.

18 months agoTest `rapid-gossip-sync` in `no-std` in CI
Matt Corallo [Thu, 6 Oct 2022 15:41:58 +0000 (15:41 +0000)]
Test `rapid-gossip-sync` in `no-std` in CI

18 months agoUpdate `rapid-gossip-sync` docs to not reference `std`-only methods
Matt Corallo [Thu, 6 Oct 2022 19:38:17 +0000 (19:38 +0000)]
Update `rapid-gossip-sync` docs to not reference `std`-only methods

18 months agoFix (and test) `Future` creation after a `Notifier` was notified 2022-10-fix-pre-notified-future
Matt Corallo [Thu, 6 Oct 2022 23:54:52 +0000 (23:54 +0000)]
Fix (and test) `Future` creation after a `Notifier` was notified

After a `Notifier` has been `notify`'d, attempts to `get_future`
should return a `Future` which is pre-completed, however this was
not the case.

This commit simply fixes the behavior, adding a test to demonstrate
the issue.

18 months agoDecay historical liquidity tracking when no new data is added 2022-07-history-tracking
Matt Corallo [Mon, 22 Aug 2022 22:41:31 +0000 (22:41 +0000)]
Decay historical liquidity tracking when no new data is added

To avoid scoring based on incredibly old historical liquidity data,
we add a new half-life here which is used to (very slowly) decay
historical liquidity tracking buckets.

18 months agoTrack a reference to scoring parameters in DirectedChannelLiquidity
Matt Corallo [Mon, 22 Aug 2022 22:40:02 +0000 (22:40 +0000)]
Track a reference to scoring parameters in DirectedChannelLiquidity

This simplifies adding additional half lives in
DirectedChannelLiquidity by simply storing a reference to the full
parameter set rather than only the single current half-life.

18 months agoCalculate a new penalty based on historical channel liquidity range
Matt Corallo [Thu, 21 Jul 2022 02:08:28 +0000 (02:08 +0000)]
Calculate a new penalty based on historical channel liquidity range

Our current `ProbabilisticScorer` attempts to build a model of the
current liquidity across the payment channel network. This works
fine to ignore channels we *just* tried to pay through, but it
fails to remember patterns over longer time horizons.

Specifically, there are *many* channels within the network that are
very often either fully saturated in one direction, or are
regularly rebalanced and rarely saturated. While our model may
discover that, when it decays its offsets or if there is a
temporary change in liquidity, it effectively forgets the "normal"
state of the channel.

This causes substantially suboptimal routing in practice, and
avoiding discarding older knowledge when new datapoints come in is
a potential solution to this.

Here, we implement one such design, using the decaying buckets
added in the previous commit to calculate a probability of payment
success based on a weighted average of recent liquidity estimates
for a channel.

For each min/max liquidity bucket pair (where the min liquidity is
less than the max liquidity), we can calculate the probability that
a payment succeeds using our traditional `amount / capacity`
formula. From there, we weigh the probability by the number of
points in each bucket pair, calculating a total probability for the
payment, and assigning a penalty using the same log-probability
calculation used for the non-historical penalties.

18 months agoTrack history of where channel liquidities have been in the past
Matt Corallo [Tue, 19 Jul 2022 22:37:16 +0000 (22:37 +0000)]
Track history of where channel liquidities have been in the past

This introduces two new fields to the `ChannelLiquidity` struct -
`min_liquidity_offset_history` and `max_liquidity_offset_history`,
both an array of 8 `u16`s. Each entry represents the proportion of
time that we spent with the min or max liquidity offset in the
given 1/8th of the channel's liquidity range. ie the first bucket
in `min_liquidity_offset_history` represents the proportion of time
we've thought the channel's minimum liquidity is lower than 1/8th's
the channel's capacity.

Each bucket is stored, effectively, as a fixed-point number with
5 bits for the fractional part, which is incremented by one (ie 32)
each time we update our liquidity estimates and decide our
estimates are in that bucket. We then decay each bucket by
2047/2048.

Thus, memory of a payment sticks around for more than 8,000
data points, though the majority of that memory decays after 1,387
data points.

18 months agoCorrect the directionality of liquidity non-update messages 2022-10-fix-score-log-direction
Matt Corallo [Wed, 5 Oct 2022 02:11:00 +0000 (02:11 +0000)]
Correct the directionality of liquidity non-update messages

When we log liquidity updates, if we decline to update anything as
the new bounds are already within the old bounds, the
directionality of the log entries was reversed.

While we're at it, we also log the old values.

18 months agoCorrect `rapid-gossip-sync` `no-std` build and test
Matt Corallo [Thu, 6 Oct 2022 15:42:41 +0000 (15:42 +0000)]
Correct `rapid-gossip-sync` `no-std` build and test

While `rapid-gossip-sync` recently gained a `no-std` feature, it
didn't actually work, as there were still dangling references to
`std` and prelude assumptions. This makes `rapid-gossip-sync`
build (and test) properly in `no-std`.

19 months agoMerge pull request #1106 from TheBlueMatt/2021-10-no-perm-err-broadcast
Matt Corallo [Thu, 29 Sep 2022 22:02:07 +0000 (22:02 +0000)]
Merge pull request #1106 from TheBlueMatt/2021-10-no-perm-err-broadcast

Do not broadcast commitment txn on Permanent mon update failure

19 months agoClarify ambiguous comment in persist methods 2021-10-no-perm-err-broadcast
Matt Corallo [Wed, 24 Aug 2022 21:07:44 +0000 (21:07 +0000)]
Clarify ambiguous comment in persist methods

19 months agoRename APIError::MonitorUpdateFailed to MonitorUpdateInProgress
Matt Corallo [Thu, 29 Sep 2022 20:26:48 +0000 (20:26 +0000)]
Rename APIError::MonitorUpdateFailed to MonitorUpdateInProgress

This much more accurately represents the error, indicating that a
monitor update is in progress asynchronously and may complete at a
later time.

19 months agoRename `handle_monitor_err!()` `handle_monitor_update_res!`
Matt Corallo [Tue, 16 Aug 2022 22:16:48 +0000 (22:16 +0000)]
Rename `handle_monitor_err!()` `handle_monitor_update_res!`

19 months agoRename `Channel::monitor_update_failed` to `monitor_updating_paused`
Matt Corallo [Tue, 16 Aug 2022 22:15:32 +0000 (22:15 +0000)]
Rename `Channel::monitor_update_failed` to `monitor_updating_paused`

19 months agoAdd a TODO for an important issue for making async mon updates safe
Matt Corallo [Tue, 16 Aug 2022 21:58:06 +0000 (21:58 +0000)]
Add a TODO for an important issue for making async mon updates safe

If we receive a monitor event from a forwarded-to channel which
contains a preimage for an HTLC, we have to propogate that preimage
back to the forwarded-from channel monitor. However, once we have
that update, we're running in a relatively unsafe state - we have
the preimage in memory, but if we were to crash the forwarded-to
channel monitor will not regenerate the update with the preimage
for us. If we haven't managed to write the monitor update to the
forwarded-from channel by that point, we've lost the preimage, and,
thus, money!

19 months agoRework `chain::Watch` return types to make async updates less scary
Matt Corallo [Mon, 18 Jul 2022 01:32:27 +0000 (01:32 +0000)]
Rework `chain::Watch` return types to make async updates less scary

When a `chain::Watch` `ChannelMonitor` update method is called, the
user has three options:
 (a) persist the monitor update immediately and return success,
 (b) fail to persist the monitor update immediately and return
     failure,
 (c) return a flag indicating the monitor update is in progress and
     will complete in the future.

(c) is rather harmless, and in some deployments should be expected
to be the return value for all monitor update calls, but currently
requires returning `Err(ChannelMonitorUpdateErr::TemporaryFailure)`
which isn't very descriptive and sounds scarier than it is.

Instead, here, we change the return type used to be a single enum
(rather than a Result) and rename `TemporaryFailure`
`UpdateInProgress`.

19 months agoMerge pull request #1740 from TheBlueMatt/2022-09-invoice-bindings-nostd
valentinewallace [Mon, 26 Sep 2022 13:22:01 +0000 (09:22 -0400)]
Merge pull request #1740 from TheBlueMatt/2022-09-invoice-bindings-nostd

Don't make references to `std` in `lightning-invoice` in bindings

19 months agoMerge pull request #1742 from tnull/2022-09-remove-done-todo
valentinewallace [Mon, 26 Sep 2022 13:19:41 +0000 (09:19 -0400)]
Merge pull request #1742 from tnull/2022-09-remove-done-todo

Remove completed TODO

19 months agoDon't make references to `std` in `lightning-invoice` in bindings 2022-09-invoice-bindings-nostd
Matt Corallo [Sun, 25 Sep 2022 14:24:13 +0000 (14:24 +0000)]
Don't make references to `std` in `lightning-invoice` in bindings

As we support `no-std` for `lightning-invoice` builds, we should
support them in `c_bindings` as well, which we add a test for in
CI here.

19 months agoRemove done TODO
Elias Rohrer [Mon, 26 Sep 2022 09:20:50 +0000 (11:20 +0200)]
Remove done TODO

The migration to `LockTime` was already done in
7e05623befc111422d1d4230f4e51629566a2ae6, which however did not also
remove the TODO.

19 months agoMerge pull request #1737 from TheBlueMatt/2022-09-future-trait
Matt Corallo [Sun, 25 Sep 2022 07:51:40 +0000 (07:51 +0000)]
Merge pull request #1737 from TheBlueMatt/2022-09-future-trait

Add a bindings-only version of `Future::register_callback`

19 months agoAdd a bindings-only version of `Future::register_callback` 2022-09-future-trait
Matt Corallo [Fri, 23 Sep 2022 21:08:26 +0000 (21:08 +0000)]
Add a bindings-only version of `Future::register_callback`

While we could, in theory, add support to the bindings logic to map
`Box<dyn Trait>`, there isn't a whole lot of use doing so when its
incredibly trivial to do directly.

This adds a trivial wrapper around `Future::register_callback` that
is only built in bindings and which is linked in the
`register_callback` docs for visibility.

19 months agoMerge pull request #1734 from TheBlueMatt/2022-09-better-lock-name
valentinewallace [Fri, 23 Sep 2022 17:05:17 +0000 (13:05 -0400)]
Merge pull request #1734 from TheBlueMatt/2022-09-better-lock-name

Rename `MultiThreadedLockableScoreLock` `MultiThreadedScoreLock`

19 months agoRename `MultiThreadedLockableScoreLock` to `MultiThreadedScoreLock` 2022-09-better-lock-name
Matt Corallo [Fri, 23 Sep 2022 08:17:01 +0000 (08:17 +0000)]
Rename `MultiThreadedLockableScoreLock` to `MultiThreadedScoreLock`

as the first is quite a mouthful, and the second isn't materially
less specific.

19 months agoMerge pull request #1733 from TheBlueMatt/2022-09-downgrade-hashbrown
valentinewallace [Thu, 22 Sep 2022 16:48:39 +0000 (12:48 -0400)]
Merge pull request #1733 from TheBlueMatt/2022-09-downgrade-hashbrown

Downgrade `hashbrown` to meet MSRV

19 months agoMerge pull request #1731 from valentinewallace/2022-09-router-test-utils-mod
valentinewallace [Thu, 22 Sep 2022 15:51:47 +0000 (11:51 -0400)]
Merge pull request #1731 from valentinewallace/2022-09-router-test-utils-mod

Move router test utils into their own module

19 months agoDowngrade `hashbrown` to meet MSRV 2022-09-downgrade-hashbrown
Matt Corallo [Thu, 22 Sep 2022 14:07:25 +0000 (14:07 +0000)]
Downgrade `hashbrown` to meet MSRV

`hashbrown` depends on `ahash` which depends on `once_cell`. Sadly,
in https://github.com/matklad/once_cell/issues/201 the `once_cell`
maintainer decided they didn't want to do the work of having an
MSRV policy for `once_cell`, making `ahash`, and thus `hashbrown`
require the latest compiler. I've reached out to `ahash` to suggest
they drop the dependency (as they could trivially work around not
having it), but until then we simply downgrade `hashbrown`.

`rust-bitcoin` also requires an older `hashbrown` so we're actually
reducing our total `no-std` code here anyway.

19 months agoImport util::test_utils as ::ln_test_utils in router
Valentine Wallace [Tue, 20 Sep 2022 14:39:39 +0000 (10:39 -0400)]
Import util::test_utils as ::ln_test_utils in router

To disambiguate between util::test_utils and router::test_utils

19 months agoRename routing::router::test_utils to ::bench_utils
Valentine Wallace [Tue, 20 Sep 2022 14:08:57 +0000 (10:08 -0400)]
Rename routing::router::test_utils to ::bench_utils

To disambiguate it from routing::test_utils

19 months agoMerge pull request #1656 from ViktorTigerstrom/2022-08-forward-htlcs-as-standalone...
Matt Corallo [Tue, 20 Sep 2022 10:19:32 +0000 (10:19 +0000)]
Merge pull request #1656 from ViktorTigerstrom/2022-08-forward-htlcs-as-standalone-lock

Move `forward_htlcs` into standalone lock

19 months agoMove router test utils into their own module
Valentine Wallace [Mon, 15 Aug 2022 18:09:35 +0000 (14:09 -0400)]
Move router test utils into their own module

Useful for testing onion message pathfinding in upcoming PRs and any future
routing modules we add

19 months agoAdd lock order docs to `ChannelManager` fields
Viktor Tigerström [Mon, 15 Aug 2022 21:32:38 +0000 (23:32 +0200)]
Add lock order docs to `ChannelManager` fields

19 months agoMerge pull request #1729 from TheBlueMatt/2022-09-lockablescore-bindings
Matt Corallo [Mon, 19 Sep 2022 14:45:07 +0000 (14:45 +0000)]
Merge pull request #1729 from TheBlueMatt/2022-09-lockablescore-bindings

Add a `MutexGuard` wrapper for the bindings-only `LockableScore`

19 months agoMerge pull request #1728 from TheBlueMatt/2022-09-slices-not-vecs
Jeffrey Czyz [Mon, 19 Sep 2022 13:30:07 +0000 (08:30 -0500)]
Merge pull request #1728 from TheBlueMatt/2022-09-slices-not-vecs

Swap `Vec<&RouteHop>` parameters for slices

19 months agoAvoid returning a reference to a u64. 2022-09-slices-not-vecs
Matt Corallo [Sun, 18 Sep 2022 13:55:08 +0000 (13:55 +0000)]
Avoid returning a reference to a u64.

In c353c3ed7c40e689a3b9fb6730c6dabbd3c92cc5 an accessor method was
added which returns an `Option<&u64>`. While this allows Rust to
return an 8-byte object, returning a reference to something
pointer-sized is a somewhat strange API.

Instead, we opt for a straight `Option<u64>`, which is sadly
somewhat larger on the stack, but is simpler and already supported
in the bindings generation.

19 months agoSwap `Vec<&RouteHop>` parameters for slices
Matt Corallo [Sun, 18 Sep 2022 13:34:39 +0000 (13:34 +0000)]
Swap `Vec<&RouteHop>` parameters for slices

In c353c3ed7c40e689a3b9fb6730c6dabbd3c92cc5, new scorer-updating
methods were added to the `Router` object, however they were
passed as a `Vec` of references. We use the list-of-references
pattern to make bindings simpler (by not requiring allocations per
entry), however there's no reason prefer to passing a `Vec` over
a slice, given the `Vec` doesn't hold ownership of the objects
anyway.

19 months agoAdd a `MutexGuard` wrapper for the bindings-only `LockableScore` 2022-09-lockablescore-bindings
Matt Corallo [Mon, 19 Sep 2022 09:11:11 +0000 (09:11 +0000)]
Add a `MutexGuard` wrapper for the bindings-only `LockableScore`

In the bindings, we don't directly export any `std` types. Instead,
we provide trivial wrappers around them which expose only a
bindings-compatible API (and which is code in-crate, where the
bindings generator can see it).

We never quite finished this for `MultiThreadedLockableScore` - due
to some limitations in the bindings generator and the way the
scores are used in `lightning-invoice`, the scoring API ended up
being further concretized in patches for the bindings. Luckily the
scoring interface has been rewritten somewhat, and it so happens
that we can now generate bindings with the upstream code.

The final piece of the puzzle is done here, where we add a struct
which wraps `MutexGuard` so that we can expose the lock for
`MultiThreadedLockableScore`.

19 months agoRemove `forward_htlc` after `channel_state` lock order
Viktor Tigerström [Mon, 5 Sep 2022 20:16:32 +0000 (22:16 +0200)]
Remove `forward_htlc` after `channel_state` lock order

The `forward_htlc` was prior to this commit only held at the same time
as the `channel_state` lock during the write process of the
`ChannelManager`. This commit removes the lock order dependency, by
taking the `channel_state`lock temporarily during the write process.

19 months agoRemove unnecessary aquiring of the `channel_state` lock
Viktor Tigerström [Mon, 8 Aug 2022 19:54:06 +0000 (21:54 +0200)]
Remove unnecessary aquiring of the `channel_state` lock

19 months agoMove `forward_htlcs` into standalone lock
Viktor Tigerström [Mon, 8 Aug 2022 19:10:33 +0000 (21:10 +0200)]
Move `forward_htlcs` into standalone lock

As we are eventually removing the `channel_state` lock, this commit
moves the `forward_htlcs` map out of the `channel_state` lock, to ease
that process.

19 months agoMerge pull request #1725 from TheBlueMatt/2022-09-no-bench-lockorder
valentinewallace [Fri, 16 Sep 2022 21:12:49 +0000 (17:12 -0400)]
Merge pull request #1725 from TheBlueMatt/2022-09-no-bench-lockorder

Stop building with lockorder debugging in benchmarks

19 months agoMerge pull request #1694 from jurvis/jurvis/2022-08-move-scorer-from-router
Jeffrey Czyz [Fri, 16 Sep 2022 19:01:38 +0000 (14:01 -0500)]
Merge pull request #1694 from jurvis/jurvis/2022-08-move-scorer-from-router

Move `LockableScore` requirement away from `Router` trait

19 months agoMove Scorer requirement away from Router trait
Jurvis Tan [Thu, 15 Sep 2022 21:58:08 +0000 (14:58 -0700)]
Move Scorer requirement away from Router trait

We do this to enable users to create routers that do not need a scorer.
This can be useful if they are running a node the delegates pathfinding.

* Move `Score` type parameterization from `InvoicePayer` and `Router` to
`DefaultRouter`
* Adds a new field, `scorer`, to `DefaultRouter`
* Move `AccountsForInFlightHtlcs` to `DefaultRouter`, which we
will use to wrap the new `scorer` field, so scoring only happens in
`DefaultRouter` explicitly.
* Add scoring related functions to `Router` trait that we used to call
directly from `InvoicePayer`.
* Instead of parameterizing `scorer` in `find_route`, we replace it with
inflight_map so `InvoicePayer` can pass on information about inflight
HTLCs to the router.
* Introduced a new tuple struct, InFlightHtlcs, that wraps functionality
for querying used liquidity.

19 months agoStop building with lockorder debugging in benchmarks 2022-09-no-bench-lockorder
Matt Corallo [Fri, 16 Sep 2022 14:40:32 +0000 (14:40 +0000)]
Stop building with lockorder debugging in benchmarks

`cargo bench` sets `#[cfg(test)]` so our current checks for
enabling our lockorder debugging end up matching when we're trying
to build performance benchmarks.

This adds explicit checks to our debug_lockorder logic to filter
out `feature = "_bench_unstable"` builds.

19 months agoDo not broadcast commitment txn on Permanent mon update failure
Matt Corallo [Tue, 5 Oct 2021 04:32:49 +0000 (04:32 +0000)]
Do not broadcast commitment txn on Permanent mon update failure

See doc updates for more info on the edge case this prevents, and
there isn't really a strong reason why we would need to broadcast
the latest state immediately. Specifically, in the case of HTLC
claims (the most important reason to ensure we have state on chain
if it cannot be persisted), we will still force-close if there are
HTLCs which need claiming and are going to expire.

Surprisingly, there were no tests which failed as a result of this
change, but a new one has been added.

19 months agoMerge pull request #1708 from tnull/2022-09-rgs-unpub-modules
Arik [Thu, 15 Sep 2022 16:55:39 +0000 (09:55 -0700)]
Merge pull request #1708 from tnull/2022-09-rgs-unpub-modules

Improve RGS documentation

19 months agoAdd `no-std` support for RGS
Elias Rohrer [Wed, 14 Sep 2022 08:17:56 +0000 (10:17 +0200)]
Add `no-std` support for RGS

19 months agoRework RGS crate-level docs
Elias Rohrer [Fri, 9 Sep 2022 11:52:31 +0000 (13:52 +0200)]
Rework RGS crate-level docs

19 months agoMerge pull request #1707 from TheBlueMatt/2022-09-no-global-features
Matt Corallo [Thu, 15 Sep 2022 00:28:32 +0000 (00:28 +0000)]
Merge pull request #1707 from TheBlueMatt/2022-09-no-global-features

Move supported-feature-set logic into the supporting modules

19 months agoAssert that all defined features are in the known features set 2022-09-no-global-features
Matt Corallo [Fri, 9 Sep 2022 04:38:14 +0000 (04:38 +0000)]
Assert that all defined features are in the known features set

Now that the features contexts track the full set of all known
features, rather than the set of supported features, all defined
features should be listed in the context definition macro.

This adds a compile-time assertion to check that all bits for known
features are set in the context known set.

19 months agoStop tracking feature bits as known or required in features.rs
Matt Corallo [Fri, 9 Sep 2022 04:31:18 +0000 (04:31 +0000)]
Stop tracking feature bits as known or required in features.rs

Now that the `*Features::known` constructor has been removed, there
is no reason to define feature bits as either optional required in
`features.rs` - that logic now belongs in the modules that are
responsible for the given features.

Instead, we only list all features in each context.

19 months agoRemove the `*Features::known` constructor
Matt Corallo [Wed, 14 Sep 2022 01:05:25 +0000 (01:05 +0000)]
Remove the `*Features::known` constructor

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we (finally) remove the `known` constructor entirely,
modifying tests in the `features` module as required.

19 months agoRemove all remaining references to `*Features::known`
Matt Corallo [Wed, 14 Sep 2022 01:05:11 +0000 (01:05 +0000)]
Remove all remaining references to `*Features::known`

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

In anticipation of removing the `known` constructor, this commit
removes all remaining references to it outside of features.rs.

19 months agoStop relying on `*Features::known` in fuzzing tests
Matt Corallo [Fri, 9 Sep 2022 04:15:40 +0000 (04:15 +0000)]
Stop relying on `*Features::known` in fuzzing tests

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in our fuzz tests.

19 months agoStop relying on `*Features::known` in BP and persister tests
Matt Corallo [Fri, 9 Sep 2022 04:00:33 +0000 (04:00 +0000)]
Stop relying on `*Features::known` in BP and persister tests

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-background-processor` and `lightning-persister` crate
tests.

19 months agoStop relying on the `*Features::known` method in net-tokio
Matt Corallo [Fri, 9 Sep 2022 02:34:27 +0000 (02:34 +0000)]
Stop relying on the `*Features::known` method in net-tokio

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-net-tokio` crate.

19 months agoStop relying on the `*Features::known` method in lightning-invoice
Matt Corallo [Mon, 12 Sep 2022 19:20:38 +0000 (19:20 +0000)]
Stop relying on the `*Features::known` method in lightning-invoice

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-invoice` crate.

19 months agoStop relying on `*Features::known` in channel{,manager}.rs
Matt Corallo [Thu, 8 Sep 2022 21:24:34 +0000 (21:24 +0000)]
Stop relying on `*Features::known` in channel{,manager}.rs

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the channel modules.

19 months agoStop relying on `*Features::known` in functional test utils
Matt Corallo [Thu, 8 Sep 2022 21:18:07 +0000 (21:18 +0000)]
Stop relying on `*Features::known` in functional test utils

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
functional_test_utils module.

19 months agoStop relying on the `*Features::known` method in functional tests
Matt Corallo [Thu, 8 Sep 2022 21:11:11 +0000 (21:11 +0000)]
Stop relying on the `*Features::known` method in functional tests

This diff is commit, like the last, stops relying on the `known`
feature set constructor, doing so entirely with import changes and
sed rules.

19 months agoStop relying on the `*Features::known` method in `routing` tests
Matt Corallo [Thu, 8 Sep 2022 21:04:11 +0000 (21:04 +0000)]
Stop relying on the `*Features::known` method in `routing` tests

As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the `routing` module,
which was only used in tests.

19 months agoList supported/required feature bits explicitly in ChannelManager
Matt Corallo [Mon, 12 Sep 2022 17:47:16 +0000 (17:47 +0000)]
List supported/required feature bits explicitly in ChannelManager

Historically, LDK has considered the "set of known/supported
feature bits" to be an LDK-level thing. Increasingly this doesn't
make sense - different message handlers may provide or require
different feature sets.

In a previous PR, we began the process of transitioning with
feature bits sent to peers being sourced from the attached message
handler.

This commit makes further progress by moving the concept of which
feature bits are supported by our ChannelManager into
channelmanager.rs itself, via the new `provided_*_features`
methods, rather than in features.rs via the `known_channel_features`
and `known` methods.

19 months agoMerge pull request #1721 from acid-bit/fix_typo
valentinewallace [Wed, 14 Sep 2022 16:28:39 +0000 (12:28 -0400)]
Merge pull request #1721 from acid-bit/fix_typo

Fix typo in comment in Cargo.toml

19 months agoMerge pull request #1720 from TheBlueMatt/2022-09-fix-fuzz-warnings
Matt Corallo [Wed, 14 Sep 2022 14:35:49 +0000 (14:35 +0000)]
Merge pull request #1720 from TheBlueMatt/2022-09-fix-fuzz-warnings

Fix compile-time warnings in fuzzing

19 months agoFix typo in comment in Cargo.toml
acid-bit [Wed, 14 Sep 2022 10:49:20 +0000 (11:49 +0100)]
Fix typo in comment in Cargo.toml

19 months agoFix warnings in fuzz which should have been fixed in f725c5a90a11e6 2022-09-fix-fuzz-warnings
Matt Corallo [Wed, 14 Sep 2022 00:50:29 +0000 (00:50 +0000)]
Fix warnings in fuzz which should have been fixed in f725c5a90a11e6

19 months agoFix compile warning in fuzzing introduced in cd0d19c005ee4fa11de93a
Matt Corallo [Wed, 14 Sep 2022 00:49:21 +0000 (00:49 +0000)]
Fix compile warning in fuzzing introduced in cd0d19c005ee4fa11de93a

19 months agoMerge pull request #1685 from wpaulino/anchors-prep
Matt Corallo [Tue, 13 Sep 2022 21:09:25 +0000 (21:09 +0000)]
Merge pull request #1685 from wpaulino/anchors-prep

19 months agoMerge pull request #1717 from TheBlueMatt/2022-09-req-features-in-handlers
valentinewallace [Tue, 13 Sep 2022 20:17:57 +0000 (16:17 -0400)]
Merge pull request #1717 from TheBlueMatt/2022-09-req-features-in-handlers

Move checking of specific require peer feature bits to handlers

19 months agoMerge pull request #1706 from jkczyz/2022-09-filtered-blocks
Matt Corallo [Tue, 13 Sep 2022 19:50:34 +0000 (19:50 +0000)]
Merge pull request #1706 from jkczyz/2022-09-filtered-blocks

Support filtered blocks in `lightning-block-sync`

19 months agoUpdate anchors test vectors to zero HTLC transaction fee variant
Wilmer Paulino [Fri, 26 Aug 2022 19:56:09 +0000 (12:56 -0700)]
Update anchors test vectors to zero HTLC transaction fee variant

Each test featuring HTLCs had a minimum and maximum feerate case. This
is no longer necessary for the zero HTLC transaction anchors variant as
the commitment feerate does not impact whether HTLCs can be trimmed or
not, only the dust limit does.

19 months agoAccount for zero fee HTLC transaction within dust limit calculation
Wilmer Paulino [Mon, 29 Aug 2022 19:34:34 +0000 (12:34 -0700)]
Account for zero fee HTLC transaction within dust limit calculation

With the zero fee HTLC transaction anchors variant, HTLCs can no longer
be trimmed due to their amount being too low to have a mempool valid
HTLC transaction. Now they can only be trimmed based on the dust limit
of each party within the channel.

19 months agoUpdate HTLC script detection to check for anchor output variants
Wilmer Paulino [Thu, 25 Aug 2022 20:23:29 +0000 (13:23 -0700)]
Update HTLC script detection to check for anchor output variants

19 months agoUse zero fee HTLC transactions for anchor channels
Wilmer Paulino [Wed, 27 Jul 2022 21:59:49 +0000 (14:59 -0700)]
Use zero fee HTLC transactions for anchor channels

This is based on the assumption that we only support the zero HTLC
transaction fee variant of anchor channels.

19 months agoExclude HTLC transactions from broadcast on anchor channels
Wilmer Paulino [Thu, 25 Aug 2022 20:36:17 +0000 (13:36 -0700)]
Exclude HTLC transactions from broadcast on anchor channels

HTLC transactions from anchor channels are constrained by a CSV of 1
block, so broadcasting them along with the unconfirmed commitment
tranasction will result in them being immediately rejected as premature.

19 months agoAvoid commitment broadcast upon detected funding spend
Wilmer Paulino [Thu, 25 Aug 2022 20:11:19 +0000 (13:11 -0700)]
Avoid commitment broadcast upon detected funding spend

There's no need to broadcast our local commitment transaction if we've
already seen a confirmed one as it'll be immediately rejected as a
duplicate/conflict.

This will also help prevent dispatching spurious events for bumping
commitment and HTLC transactions through anchor outputs (once
implemented in future work) and the dispatch for said events follows the
same flow as our usual commitment broadcast.

19 months agoUse proper sighash flag for remote HTLCs with anchor outputs
Wilmer Paulino [Thu, 25 Aug 2022 20:27:00 +0000 (13:27 -0700)]
Use proper sighash flag for remote HTLCs with anchor outputs

19 months agoSupport filtered blocks in lightning-block-sync
Jeffrey Czyz [Thu, 8 Sep 2022 20:17:05 +0000 (15:17 -0500)]
Support filtered blocks in lightning-block-sync

Expand the BlockSource trait to allow filtered blocks now that
chain::Listen supports them (d629a7edb7241eee7fde9f5ccdf1c481d2d6297b).
This makes it possible to use BIP 157/158 compact block filters with
lightning-block-sync.

19 months agoMerge pull request #1703 from TheBlueMatt/2022-09-badonion-first-check
valentinewallace [Tue, 13 Sep 2022 17:47:23 +0000 (13:47 -0400)]
Merge pull request #1703 from TheBlueMatt/2022-09-badonion-first-check

Correctly handle BADONION onion errors

19 months agoAdd now-missing `unwrap`s on test calls to `peer_connected`. 2022-09-req-features-in-handlers
Matt Corallo [Mon, 12 Sep 2022 19:09:50 +0000 (19:09 +0000)]
Add now-missing `unwrap`s on test calls to `peer_connected`.

19 months agoMove checking of specific require peer feature bits to handlers
Matt Corallo [Mon, 12 Sep 2022 19:06:17 +0000 (19:06 +0000)]
Move checking of specific require peer feature bits to handlers

As we remove the concept of a global "known/supported" feature set
in LDK, we should also remove the concept of a global "required"
feature set. This does so by moving the checks for specific
required features into handlers.

Specifically, it allows the handler `peer_connected` method to
return an `Err` if the peer should be disconnected. Only one such
required feature bit is currently set - `static_remote_key`, which
is required in `ChannelManager`.