-
Notifications
You must be signed in to change notification settings - Fork 367
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
Abstract ChannelManager
outbound payment logic
#1923
Abstract ChannelManager
outbound payment logic
#1923
Conversation
ada18d3
to
a62a50a
Compare
Codecov 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
b32532c
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.
Nice!
b32532c
to
99126ee
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.
The moves and renames LGTM!
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
8e49b02
Compare
77e2014
to
d108bef
Compare
Lmk when I can squash, @jkczyz |
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.
Feel free to squash
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
afdaa64
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, is it really worth breaking the move-only-ness to drop a ;
:). Not worth fixing, really.
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, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likwise, I've mostly noticed them indented.
@@ -433,8 +435,8 @@ impl OutboundPayments { | |||
} | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
Will address the latest feedback in a new PR shortly! |
Moves
ChannelManager
outbound 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.