-
Notifications
You must be signed in to change notification settings - Fork 385
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
Fix DefaultRouter type restrained to only MutexGuard #2383
Conversation
Hmm, I really hate the dyn and Box indirection here, but I think you're onto something. I think maybe we can make a new concrete diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs
index 787777a9d..0c74318f5 100644
--- a/lightning/src/routing/router.rs
+++ b/lightning/src/routing/router.rs
@@ -33,9 +33,10 @@ use core::{cmp, fmt};
use core::ops::{Deref,DerefMut};
/// A [`Router`] implemented using [`find_route`].
-pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Score<Sco
reParams = SP>> where
+pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, D, Sc: Score<
ScoreParams = SP>> where
L::Target: Logger,
- S::Target: for <'a> LockableScore<'a, Locked = 'a + DerefMut<Target = Sc>>,
+ for<'a> D: 'a + DerefMut<Target = Sc>,
+ S::Target: for <'a> LockableScore<'a, Locked = D>,
{
network_graph: G,
logger: L, |
Hmm. let me try abit more, i kind of get what you mean - to not try to use dyn DerefMut and instead properly wrap that locked functionality with a concrete object thats passed in as a generic |
Yea but sorry the patch missed the required additional Sized bound on D. |
b512072
to
bc2a02c
Compare
d6fa5df
to
87328f7
Compare
Oops, okay, sorry for the runaround, I played with this more and I think I have a working suggestion: instead of this change, make the
then we can still bound the
|
88edeb1
to
0ab8b3e
Compare
This is brilliant! thank you! |
8e9383a
to
00a8a90
Compare
#[cfg(c_bindings)] | ||
impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'a, T> { | ||
type ScoreParams = <T as Score>::ScoreParams; | ||
fn channel_penalty_msat(&self, scid: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage, score_params: &Self::ScoreParams) -> u64 { | ||
self.0.channel_penalty_msat(scid, source, target, usage, score_params) | ||
} | ||
fn payment_path_failed(&mut self, path: &Path, short_channel_id: u64) { | ||
self.0.payment_path_failed(path, short_channel_id) | ||
} | ||
fn payment_path_successful(&mut self, path: &Path) { | ||
self.0.payment_path_successful(path) | ||
} | ||
fn probe_failed(&mut self, path: &Path, short_channel_id: u64) { | ||
self.0.probe_failed(path, short_channel_id) | ||
} | ||
fn probe_successful(&mut self, path: &Path) { | ||
self.0.probe_successful(path) | ||
} | ||
} |
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.
now that MultiThreadedScoreLock<'a, T>
implements DerefMut
, this implementation is in conflict with scoring.rs:120-142 and can be removed.
#[cfg(c_bindings)] | ||
/// A locked `MultiThreadedLockableScore`. | ||
pub struct MultiThreadedScoreLock<'a, T: Score>(MutexGuard<'a, T>); | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: 'a + Score> Writeable for MultiThreadedScoreLock<'a, T> { | ||
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> { | ||
self.0.write(writer) | ||
} | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: 'a + Score> DerefMut for MultiThreadedScoreLock<'a, T> { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
self.0.deref_mut() | ||
} | ||
} | ||
|
||
#[cfg(c_bindings)] | ||
impl<'a, T: 'a + Score> Deref for MultiThreadedScoreLock<'a, T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.0.deref() | ||
} | ||
} | ||
|
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.
rearranged MultiThreadedScoreLock
and MultiThreadedLockableScore
methods to be colocated since their names are too similar and methods were interweaved
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2383 +/- ##
==========================================
- Coverage 90.32% 90.31% -0.01%
==========================================
Files 106 106
Lines 54968 54965 -3
Branches 54968 54965 -3
==========================================
- Hits 49651 49644 -7
- Misses 5317 5321 +4
☔ View full report in Codecov by Sentry. |
@TheBlueMatt this one is now ready for review :) |
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.
Awesome, thanks so much this is great. Can you add more details to the commit message, what is in the pr text would be fine.
Since I think this is ready let's make sure we get it for 116. |
Type of DerefMut for DefaultRouter was specialized to only MutexGuard. It should be generic around RefMut and MutexGuard. This commit fixes that
@TheBlueMatt this is good to go i think |
Type of deref mut for default router was specialized to only MutexGuard. It should be generic around RefMut and MutexGuard. This PR fixes that