Add 'send_circular_payment' helper and 'send_spontaneous_payment_with…#4616
Add 'send_circular_payment' helper and 'send_spontaneous_payment_with…#4616Ferryx349 wants to merge 1 commit into
Conversation
|
I've assigned @wpaulino as a reviewer! |
Review SummaryIssues FoundInline comments posted:
Prior comments statusThe four issues from the previous review pass appear to have been addressed in the current code:
Cross-cutting notes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4616 +/- ##
==========================================
+ Coverage 86.11% 86.39% +0.28%
==========================================
Files 157 158 +1
Lines 108841 109382 +541
Branches 108841 109382 +541
==========================================
+ Hits 93725 94504 +779
+ Misses 12497 12325 -172
+ Partials 2619 2553 -66
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…_route' to ChannelManager Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
| path.hops.last().map(|hop| (hop.pubkey, hop.cltv_expiry_delta as u32)) | ||
| }) | ||
| .unwrap_or_else(|| { | ||
| (PublicKey::from_slice(&[2; 32]).unwrap(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32) |
There was a problem hiding this comment.
Bug (pre-existing, preserved during refactor): [2; 32] produces a 32-byte array, but secp256k1::PublicKey::from_slice expects 33 bytes for a compressed key. This unwrap() will always panic if reached.
Every other usage in the codebase uses [2; 33]. This code path is only hit when the route has zero paths (so it's currently unreachable in practice), but it's still a latent panic that should be fixed while this code is being moved:
| (PublicKey::from_slice(&[2; 32]).unwrap(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32) | |
| (PublicKey::from_slice(&[2; 33]).unwrap(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32) |
| } | ||
|
|
||
| /// Sends a spontaneous payment along a given route. | ||
| #[rustfmt::skip] |
There was a problem hiding this comment.
This is a new public API method but the documentation is very sparse. At minimum it should mention no auto-retry behavior and reference send_spontaneous_payment for more context, similar to how send_payment_with_route references send_payment:
| #[rustfmt::skip] | |
| /// Sends a spontaneous payment along a given route. See | |
| /// [`Self::send_spontaneous_payment`] for more info. | |
| /// | |
| /// LDK will not automatically retry this payment, though it may be manually re-sent after an | |
| /// [`Event::PaymentFailed`] is generated. |
| bool, | ||
| ) -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>), | ||
| ) | ||
| -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>), |
There was a problem hiding this comment.
got these after doing fmt in channelmanager...
Fixes- #3791
This PR adds two new methods to
ChannelManager:send_circular_payment
A helper for circular channel rebalancing. It:
find_routetargeting the inbound channel's counterparty, withfirst_hopsrestricted to only the outbound channel to force the router to use it as the first hop.RouteHopback to our own node over the inbound channel's SCID, withfee_msatset to the full payment amount as required for the last hop and the preceding hop'sfee_msatadjusted to counterparty's forwarding fee.send_spontaneous_payment_with_route.The existing guard in
pay_route_internalalready permits our node as the last hop in a path ("simple rebalance loop to us"), so no changes to the payment sending internals were needed.Tests
test_circular_payment_rebalance: covers the happy path (0→1→2→0), same-channel error, and channel-not-found error.test_circular_payment_no_route: verifiesRouteNotFoundis returned when no path exists between the two counterparties.This is my first contribution to LDK. I tried to follow the patterns established by
send_payment_with_routeandsend_spontaneous_preflight_probesas closely as possible. Happy to revise anything that doesn't match project conventions.CC: @tnull