-
Notifications
You must be signed in to change notification settings - Fork 407
Add MPP receive timeout handling #1353
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
Add MPP receive timeout handling #1353
Conversation
lightning/src/ln/channelmanager.rs
Outdated
@@ -3234,6 +3238,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
phantom_shared_secret, | |||
}, | |||
value: amt_to_forward, | |||
ticks: 0, |
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 should probably call this timer_ticks
.
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.
Yep, probably should :)
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.
Looks basically good to me!
lightning/src/ln/channelmanager.rs
Outdated
@@ -3234,6 +3238,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
phantom_shared_secret, | |||
}, | |||
value: amt_to_forward, | |||
ticks: 0, |
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.
Yep, probably should :)
lightning/src/ln/channelmanager.rs
Outdated
} | ||
} | ||
|
||
for payment_hash in &mut timed_out_payment_hashes { |
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.
You should be able to use claimable_htlcs.retain()
instead of iterating and removing here.
37afbe4
to
5403dfb
Compare
Codecov Report
@@ Coverage Diff @@
## main #1353 +/- ##
==========================================
+ Coverage 90.75% 90.77% +0.01%
==========================================
Files 73 73
Lines 40979 41045 +66
Branches 40979 41045 +66
==========================================
+ Hits 37191 37258 +67
+ Misses 3788 3787 -1
Continue to review full report at Codecov.
|
lightning/src/ln/channelmanager.rs
Outdated
channel_state.claimable_htlcs.retain(|payment_hash, htlcs| { | ||
if htlcs.into_iter().all(|htlc| { | ||
if let OnionPayload::Invoice(ref final_hop_data) = htlc.onion_payload { | ||
if htlc.value < final_hop_data.total_msat { |
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 feel like we should handle all-parts-received MPP payments and non-MPP payments the same - ie instead of just checking if this is an MPP payment here, we should check if we've actually received all the parts we need (by summing up the HTLCs for each given payment hash) before we timeout-fail parts.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
Wait, scratch my comment. I understand now. 🤦
b0b3ad1
to
d0369db
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.
LGTM, if you want to expand the test to also test that we dont time out if we're still waiting on parts (and that you can then receive the payment after the other parts come in) that'd be cool too.
Yeah, I definitely want to do that! |
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.
A few optional nits. I'm ACK after the new test changes :)
lightning/src/ln/channelmanager.rs
Outdated
} else if !htlcs.into_iter().all(|htlc| { | ||
htlc.timer_ticks += 1; | ||
return htlc.timer_ticks < MPP_TIMEOUT_TICKS |
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: IMO avoiding double negatives is more readable
so s/!htlcs/htlcs
, s/</>=
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 agree. Looks like I'd also need to change the .all()
to a .any()
:)
lightning/src/ln/functional_tests.rs
Outdated
@@ -55,6 +55,8 @@ use sync::{Arc, Mutex}; | |||
use ln::functional_test_utils::*; | |||
use ln::chan_utils::CommitmentTransaction; | |||
|
|||
use crate::ln::channelmanager::MPP_TIMEOUT_TICKS; |
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: s/crate:://
d0369db
to
daa89dd
Compare
Cleaned up a little more and expanded the test to cover the success case too (also checking that timeouts don't affect when we have all parts) and rather moved the tests to |
lightning/src/ln/channelmanager.rs
Outdated
@@ -3668,6 +3674,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
|
|||
true | |||
}); | |||
|
|||
channel_state.claimable_htlcs.retain(|payment_hash, htlcs| { | |||
if htlcs.is_empty() { return false } |
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 be unreachable, maybe add a debug_assert!(false);
here before the return.
daa89dd
to
4086ce8
Compare
Closes #1050.