Skip to content

Commit

Permalink
Remove old loading channel from store code
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jan 10, 2025
1 parent 75ed475 commit 9c9aece
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 52 deletions.
19 changes: 0 additions & 19 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,25 +836,6 @@ where
self.source = source;
}

pub fn load_owned_channel_info(&mut self) {
for (_peer_id, channel_id, _state) in self.store.get_active_channel_states(None) {
match self.store.get_channel_actor_state(&channel_id) {
Some(channel_actor_state) => {
assert_eq!(channel_actor_state.local_pubkey, self.source);
match ChannelInfo::try_from(&channel_actor_state) {
Ok(channel_info) => {
self.channels
.insert(channel_info.channel_outpoint.clone(), channel_info);
}
Err(_) => {}
};
}
// It is possible that after we obtained the list of channels, the channel is deleted.
None => {}
}
}
}

/// Returns a list of `PaymentHopData` for all nodes in the route,
/// including the origin and the target node.
pub fn build_route(
Expand Down
15 changes: 10 additions & 5 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,16 @@ where
}
NetworkActorEvent::OwnedChannelUpdateEvent(owned_channel_update_event) => {
let mut graph = self.network_graph.write().await;
debug!(
"Received owned channel update event: {:?}",
owned_channel_update_event
);
let is_down =
matches!(owned_channel_update_event, OwnedChannelUpdateEvent::Down(_));
graph.process_owned_channel_update_event(owned_channel_update_event);
if is_down {
debug!("Owned channel is down");
}
}
}
Ok(())
Expand Down Expand Up @@ -1591,11 +1600,7 @@ where
payment_session: &mut PaymentSession,
payment_data: &SendPaymentData,
) -> Result<Vec<PaymentHopData>, Error> {
// Load owned channel info before building route, so that we use private channels and also the
// exact balance of the channels.
let mut rwgraph = self.network_graph.write().await;
rwgraph.load_owned_channel_info();
let graph = tokio::sync::RwLockWriteGuard::downgrade(rwgraph);
let graph = self.network_graph.read().await;
match graph.build_route(payment_data.clone()) {
Err(e) => {
let error = format!("Failed to build route, {}", e);
Expand Down
32 changes: 4 additions & 28 deletions src/fiber/tests/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ async fn test_send_payment_middle_hop_stopped() {
true,
)
.await;
let [mut node_0, _node_1, mut node_2, node_3, mut node_4] = nodes.try_into().expect("5 nodes");
let [mut node_0, _node_1, _node_2, node_3, mut node_4] = nodes.try_into().expect("5 nodes");

// dry run node_0 -> node_3 will select 0 -> 4 -> 3
let res = node_0
Expand All @@ -1505,40 +1505,16 @@ async fn test_send_payment_middle_hop_stopped() {
node_4.stop().await;
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;

let res = node_0
.send_payment_keysend(&node_3, 1000, true)
.await
.unwrap();
eprintln!("res: {:?}", res);
// when node_4 stopped, the first try path is still 0 -> 4 -> 3
// so the fee is 1
assert_eq!(res.fee, 1);

let res = node_0
.send_payment_keysend(&node_3, 1000, false)
.await
.unwrap();
eprintln!("res: {:?}", res);
assert_eq!(res.fee, 1);

node_0.wait_until_success(res.payment_hash).await;

// after the first payment try failed, the payment session will find another path
// 0 -> 1 -> 2 -> 3, so it will succeed, but the fee change from 1 to 3
let payment = node_0.get_payment_result(res.payment_hash).await;
assert_eq!(payment.fee, 3);
eprintln!("payment: {:?}", payment);

// node_2 stopped, payment will fail
node_2.stop().await;
// when node_4 stopped, node 0 learned that channel 0 -> 4 was not available
// so it will try another path 0 -> 1 -> 2 -> 3
let res = node_0
.send_payment_keysend(&node_3, 1000, false)
.await
.unwrap();
eprintln!("res: {:?}", res);
assert_eq!(res.fee, 3);

node_0.wait_until_failed(res.payment_hash).await;
node_0.wait_until_success(res.payment_hash).await;
}

#[tokio::test]
Expand Down

0 comments on commit 9c9aece

Please sign in to comment.