Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pending payments through ChannelManager #1873

Conversation

jurvis
Copy link
Contributor

@jurvis jurvis commented Nov 25, 2022

Addresses #1157

@jurvis
Copy link
Contributor Author

jurvis commented Nov 25, 2022

Still need to add tests and documentation, but seeking concept ACK

@TheBlueMatt
Copy link
Collaborator

Yea, I think this is the right approach. Will need careful docs.

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 04cdc07 to 91cc02e Compare December 5, 2022 01:24
@jurvis jurvis marked this pull request as ready for review December 5, 2022 01:24
@jurvis
Copy link
Contributor Author

jurvis commented Dec 5, 2022

Tests currently only make assertions for PendingPaymentStatus::Fulfilled and PendingPaymentStatus::Retryable.

I was thinking of testing PendingPaymentStatus::Abandoned by making an assertion after abandon_payment is called in this test, but it looks like it gets removed from pending_outbound_payments since its session_privs.len() is 0. Any suggestions on how to proceed?

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 91cc02e to aff6659 Compare December 5, 2022 01:32
@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2022

Codecov Report

Base: 90.80% // Head: 90.77% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (19ea6ba) compared to base (e0a0add).
Patch coverage: 89.18% of modified lines in pull request are covered.

❗ Current head 19ea6ba differs from pull request most recent head 90ce06b. Consider uploading reports for the commit 90ce06b to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1873      +/-   ##
==========================================
- Coverage   90.80%   90.77%   -0.04%     
==========================================
  Files          98       98              
  Lines       51507    51542      +35     
  Branches    51507    51542      +35     
==========================================
+ Hits        46770    46785      +15     
- Misses       4737     4757      +20     
Impacted Files Coverage Δ
lightning/src/ln/channelmanager.rs 87.15% <78.94%> (-0.04%) ⬇️
lightning/src/ln/payment_tests.rs 98.75% <100.00%> (+0.02%) ⬆️
lightning/src/chain/channelmonitor.rs 90.87% <0.00%> (-0.20%) ⬇️
lightning/src/ln/functional_tests.rs 96.91% <0.00%> (-0.20%) ⬇️
lightning/src/chain/onchaintx.rs 94.56% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jurvis
Copy link
Contributor Author

jurvis commented Dec 13, 2022

@TheBlueMatt thanks for the review and feedback on the documentation. My apologies that it has taken me some time to address them.

I just pushed fb0b1af that tidied up the language for users and renamed the PendingPaymentStatus enum to PendingPaymentDetails instead after moving amount_msat into the Retryable variant.

@jkczyz jkczyz self-requested a review December 13, 2022 16:17
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 48965a9 to 15aec58 Compare December 15, 2022 05:28
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
Comment on lines +1813 to +1746
PendingOutboundPayment::Abandoned { payment_hash, .. } => {
Some(RecentPaymentDetails::Abandoned { payment_hash: *payment_hash })
},
PendingOutboundPayment::Fulfilled { payment_hash, .. } => {
Some(RecentPaymentDetails::Fulfilled { payment_hash: *payment_hash })
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheBlueMatt What's the use case for including these two? Looking back at #1157, seems the issue was originally filed to support the sample node. But a later comment noted using PendingOutboundPayment isn't sufficient: lightningdevkit/ldk-sample#40 (comment)

If we instead just want anything pending, shouldn't Retryable be enough? Do we care that there are still inflight HTLCs if we've either given up on the payment or already have the preimage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry I missed this. I think we need to include the Fulfilled and Abandoned cases here as one use-case for listing pending payments is to figure out if you need to retry a payment - if you don't see a payment there, you should (consider) retrying it (as noted at #1157 (comment)). If the payment has been fulfilled, but you have not yet seen/processed the PaymentSent event, you may retry it, but shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for clarifying @TheBlueMatt. I thought this was worth clarifying in docs too so I added it in d626653 for ChannelManager::list_pending_payments. Let me know if the wording can be improved/if I missed anything

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jkczyz
Copy link
Contributor

jkczyz commented Dec 21, 2022

Note that #1923 moved PendingOutboundPayment, so will need to adjust once we're ready to rebase.

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from b4294ec to d626653 Compare December 24, 2022 21:44
/// payment is returned as [`RecentPaymentDetails::Fulfilled`], you may retry it, but should
/// not.
pub fn list_pending_payments(&self) -> Vec<RecentPaymentDetails> {
self.pending_outbound_payments.pending_outbound_payments.lock().unwrap().iter()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pending_outbound_payments field in OutboundPayments may be worth renaming to avoid self.pending_outbound_payments.pending_outbound_payments.

thoughts? cc // @jkczyz @valentinewallace @TheBlueMatt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would be supportive of reaming. Perhaps id_to_pending_payment, payment_by_id, or the like? Open to other alternatives given we may want to be deliberate about where "pending" is used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it for another PR - there's a ton of code motion in channelmanager.rs and friends right now between lock changes, payment retries, etc. The smaller we can keep this PR the better.

@jurvis
Copy link
Contributor Author

jurvis commented Dec 24, 2022

rebased to fix conflicts from PendingOutboundPayment refactor. left a tiny comment on naming that needs some input: https://github.com/lightningdevkit/rust-lightning/pull/1873/files#r1056876283

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
/// payment is returned as [`RecentPaymentDetails::Fulfilled`], you may retry it, but should
/// not.
pub fn list_pending_payments(&self) -> Vec<RecentPaymentDetails> {
self.pending_outbound_payments.pending_outbound_payments.lock().unwrap().iter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would be supportive of reaming. Perhaps id_to_pending_payment, payment_by_id, or the like? Open to other alternatives given we may want to be deliberate about where "pending" is used.

lightning/src/ln/channelmanager.rs Show resolved Hide resolved
@jurvis
Copy link
Contributor Author

jurvis commented Jan 10, 2023

back after a bunch of travel, hope to land this soon 🤞

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator

Looks like this needs a rebase due to a lockorder violation the CI is complaining about.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from da4cdd4 to 2406430 Compare January 19, 2023 06:09
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM. Just need to match some docs in list_recent_payments.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 2406430 to 8a2c3e8 Compare January 23, 2023 06:13
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some grammar nits

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@jkczyz
Copy link
Contributor

jkczyz commented Jan 23, 2023

Regarding the failed CI checks, let's see if a rebase helps once @TheBlueMatt is ready.

@TheBlueMatt
Copy link
Collaborator

Feel free to rebase whenever you want.

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 8a2c3e8 to 634e4fe Compare January 24, 2023 03:44
@jurvis
Copy link
Contributor Author

jurvis commented Jan 24, 2023

hmm, looks like there is still a lockorder violation, likely due to accessing pending_outbound_payments -- any ideas?

@jkczyz
Copy link
Contributor

jkczyz commented Jan 24, 2023

hmm, looks like there is still a lockorder violation, likely due to accessing pending_outbound_payments -- any ideas?

get_channel_ref! macro takes some locks, so you'll want to move the calls to list_recent_payments outside of the scope in test_trivial_inflight_htlc_tracking.

@jurvis
Copy link
Contributor Author

jurvis commented Jan 24, 2023

ah, gotcha. that was it. thanks for the help!

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 634e4fe to 50eb269 Compare January 24, 2023 06:06
jkczyz
jkczyz previously approved these changes Jan 24, 2023
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
Comment on lines 2487 to 2490
/// Additionally, if the process of sending a payment begins, but we crash before send_payment
/// returns (or prior to MonitorUpdate completion if you're using
/// [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
/// [`ChannelManager::list_recent_payments`] for more information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's weave this into the paragraph above: "Thus, in order to ensure duplicate payments are not sent ..."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what I meant was move what you wrote to that paragraph above rather than repeat part of that down here.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator

LGTM, needs a rebase tho.

Copy link
Contributor

@alecchendev alecchendev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments mainly looking at the public docs from a pair of fresh eyes and noted anything that came to mind :)

Comment on lines 1143 to 1168
/// Total amount (in msat) across all paths for this payment, not just the amount currently
/// inflight.
total_msat: u64,
Copy link
Contributor

@alecchendev alecchendev Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it says "all paths" is that said to account for MPP? Like if there were 2 paths for this payment, total_msat is the sum of the value received across both those paths?

Also I think it would maybe be helpful to add that this doesn't include fees? May need to double check, but from what I see in PendingOutboundPayment::Retryable it doesn't seem to(?). Since this is a sort of simpler interface on top of PendingOutboundPayment and because it lacks the other fee related fields that PendingOutboundPayment has (that might help a user infer whether total_msat includes fees), I figured I'd ask if it might be helpful to include in docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it says "all paths" is that said to account for MPP? Like if there were 2 paths for this payment, total_msat is the sum of the value received across both those paths?

Yup!

Also I think it would maybe be helpful to add that this doesn't include fees? May need to double check, but from what I see in PendingOutboundPayment::Retryable it doesn't seem to(?). Since this is a sort of simpler interface on top of PendingOutboundPayment and because it lacks the other fee related fields that PendingOutboundPayment has (that might help a user infer whether total_msat includes fees), I figured I'd ask if it might be helpful to include in docs.

I think that's valid feedback, thanks for pointing it out -- I'll add it :)

lightning/src/ln/channelmanager.rs Show resolved Hide resolved
@jurvis
Copy link
Contributor Author

jurvis commented Feb 1, 2023

Left some comments mainly looking at the public docs from a pair of fresh eyes and noted anything that came to mind :)

@alecchendev love it! thanks for the review and welcome to the project!

Comment on lines 2487 to 2521
/// Thus, in order to ensure duplicate payments are not sent, if we begin the process of sending
/// a payment, but crash before `send_payment` returns (or prior to [`ChannelMonitorUpdate`]
/// persistence if you're using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be
/// lost on restart. See [`ChannelManager::list_recent_payments`] for more information.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err.. sorry, what I meant was what you wrote in the previous commit belongs as part of the paragraph starting on line 2461. That paragraph says, "you should implement your own tracking of payments." So it seems like a natural place to talk about list_recent_payments.

@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 90ce06b to 24e2f9f Compare February 3, 2023 16:05
@jurvis
Copy link
Contributor Author

jurvis commented Feb 3, 2023

Added some doc improvements and rebased to resolve a conflict on 90ce06b

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up the docs! Much easier to parse them with the headings. Just some nits around them.

lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
Adds a new method, `list_recent_payments ` to `ChannelManager` that
returns an array of `RecentPaymentDetails` containing the payment
status (Fulfilled/Retryable/Abandoned) and its total amount across all
paths.
@jurvis jurvis force-pushed the jurvis/2022-11-expose-pending-payments branch from 24e2f9f to c98f80d Compare February 3, 2023 18:16
@TheBlueMatt TheBlueMatt merged commit 760ab65 into lightningdevkit:main Feb 3, 2023
k0k0ne pushed a commit to bitlightlabs/rust-lightning that referenced this pull request Sep 30, 2024
0.0.114 - Mar 3, 2023 - "Faster Async BOLT12 Retries"

API Updates
===========

 * `InvoicePayer` has been removed and its features moved directly into
   `ChannelManager`. As such it now requires a simplified `Router` and supports
   `send_payment_with_retry` (and friends). `ChannelManager::retry_payment` was
   removed in favor of the automated retries. Invoice payment utilities in
   `lightning-invoice` now call the new code (lightningdevkit#1812, lightningdevkit#1916, lightningdevkit#1929, lightningdevkit#2007, etc).
 * `Sign`/`BaseSign` has been renamed `ChannelSigner`, with `EcdsaChannelSigner`
   split out in anticipation of future schnorr/taproot support (lightningdevkit#1967).
 * The catch-all `KeysInterface` was split into `EntropySource`, `NodeSigner`,
   and `SignerProvider`. `KeysManager` implements all three (lightningdevkit#1910, lightningdevkit#1930).
 * `KeysInterface::get_node_secret` is now `KeysManager::get_node_secret_key`
   and is no longer required for external signers (lightningdevkit#1951, lightningdevkit#2070).
 * A `lightning-transaction-sync` crate has been added which implements keeping
   LDK in sync with the chain via an esplora server (lightningdevkit#1870). Note that it can
   only be used on nodes that *never* ran a previous version of LDK.
 * `Score` is updated in `BackgroundProcessor` instead of via `Router` (lightningdevkit#1996).
 * `ChainAccess::get_utxo` (now `UtxoAccess`) can now be resolved async (lightningdevkit#1980).
 * BOLT12 `Offer`, `InvoiceRequest`, `Invoice` and `Refund` structs as well as
   associated builders have been added. Such invoices cannot yet be paid due to
   missing support for blinded path payments (lightningdevkit#1927, lightningdevkit#1908, lightningdevkit#1926).
 * A `lightning-custom-message` crate has been added to make combining multiple
   custom messages into one enum/handler easier (lightningdevkit#1832).
 * `Event::PaymentPathFailure` is now generated for failure to send an HTLC
   over the first hop on our local channel (lightningdevkit#2014, lightningdevkit#2043).
 * `lightning-net-tokio` no longer requires an `Arc` on `PeerManager` (lightningdevkit#1968).
 * `ChannelManager::list_recent_payments` was added (lightningdevkit#1873).
 * `lightning-background-processor` `std` is now optional in async mode (lightningdevkit#1962).
 * `create_phantom_invoice` can now be used in `no-std` (lightningdevkit#1985).
 * The required final CLTV delta on inbound payments is now configurable (lightningdevkit#1878)
 * bitcoind RPC error code and message are now surfaced in `block-sync` (lightningdevkit#2057).
 * Get `historical_estimated_channel_liquidity_probabilities` was added (lightningdevkit#1961).
 * `ChannelManager::fail_htlc_backwards_with_reason` was added (lightningdevkit#1948).
 * Macros which implement serialization using TLVs or straight writing of struct
   fields are now public (lightningdevkit#1823, lightningdevkit#1976, lightningdevkit#1977).

Backwards Compatibility
=======================

 * Any inbound payments with a custom final CLTV delta will be rejected by LDK
   if you downgrade prior to receipt (lightningdevkit#1878).
 * `Event::PaymentPathFailed::network_update` will always be `None` if an
   0.0.114-generated event is read by a prior version of LDK (lightningdevkit#2043).
 * `Event::PaymentPathFailed::all_paths_removed` will always be false if an
   0.0.114-generated event is read by a prior version of LDK. Users who rely on
   it to determine payment retries should migrate to `Event::PaymentFailed`, in
   a separate release prior to upgrading to LDK 0.0.114 if downgrading is
   supported (lightningdevkit#2043).

Performance Improvements
========================

 * Channel data is now stored per-peer and channel updates across multiple
   peers can be operated on simultaneously (lightningdevkit#1507).
 * Routefinding is roughly 1.5x faster (lightningdevkit#1799).
 * Deserializing a `NetworkGraph` is roughly 6x faster (lightningdevkit#2016).
 * Memory usage for a `NetworkGraph` has been reduced substantially (lightningdevkit#2040).
 * `KeysInterface::get_secure_random_bytes` is roughly 200x faster (lightningdevkit#1974).

Bug Fixes
=========

 * Fixed a bug where a delay in processing a `PaymentSent` event longer than the
   time taken to persist a `ChannelMonitor` update, when occurring immediately
   prior to a crash, may result in the `PaymentSent` event being lost (lightningdevkit#2048).
 * Fixed spurious rejections of rapid gossip sync data when the graph has been
   updated by other means between gossip syncs (lightningdevkit#2046).
 * Fixed a panic in `KeysManager` when the high bit of `starting_time_nanos`
   is set (lightningdevkit#1935).
 * Resolved an issue where the `ChannelManager::get_persistable_update_future`
   future would fail to wake until a second notification occurs (lightningdevkit#2064).
 * Resolved a memory leak when using `ChannelManager::send_probe` (lightningdevkit#2037).
 * Fixed a deadlock on some platforms at least when using async `ChannelMonitor`
   updating (lightningdevkit#2006).
 * Removed debug-only assertions which were reachable in threaded code (lightningdevkit#1964).
 * In some cases when payment sending fails on our local channel retries no
   longer take the same path and thus never succeed (lightningdevkit#2014).
 * Retries for spontaneous payments have been fixed (lightningdevkit#2002).
 * Return an `Err` if `lightning-persister` fails to read the directory listing
   rather than panicing (lightningdevkit#1943).
 * `peer_disconnected` will now never be called without `peer_connected` (lightningdevkit#2035)

Security
========

0.0.114 fixes several denial-of-service vulnerabilities which are reachable from
untrusted input from channel counterparties or in deployments accepting inbound
connections or channels. It also fixes a denial-of-service vulnerability in rare
cases in the route finding logic.
 * The number of pending un-funded channels as well as peers without funded
   channels is now limited to avoid denial of service (lightningdevkit#1988).
 * A second `channel_ready` message received immediately after the first could
   lead to a spurious panic (lightningdevkit#2071). This issue was introduced with 0conf
   support in LDK 0.0.107.
 * A division-by-zero issue was fixed in the `ProbabilisticScorer` if the amount
   being sent (including previous-hop fees) is equal to a channel's capacity
   while walking the graph (lightningdevkit#2072). The division-by-zero was introduced with
   historical data tracking in LDK 0.0.112.

In total, this release features 130 files changed, 21457 insertions, 10113
deletions in 343 commits from 18 authors, in alphabetical order:
 * Alec Chen
 * Allan Douglas R. de Oliveira
 * Andrei
 * Arik Sosman
 * Daniel Granhão
 * Duncan Dean
 * Elias Rohrer
 * Jeffrey Czyz
 * John Cantrell
 * Kurtsley
 * Matt Corallo
 * Max Fang
 * Omer Yacine
 * Valentine Wallace
 * Viktor Tigerström
 * Wilmer Paulino
 * benthecarman
 * jurvis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants