Commit graph

4604 commits

Author SHA1 Message Date
Jeffrey Czyz
ac6d4cb9ad
Include OfferId in VerifiedInvoiceRequest
Extract the OfferId from the offer metadata sent back in the
InvoiceRequest and include it in VerifiedInvoiceRequest. This can be
used to correspond the eventual payment for the invoice response by
including it in the invoice's blinded payment paths.
2024-04-18 09:15:21 -05:00
Jeffrey Czyz
b9970ff41b
Define an OfferId for BOLT 12 Offers
Use a merkle root hash of the offer TLV records to define an offer id.
Will be included in a BOLT 12 invoice's blinded payment paths in order
for the recipient to identify which offer the payment is for.
2024-04-18 09:12:33 -05:00
Jeffrey Czyz
9be364f60e
Pass PaymentContext through HTLC processing
PendingInboundPayment::BlindedReceive includes a PaymentContext, which
the recipient includes in each blinded path. Included this when
processing HTLCs in ChannelManager, first into PendingHTLCRouting and
then to OnionPayload. Later, this will be included in the PaymentPurpose
when surfaced to user in PaymentClaimable and PaymentClaimed events.
2024-04-18 09:12:32 -05:00
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
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
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
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
37fbd3a41a
Run rustfmt on sign/type_resolver.rs 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
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
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
Matt Corallo
cc78b77c71 Fix unknown handling in impl_writeable_tlv_based_enum_upgradable
`impl_writeable_tlv_based_enum_upgradable` professed to supporting
upgrades by returning `None` from `MaybeReadable` when unknown
variants written by newer versions of LDK were read. However, it
generally didn't support this as it didn't discard bytes for
unknown types, resulting in corrupt reading.

This is fixed here for enum variants written as a TLV stream,
however we don't have a length prefix for tuple enum variants, so
the documentation on the macro is updated to mention that
downgrades are not supported for tuple variants.
2024-04-07 19:55:56 +00:00
dunxen
1d9e541c57
Merge pull request #2704 from jkczyz/2023-11-channelmanager-docs
`ChannelManager` documentation refresh
2024-04-07 20:34:57 +02:00
Jeffrey Czyz
998fffb99b
Add BOLT 12 Refunds section to ChannelManager docs 2024-04-06 11:11:30 +02:00
Jeffrey Czyz
761f09b04c
Add BOLT 12 Offers section to ChannelManager docs 2024-04-06 11:11:30 +02:00
Jeffrey Czyz
7cf899bfc9
Add a payments section to ChannelManager docs 2024-04-06 11:11:23 +02:00
Jeffrey Czyz
11d07c6252
Add a channels section to ChannelManager docs 2024-04-05 13:15:03 +02:00
Jeffrey Czyz
f3db184876
Add an operations section to ChannelManager docs 2024-04-05 13:15:03 +02:00
Jeffrey Czyz
c39c398f06
ChannelManager initialization docs with example 2024-04-05 13:14:57 +02:00
Elias Rohrer
3a9fe209e1
Merge pull request #2954 from TheBlueMatt/2024-03-test-ci-beta-fail
Fix new warnings causing CI build failures on rustc beta
2024-04-05 12:53:40 +02:00
Gursharan Singh
3eb61f7e9b
Merge pull request #2967 from tnull/2024-03-refactor-drop-handle-message
Split `PeerManager::handle_message` to avoid explicit `mem::drop`
2024-04-05 12:26:51 +02:00
Matt Corallo
d1d7d8787e Mark several test_utils which are only used in test as cfg(test) 2024-04-05 09:05:56 +00:00
Matt Corallo
d9b9854e87 Drop now-unused methods on Time
We no longer use `Time` during scoring, which makes several of its
methods now useless. We remove those here.
2024-04-05 09:05:56 +00:00
Matt Corallo
ae0d825d89 Use crate::prelude::* rather than specific imports
New rustc beta now warns on duplicate imports when one of the
imports is from a wildcard import or the default prelude. Thus, to
avoid this here we prefer to always use `crate::prelude::*` and let
it decide if we actually need to import anything.
2024-04-05 09:05:54 +00:00
Matt Corallo
061d396b07 Add more std prelude items to crate::prelude
New rustc beta now warns on duplicate imports when one of the
imports is from a wildcard import or the default prelude. Thus, for
simplicity, we need to make our `crate::prelude` mostly identical
to the `std` one, allowing us to always simply use the
`crate::prelude` and let it decide if we need to import anything.
2024-04-05 09:05:26 +00:00
Matt Corallo
cd327089a8 Allow(unused_imports) on prelude imports
New rustc now warns on duplicate imports when one of the imports
is from a wildcard import or the default prelude. Thus, because we
often don't actually use the imports from our prelude (as they
exist to duplicate the `std` default prelude), we have to mark most
of our `crate::prelude` imports with `#[allow(unused_imports)]`,
which we do here.
2024-04-05 09:05:26 +00:00