-
Notifications
You must be signed in to change notification settings - Fork 416
[LSPS5 FollowUp] Simplify LSPS5/client peer state #3969
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
[LSPS5 FollowUp] Simplify LSPS5/client peer state #3969
Conversation
👋 Thanks for assigning @tnull as a reviewer! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3969 +/- ##
==========================================
+ Coverage 88.94% 88.99% +0.04%
==========================================
Files 174 174
Lines 124201 124199 -2
Branches 124201 124199 -2
==========================================
+ Hits 110472 110525 +53
+ Misses 11251 11200 -51
+ Partials 2478 2474 -4
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:
|
c8e9948
to
fba3056
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.
Did a first pass, mostly looks good.
} | ||
|
||
self.map.insert(key.clone(), value); | ||
self.order.push_back(key.clone()); |
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 think this clone
is unnecessary?
if let Some(oldest) = self.order.pop_front() { | ||
self.map.remove(&oldest); | ||
} | ||
} |
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.
Can we sprinkle in some debug_assert
s ensuring that neither map
nor order
ever exceed cap at the end of the methods taking &mut
?
assert!(m.get(&"key").is_none()); | ||
} | ||
|
||
#[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.
These tests would be a prime example were proptest
s would be easily applicable and would extend test coverage.
lightning-liquidity/src/utils/mod.rs
Outdated
@@ -57,4 +57,5 @@ mod tests { | |||
} | |||
} | |||
|
|||
pub(crate) mod bounded_map; |
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.
Huh, why are these mod
definitions at the bottom by now? Let's move them to the top please, and let's keep pub
and pub(crate)
definitions in separate groups.
@@ -345,6 +351,19 @@ where | |||
} | |||
}; | |||
self.with_peer_state(*counterparty_node_id, handle_response); | |||
|
|||
let mut outer_state_lock = self.per_peer_state.write().unwrap(); |
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.
Mind moving this out to a dedicated method?
👋 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. |
thanks for the review @tnull ! all comments are addressed in fixup commits |
1332159
to
91c7904
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.
Feel free to squash fixups!
91c7904
to
5d25ab1
Compare
done! @tnull |
5d25ab1
to
993c366
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
✅ Added second reviewer: @valentinewallace |
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.
Have a Vec or VecDeque with capacity to keep track of the requests, truncate when limit is reached, and then do vec.iter().position(|v, _, _| v == r_id) for retrieval (which is kind of ugly and not O(1) like in hashmaps)
Sure, but for N=5 its probably faster than doing the SipHash-1-3 required to do that HashMap O(1), not to mention it avoids a second allocated datastructure. Let's definitely not overengineer this - walking a Vec is totally fine for N=5.
Client will no longer use a time provider to expire pending requests. Instead, it will just keep the X most recent requests (coming in next commit).
993c366
to
ec6a9f0
Compare
thanks for reviewing @TheBlueMatt just pushed fixup commit ec6a9f0 where I drop the bounded_map and change everything so it uses vecs for keeping track of the client's pending requests. let me know what you think |
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 think this LGTM, feel free to squash if @tnull is fine with dropping the fancy map.
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.
Fixup LGTM, please squash so we can get this landed.
ec6a9f0
to
cf23e91
Compare
thanks for taking a look @tnull. fixup squashed! offtopic question about process: I'm not sure if there's an easy way to verify that the squash was actually just a squash and nothing more. for example, I just split the fixup into the last two commits and reworded the second one. I did not change anything else, but there's no easy way for you to quickly confirm that I didn't accidentally change something else |
For one you can hit the 'Compare' button above to see the diff between pushes. I also always check out the working branch locally to review, so can simply do a diff to see if/what changed. As a bonus you can use |
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.
Going ahead landing this given that the current state had two 'LGTM' before
Addressing some LSPS5 follow ups, specifically comments #3662 (comment) and #3662 (comment)
This PR introduces changes so the LSPS5/client drops the TimeProvider, and now instead of just expiring pending requests after a certain time, it just keeps the 5 most recent requests of each type (the
5
here can be changed, not married to the value, I put it just to put something. Thoughts @tnull @TheBlueMatt ?)My preference for implementing this was:
Some alternatives for making this change were
vec.iter().position(|v, _, _| v == r_id)
for retrieval (which is kind of ugly and not O(1) like in hashmaps)I went with the last option, but I'm open to alternatives
Also, the last commit introduces a change where the peerstate is cleaned if there are no pending requests with that peer