Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 14, 2024
1 parent 23a1091 commit af9bb81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ where
&self,
payment_data: SendPaymentData,
) -> Result<Vec<PaymentHopData>, PathFindError> {
let payment_data = payment_data.clone();
let source = self.get_source_pubkey();
let target = payment_data.target_pubkey;
let amount = payment_data.amount;
Expand Down Expand Up @@ -792,17 +791,13 @@ where
}

let mut current = source_node.node_id;
loop {
if let Some(elem) = distances.get(&current) {
let next_hop = elem.next_hop.as_ref().expect("next_hop is none");
result.push(PathEdge {
target: next_hop.0,
channel_outpoint: next_hop.1.clone(),
});
current = next_hop.0;
} else {
break;
}
while let Some(elem) = distances.get(&current) {
let next_hop = elem.next_hop.as_ref().expect("next_hop is none");
result.push(PathEdge {
target: next_hop.0,
channel_outpoint: next_hop.1.clone(),
});
current = next_hop.0;
if current == target {
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/fiber/tests/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ fn test_graph_payment_pay_self_with_one_node() {

let route = network.graph.build_route(payment_data);
assert!(route.is_ok());
let route = route.unwrap();
assert_eq!(route[1].next_hop, Some(node0.into()));
}

#[test]
Expand All @@ -907,6 +909,7 @@ fn test_graph_build_route_with_double_edge_node() {
network.add_edge_with_config(2, 3, Some(500), Some(2), Some(50), None, None, Some(1));

let node0 = network.keys[0];
let node1 = network.keys[2];

// node0 is the source node
let command = SendPaymentCommand {
Expand All @@ -925,6 +928,9 @@ fn test_graph_build_route_with_double_edge_node() {
let payment_data = SendPaymentData::new(command, node0.into()).unwrap();
let route = network.graph.build_route(payment_data);
assert!(route.is_ok());
let route = route.unwrap();
assert_eq!(route[0].next_hop, Some(node1.into()));
assert_eq!(route[1].next_hop, Some(node0.into()));
}

#[test]
Expand Down

0 comments on commit af9bb81

Please sign in to comment.