-
Notifications
You must be signed in to change notification settings - Fork 369
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
Expose pending payments through ChannelManager
#1873
Conversation
Still need to add tests and documentation, but seeking concept ACK |
Yea, I think this is the right approach. Will need careful docs. |
04cdc07
to
91cc02e
Compare
Tests currently only make assertions for I was thinking of testing |
91cc02e
to
aff6659
Compare
Codecov ReportBase: 90.80% // Head: 90.77% // Decreases project coverage by
📣 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
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. |
@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 |
48965a9
to
15aec58
Compare
PendingOutboundPayment::Abandoned { payment_hash, .. } => { | ||
Some(RecentPaymentDetails::Abandoned { payment_hash: *payment_hash }) | ||
}, | ||
PendingOutboundPayment::Fulfilled { payment_hash, .. } => { | ||
Some(RecentPaymentDetails::Fulfilled { payment_hash: *payment_hash }) | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump @TheBlueMatt
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Note that #1923 moved |
b4294ec
to
d626653
Compare
/// 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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
rebased to fix conflicts from |
/// 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() |
There was a problem hiding this comment.
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.
back after a bunch of travel, hope to land this soon 🤞 |
Looks like this needs a rebase due to a lockorder violation the CI is complaining about. |
da4cdd4
to
2406430
Compare
There was a problem hiding this 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
.
2406430
to
8a2c3e8
Compare
There was a problem hiding this 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
Regarding the failed CI checks, let's see if a rebase helps once @TheBlueMatt is ready. |
Feel free to rebase whenever you want. |
8a2c3e8
to
634e4fe
Compare
hmm, looks like there is still a lockorder violation, likely due to accessing |
|
ah, gotcha. that was it. thanks for the help! |
634e4fe
to
50eb269
Compare
lightning/src/ln/channelmanager.rs
Outdated
/// 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. |
There was a problem hiding this comment.
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 ..."
There was a problem hiding this comment.
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.
LGTM, needs a rebase tho. |
There was a problem hiding this 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 :)
lightning/src/ln/channelmanager.rs
Outdated
/// Total amount (in msat) across all paths for this payment, not just the amount currently | ||
/// inflight. | ||
total_msat: u64, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
@alecchendev love it! thanks for the review and welcome to the project! |
lightning/src/ln/channelmanager.rs
Outdated
/// 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. | ||
/// |
There was a problem hiding this comment.
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
.
90ce06b
to
24e2f9f
Compare
Added some doc improvements and rebased to resolve a conflict on 90ce06b |
There was a problem hiding this 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.
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.
24e2f9f
to
c98f80d
Compare
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
Addresses #1157