Prefactor for Trampoline MPP accumulation#4510
Prefactor for Trampoline MPP accumulation#4510carlaKC wants to merge 18 commits intolightningdevkit:mainfrom
Conversation
|
👋 Thanks for assigning @valentinewallace as a reviewer! |
40f75a4 to
f15271e
Compare
|
No issues found. This is a re-review of the same PR. My prior review covered all the critical invariants and found no issues. After a second thorough pass examining the entire diff, I confirm:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4510 +/- ##
========================================
Coverage 86.19% 86.19%
========================================
Files 160 160
Lines 107537 107713 +176
Branches 107537 107713 +176
========================================
+ Hits 92693 92848 +155
- Misses 12220 12238 +18
- Partials 2624 2627 +3
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:
|
|
🔔 1st Reminder Hey @valentinewallace! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @valentinewallace! This PR has been waiting for your review. |
|
Some discussion in the dependent PR, taking @valentinewallace off as a reviewer for now to save some bot-spam. |
f15271e to
6aae0dd
Compare
|
Updated to include suggested refactor, and pulled some of the blinded path test utils up into this PR as well. |
6aae0dd to
0e82461
Compare
valentinewallace
left a comment
There was a problem hiding this comment.
Nothing blocking, thanks for that mpp part refactor! Probably can get a 2nd reviewer on here. I didn't review the code moves that carefully but claude said they're legit
lightning/src/ln/channelmanager.rs
Outdated
|
|
||
| impl ClaimableHTLC { | ||
| // Increments timer ticks and returns a boolean indicating whether HTLC is timed out. | ||
| fn mpp_timer_tick(&mut self) -> bool { |
There was a problem hiding this comment.
nit: I'd prefer to in-line this if it's only used in one place
| user_channel_id: val.prev_hop.user_channel_id.unwrap_or(0), | ||
| cltv_expiry: val.cltv_expiry, | ||
| value_msat: val.value, | ||
| counterparty_node_id: val.mpp_part.prev_hop.counterparty_node_id, |
There was a problem hiding this comment.
nit: it looks like mpp_part.prev_hop is accessed in a million places - might be nice to have a helper
There was a problem hiding this comment.
Considered this but I found it a bit ick to have some fields accessed with a helper and others directly - direct access also didn't mess up the formatting quite enough for it to be worthwhile.
Defer to second reviewer to make a call? Happy to change !
lightning/src/ln/channelmanager.rs
Outdated
| }; | ||
| check_total_value!(purpose); | ||
|
|
||
| if let Err(_) = self.handle_claimable_htlc( |
There was a problem hiding this comment.
nit: Err(()) if possible in case it changes so we're forced to update it
|
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
0e82461 to
b2ac8f4
Compare
|
Addressed 2x nits. |
|
✅ Added second reviewer: @joostjager |
TheBlueMatt
left a comment
There was a problem hiding this comment.
Only one real comment.
lightning/src/ln/channelmanager.rs
Outdated
| sender_intended_value: outgoing_amt_msat, | ||
| timer_ticks: 0, | ||
| total_value_received: None, | ||
| htlc_value, |
There was a problem hiding this comment.
I will say, constructors in rust are way less readable then destructuring where you get the parameter name beside the value we're assigning :/
There was a problem hiding this comment.
Yeah fair, I was also on the fence - will remove
lightning/src/ln/channelmanager.rs
Outdated
|
|
||
| /// Returns a boolean indicating whether the HTLC has timed out on chain, accounting for a buffer | ||
| /// that gives us time to resolve it. | ||
| fn check_onchain_timeout(&self, height: u32, buffer: u32) -> bool { |
There was a problem hiding this comment.
nit: should buffer be hard-coded? its currently a constant across the code base and while we might want to make that configurable it probably should be constant between trampoline and not-trampoline.
lightning/src/ln/channelmanager.rs
Outdated
| let ref mut claimable_payment = claimable_payments | ||
| .claimable_payments | ||
| .entry(payment_hash) | ||
| // Note that if we insert here we MUST NOT fail_htlc!() |
There was a problem hiding this comment.
We don't fail_htlc from here anymore.
| /// Both [`ForwardTlvs`] (channel-based forwarding) and [`TrampolineForwardTlvs`] (trampoline | ||
| /// node-based forwarding) implement this trait, allowing blinded path construction to be generic | ||
| /// over the forwarding mechanism. | ||
| pub trait ForwardTlvsInfo: Writeable + Clone { |
There was a problem hiding this comment.
hmm, do we really want people implementing their own ForwardTlvsInfo? Should we instead make it an internal thing and expose wrapper types?
There was a problem hiding this comment.
Going with a sealed supertrait b/c it felt a bit cleaner and we have the pattern elsewhere.
Happy to do a wrapper if that's your pref!
Pull out all fields that are common to incoming claimable and trampoline MPP HTLCs. This will be used in future commits to accumulate MPP HTLCs that are part of trampoline forwards - we can't claim these, but need to accumulate them in the same way as receives before forwarding onwards.
We'll use this shared logic when we need to timeout trampoline HTLCs. Note that there's a slight behavior change in this commit. Previously, we'd do a first pass to check out total received value and return early if we'd reached it without applying a MPP tick to any HTLC. Now, we'll apply the MPP tick as we accumulate our total value received. This does not make any difference, because we never MPP-timeout fully accumulated MPP payments so it doesn't matter if we've applied the tick when we've reached our full amount.
We'll re-use this to check trampoline MPP timeout in future commits.
In the commit that follows we're going to need to take ownership of our htlc before this macro is used, so we pull out the information we need in advance.
We're going to use the same logic for trampoline and for incoming MPP payments, so we pull this out into a separate function.
To allow re-use with trampoline payments which won't use the ClaimablePayment type, make handling generic for anything with MPP parts. Here we also move counterparty skimmed logic to claimable payments, as this doesn't apply for trampoline.
For trampoline payments, we don't want to enforce a minimum cltv delta between our incoming and outer onion outgoing CLTV because we'll calculate our delta from the inner trampoline onion's value. However, we still want to check that we get at least the CLTV that the sending node intended for us and we still want to validate our incoming value. Refactor to allow setting a zero delta, for use for trampoline payments.
To use helper functions for either trampoline or regular paths.
We only want to support trampoline and regular blinded paths, so we don't want to support implementation outside of this crate. We need the trait itself to be public as it's part of a public struct.
To create trampoline forwarding and single hop receiving tails.
b2ac8f4 to
380f744
Compare
|
Diff for last review round! |
This PR contains a set of refactors pulled out of #4493: