Commit graph

4015 commits

Author SHA1 Message Date
Jeffrey Czyz
6dc42235ba
Allow sending onion messages to 1-hop blinded path
This allows for specifying the introduction node as the message
recipient.
2023-10-18 18:31:27 -05:00
Jeffrey Czyz
8b442fe4eb
Enqueue onion messages in handlers
When constructing onion messages to send initially (opposed to replying
to one from a handler), the user must construct an OnionMessagePath first
before calling OnionMessener::send_onion_message. Additionally, having a
reference to OnionMessener isn't always desirable. For instance, in an
upcoming commit, ChannelManager will implement OffersMessageHandler,
which OnionMessenger needs a reference to. If ChannelManager had a
reference to OnionMessenger, too, there would be a dependency cycle.

Instead, modify OffersMessageHandler and CustomOnionMessageHandler's
interfaces to include a method for releasing pending onion messages.
That way, ChannelManager may, for instance, construct and enqueue an
InvoiceRequest for sending without needing a reference to
OnionMessenger.

Additionally, OnionMessenger has responsibility for path finding just as
it does when replying to messages from a handler. It performs this when
extracting messages from the handlers before returning the next message
to send to a peer.
2023-10-18 18:31:16 -05:00
Jeffrey Czyz
840efd5334
Generalize CustomOnionMessageContents trait
Rename CustomOnionMessageContents to OnionMessageContents and use it as
a trait bound on messages passed to OnionMessenger methods. This allows
using the trait in an upcoming commit as a bound on the contents of
PendingOnionMessage.

Also, make ParsedOnionMessageContent implement OnionMessageContents so
that Payload can be bounded by OnionMessageContents directly, but used
when either reading a ParsedOnionMessageContent or writing a specific
type of OnionMessageContents (e.g., OffersMessage).
2023-10-18 18:15:05 -05:00
benthecarman
439f916f52
Remove channel monitor sync in progress log
This log is super spammy for us and isn't very useful.
2023-10-18 17:53:27 -05:00
Jeffrey Czyz
94573dda33
Rename OnionMessageContents
In preparation for needing the name OnionMessageContents for a trait to
bound methods, rename it to ParsedOnionMessageContents. In the next
commit, it's use will be limited to reading only, and the new trait will
be a bound on method parameters instead.
2023-10-18 17:18:03 -05:00
Jeffrey Czyz
81c6147a9e
Generalize respond_with_onion_message
OnionMessenger can send onion message responses from its handlers using
respond_with_onion_message, which finds a path to the destination and
enqueues the response for sending. Generalize this as it can be used not
only for responses but for initial sends as well.
2023-10-18 17:09:27 -05:00
Jeffrey Czyz
cfe6b952a8
Import msgs::OnionMessage 2023-10-18 17:09:24 -05:00
Jeffrey Czyz
a4894bd3ca
Clean up onion messenger parameters and docs 2023-10-18 17:00:04 -05:00
Jeffrey Czyz
b78cb69de3
Avoid overloading introduction_node_id 2023-10-18 17:00:04 -05:00
Jeffrey Czyz
86e2b0059f
Remove OnionMessageProvider
OnionMessageProvider is a super-trait of OnionMessageHandler, but they
don't need to be used separately. Additionally, the former is misplaced
in the events module. Remove OnionMessageProvider and add it's only
method, next_onion_message_for_peer, into OnionMessageHandler.
2023-10-18 17:00:04 -05:00
Jeffrey Czyz
a6cd661712
Update OnionMessenger docs for Offers 2023-10-18 17:00:03 -05:00
Matt Corallo
0357cafbbb
Merge pull request #2663 from TheBlueMatt/2023-10-peer-race-send-discon
Fix race between outbound messages and peer disconnection
2023-10-18 21:54:57 +00:00
Matt Corallo
34f8dd9a49
Merge pull request #2658 from wpaulino/bogus-channel-reestablish
Send bogus ChannelReestablish for unknown channels
2023-10-18 21:47:31 +00:00
Matt Corallo
28602d9dd8
Merge pull request #2599 from Evanfeenstra/peel-onion
public static peel_onion method on OnionMessenger
2023-10-18 21:11:52 +00:00
Matt Corallo
4366369ef5 Fix race between outbound messages and peer disconnection
Previously, outbound messages held in `process_events` could race
with peer disconnection, allowing a message intended for a peer
before disconnection to be sent to the same peer after
disconnection.

The fix is simple - hold the peers read lock while we fetch
pending messages from peers (as we disconnect with the write lock).
2023-10-18 19:35:00 +00:00
Wilmer Paulino
ed38eac1a3
Release short_to_chan_info lock throughout forwarding_channel_not_found
Not doing so caused a lock order inversion between the locks
`ChannelManager::best_block` and `ChannelManager::short_to_chan_info`
after the addition of `test_trigger_lnd_force_close`.

It turns out that we were holding the `short_to_chan_info` for longer
than needed when processing HTLC forwards. We only need to acquire it to
quickly obtain channel info, and there aren't any other locks within
`forwarding_channel_not_found` that depend on it being held.
2023-10-18 11:25:27 -07:00
Wilmer Paulino
94e0ecec68
Disconnect peer when force closing a funded channel with an error
We do this to ensure that the counterparty will always broadcast their
latest state when we broadcast ours. Usually, they'll do this with the
`error` message alone, but if they don't receive it or ignore it, then
we'll force them to broadcast by sending them a bogus
`channel_reestablish` upon reconnecting. Note that this doesn't apply to
unfunded channels as there is no commitment transaction to broadcast.
2023-10-18 11:25:27 -07:00
Wilmer Paulino
9f7de472fb
Send bogus ChannelReestablish for unknown channels
Unfortunately, lnd doesn't force close on errors
(abb1e3463f/htlcswitch/link.go (L2119)).
One of the few ways to get an lnd counterparty to force close is by
replicating what they do when restoring static channel backups (SCBs).
They send an invalid `ChannelReestablish` with `0` commitment numbers
and an invalid `your_last_per_commitment_secret`.

Since we received a `ChannelReestablish` for a channel that doesn't
exist, we can assume it's likely the channel closed from our point of
view, but it remains open on the counterparty's side. By sending this
bogus `ChannelReestablish` message now as a response to theirs, we
trigger them to force close broadcasting their latest state. If the
closing transaction from our point of view remains unconfirmed, it'll
enter a race with the counterparty's to-be-broadcast latest commitment
transaction.
2023-10-18 11:25:25 -07:00
Evan Feenstra
fe6f166bca public static peel_onion method on OnionMessenger 2023-10-17 14:48:09 -07:00
valentinewallace
22a0bfc073
Merge pull request #2662 from jkczyz/2023-10-chain-hash
Use `ChainHash` instead of `BlockHash` as applicable
2023-10-17 11:05:45 -04:00
valentinewallace
5fdc770b46
Merge pull request #2665 from TheBlueMatt/2023-10-scanable-test-logs
Make test log lines somewhat more eye-scannable
2023-10-16 15:59:32 -04:00
Jeffrey Czyz
54f96ef944
Use ChainHash instead of BlockHash as applicable
ChainHash is more appropriate for places where an arbitrary BlockHash is
not desirable. This type was introduced in later versions of the bitcoin
crate, thus BlockHash was used instead.

Using ChainHash also makes it easier to check if ChannelManager is
compatible with an Offer.
2023-10-16 13:29:53 -05:00
Matt Corallo
c86cacd29d
Merge pull request #2625 from tnull/2023-09-moar-tests-n-fixes
Improve test coverage of #2575 router fixes
2023-10-15 20:18:56 +00:00
Matt Corallo
ab2117796d Make test log lines somewhat more eye-scannable
When running tests, our log output should be reasonably readable
by developers, but currently it repeats the module twice (via the
module and file name), and then starts the log line at a variable
location.

Instead, we only print the module and then align the start of the
log lines so that the output is much more scannable.
2023-10-15 20:04:35 +00:00
Vladimir Fomene
33715e87d8
fix: use the update_add_htlc's cltv_expiry for comparison
As noted in BOLT 4, we should be using the update_add_htlc's cltv_expiry,
not the CLTV expiry set by the sender in the onion for this comparison.
See here: 4dcc377209/04-onion-routing.md (L334)
2023-10-13 14:05:21 +03:00
Fedeparma74
7cdb31ae20 Fix deadlock when closing an unavailable channel 2023-10-11 10:50:28 +02:00
valentinewallace
1f1a8dd5c5
Merge pull request #2651 from G8XSU/rm-same-feerate-log
Remove log for not changing feerate when it was equal
2023-10-06 13:18:32 -10:00
Matt Corallo
89749eddec
Merge pull request #2649 from benthecarman/display-outpoint
Impl Display for Outpoint
2023-10-06 19:00:01 +00:00
benthecarman
42c5640d19
Impl Display for Outpoint 2023-10-05 22:45:29 -05:00
Gursharan Singh
2ee554a1c4
Remove log for not changing feerate when it was equal
Log is not required in this case and creates unnecessary log lines at
trace level.
2023-10-05 15:19:36 -10:00
Matt Corallo
eea19de198
Merge pull request #2640 from sr-gi/20231003-expose-from-be-bytes
Makes Features::from_be_bytes public
2023-10-05 23:45:59 +00:00
Sergi Delgado Segura
2b1d6937a8 Makes Features::from_be_bytes public
Downstream projects building Feature<T> are most likely doing so with a
big-endian byte array, however only `from_le_bytes` is exposed.
2023-10-05 15:27:13 -04:00
Matt Corallo
c74874604e Bump crate versions to 0.0.117/invoice 0.25 2023-10-03 23:00:48 +00:00
Matt Corallo
7aefa3131c
Merge pull request #2631 from TheBlueMatt/2023-09-pm-no-refs-reqd
Fix `Simple*PeerManager` to not require refs to the `UtxoLookup`
2023-10-03 17:12:19 +00:00
Matt Corallo
0ce1c5a674
Merge pull request #2634 from TheBlueMatt/2023-09-claimable-unwrap
Avoid unwrap'ing `channel_parameters` in to_counterparty signing
2023-10-03 17:12:08 +00:00
Matt Corallo
0b4bb24af8 Clean up at least some lifetimes on SimpleRefPeerManager
Rather than simply a, b, c, d...we at least use names for a few
things, also splitting the reused 'f lifetime.
2023-10-03 04:36:25 +00:00
Matt Corallo
60567da0bd Note when we're allowed to unwrap channel parameters in docs
This further documents the parameter-fetching utilities in
`InMemorySigner` to hopefully make them more robust against future
spurious `unwrap`s.
2023-10-03 04:32:40 +00:00
Matt Corallo
65569ed5d6 Make InMemorySigner parameter-fetching utilities return Options
In the previous commit we fixed a bug where we were spuriously
(indirectly) `unwrap`ing the `channel_parameters` in
`InMemorySigner`. Here we make such bugs much less likely in the
future by having the utilities which do the `unwrap`ing internally
return `Option`s instead.

This makes the `unwrap`s clear at the callsite.
2023-10-03 04:25:03 +00:00
Matt Corallo
04841acb86
Merge pull request #2595 from TheBlueMatt/2023-09-117-bindings-part1
Various cleanups to make bindings generation simpler
2023-10-03 03:56:46 +00:00
Matt Corallo
a938fecc00
Merge pull request #2632 from TheBlueMatt/2023-09-writeable-rwlock
Implement Readable/Writeable for RwLock wrappers
2023-10-03 03:45:03 +00:00
Matt Corallo
6a55dcce83 Avoid unwrap'ing channel_parameters in to_counterparty signing
Previously, `StaticPaymentOutputDescriptor`s did not include
`channel_parameters` for the signer. As a result, when going to
spend old `StaticPaymentOutputDescriptor`s,
`InMemorySigner::sign_counterparty_payment_input` may be called
with `channel_parameters` set to `None`. This should be fine, but
in fa2a2efef4 we started relying on
it (indirectly via `channel_features`) for signing. This caused an
`unwrap` when spending old output descriptors.

This is fixed here by simply avoiding the unwrap and assuming old
`StaticPaymentOutputDescriptor`s represent non-anchor channels.
2023-10-01 00:40:20 +00:00
Matt Corallo
7a583bb756 Remove unused mem::drop which drops a reference 2023-10-01 00:05:01 +00:00
Matt Corallo
6b75fafaf3 Fix new unused variable warning in test_utils.rs 2023-10-01 00:05:01 +00:00
Matt Corallo
34f36d5ffe Drop various bounds on types passed to MonitorUpdatingPersister
The new `MonitorUpdatingPersister` has a few redundant type bounds
(re-specified on functions after having been specified on the
struct itself), which we remove here.

Further, it requires a `Deref<FeeEstimator>` which is `Clone`able.
This is generally fine in rust, but annoying in bindings, so we
simply elide it in favor if a `&Deref<FeeEstimator>`.
2023-10-01 00:05:01 +00:00
Matt Corallo
07205a2869 Make create_onion_message a freestanding function
The new `create_onion_message` function in `OnionMessenger` is hard
to handle - it has various generic requirements indirectly via the
struct, but they're not bounded by any of the method parameters.
Thus, you can't simply call `OnionMessenger::create_onion_message`,
as various bounds are not specified.

Instead, we move it to a freestanding function so that it can be
called directly without explicitly setting bounds.
2023-10-01 00:05:01 +00:00
Matt Corallo
6ce4c6cbc5 Mark AChannelManager no-export
The trait itself has no purpose for bindings, as all structs are
concretized anyway. Further, the bindings have specific handling
for generic bounding traits like this.
2023-10-01 00:05:01 +00:00
Matt Corallo
09cd4ed976 Mark SpendableOutputDescriptor::to_psbt_input as no-export
Its honestly likely not all that useful as its not materially
interoperable with other PSBT libraries. Instead, users should
simply fetch the full PSBT and use the inputs from it as they see
fit.
2023-10-01 00:05:01 +00:00
Matt Corallo
9c78d8e90e Drop unnecessary crate:: prefix when accessing bitcoin in macro
Unexported macros don't need to use the `$crate` prefix.
2023-10-01 00:05:01 +00:00
Matt Corallo
095fca9293 Avoid ref to a Vec when accessing custom onion TLVs
The bindings can't easily return a reference to a `Vec`, so we
instead split the implementation into vec/slice depending on the
`c_bindings` flag.
2023-10-01 00:05:01 +00:00
Matt Corallo
087c8f683a Avoid blanket impls in bindings builds
The C bindings implements `Deref` for all traits, so having a
blanket `Deref` implementation ends up conflicting with this.
2023-10-01 00:05:01 +00:00