-
Notifications
You must be signed in to change notification settings - Fork 407
add another lock to lockable_score #2197
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 another lock to lockable_score #2197
Conversation
b6f42c4
to
10a4763
Compare
Looks like CI is sad because the code under |
10a4763
to
6a6ed2b
Compare
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 #2197 +/- ##
==========================================
- Coverage 90.54% 90.53% -0.01%
==========================================
Files 109 109
Lines 57188 57189 +1
Branches 57188 57189 +1
==========================================
- Hits 51780 51777 -3
- Misses 5408 5412 +4
☔ View full report in Codecov by Sentry. |
6a6ed2b
to
ee8e824
Compare
Looks like this needs a small rebase as some other changes have landed (which make this much more useful for devs, though), sorry about that! |
ee8e824
to
d6cdcb6
Compare
Any desire to pick this back up @jbesraa? It needs a rebase, sadly. |
d6cdcb6
to
f12efd0
Compare
hey @TheBlueMatt |
3dcdd43
to
334cb06
Compare
up^^ |
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.
Nice thanks! Sorry for the delay while 0.0.116 was getting out the door.
4dd4861
to
46fb68d
Compare
@TheBlueMatt @wpaulino this is ready for another review |
54a3b68
to
3caa653
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.
Thanks for working on this, really just one thing we need to figure out.
3caa653
to
427e7e3
Compare
813c5ff
to
5457d8b
Compare
5457d8b
to
2b98309
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.
CI needs a small fix for the c_bindings
build:
diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs
index 63c466b7..4707bb23 100644
--- a/lightning/src/util/test_utils.rs
+++ b/lightning/src/util/test_utils.rs
@@ -118,8 +118,8 @@ impl<'a> Router for TestRouter<'a> {
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
assert_eq!(find_route_query, *params);
if let Ok(ref route) = find_route_res {
- let scorer = &self.scorer.read().unwrap();
- let scorer = ScorerAccountingForInFlightHtlcs::new(&scorer, &inflight_htlcs);
+ let scorer = &self.scorer.read().unwrap();
+ let scorer = ScorerAccountingForInFlightHtlcs::new(&*scorer, &inflight_htlcs);
for path in &route.paths {
let mut aggregate_msat = 0u64;
for (idx, hop) in path.hops.iter().rev().enumerate() {
2b98309
to
b099f75
Compare
@wpaulino thank you so much! made the requested changes and the ci seems to be happier |
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.
Basically there! A few pretty small comments, otherwise ACK.
} | ||
} | ||
|
||
impl<'a, SP:Sized, T: 'a + ScoreUpdate + ScoreLookUp<ScoreParams = SP>> LockableScore<'a> for RwLock<T> { |
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.
This also needs a #[cfg(not(c_bindings))]
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.
because this depends on std?
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.
The bindings don't know anything about std types. While we can manually write wrappers for std types if we wish, its much simpler to write the wrapper here and the bindings can pick up the wrapper type and auto-generate bindings for it.
e98ad1d
to
4347b2a
Compare
New push LGTM, feel free to squash, @wpaulino usually doesn't mind. |
4347b2a
to
c08f2aa
Compare
lightning/src/routing/scoring.rs
Outdated
@@ -86,8 +86,24 @@ use crate::sync::{Mutex, MutexGuard}; | |||
macro_rules! define_score { ($($supertrait: path)*) => { | |||
/// An interface used to score payment channels for path finding. | |||
/// | |||
/// ScoreUpdate is used to update the scorer's internal state after a payment attempt. |
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.
Space not tab after ///
. Likewise for ScoreLookUp
docs.
lightning/src/routing/scoring.rs
Outdated
@@ -86,8 +86,24 @@ use crate::sync::{Mutex, MutexGuard}; | |||
macro_rules! define_score { ($($supertrait: path)*) => { | |||
/// An interface used to score payment channels for path finding. | |||
/// | |||
/// ScoreUpdate is used to update the scorer's internal state after a payment attempt. | |||
pub trait ScoreUpdate $(: $supertrait)* { |
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.
Would move this after ScoreLookUp
to make the patchset smaller. Likewise for the impl
blocks that follow and for ProbabilisticScorerUsingTime
.
lightning/src/routing/scoring.rs
Outdated
@@ -86,8 +86,24 @@ use crate::sync::{Mutex, MutexGuard}; | |||
macro_rules! define_score { ($($supertrait: path)*) => { | |||
/// An interface used to score payment channels for path finding. | |||
/// | |||
/// ScoreUpdate is used to update the scorer's internal state after a payment attempt. |
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.
Add ticks around identifiers. Likewise for ScoreLookUp
.
lightning/src/util/test_utils.rs
Outdated
impl Score for TestScorer { | ||
impl ScoreUpdate for TestScorer { | ||
fn payment_path_failed(&mut self, _actual_path: &Path, _actual_short_channel_id: u64) {} | ||
|
||
fn payment_path_successful(&mut self, _actual_path: &Path) {} | ||
|
||
fn probe_failed(&mut self, _actual_path: &Path, _: u64) {} | ||
|
||
fn probe_successful(&mut self, _actual_path: &Path) {} | ||
} | ||
|
||
impl ScoreLookUp for TestScorer { |
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.
Likewise regarding order.
c08f2aa
to
ad705fb
Compare
no code changes, did a reorder and some docs fixes as suggested |
lightning/src/routing/scoring.rs
Outdated
impl Score for FixedPenaltyScorer { | ||
type ScoreParams = (); | ||
fn channel_penalty_msat(&self, _: u64, _: &NodeId, _: &NodeId, _: ChannelUsage, _score_params: &Self::ScoreParams) -> u64 { | ||
self.penalty_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.
Ordering here.
@@ -1235,50 +1302,7 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac | |||
} | |||
} | |||
|
|||
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for ProbabilisticScorerUsingTime<G, L, T> where L::Target: Logger { |
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.
Also here.
@@ -1176,7 +1177,10 @@ impl Score for TestScorer { | |||
} | |||
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.
nit: only one blank line between blocks
lightning/src/routing/scoring.rs
Outdated
@@ -117,14 +122,16 @@ pub trait Score $(: $supertrait)* { | |||
fn probe_successful(&mut self, path: &Path); | |||
} | |||
|
|||
impl<S: Score, T: DerefMut<Target=S> $(+ $supertrait)*> Score for T { | |||
type ScoreParams = S::ScoreParams; | |||
impl<SP:Sized, S: ScoreLookUp<ScoreParams = SP>, T: Deref<Target=S> $(+ $supertrait)*> ScoreLookUp for T { |
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: space after :
for trait bounds
- Split Score from LockableScore to ScoreLookUp to handle read operations and ScoreUpdate to handle write operations - Change all struct that implemented Score to implement ScoreLookUp and/or ScoreUpdate - Change Mutex's to RwLocks to allow multiple data readers - Change LockableScore to Deref in ScorerAccountingForInFlightHtlcs as we only need to read - Add ScoreLookUp and ScoreUpdate docs - Remove reference(&'a) and Sized from Score in ScorerAccountingForInFlightHtlcs as Score implements Deref - Split MultiThreadedScoreLock into MultiThreadedScoreLockWrite and MultiThreadedScoreLockRead. After splitting LockableScore, we split MultiThreadedScoreLock following the same way, splitting a single score into two srtucts, one for read and other for write. MultiThreadedScoreLock is used in c_bindings.
ad705fb
to
3695b2a
Compare
thanks @jkczyz. pushed the changes |
Please do not unnecessarily rebase onto a newer upstream HEAD (ie rebase onto the same merge commit as you were based on before unless there are conflicts). |
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.
Only changes since @wpaulino's ACK at dc95f704ec62f4ec995ae09429977c609d195033 and the current commit are move + whitespace only, plus:
the ScoreUpdate
docs changing from:
/// An interface used to score payment channels for path finding.
-/// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
///
-/// ScoreUpdate is used to update the scorer's internal state after a payment attempt.
-pub trait ScoreUpdate $(: $supertrait)* {
to
+/// `ScoreUpdate` is used to update the scorer's internal state after a payment attempt.
+pub trait ScoreUpdate $(: $supertrait)* {
and the ScoreLookUp
docs changing from:
-/// ScoreLookUp is used to determine the penalty for a given channel.
to
/// An interface used to score payment channels for path finding.
///
+/// `ScoreLookUp` is used to determine the penalty for a given channel.
+///
+/// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
pub trait ScoreLookUp $(: $supertrait)* {
resolves #2192