Commit graph

7049 commits

Author SHA1 Message Date
Matt Corallo
23d9514259 Simplify and clarify derive_add_tweak documentation 2024-04-22 13:00:29 +00:00
Wilmer Paulino
2c0fcf21f2
Merge pull request #2761 from yellowred/self_sufficient_psbt
Implement PSBT fields that were missing for a Signer
2024-04-18 17:45:56 -07:00
olegkubrakov
e08f7de3fa Implement Script for Witness and Add Tweak in PSBT.
Adding Witness Script and key tweaks makes
a Partially Signed Bitcoin Transaction the single data
source needed for a Signer to produce valid signatures.
A Signer is not required to be able to generate L2 keys,
e.g delayed payment basepoint.
2024-04-18 16:57:54 -07:00
Matt Corallo
195e666953
Merge pull request #2964 from jbesraa/prune-stale-chanmonitor
Add `archive_fully_resolved_monitors` to `ChainMonitor`
2024-04-18 14:39:43 -07:00
Gursharan Singh
ae4c35c3e0
Merge pull request #2998 from tnull/2024-04-fix-potential-lock-race-in-CM-write 2024-04-18 13:21:08 -07:00
Jeffrey Czyz
19dae8b193
Merge pull request #3001 from optout21/splicing-feature-bit-with-any
Add splicing feature flag
2024-04-18 14:24:00 -05:00
Gursharan Singh
6264a44259
Merge pull request #2999 from keyuebao/keyue/update-ldk-docs
Update docs for ChannelClosed Event
2024-04-18 10:26:07 -07:00
jbesraa
4b5504366b Add ChainMonitor::archive_fully_resolved_monitor_channels
Archives fully resolved channel monitors by adding them to a backup
  location and removing them from the primary storage & the monitor set.

  This is useful for pruning fully resolved monitors from the monitor
  set and primary storage so they are not reloaded on every new new
  block connection.

  We also add a new function, `archive_persisted_channel` to the
  `Persist` trait that writes the monitor to an archive storage and
  removes it from the primary storage.
2024-04-18 17:12:07 +00:00
jbesraa
9a1649c2b2 Add ChannelMonitor::is_fully_resolved function
Checks if the monitor is fully resolved. Resolved monitor is one that has claimed all of
  its ouputs and balacnes.

  This function returns true only if `get_claimable_balances` has been empty for at least
  2016 blocks.
2024-04-18 15:53:21 +00:00
Matt Corallo
fd237101fd
Merge pull request #2825 from tnull/2024-01-upstream-output-sweeper
Add `OutputSweeper` utility persisting and sweeping spendable outputs
2024-04-18 08:24:47 -07:00
Matt Corallo
56a87ccf7b
Merge pull request #2970 from jkczyz/2024-03-offer-id
Include a `PaymentContext` in `PaymentPurpose`
2024-04-18 08:21:19 -07:00
Elias Rohrer
be8c0d099d
Edit Event::SpendableOutputs docs to mention OutputSweeper 2024-04-18 16:20:03 +02:00
Elias Rohrer
681106d23f
Add basic OutputSweeper test in BP
.. we simply check that the `OutputSweeper` generates a spending tx and
that the `TrackedSpendableOutput` is pruned once it reaches
`ANTI_REORG_DELAY`.
2024-04-18 16:20:03 +02:00
Elias Rohrer
a574f8b4a7
Allow delaying generation and broadcasting of spending txs
.. which enables users to batch output spends.
2024-04-18 16:20:03 +02:00
Elias Rohrer
071337a1f1
Add OutputSweeper utility persisting and sweeping spendable outputs
We add a `OutputSweeper` utility that allows to track the state of
spendable output descriptors as emitted by `Event::SpendableOutputs`.

To this end, the `OutputSweeper` persists the necessary information in
our `KVStore` and regularly tries to sweep the spendable outputs,
removing them after reaching threshold confirmations, i.e.,
`ANTI_REORG_DELAY`.
2024-04-18 16:20:03 +02:00
Elias Rohrer
ec956516d1
Add ConfirmationTarget::OutputSpendingFee 2024-04-18 16:20:02 +02:00
Jeffrey Czyz
478911d42a
Update PaymentPurpose's payment_preimage docs
Clarify that payment_preimage should only be used to claim a payment
when handling Event::PaymentClaimable, not Event::PaymentClaimed.
2024-04-18 09:15:25 -05:00
Jeffrey Czyz
8367e02110
Include InvoiceRequest fields in PaymentContext
When receiving a payment, it's useful to know information about the
InvoiceRequest. Include this data in PaymentContext::Bolt12Offer so
users can display information about an inbound payment (e.g., the payer
note).
2024-04-18 09:15:25 -05:00
Jeffrey Czyz
b06b2c787a
Test for PaymentContext in offers_tests.rs 2024-04-18 09:15:23 -05:00
Jeffrey Czyz
0c52ea23dc
Use BOLT 12 PaymentPurpose variants
When constructing a PaymentPurpose in ChannelManager, use the
PaymentContext from OnionPayload to determine which variant to
construct, including those for BOLT 12 payments.
2024-04-18 09:15:23 -05:00
Jeffrey Czyz
54ca54d191
BOLT 12 variants of PaymentPurpose
In order to provide more context in PaymentClaimable and PaymentClaimed
events, introduce new variants of PaymentPurpose for use with BOLT 12
payments. Separate variants are used for offers and refunds. An unknown
variant is used for backwards compatibility and ease of testing, but is
otherwise not publicly constructable.
2024-04-18 09:15:22 -05:00
Jeffrey Czyz
ef3ec8f146
Add PaymentPurpose::is_keysend utility method 2024-04-18 09:15:22 -05:00
Jeffrey Czyz
e74f24332f
Rename InvoicePayment to Bolt11InvoicePayment
PaymentPurpose will be expanded to include BOLT 12 payment context.
Rename the InvoicePayment variant accordinly before new variants are
added.
2024-04-18 09:15:22 -05:00
Jeffrey Czyz
09ce1b5d16
Include Refund context in blinded payment paths
When requesting a payment for a refund, include a context in the
Bolt12Invoice's blinded payment paths indicated it is for such. When the
eventual payment is received, the user can use the payment hash to
correlate it with the corresponding Refund.
2024-04-18 09:15:21 -05:00
Jeffrey Czyz
48d9245f19
Include Offer context in blinded payment paths
When constructing blinded payment paths for a Bolt12Invoice response,
include the OfferId so that the eventual payment can be correlated with
the Offer.
2024-04-18 09:15:21 -05:00
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
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