Commit graph

7068 commits

Author SHA1 Message Date
Gursharan Singh
7de602a38a
Stop tracking MonitorUpdates from ChainSync in pending_monitor_updates
We no longer need to track them since we no longer hold events for
pending MonitorUpdates resulting from ChainSync.
2024-04-26 16:06:44 -07:00
Gursharan Singh
e084ab26e1
Stop storing last_chain_persist_height
We only used to store last_chain_persist_height to release
events held for more than LATENCY_GRACE_PERIOD_BLOCKS due to
pending monitor update with UpdateOrigin::ChainSync. Since we no
longer pause events for ChainSync persistence, we no longer need to
store last_chain_persist_height.
2024-04-26 16:02:20 -07:00
Gursharan Singh
cb86399f2e
Don't pause events for chainsync persistence
We used to wait on ChannelMonitor persistence to avoid
duplicate payment events. But this can still happen in cases where
ChannelMonitor handed the event to ChannelManager and we did not persist
ChannelManager after event handling.
It is expected to receive payment duplicate events and clients should handle these
events in an idempotent manner. Removing this hold-up of events simplifies
the logic and makes it easier to not persist ChannelMonitors on every block connect.
2024-04-26 14:37:41 -07:00
Elias Rohrer
9a438eea3b
Merge pull request #3015 from tnull/2024-04-sweeper-error-on-persistence-failure
Make `OutputSweeper::track_spendable_outputs` fallible
2024-04-24 16:35:51 +02:00
Elias Rohrer
afb452a813
Make OutputSweeper::track_spendable_outputs fallible
.. as otherwise we might only log an error and continue if we fail to
persist the sweeper state.
2024-04-24 09:46:34 +02:00
Matt Corallo
0e22b1245a
Merge pull request #2981 from dunxen/2024-03-PR2419fixups
Fixups for #2419
2024-04-23 06:48:40 -07:00
Duncan Dean
59a8bd5d65
Add intermediate ConstructedTransaction 2024-04-23 11:33:05 +02:00
Duncan Dean
a04dde7664
Add lower bound segwit input weight estimates 2024-04-23 11:30:59 +02:00
Duncan Dean
a6bee822fb
Add descriptions to test cases 2024-04-23 11:30:33 +02:00
Duncan Dean
62d4952348
Abort if we add a duplicate input 2024-04-23 11:30:00 +02:00
Duncan Dean
ebd57c5d53
Make sent_tx_* fallible and handle errors & simplify counterparty_weight_contributed calc 2024-04-23 11:29:45 +02:00
Duncan Dean
774b048d8f
Check if msg.script.is_witness_program() before checking version 2024-04-23 11:29:24 +02:00
Duncan Dean
4eb70fdf7a
Use HashMaps as, well, HashMaps (don't iter for key match) 2024-04-23 11:29:18 +02:00
Gursharan Singh
d25d55a682
Merge pull request #2990 from TheBlueMatt/2024-04-log-in-flights
Log pending in-flight updates when we are missing a monitor
2024-04-22 10:29:35 -07:00
Matt Corallo
93e77632d6 Debug-log monitor update starts and completions in ChainMonitor
When a `ChannelMonitor[Update]` persistence completes, we rely on
logging in `ChannelManager` to hear about it. However, this won't
happen at all if there's still pending updates as no `MonitorEvent`
will be generated.

Thus, here, we add logging directly in `ChainMonitor`, ensuring we
can deduce when individual updates completed from debug logs.
2024-04-22 12:21:33 +00:00
Matt Corallo
6ee8d81a58
Merge pull request #3009 from tnull/2024-04-fix-sweeper-typo
Fix typo in `OutputSweeper`
2024-04-22 04:36:41 -07:00
Elias Rohrer
9ac9d8e19f
Fix typo in OutputSweeper
... as 'ouputs' isn't a thing.
2024-04-22 11:29:42 +02:00
Matt Corallo
800f750cc9
Merge pull request #3005 from TheBlueMatt/2024-04-0.0.123-beta
Cut 0.0.123-beta
2024-04-19 07:51:06 -07:00
Matt Corallo
49b375311b Bump crate versions to 0.0.123-beta/invoice 0.31-beta 2024-04-19 01:03:03 +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