Skip to content

Commit

Permalink
add comments for find_route
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 13, 2024
1 parent 8f9bdde commit 856b98b
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,19 @@ where
) -> Result<Vec<PathEdge>, GraphError> {
let started_time = std::time::Instant::now();
let nodes_len = self.nodes.len();
let route_to_self = source == target;

let mut result = vec![];
let mut nodes_visited = 0;
let mut edges_expanded = 0;
let mut nodes_heap = NodeHeap::new(nodes_len);
let mut distances = HashMap::<Pubkey, NodeHeapElement>::new();
// a map from node_id to the selected channel outpoint
// suppose the scenario of A <-- channel_1 --> B <-- channel_2 --> A
// when we starting iterate channels from A, we may considerting channel_1 and channel_2,
// and we selected channel_1 according to weight
// in this case, `last_hop_channels` stores (B -> channel_1) so that we can skip channel_1 when we iterate channels from B
let mut last_hop_channels = HashMap::new();

if amount == 0 {
return Err(GraphError::Amount(
Expand Down Expand Up @@ -645,8 +653,7 @@ where
next_hop: None,
incoming_htlc_expiry: 0,
});
let route_to_self = source == target;
let mut last_hop_channels = HashMap::new();

while let Some(cur_hop) = nodes_heap.pop() {
nodes_visited += 1;

Expand Down Expand Up @@ -676,11 +683,6 @@ where
// if the amount to send is greater than the amount we have, skip this edge
if let Some(max_fee_amount) = max_fee_amount {
if amount_to_send > amount + max_fee_amount {
debug!(
"amount_to_send: {:?} is greater than sum_amount sum_amount: {:?}",
amount_to_send,
amount + max_fee_amount
);
continue;
}
}
Expand All @@ -690,19 +692,9 @@ where
|| (channel_update.htlc_maximum_value != 0
&& amount_to_send > channel_update.htlc_maximum_value)
{
debug!(
"amount_to_send is greater than channel capacity: {:?} capacity: {:?}, htlc_max_value: {:?}",
amount_to_send,
channel_info.capacity(),
channel_update.htlc_maximum_value
);
continue;
}
if amount_to_send < channel_update.htlc_minimum_value {
debug!(
"amount_to_send is less than htlc_minimum_value: {:?} min_value: {:?}",
amount_to_send, channel_update.htlc_minimum_value
);
continue;
}
let incoming_htlc_expiry = cur_hop.incoming_htlc_expiry
Expand Down

0 comments on commit 856b98b

Please sign in to comment.