Skip to content

Commit 895f12d

Browse files
committed
Add additional TRACE-level logging during pathfinding in router
1 parent f900252 commit 895f12d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/routing/router.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct DummyDirectionalChannelInfo {
168168
/// so that we can choose cheaper paths (as per Dijkstra's algorithm).
169169
/// Fee values should be updated only in the context of the whole path, see update_value_and_recompute_fees.
170170
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
171-
#[derive(Clone)]
171+
#[derive(Clone, Debug)]
172172
struct PathBuildingHop<'a> {
173173
// The RouteHintHop fields which will eventually be used if this hop is used in a final Route.
174174
// Note that node_features is calculated separately after our initial graph walk.
@@ -506,6 +506,8 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
506506
// - when we want to stop looking for new paths.
507507
let mut already_collected_value_msat = 0;
508508

509+
log_trace!(logger, "Building path from {} (payee) to {} (us/payer) for value {} msat.", payee, our_node_id, final_value_msat);
510+
509511
macro_rules! add_entry {
510512
// Adds entry which goes from $src_node_id to $dest_node_id
511513
// over the channel with id $chan_id with fees described in
@@ -891,6 +893,8 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
891893
}
892894
}
893895

896+
log_trace!(logger, "Starting main path collection loop with {} nodes pre-filled from first/last hops.", targets.len());
897+
894898
// At this point, targets are filled with the data from first and
895899
// last hops communicated by the caller, and the payment receiver.
896900
let mut found_new_path = false;
@@ -954,6 +958,9 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
954958
ordered_hops.last_mut().unwrap().0.hop_use_fee_msat = 0;
955959
ordered_hops.last_mut().unwrap().0.cltv_expiry_delta = final_cltv;
956960

961+
log_trace!(logger, "Found a path back to us from the target with {} hops contributing up to {} msat: {:?}",
962+
ordered_hops.len(), value_contribution_msat, ordered_hops);
963+
957964
let mut payment_path = PaymentPath {hops: ordered_hops};
958965

959966
// We could have possibly constructed a slightly inconsistent path: since we reduce
@@ -989,8 +996,9 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
989996
// If we weren't capped by hitting a liquidity limit on a channel in the path,
990997
// we'll probably end up picking the same path again on the next iteration.
991998
// Decrease the available liquidity of a hop in the middle of the path.
992-
let victim_liquidity = bookkeeped_channels_liquidity_available_msat.get_mut(
993-
&payment_path.hops[(payment_path.hops.len() - 1) / 2].0.short_channel_id).unwrap();
999+
let victim_scid = payment_path.hops[(payment_path.hops.len() - 1) / 2].0.short_channel_id;
1000+
log_trace!(logger, "Disabling channel {} for future path building iterations to avoid duplicates.", victim_scid);
1001+
let victim_liquidity = bookkeeped_channels_liquidity_available_msat.get_mut(&victim_scid).unwrap();
9941002
*victim_liquidity = 0;
9951003
}
9961004

@@ -1032,6 +1040,8 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
10321040
// In the latter case, making another path finding attempt won't help,
10331041
// because we deterministically terminated the search due to low liquidity.
10341042
if already_collected_value_msat >= recommended_value_msat || !found_new_path {
1043+
log_trace!(logger, "Have now collected {} (seeking {}) in paths. Last path loop {} a new path.",
1044+
already_collected_value_msat, recommended_value_msat, if found_new_path { "found" } else { "did not find" });
10351045
break 'paths_collection;
10361046
} else if found_new_path && already_collected_value_msat == final_value_msat && payment_paths.len() == 1 {
10371047
// Further, if this was our first walk of the graph, and we weren't limited by an
@@ -1040,8 +1050,10 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
10401050
// potentially allowing us to pay fees to meet the htlc_minimum on the new path while
10411051
// still keeping a lower total fee than this path.
10421052
if !hit_minimum_limit {
1053+
log_trace!(logger, "Collected exactly our payment amount on the first pass, without hitting an htlc_minimum_msat limit, exiting.");
10431054
break 'paths_collection;
10441055
}
1056+
log_trace!(logger, "Collected our payment amount on the first pass, but running again to collect extra paths with a potentially higher limit.");
10451057
path_value_msat = recommended_value_msat;
10461058
}
10471059
}
@@ -1152,7 +1164,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
11521164
}
11531165

11541166
let route = Route { paths: selected_paths };
1155-
log_trace!(logger, "Got route: {}", log_route!(route));
1167+
log_info!(logger, "Got route to {}: {}", payee, log_route!(route));
11561168
Ok(route)
11571169
}
11581170

0 commit comments

Comments
 (0)