Uh oh!
There was an error while loading. Please reload this page.
Track in-flight HTLCs across payments when routing - #1643
Conversation
Uh 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.
fa440fa to
d03d6a8Compare
commented
Aug 6, 2022
@TheBlueMatt Would good to have some early feedback on this PR. Upcoming commits will use in-flight HTLC tracking during routing. Follow-up PR will deal with persistence. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
commented
Aug 8, 2022
Going to be using this for review club session 5. Nice to dig into payment logic a bit. :) |
commented
Aug 8, 2022
hm, I think we do need to pass in the inflight htlcs map into |
commented
Aug 8, 2022
Yea, if we want to exactly match the behavior, but I'm not sure that is neccessary - it'll result in a few suboptimal decisions, but we can do it only in the scorer and we'll still get most of the way there, without more complexity in the router itself. |
commented
Aug 8, 2022
There may be another case when computing rust-lightning/lightning/src/routing/router.rs Lines 1002 to 1004 in d024251 |
commented
Aug 9, 2022
Yea, that's generally what I was referring to - we'll not make the same decisions we'd like to around how much we'd maximally want to send over a channel. I do kinda now wonder if we shouldn't have made that a method on the scorer, but either way, I'm not sure its totally critical that we get it exactly right here - at worse we'll end up refusing to re-use channels that we already have pending payments over where we may have been willing to re-use some small part of their capacity. |
commented
Aug 9, 2022
which method? rust-lightning/lightning/src/routing/scoring.rs Lines 807 to 808 in d024251 |
commented
Aug 9, 2022
@TheBlueMatt Did you mean should have not shouldn't have? |
commented
Aug 9, 2022
Err, yes lol. |
commented
Aug 9, 2022
Another thing to keep in mind is that we'd eventually like to move the |
Uh 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.
Uh 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.
Uh 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.
Uh 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.
Uh 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.
Uh 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.
Uh 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.
Uh 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.
f827add to
b184beeCompareUh 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.
Uh 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.
Uh 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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e8e05fd to
e657138Compare
commented
Aug 21, 2022
I think this is ready for review :) |
Uh 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.
Uh 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.
Uh 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.
Uh 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.
Uh 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.
033028b to
9911955CompareUh 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.
1abd3df to
a434146CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
a434146 to
08130b7Compare
left a comment
There was a problem hiding this comment.
LGTM. @TheBlueMatt could you take another look?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Introduces a new `PaymentInfo` struct that contains both the previous `attempts` count that was tracked as well as the paths that are also currently inflight.
08130b7 to
51b90abCompare| let final_value_msat = invoice.amount_milli_satoshis().unwrap(); | ||
| let route = TestRouter::route_for_value(final_value_msat); | ||
| let router = TestRouter {}; | ||
| let scorer = RefCell::new(TestScorer::new()); |
There was a problem hiding this comment.
Are these RefCells really needed? Wouldn't just creating TestScorers work generally?
There was a problem hiding this comment.
I believe this is because InvoicePayer expects the scorer to implement LockableScore.
TestScorer here is really just a mocked version of a scorer that we'd expect users to implement on their own
There was a problem hiding this comment.
Yeah, a scorer needs to be locked to (a) use its mutable interface in InvoicePayer's event handling and (b) use its immutable interface when routing such that its state doesn't change between calls. Additionally, another reference to it may be needed for serialization.
There was a problem hiding this comment.
I see, thanks! MinCostFlowRouter pull request is at a point where it needs to be tested together with InvoicePayer and tracking in-flight HTLCs, but in a conversion with @TheBlueMatt, he said that as MinCostFlowRouter needs to access liquidity tracking, but not a custom scorer provided by LDK users, LiquidityTracker should be a separate trait implemented by the scorers. Another option in my opinion would be keeping liquidity tracking from scoring totally separate, and DefaultRouter should request the estimated liquidity information and provide it to the immutable Scorer (that can be customized by LDK user, while liquidity tracking implementation probably shouldn't be surfaced in the API).
What do you guys think?
Here's a link to the comments:
There was a problem hiding this comment.
Yeah, I think we want at least two follow-ups to this PR:
(1) Move the LockableScore type parameter to DefaultRouter since some routers (e.g., remote server routing) don't need a scorer.
(2) Move liquidity tracking to either the Payer trait or a dedicated one, having InvoicePayer query it and pass the liquidity information to Router akin to how it currently passes a scorer.
The latter comes from an observation that I made in review club. ChannelManager actually knows all the liquidity information given it is the one producing PaymentPathFailed and PaymentPathSuccessful events. It also would make liquidity tracking persist across restarts.
See also #1157 for exposing pending payments more generally, which should be considered when making this change.
51b90ab to
c43843eCompareUh oh!
There was an error while loading. Please reload this page.
c43843e to
e1fddf1CompareUh oh!
There was an error while loading. Please reload this page.
Added two methods, `process_path_inflight_htlcs` and `remove_path_inflight_htlcs`, that updates that `payment_cache` map with path information that may have failed, succeeded, or have been given up on. Introduced `AccountForInflightHtlcs`, which will wrap our user-provided scorer. We move the `S:Score` type parameterization from the `Router` to `find_route`, so we can use our newly introduced `AccountForInflightHtlcs`. `AccountForInflightHtlcs` keeps track of a map of inflight HTLCs by their short channel id, direction, and give us the value that is being used up. This map will in turn be populated prior to calling `find_route`, where we’ll use `create_inflight_map`, to generate a current map of all inflight HTLCs based on what was stored in `payment_cache`.
Made sure that every hop has a unique receipient. When we simulate calling `channel_penalty_msat` in `TestRouter`’s find route, use actual previous node ids instead of just using the payer’s.
e1fddf1 to
80daf94Compare
Addresses #1267.
Purpose
As a sender, we want to keep track of all the HTLCs that are currently in flight. We currently do that between pathfinding attempts in
find_route. However, that information is not currently shared across payments, leading to some inaccuracies.Proposed Implementation
Accounting for the HTLCs will consist of two efforts: keeping track of them, and using them.
Keep Track
In
pay_internal, we want to respond to specific results ofsend_paymentwhich will tell us when we'll need to store the path information for use later.Path information is then stored in
payment_cacheof our payer.Using
Before
find_routeis called, we retrieve all the paths we stored, and loop through them to construct a HashMap (HashMap<(u64, bool), u64>) mapping a channel's short channel id and direction with the amount being sent.This map is wrapped with our user-supplied score in a
AccountForInFlightHtlcsstruct, which will serve to delegateScorefunctions to its underlying scorer. It will also use our new liquidity map to construct aChannelUsageaccounting for the inflight HTLCs to be passed tochannel_penalty_msat.Last Edited: 2022-08-15T05:27:11.602Z
Other Notes
Future opportunities: