Skip to content

Commit 612f17c

Browse files
committed
Group counters of ignored route candidates to struct
1 parent a801adc commit 612f17c

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

lightning/src/routing/router.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,32 @@ impl<'a> fmt::Display for LoggedCandidateHop<'a> {
20242024
}
20252025
}
20262026

2027+
2028+
// Remember how many candidates we ignored to allow for some logging afterwards.
2029+
#[derive(Default)]
2030+
struct IgnoredCandidatesStats {
2031+
value_contribution: u32,
2032+
cltv_delta_limit: u32,
2033+
path_length_limit: u32,
2034+
previously_failed: u32,
2035+
total_fee_limit: u32,
2036+
avoid_overpayment: u32,
2037+
htlc_minimum_msat_limit: u32,
2038+
}
2039+
2040+
impl IgnoredCandidatesStats {
2041+
// Return total number of ignored cantotal number of ignored candidates.
2042+
const fn ignored_total(&self) -> u32 {
2043+
self.value_contribution +
2044+
self.cltv_delta_limit +
2045+
self.path_length_limit +
2046+
self.previously_failed +
2047+
self.total_fee_limit +
2048+
self.avoid_overpayment +
2049+
self.htlc_minimum_msat_limit
2050+
}
2051+
}
2052+
20272053
#[inline]
20282054
fn sort_first_hop_channels(
20292055
channels: &mut Vec<&ChannelDetails>, used_liquidities: &HashMap<CandidateHopId, u64>,
@@ -2345,14 +2371,9 @@ where L::Target: Logger {
23452371
log_trace!(logger, "Building path from {} to payer {} for value {} msat.",
23462372
LoggedPayeePubkey(payment_params.payee.node_id()), our_node_pubkey, final_value_msat);
23472373

2374+
23482375
// Remember how many candidates we ignored to allow for some logging afterwards.
2349-
let mut num_ignored_value_contribution: u32 = 0;
2350-
let mut num_ignored_path_length_limit: u32 = 0;
2351-
let mut num_ignored_cltv_delta_limit: u32 = 0;
2352-
let mut num_ignored_previously_failed: u32 = 0;
2353-
let mut num_ignored_total_fee_limit: u32 = 0;
2354-
let mut num_ignored_avoid_overpayment: u32 = 0;
2355-
let mut num_ignored_htlc_minimum_msat_limit: u32 = 0;
2376+
let mut ignored_stats = IgnoredCandidatesStats::default();
23562377

23572378
macro_rules! add_entry {
23582379
// Adds entry which goes from $candidate.source() to $candidate.target() over the $candidate hop.
@@ -2370,13 +2391,7 @@ where L::Target: Logger {
23702391
final_cltv_expiry_delta,
23712392
recommended_value_msat,
23722393
&logger,
2373-
&mut num_ignored_value_contribution,
2374-
&mut num_ignored_path_length_limit,
2375-
&mut num_ignored_cltv_delta_limit,
2376-
&mut num_ignored_previously_failed,
2377-
&mut num_ignored_total_fee_limit,
2378-
&mut num_ignored_avoid_overpayment,
2379-
&mut num_ignored_htlc_minimum_msat_limit,
2394+
&mut ignored_stats,
23802395
&mut hit_minimum_limit,
23812396
&mut dist,
23822397
our_node_id,
@@ -2924,17 +2939,14 @@ where L::Target: Logger {
29242939
}
29252940
}
29262941

2927-
let num_ignored_total = num_ignored_value_contribution + num_ignored_path_length_limit +
2928-
num_ignored_cltv_delta_limit + num_ignored_previously_failed +
2929-
num_ignored_avoid_overpayment + num_ignored_htlc_minimum_msat_limit +
2930-
num_ignored_total_fee_limit;
2942+
let num_ignored_total = ignored_stats.ignored_total();
29312943
if num_ignored_total > 0 {
29322944
log_trace!(logger,
29332945
"Ignored {} candidate hops due to insufficient value contribution, {} due to path length limit, {} due to CLTV delta limit, {} due to previous payment failure, {} due to htlc_minimum_msat limit, {} to avoid overpaying, {} due to maximum total fee limit. Total: {} ignored candidates.",
2934-
num_ignored_value_contribution, num_ignored_path_length_limit,
2935-
num_ignored_cltv_delta_limit, num_ignored_previously_failed,
2936-
num_ignored_htlc_minimum_msat_limit, num_ignored_avoid_overpayment,
2937-
num_ignored_total_fee_limit, num_ignored_total);
2946+
ignored_stats.value_contribution, ignored_stats.path_length_limit,
2947+
ignored_stats.cltv_delta_limit, ignored_stats.previously_failed,
2948+
ignored_stats.htlc_minimum_msat_limit, ignored_stats.avoid_overpayment,
2949+
ignored_stats.total_fee_limit, num_ignored_total);
29382950
}
29392951

29402952
// Step (5).
@@ -3108,13 +3120,7 @@ fn add_entry_internal<'a, L: Deref, S: ScoreLookUp>(
31083120
final_cltv_expiry_delta: u32,
31093121
recommended_value_msat: u64,
31103122
logger: &L,
3111-
num_ignored_value_contribution: &mut u32,
3112-
num_ignored_path_length_limit: &mut u32,
3113-
num_ignored_cltv_delta_limit: &mut u32,
3114-
num_ignored_previously_failed: &mut u32,
3115-
num_ignored_total_fee_limit: &mut u32,
3116-
num_ignored_avoid_overpayment: &mut u32,
3117-
num_ignored_htlc_minimum_msat_limit: &mut u32,
3123+
ignored_stats: &mut IgnoredCandidatesStats,
31183124
hit_minimum_limit: &mut bool,
31193125
dist: &mut Vec<Option<PathBuildingHop<'a>>>,
31203126
our_node_id: NodeId,
@@ -3228,12 +3234,12 @@ where
32283234
LoggedCandidateHop(&candidate),
32293235
effective_capacity);
32303236
}
3231-
*num_ignored_value_contribution += 1;
3237+
ignored_stats.value_contribution += 1;
32323238
} else if exceeds_max_path_length {
32333239
if should_log_candidate {
32343240
log_trace!(logger, "Ignoring {} due to exceeding maximum path length limit.", LoggedCandidateHop(&candidate));
32353241
}
3236-
*num_ignored_path_length_limit += 1;
3242+
ignored_stats.path_length_limit += 1;
32373243
} else if exceeds_cltv_delta_limit {
32383244
if should_log_candidate {
32393245
log_trace!(logger, "Ignoring {} due to exceeding CLTV delta limit.", LoggedCandidateHop(&candidate));
@@ -3246,19 +3252,19 @@ where
32463252
);
32473253
}
32483254
}
3249-
*num_ignored_cltv_delta_limit += 1;
3255+
ignored_stats.cltv_delta_limit += 1;
32503256
} else if payment_failed_on_this_channel {
32513257
if should_log_candidate {
32523258
log_trace!(logger, "Ignoring {} due to a failed previous payment attempt.", LoggedCandidateHop(&candidate));
32533259
}
3254-
*num_ignored_previously_failed += 1;
3260+
ignored_stats.previously_failed += 1;
32553261
} else if may_overpay_to_meet_path_minimum_msat {
32563262
if should_log_candidate {
32573263
log_trace!(logger,
32583264
"Ignoring {} to avoid overpaying to meet htlc_minimum_msat limit ({}).",
32593265
LoggedCandidateHop(&candidate), candidate.htlc_minimum_msat());
32603266
}
3261-
*num_ignored_avoid_overpayment += 1;
3267+
ignored_stats.avoid_overpayment += 1;
32623268
*hit_minimum_limit = true;
32633269
} else if over_path_minimum_msat {
32643270
// Note that low contribution here (limited by available_liquidity_msat)
@@ -3330,7 +3336,7 @@ where
33303336
);
33313337
}
33323338
}
3333-
*num_ignored_total_fee_limit += 1;
3339+
ignored_stats.total_fee_limit += 1;
33343340
} else {
33353341
let channel_usage = ChannelUsage {
33363342
amount_msat: amount_to_transfer_over_msat,
@@ -3431,7 +3437,7 @@ where
34313437
);
34323438
}
34333439
}
3434-
*num_ignored_htlc_minimum_msat_limit += 1;
3440+
ignored_stats.htlc_minimum_msat_limit += 1;
34353441
}
34363442
}
34373443
}

0 commit comments

Comments
 (0)