Commit graph

3949 commits

Author SHA1 Message Date
Matt Corallo
990e346798
Merge pull request #1714 from TheBlueMatt/2022-09-111-bindings-discovered-cleanups
Small Cleanups Discovered during Bindings for 0.0.111
2022-09-12 20:51:51 +00:00
Matt Corallo
3f3335ac48
Merge pull request #1715 from TheBlueMatt/2022-09-fix-msg-send
Fix encryption of broadcasted gossip messages
2022-09-12 20:01:32 +00:00
Matt Corallo
b78359af9e Update Simple*PeerManager type aliases to support Onion Messages
Note that `SimpleArcPeerHandler` is also updated to not wrap
`IgnoringMessageHandler` in an `Arc`, as `IgnoringMessageHandler`
is already zero-sized.
2022-09-12 18:33:55 +00:00
Matt Corallo
dbd0ab8cf8
Merge pull request #1716 from TheBlueMatt/2022-09-log-unreadable-type
Include the message type when we send unreadable gossip msg errors
2022-09-12 18:10:47 +00:00
Matt Corallo
45ec1db2e0 Encrypt+MAC most P2P messages in-place
For non-gossip-broadcast messages, our current flow is to first
serialize the message into a `Vec`, and then allocate a new `Vec`
into which we write the encrypted+MAC'd message and header.

This is somewhat wasteful, and its rather simple to instead
allocate only one buffer and encrypt the message in-place.
2022-09-12 18:06:52 +00:00
Matt Corallo
8ec92f5b6b Fix encryption of broadcasted gossip messages
In 47e818f198, forwarding broadcasted
gossip messages was split into a separate per-peer message buffer.
However, both it and the original regular-message queue are
encrypted immediately when the messages are enqueued. Because the
lightning P2P encryption algorithm is order-dependent, this causes
messages to fail their MAC checks as the messages from the two
queues may not be sent to peers in the order in which they were
encrypted.

The fix is to simply queue broadcast gossip messages unencrypted,
encrypting them when we add them to the regular outbound buffer.
2022-09-12 18:06:52 +00:00
Matt Corallo
be7107f212 Drop unused type parameter on BlindedRoute::new
I'm not sure why rustc didn't complain about the unused parameter
or why we're allowed to get away without explicitly bounding the
`Sign` in the `KeysInterface`, but the current code requires all
`BlindedPath` construction to explicitly turbofish an unused type.
2022-09-12 16:26:58 +00:00
Matt Corallo
88ec5da4b3 Add relevant (C-not exported) tags on OnionMessenger aliases
The "helpful" type aliases don't make sense for C bindings as all
generics are concretized anyway.
2022-09-12 16:26:58 +00:00
Matt Corallo
95eb2b52be Inline generic bounds rather than using the where clause
The bindings generator is pretty naive in its generic resolution
and doesn't like `where` clauses for bounds that are simple traits.
This should eventually change, but for now its simplest to just
inline the relevant generic bounds.
2022-09-12 16:26:58 +00:00
Matt Corallo
0f3536f87a Do not use blanket impls when building for c_bindings
The C bindings generator isn't capable of figuring out if a blanket
impl applies in a given context, and instead opts to always write
out any relevant impl's for a trait. Thus, blanket impls should be
disabled when building with `#[cfg(c_bindings)]`.
2022-09-12 16:26:58 +00:00
Matt Corallo
8b3516208a Rename {Signed,}RawInvoice::hash to avoid naming collisions
Now that `{Signed,}RawInvoice` implement the std `Hash` trait,
having a method called `hash` is ambiguous.

Instead, we rename the `hash` methods `signed_hash` to make it
clear that the hash is the one used for the purpose of signing the
invoice.
2022-09-12 16:26:58 +00:00
Matt Corallo
c4466bdb95 Include the message type when we send unreadable gossip msg errors 2022-09-12 15:35:56 +00:00
Matt Corallo
15a5966fa2
Merge pull request #1710 from TheBlueMatt/2022-09-compile-warn
Fix several compile warnings added in some of my recent commits
2022-09-11 14:54:05 +00:00
Matt Corallo
0cc3572719 Fix several compile warnings when testing in no-std mode 2022-09-10 00:18:32 +00:00
Matt Corallo
610511ced6 Fix (really dumb) warning rustc introduced in latest beta 2022-09-09 21:49:05 +00:00
Matt Corallo
f14ea3dd18 Fix several compile warnings added in some of my recent commits 2022-09-09 21:49:05 +00:00
Matt Corallo
877a5fc9c0
Merge pull request #1688 from valentinewallace/2022-08-flip-om-feature-bit
Onion messages: flip feature bit 🎉
2022-09-09 21:48:33 +00:00
Matt Corallo
ad24b8c891
Merge pull request #1713 from TheBlueMatt/2022-09-bad-doc-versions
Correct `get_claimable_balance` version info
2022-09-09 21:13:36 +00:00
Matt Corallo
e94e403dda
Merge pull request #1711 from TheBlueMatt/2022-08-0conf-panic
Fix spurious panic on receipt of a block while awaiting funding
2022-09-09 20:24:07 +00:00
Valentine Wallace
5d9dddd1f6
Update ChannelMessageHandler::provided_node_features docs
To be uniform with the other handler provided_node_features docs
2022-09-09 16:01:41 -04:00
Valentine Wallace
9c3b6d2edd
Don't advertise onion messages in known channel features 2022-09-09 16:00:26 -04:00
Valentine Wallace
90f5906082
OR InitFeatures and NodeFeatures from onion message handler
Similar to how we OR our InitFeaures and NodeFeatures across both our channel
and routing message handlers, we also want to OR the features of our onion
message handler.
2022-09-09 16:00:21 -04:00
Valentine Wallace
1ac3fccd98
Support forwarding onion messages in advertised features
In upcoming commit(s), onion message support will be advertised conditionally
based on the OnionMessageProvider provided to PeerManager.
2022-09-09 15:59:44 -04:00
Valentine Wallace
f5e12559b5
Add missing wumbo feature bit docs 2022-09-09 15:58:24 -04:00
Valentine Wallace
7eee7974b0
Add a new NodeFeatures constructor to capture the types of flags
When ChannelMessageHandler implementations wish to return a NodeFeatures 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 a
NodeFeatures with all known flags and then clearing the ones they don't want.

Instead of spreading this logic across the codebase, this consolidates such
construction into one place in features.rs.
2022-09-09 15:58:24 -04:00
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
Matt Corallo
d29f8ff2fa Correct get_claimable_balance version info
5a8ede09fb updated the documentation
on `get_claimable_balance` to note that if a channel went on-chain
with an LDK version older than 0.0.108 some
counterparty-revoked-output claimable balances my be missing.
However, this failed to account for the fact that we rely on the
entirely-new-in-0.0.111
`confirmed_commitment_tx_counterparty_output` field for some
balances as well.

Thus, the comment should have been in terms of 0.0.111, not
0.0.108.
2022-09-09 19:30:30 +00:00
Matt Corallo
3a3c931c5a
Merge pull request #1709 from tnull/2022-09-make-access-error-debug
Derive `Debug` for `AccessError`
2022-09-09 18:46:41 +00:00
Matt Corallo
cb1db61300 Fix spurious panic on receipt of a block while awaiting funding
When we receive a block we always test if we should send our
channel_ready via `check_get_channel_ready`. If the channel in
question requires confirmations, we quickly return if the funding
transaction has not yet confirmed (or even been defined), however
for 0conf channels the checks are necessarily more involved.

In any case, we wish to panic if the funding transaction has
confirmations prior to when it should have been broadcasted. This
is useful as it is easy for users to violate our broadcast-time
invariants without noticing and the panic gives us an opportunity
to catch it.

Sadly, in the case of 0conf channels, if we hadn't yet seen the
funding transaction at all but receive a block we would hit this
sanity check as we don't check whether there are actually funding
transaction confirmations prior to panicing.
2022-09-09 17:19:21 +00: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
Elias Rohrer
689ac256ab
Derive Debug for AccessError 2022-09-09 15:18:43 +02: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