Commit graph

7122 commits

Author SHA1 Message Date
Jeffrey Czyz
c881538478
Add PaymentContext to payment::ReceiveTlvs
Providing LDK-specific data in a BlindedPath allows for the data to be
received with the corresponding payment. This is useful as it can then
be surfaced in PaymentClaimable events where the user may correlated
with an Offer, for instance. Define a PaymentContext enum for including
various context (e.g., offer, refund, static invoice).
2024-04-18 09:12:31 -05:00
Jeffrey Czyz
12c3a24beb
Return the invoice when requesting a refund
When sending an invoice for a refund, information from the invoice may
be useful for caller. For instance, the payment_hash can be used to
track whether the refund was paid. Return the invoice to facilitate this
use case.
2024-04-18 09:12:30 -05:00
Elias Rohrer
cd4cc203a2
Introduce ChangeDestinationSource trait
.. which users should implement on their on-chain wallet to allow us to
retrieve a new change destination script.
2024-04-18 16:09:04 +02:00
Elias Rohrer
d8021c7891
Introduce OutputSpender trait and implement for (Phantom)KeysManager
.. we move `spend_spendable_outputs` to a new trait which we can easily
reuse in `OutputSweeper` later.
2024-04-18 16:09:04 +02:00
optout
8c334cb579
Add splicing feature flag (also triggers dual_funding) 2024-04-18 08:40:34 +02:00
Keyue Bao
d2c1650bbd Update docs for ChannelClosed Event 2024-04-17 08:59:04 -07:00
Elias Rohrer
ce36f2c20b
Acquire per_peer_state write lock earlier in ChannelManager::write
Previously, we would hold the `per_peer_state` `read` lock during the
serialization of channel objects. While this might have reduced lock
congestion minimally, we also calculated the number of serializable
peers in this phase, only to use it later after dropping and reacquiring
the `per_peer_state` `write` lock.

This could potentially result in inconsistiencies if the
`serializable_peer_count` would change after we dropped the `read` lock
but before we acquired the `write` lock.

To mitigate the issue we just acquire the `write` lock ealier and hold
it for the remainder of `ChannelManager::write`.
2024-04-17 12:02:00 +02:00
Matt Corallo
ac9a2c8a20
Merge pull request #2991 from optout21/txsigs-splicing
Add tx_signatures.tlvs field (splicing-specific field in dual funding message)
2024-04-16 13:27:54 -07:00
optout
bdbb177469
Add tx_signatures.tlvs field (splicing-specific field in dual funding message) 2024-04-16 07:32:37 +02:00
Matt Corallo
3b1b0a561a
Merge pull request #2993 from wpaulino/handshake-complete-timer-tick-occurred-race
Fix race between handshake_complete and timer_tick_occurred
2024-04-15 21:21:47 +00:00
Jeffrey Czyz
01814dcef2
Implement Eq and Hash for Bolt12Invoice
Bolt12Invoice will be added to a new Event::InvoiceGenerated variant.
These traits along with PartialEq are required to be implemented for any
type used in an Event.
2024-04-15 16:11:13 -05:00
Jeffrey Czyz
e239c92cda
Refactor handling of Bolt12Invoice
In order to provide an InvoiceGenerated event, it would be cleaner to
have one location where a Bolt12Invoice is successfully created.
Refactor the handling code to this end and clean-up line length by
making some of the type conversions more streamlined.
2024-04-15 16:11:13 -05:00
Jeffrey Czyz
7e085c5ce4
Refactor handling of InvoiceRequest
In order to generate and InvoiceSent event, it would be cleaner to have
one location where a Bolt12Invoice is successfully generated. Refactor
the handling code to this end and clean-up line length by making some of
the type conversions more streamlined.
2024-04-15 16:11:12 -05:00
Matt Corallo
59778dac48
Merge pull request #2961 from jkczyz/2024-03-compact-blinded-paths
Compact blinded path handling
2024-04-15 17:56:29 +00:00
Jeffrey Czyz
fe114efa8b
Fix typos 2024-04-15 11:00:28 -05:00
Jeffrey Czyz
b7f73fa188
Resolve blinded path when creating onion message
Add a version of the create_onion_message utility function that attempts
to resolved the introduction node of the destination's BlindedPath using
a ReadOnlyNetworkGraph`. Otherwise, if given a path using the compact
representation, using create_onion_message would fail. Keep the current
version for use internally and for external uses where the blinded path
is known to be resolved.
2024-04-15 10:59:03 -05:00
Jeffrey Czyz
3f90d77122
Cache introduction_node_id lookup in get_route 2024-04-15 10:58:31 -05:00
Jeffrey Czyz
9f1ffab24c
Look up node id from scid in OnionMessenger
When forwarding onion messages, the next node may be represented by a
short channel id instead of a node id. Parameterize OnionMessenger with
a NodeIdLookUp trait to find which node is the next hop. Implement the
trait for ChannelManager for forwarding to channel counterparties.

Also use this trait when advancing a blinded path one hop when the
sender is the introduction node.
2024-04-15 10:58:30 -05:00
Jeffrey Czyz
32a5139eb5
Resolve IntroductionNode::DirectedShortChannelId
When OnionMessenger creates an OnionMessage to a Destination, the latter
may contain an IntroductionNode::DirectedShortChannelId inside a
BlindedPath. Resolve these in DefaultMessageRouter and handle unresolved
ones in OnionMessenger.
2024-04-15 10:58:30 -05:00
Jeffrey Czyz
7002180261
Generalize BlindedPath::introduction_node_id field
Allow using either a node id or a directed short channel id in blinded
paths. This allows for a more compact representation of blinded paths,
which is advantageous for reducing offer QR code size.

Follow-up commits will implement handling the directed short channel id
case in OnionMessenger as it requires resolving the introduction node in
MessageRouter.
2024-04-15 10:58:30 -05:00
Jeffrey Czyz
e0bc6fa8b2
Add source reference to BlindedPathCandidate hop
Blinded paths currently contain a node id for the introduction node.
However, a compact representation will allow a directed short channel id
instead. Update BlindedPathCandidate and OneHopBlindedPathCandidate to
store a NodeId reference from either the NetworkGraph or from the user-
provided first hops.

This approach avoids looking up the introduction node id on demand,
which may not be resolvable. Thus, that would require returning an
Option from CandidateRouteHop::source and handle None accordingly.
2024-04-15 10:58:23 -05:00
valentinewallace
322e1f3a98
Merge pull request #2987 from TheBlueMatt/2024-04-test-ser-bug
Add test coverage for cc78b77c71
2024-04-15 11:23:09 -04:00
Matt Corallo
bc4a5eae32
Merge pull request #2971 from jbesraa/review-club/2815
Fix comparison in `get_dust_buffer_feerate`
2024-04-13 19:59:05 +00:00
jbesraa
c01745eec7
Fix cmp::max execution in ChannelContext::get_dust_buffer_feerate
The current `cmp::max` doesnt align with the function comment, ie its
  comparing 2530 and `feerate_plus_quarter` instead of `feerate_per_kw
  + 2530` and `feerate_plus_quarter` which is fixed in this commit
2024-04-12 23:41:14 +03:00
Wilmer Paulino
b835e4f67a
Fix race between handshake_complete and timer_tick_occurred
The initial noise handshake on connection establishment must complete
within a single timer tick. This timeout is enforced via
`awaiting_pong_timer_tick_intervals` whenever a timer tick fires while
our handshake has yet to complete. Currently, on an inbound connection,
if a timer tick fires after we've sent act two of the noise handshake
along with our init message and before receiving the counterparty's init
message, we begin enforcing such timeout. Even if we immediately
continue to process the counterparty's init message to complete to
handshake, the timeout enforcement is not cleared. With the handshake
complete, `awaiting_pong_timer_tick_intervals` is now tracked to enforce
a pong timeout, except a ping was never actually sent. If a single timer
tick fires again without having received a message from the peer, or
enough timer ticks fire to trigger the
`MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER` logic, we'll end up
disconnecting the peer due to a timeout for a pong we'll never receive.

We fix this by always resetting `awaiting_pong_timer_tick_intervals`
upon processing our counterparty's init message.
2024-04-12 10:57:34 -07:00
Matt Corallo
10480f009e Log pending in-flight updates when we are missing a monitor
If we are missing a `ChannelMonitor` for which the `ChannelManager`
has pending updates, it may be useful to print what the updates we
have actually are, at least useful in identifying the bug(s).
2024-04-11 15:20:08 +00:00
Jeffrey Czyz
63ebaccca3
Add BlindedPath::introduction_node_id method
Blinded paths use a pubkey to identify the introduction node, but it
will soon allow using a directed short channel id instead. Add an
introduction_node_id method to BlindedPath to facilitate lookup in the
latter case.
2024-04-10 19:11:20 -05:00
Jeffrey Czyz
b783736356
Add IndexedMap::get_key_value
Useful for applying Option::map when needing both the key and value for
when needing a reference to the key with a longer lifetime.
2024-04-10 19:11:19 -05:00
Jeffrey Czyz
d85e0d619a
Generalize onion message ForwardTlvs::next_node_id
Allow either using a node id or a short channel id when forwarding an
onion message. This allows for a more compact representation of blinded
paths, which is advantageous for reducing offer QR code size.

Follow-up commits will implement handling the short channel id case as
it requires looking up the destination node id.
2024-04-10 19:11:19 -05:00
Matt Corallo
1d2a27d119
Merge pull request #2910 from tnull/2024-02-rustfmt-sign-mod
`rustfmt`:  Format `sign` module
2024-04-10 20:50:46 +00:00
Valentine Wallace
38b78eccb5 Add test coverage for cc78b77c71
cc78b77c71 fixed an important
downgrade bug, but neglected to add test coverage. Here we recitfy
that by adding a few simple tests of common cases.

Tests heavily tweaked by Matt Corallo <git@bluematt.me>.
2024-04-09 15:43:57 +00:00
Elias Rohrer
3a199c6987
Remove no-std-check/src/lib.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
822635716c
Remove msrv-no-dev-deps-check/src/lib.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
039da78ea9
Run rustfmt on msrv-no-dev-deps-check/src/lib.rs 2024-04-09 13:09:51 +02:00
Elias Rohrer
8e6a27c9b3
Remove sign/type_resolver.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
37fbd3a41a
Run rustfmt on sign/type_resolver.rs 2024-04-09 13:09:51 +02:00
Elias Rohrer
b3f8470996
Remove sign/taproot.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:51 +02:00
Elias Rohrer
1693e704b4
Run rustfmt on sign/taproot.rs 2024-04-09 13:09:50 +02:00
Elias Rohrer
0c220c1e0c
Remove sign/mod.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:09:50 +02:00
Elias Rohrer
540534b716
Run rustfmt on sign/mod.rs 2024-04-09 13:09:37 +02:00
Elias Rohrer
7442548263
Move input_idx retrieval into closure 2024-04-09 13:08:25 +02:00
Elias Rohrer
c906fac293
Move htlc_basepoint to variable 2024-04-09 13:08:25 +02:00
Elias Rohrer
2690823c9d
Move hash_to_message to variable 2024-04-09 13:08:25 +02:00
Elias Rohrer
b6059e9f39
Move low-R comments into blocks 2024-04-09 13:08:25 +02:00
Elias Rohrer
5cc321594d
Pull anchor check into helper function 2024-04-09 13:08:25 +02:00
Elias Rohrer
113b0f1a0e
Remove sign/ecdsa.rs from rustfmt exclusion list
.. now continously checking its formatting in CI.
2024-04-09 13:08:24 +02:00
Elias Rohrer
93ec3bddba
Run rustfmt on sing/ecdsa.rs 2024-04-09 13:08:24 +02:00
valentinewallace
eaf76f6cce
Merge pull request #2969 from TheBlueMatt/2024-03-fix-upgradable-enum 2024-04-08 16:34:14 +02:00
Matt Corallo
f852d16d92 Allow MaybeReadable to not fully read in upgradable_option
Whils this is generally not supported, issues in our
`MaybeReadable` implementations may occur, and we should try to be
robust against them.
2024-04-07 19:55:56 +00:00
Matt Corallo
d6770d4a74 Ensure we read the full TLV stream length when maybe-reading None
If we are reading an object that is `MaybeReadable` in a TLV stream
using `upgradable_required`, it may return early with `Ok(None)`.
In this case, it will not read any further TLVs from the TLV
stream. This is fine, except that we generally expect
`MaybeReadable` always consume the correct number of bytes for the
full object, even if it doesn't understand it.

This could pose a problem, for example, in cases where we're
reading a TLV-stream `MaybeReadable` object inside another
TLV-stream object. In that case, the `MaybeReadable` object may
return `Ok(None)` and not consume all the available bytes, causing
the outer TLV read to fail as the TLV length does not match.
2024-04-07 19:55:56 +00:00