Commit graph

3920 commits

Author SHA1 Message Date
Valentine Wallace
c106d4ff9f
OR NodeFeatures from both Channel and Routing message handlers
When we broadcast a node announcement, the features we support are really a
combination of all the various features our different handlers support. This
commit captures this concept by OR'ing our NodeFeatures across both our channel
and routing message handlers.
2022-09-09 15:58:20 -04:00
Valentine Wallace
fe8b4c7836
Enable all feature sets to OR with another set of the same type 2022-09-09 12:48:09 -04:00
Matt Corallo
3fb3218b6c
Merge pull request #1701 from TheBlueMatt/2022-09-feature-or
Fetch InitFeatures from both Channel and Routing Message Handlers
2022-09-09 16:47:25 +00:00
Matt Corallo
1b67b0b056 Make clear_initial_routing_sync more consistent with other APIs 2022-09-09 15:36:46 +00:00
Matt Corallo
e34a2bc722 Add a new InitFeatures constructor to capture the types of flags
When `ChannelMessageHandler` implementations wish to return an
`InitFeatures` which contain all the known flags that are relevant
to channel handling, but not gossip handling, they currently need
to do so by manually constructing an InitFeatures with all known
flags and then clearing the ones they dont want.

Instead of spreading this logic out across the codebase, this
consolidates such construction to one place in features.rs.
2022-09-09 15:36:46 +00:00
Matt Corallo
06cb48afd4 OR InitFeatures from both Channel and Routing message handlers
When we go to send an Init message to new peers, the features we
support are really a combination of all the various features our
different handlers support. This commit captures this concept by
OR'ing our InitFeatures across both our Channel and Routing
handlers.

Note that this also disables setting the `initial_routing_sync`
flag in init messages, as was intended in
e742894492, per the comment added on
`clear_initial_routing_sync`, though this should not be a behavior
change in practice as nodes which support gossip queries ignore the
initial routing sync flag.
2022-09-09 15:36:46 +00:00
Matt Corallo
950ccc4340 Fetch our InitFeatures from ChannelMessageHandler
Like we now do for `NodeFeatures`, this converts to asking our
registered `ChannelMessageHandler` for our `InitFeatures` instead
of hard-coding them to the global LDK known set.

This allows handlers to set different feature bits based on what
our configuration actually supports rather than what LDK supports
in aggregate.
2022-09-09 15:36:46 +00:00
Matt Corallo
ba69536843
Merge pull request #1699 from TheBlueMatt/2022-08-announcement-rework 2022-09-09 00:34:10 +00:00
Matt Corallo
fa1a0d8531
Merge pull request #1704 from TheBlueMatt/2022-09-always-probe-failed
Dont use PaymentPathFailed a probe fails without making it out
2022-09-08 20:35:15 +00:00
Matt Corallo
e2495f237e Add a folder to track CHANGELOG entries for the next release 2022-09-08 19:50:36 +00:00
Matt Corallo
989cb064b5 Move broadcast_node_announcement to PeerManager
Some `NodeFeatures` will, in the future, represent features which
are not enabled by the `ChannelManager`, but by other message
handlers handlers. Thus, it doesn't make sense to determine the
node feature bits in the `ChannelManager`.

The simplest fix for this is to change to generating the
node_announcement in `PeerManager`, asking all the connected
handlers which feature bits they support and simply OR'ing them
together. While this may not be sufficient in the future as it
doesn't consider feature bit dependencies, support for those could
be handled at the feature level in the future.

This commit moves the `broadcast_node_announcement` function to
`PeerHandler` but does not yet implement feature OR'ing.
2022-09-08 19:50:36 +00:00
Matt Corallo
6b0afbe4d4 Send channel_{announcement,update} msgs on connection, not timer
When we connect to a new peer, immediately send them any
channel_announcement and channel_update messages for any public
channels we have with other peers. This allows us to stop sending
those messages on a timer when they have not changed and ensures
we are sending messages when we have peers connected, rather than
broadcasting at startup when we have no peers connected.
2022-09-08 19:50:36 +00:00
Matt Corallo
66011920bc Improve debuggability when tests fail due to excess events 2022-09-08 18:54:20 +00:00
Matt Corallo
e7673971be Dont use PaymentPathFailed a probe fails without making it out
When we fail to forward a probe HTLC at all and immediately fail it
(e.g. due to the first hop channel closing) we'd previously
spuriously generate only a `PaymentPathFailed` event. This violates
the expected API, as users expect a `ProbeFailed` event instead.

This fixes the oversight by ensuring we generate the correct event.

Thanks to @jkczyz for pointing out this issue.
2022-09-08 18:54:08 +00:00
Matt Corallo
fd328e71da Drop redundant code in fail_holding_cell_htlcs
`fail_holding_cell_htlcs` calls through to
`fail_htlc_backwards_internal` for HTLCs that need to be
failed-backwards but opts to generate its own payment failure
events for `HTLCSource:;OutboundRoute` HTLCs. There is no reason
for that as `fail_htlc_backwards_internal` will also happily
generate (now-)equivalent events for `HTLCSource::OutboundRoute`
HTLCs.

Thus, we can drop the redundant code and always call
`fail_htlc_backwards_internal` for each HTLC in
`fail_holding_cell_htlcs`.
2022-09-08 18:54:05 +00:00
Matt Corallo
5e65c49a82
Merge pull request #1702 from TheBlueMatt/2022-09-one-hop-retryable
Mark failed one-hop HTLCs as retrably
2022-09-08 17:34:04 +00:00
Matt Corallo
a59b9d8079
Merge pull request #1700 from TheBlueMatt/2022-09-missing-event-deser
Add missing deserialization of Event::HTLCHandlingFailed
2022-09-08 15:41:58 +00:00
Matt Corallo
089ccbb671 Add missing deserialization of Event::HTLCHandlingFailed
17e6c374c5 added the
`HTLCHandlingFailed` event, including serialization thereof,
however failed to add corresponding deserialization. This corrects
that oversight by adding said deserialization.

Thanks to @wpaulino for catching the oversight.
2022-09-07 21:57:10 +00:00
Matt Corallo
c57bb42204 Rename rejected_by_dest -> payment_failed_permanently
The `rejected_by_dest` field of the `PaymentPathFailed` event has
always been a bit of a misnomer, as its really more about retry
than where a payment failed. Now is as good a time as any to
rename it.
2022-09-07 20:58:05 +00:00
Matt Corallo
f76f60ff85 Mark failed counterparty-is-destination HTLCs retryable
When our counterparty is the payment destination and we receive
an `HTLCFailReason::Reason` in `fail_htlc_backwards_internal` we
currently always set `rejected_by_dest` in the `PaymentPathFailed`
event, implying the HTLC should *not* be retried.

There are a number of cases where we use `HTLCFailReason::Reason`,
but most should reasonably be treated as retryable even if our
counterparty was the destination (i.e. `!rejected_by_dest`):
 * If an HTLC times out on-chain, this doesn't imply that the
   payment is no longer retryable, though the peer may well be
   offline so retrying may not be very useful,
 * If a commitment transaction "containing" a dust HTLC is
   confirmed on-chain, this definitely does not imply the payment
   is no longer retryable
 * If the channel we intended to relay over was closed (or
   force-closed) we should retry over another path,
 * If the channel we intended to relay over did not have enough
   capacity we should retry over another path,
 * If we received a update_fail_malformed_htlc message from our
   peer, we likely should *not* retry, however this should be
   exceedingly rare, and appears to nearly never appear in practice

Thus, this commit simply disables the behavior here, opting to
treat all `HTLCFailReason::Reason` errors as retryable.

Note that prior to 93e645daf4 this
change would not have made sense as it would have resulted in us
retrying the payment over the same channel in some cases, however
we now "blame" our own channel and will avoid it when routing for
the same payment.
2022-09-07 20:43:17 +00:00
valentinewallace
301efc8a81
Merge pull request #1697 from TheBlueMatt/2022-08-event-docs
Clarify and consolidate event handling requirements
2022-09-06 22:04:39 -04:00
valentinewallace
f4a26dd0fd
Merge pull request #1698 from TheBlueMatt/2022-09-release-names
Add release names to CHANGELOG
2022-09-06 21:57:16 -04:00
valentinewallace
e45db2bf6c
Merge pull request #1691 from TheBlueMatt/2022-08-dust-retry
Correct payment resolution after on chain failure of dust HTLCs
2022-09-06 20:02:50 -04:00
Matt Corallo
c5e2904efe Add release names to CHANGELOG
There have been release names in Github for some time, though some
releases were missed. This adds them to CHANGELOG.
2022-09-06 22:41:09 +00:00
Matt Corallo
ce7e7d302a Clarify and consolidate event handling requirements
We've seen a bit of user confusion about the requirements for event
handling, largely because the idempotency and consistency
requirements weren't super clearly phrased. While we're at it, we
also consolidate some documentation out of the event handling
function onto the trait itself.

Fixes #1675.
2022-09-06 20:56:24 +00:00
Matt Corallo
a795e45b42 Correct payment resolution after on chain failure of dust HTLCs
Previously, we wouldn't mark a dust HTLC as permanently resolved if
the commitment transaction went on chain. This resulted in us
always considering the HTLC as pending on restart, when we load the
pending payments set from the monitors.

Fixes #1653.
2022-09-06 20:23:18 +00:00
valentinewallace
8c6cb9953a
Merge pull request #1657 from TheBlueMatt/2022-08-async-man-update
Add a background processor which is async
2022-09-06 16:06:06 -04:00
Matt Corallo
ee2f1a929e
Merge pull request #1695 from TheBlueMatt/2022-08-log-chan_update
Ensure we log private channel_updates at a non-GOSSIP log level
2022-09-06 19:15:05 +00:00
Matt Corallo
602cf5c12b Ensure we log private channel_updates at a non-GOSSIP log level
If we receive a channel_update for one of our private channels, we
will not log the message at the usual TRACE log level as the
message falls into the gossip range. However, for our own channels
they aren't *just* gossip, as we store that info and it changes
how we generate invoices. Thus, we add a log in `ChannelManager`
here at the DEBUG log level.
2022-09-06 17:49:40 +00:00
Matt Corallo
2a5bac22bf Add a background processing function that is async.
Adds a method which operates like BackgroundProcessor::start but
instead of functioning by spawning a background thread it is async.
2022-09-06 17:42:24 +00:00
Matt Corallo
c6890cfc33 Add a Future which can receive manager persistence events
This allows users who don't wish to block a full thread to receive
persistence events.

The `Future` added here is really just a trivial list of callbacks,
but from that we can build a (somewhat ineffecient)
std::future::Future implementation and can (at least once a mapping
for Box<dyn Trait> is added) include the future in no-std bindings
as well.

Fixes #1595
2022-09-06 17:42:21 +00:00
Matt Corallo
2035cebe8a Remove internal references to persistence in waker.rs 2022-09-06 16:22:58 +00:00
Matt Corallo
f99301dd8a
Merge pull request #1692 from TheBlueMatt/2022-08-time-goes-backwards
Handle monotonic clock going backwards during runtime
2022-09-03 16:15:33 +00:00
Matt Corallo
fc7b14b184
Merge pull request #1650 from valentinewallace/2022-08-take-onionmsgs-public 2022-09-02 22:20:32 +00:00
Matt Corallo
82474d3564 Handle monotonic clock going backwards during runtime
We've had some users complain that `duration_since` is panic'ing
for them. This is possible if the machine being run on is buggy and
the "monotonic clock" goes backwards, which sadly some ancient
systems can do.

Rust addressed this issue in 1.60 by forcing
`Instant::duration_since` to not panic if the machine is buggy
(and time goes backwards), but for users on older rust versions we
do the same by hand here.
2022-09-02 21:57:32 +00:00
Matt Corallo
c8ae6c1923 Move open_zero_conf_channel utility to common test utils 2022-09-02 21:29:32 +00:00
Valentine Wallace
a8ea0bde59
Limit OnionMessenger outbound buffer size
Drop OMs if they push us over the max OnionMessenger outbound buffer size
2022-09-02 16:35:35 -04:00
Valentine Wallace
04f4673428
Don't construct OnionMessage while holding peer lock 2022-09-02 16:27:38 -04:00
Valentine Wallace
b9b02b48fb
Refuse to send and forward OMs to disconnected peers
We also refuse to connect to peers that don't advertise onion message
forwarding support.
2022-09-02 16:27:30 -04:00
Valentine Wallace
0b1f476b83
Expose onion message module as public
And fix warnings
2022-09-02 16:25:32 -04:00
Jeffrey Czyz
00f08c910f
Merge pull request #1643 from jurvis/jurvis/2022-07-inflights-htlcs-across-payments
Track in-flight HTLCs across payments when routing
2022-09-01 15:01:30 -05:00
jurvis
80daf942b2
Make payment tests more realistic
Made sure that every hop has a unique receipient. When we simulate
calling `channel_penalty_msat` in `TestRouter`’s find route, use
actual previous node ids instead of just using the payer’s.
2022-08-31 18:50:03 -07:00
jurvis
c70bd1fd55
Keep track of inflight HTLCs across payments
Added two methods, `process_path_inflight_htlcs` and
`remove_path_inflight_htlcs`, that updates that `payment_cache` map with
path information that may have failed, succeeded, or have been given up
on.

Introduced `AccountForInflightHtlcs`, which will wrap our user-provided
scorer. We move the `S:Score` type parameterization from the `Router` to
`find_route`, so we can use our newly introduced
`AccountForInflightHtlcs`.

`AccountForInflightHtlcs` keeps track of a map of inflight HTLCs by
their short channel id, direction, and give us the value that is being
used up.

This map will in turn be populated prior to calling `find_route`, where
we’ll use `create_inflight_map`, to generate a current map of all
inflight HTLCs based on what was stored in `payment_cache`.
2022-08-31 18:50:02 -07:00
Matt Corallo
0624cf9e47
Merge pull request #1687 from TheBlueMatt/2022-08-fuzz-msrv
Drop honggfuzz `arbitrary` dependency to meet MSRV
2022-08-30 17:12:47 +00:00
Matt Corallo
7223f70616 Drop honggfuzz arbitrary dependency to meet MSRV 2022-08-30 15:15:00 +00:00
jurvis
706b638196
Change payment_cache to accept PaymentInfo
Introduces a new `PaymentInfo` struct that contains both the previous
`attempts` count that was tracked as well as the paths that are also
currently inflight.
2022-08-29 22:51:43 -07:00
Jeffrey Czyz
99123cd91a
Merge pull request #1604 from valentinewallace/2022-07-OMs-followup
Onion messages: add some initial rate limiting
2022-08-29 12:17:36 -05:00
Valentine Wallace
f4834def9d
Implement buffering onion messages for peers.
In this commit, we check if a peer's outbound buffer has room for onion
messages, and if so pulls them from an implementer of a new trait,
OnionMessageProvider.

Makes sure channel messages are prioritized over OMs, and OMs are prioritized
over gossip.

The onion_message module remains private until further rate limiting is added.
2022-08-26 19:03:07 -04:00
Valentine Wallace
b28783a0b5
Implement OnionMessageProvider for OnionMessenger 2022-08-26 19:03:05 -04:00
Valentine Wallace
544f72b37c
PeerManager: bump the read pause limit
...to make sure we can still get channel messages out after enqueuing some big gossip messages.
2022-08-26 19:03:05 -04:00