Uh oh!
There was an error while loading. Please reload this page.
Abstract ChannelManager outbound payment logic - #1923
Conversation
ada18d3 to
a62a50aCompareCodecov ReportBase: 90.73% // Head: 91.46% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@## main #1923 +/- ##
==========================================
+ Coverage 90.73% 91.46% +0.73%
==========================================
Files 94 96 +2 Lines 49603 53540 +3937 Branches 49603 53540 +3937 ==========================================
+ Hits 45006 48969 +3963 + Misses 4597 4571 -26
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. |
a62a50a to
b32532cCompareUh oh!
There was an error while loading. Please reload this page.
b32532c to
99126eeCompare
dunxen
left a comment
There was a problem hiding this comment.
The moves and renames LGTM!
Uh oh!
There was an error while loading. Please reload this page.
We want to move all outbound payment-related things to this new module, to help break up ChannelManager so future payment retries work doesn't increase the size of ChannelManager.
And re-export it in channelmanager.rs so it can remain public
99126ee to
8e49b02CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
77e2014 to
d108befComparevalentinewallace
commented
Dec 19, 2022
Lmk when I can squash, @jkczyz |
Uh oh!
There was an error while loading. Please reload this page.
This allows us to move a lot of outbound payment logic out of ChannelManager and into the new outbound_payment module, and helps avoid growing ChannelManager when we add retry logic to it in upcoming work.
Separating out this commit to keep the main refactor move-only
Once ChannelManager supports payment retries, it will make more sense for its current send_payment method to be named send_payment_with_route because retrying should be the default. Here we get a head start on this by making the rename in outbound_payment, but not changing the public interface yet.
d108bef to
afdaa64Compare
dunxen
left a comment
There was a problem hiding this comment.
The commits were pretty easy to follow! Cleans up ChannelManager a load.
| #[cfg(test)] | ||
| pub(crate) fn test_add_new_pending_payment(&self, payment_hash: PaymentHash, payment_secret: Option<PaymentSecret>, payment_id: PaymentId, route: &Route) -> Result<Vec<[u8; 32]>, PaymentSendFailure> { | ||
| let best_block_height = self.best_block.read().unwrap().height(); | ||
| self.pending_outbound_payments.add_new_pending_payment(payment_hash, payment_secret, payment_id, route, &self.keys_manager, best_block_height) |
There was a problem hiding this comment.
nit: should the exposure of the real add_new_pending_payment be via a test-only wrapper so that non-test channelmanager code can't call it?
There was a problem hiding this comment.
Yeah, it's definitely safer. Good for a follow-up.
| if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(*payment_id) { | ||
| if !payment.get_mut().remove(&session_priv_bytes, Some(&path)) { | ||
| log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0)); | ||
| return |
There was a problem hiding this comment.
Heh, is it really worth breaking the move-only-ness to drop a ; :). Not worth fixing, really.
There was a problem hiding this comment.
Oops, that mistakenly introduced when parameterizing the method by pending_events. I'll fix if Jeff has feedback that needs to go in this PR.
| log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0)); | ||
| let path_failure = { | ||
| #[cfg(test)] |
There was a problem hiding this comment.
This indentation no longer makes any sense - it was left completely unindented since its a cfg (in the standard C ifdef style), but we could also put it indented like the line itself (is this standard?). It doesn't really make sense randomly indented once.
There was a problem hiding this comment.
I've personally seen more code where it has the same indentation as the line itself (and not ifdef style). Don't think there's a standard though.
There was a problem hiding this comment.
Likwise, I've mostly noticed them indented.
| log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0)); | ||
| let path_failure = { | ||
| #[cfg(test)] |
There was a problem hiding this comment.
Likwise, I've mostly noticed them indented.
| fn send_payment_internal<K: Deref, F> | ||
| (&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, | ||
| fn send_payment_internal<K: Deref, F>( |
There was a problem hiding this comment.
nit: I'd also move the closing ) to the next line here and all the following methods as you did in the methods before this (ec55730).
valentinewallace
commented
Dec 20, 2022
Will address the latest feedback in a new PR shortly! |
Moves
ChannelManageroutbound payment logic into its own module, in preparation for payment retries.Just code moves mostly. I kept the serialization changes surgical but we could probably move more logic there too.